Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added possibility to run view test with custom views count
  • Loading branch information
tmeshkova committed Oct 19, 2014
1 parent a703809 commit 6fd383b
Showing 1 changed file with 64 additions and 21 deletions.
85 changes: 64 additions & 21 deletions embedding/embedlite/tests/embedLiteViewInitTest.cpp
Expand Up @@ -7,48 +7,81 @@
#include "mozilla/embedlite/EmbedLiteApp.h"
#include "mozilla/embedlite/EmbedLiteView.h"
#include "qmessagepump.h"
#include <list>

#ifdef MOZ_WIDGET_QT
#include <QGuiApplication>
#endif

using namespace mozilla::embedlite;

class MyListener : public EmbedLiteAppListener, public EmbedLiteViewListener
class MyViewListener;
class MyListener : public EmbedLiteAppListener
{
public:
MyListener(EmbedLiteApp* aApp) : mApp(aApp), mView(NULL) {
MyListener(EmbedLiteApp* aApp) : mApp(aApp) {
}
virtual ~MyListener() { }
virtual void Initialized() {
printf("Embedding initialized, let's make view");
mView = mApp->CreateView();
virtual void Initialized();
virtual void Destroyed() {
printf("Embedding destroyed\n");
qApp->quit();
}
void OnViewDestroyed(MyViewListener* aViewListener) {
printf("Embedding view destroyed\n");
viewListeners.remove(aViewListener);
mApp->PostTask(&MyListener::DoDestroyApp, this, 100);
}
static void DoDestroyApp(void* aData) {
MyListener* self = static_cast<MyListener*>(aData);
printf("DoDestroyApp\n");
self->mApp->Stop();
}
EmbedLiteApp* App() { return mApp; }

private:
EmbedLiteApp* mApp;
std::list<MyViewListener*> viewListeners;
};

class MyViewListener : public EmbedLiteViewListener
{
public:
MyViewListener(MyListener* appListener)
: mAppListener(appListener)
, mView(NULL)
{
mView = mAppListener->App()->CreateView();
mView->SetListener(this);
}
virtual ~MyViewListener() {
printf("~MyViewListener\n");
}
virtual void ViewInitialized() {
printf("Embedding has created view:%p, Yay\n", mView);
// FIXME if resize is not called,
// then Widget/View not initialized properly and prevent destroy process
mView->SetViewSize(800, 600);
mView->LoadURL("data:text/html,<body bgcolor=red>TestApp</body>");
}
virtual void Destroyed() {
printf("Embedding destroyed\n");
qApp->quit();
}
virtual void ViewDestroyed() {
printf("OnViewDestroyed\n");
mApp->PostTask(&MyListener::DoDestroyApp, this, 100);
mAppListener->App()->PostTask(&MyViewListener::DeleteSelf, this, 100);
}
static void DoDestroyApp(void* aData) {
MyListener* self = static_cast<MyListener*>(aData);
printf("DoDestroyApp\n");
self->mApp->Stop();
static void DeleteSelf(void* aData) {
MyViewListener* self = static_cast<MyViewListener*>(aData);
printf("Delete View Listener\n");
self->mAppListener->OnViewDestroyed(self);
delete self;
}
static void DoDestroyView(void* aData) {
MyListener* self = static_cast<MyListener*>(aData);
MyViewListener* self = static_cast<MyViewListener*>(aData);
printf("DoDestroyView\n");
self->mApp->DestroyView(self->mView);
self->mAppListener->App()->DestroyView(self->mView);
}
virtual void OnFirstPaint(int32_t aX, int32_t aY) {
printf("OnFirstPaint pos[%i,%i]\n", aX, aY);
mAppListener->App()->PostTask(&MyViewListener::DoDestroyView, this, 100);
}
virtual void OnLocationChanged(const char* aLocation, bool aCanGoBack, bool aCanGoForward) {
printf("OnLocationChanged: loc:%s, canBack:%i, canForw:%i\n", aLocation, aCanGoBack, aCanGoForward);
Expand All @@ -68,10 +101,6 @@ class MyListener : public EmbedLiteAppListener, public EmbedLiteViewListener
virtual void OnSecurityChanged(const char* aStatus, unsigned int aState) {
printf("OnSecurityChanged: status:%s, stat:%u\n", aStatus, aState);
}
virtual void OnFirstPaint(int32_t aX, int32_t aY) {
printf("OnFirstPaint pos[%i,%i]\n", aX, aY);
mApp->PostTask(&MyListener::DoDestroyView, this, 100);
}
virtual void OnScrolledAreaChanged(unsigned int aWidth, unsigned int aHeight) {
printf("OnScrolledAreaChanged: sz[%u,%u]\n", aWidth, aHeight);
}
Expand All @@ -81,12 +110,26 @@ class MyListener : public EmbedLiteAppListener, public EmbedLiteViewListener
virtual void OnObserve(const char* aTopic, const char16_t* aData) {
printf("OnObserve: top:%s, data:%s\n", aTopic, NS_ConvertUTF16toUTF8(aData).get());
}
EmbedLiteView* View() { return mView; }

private:
EmbedLiteApp* mApp;
MyListener* mAppListener;
EmbedLiteView* mView;
};

void MyListener::Initialized()
{
printf("Embedding initialized, let's make view");
int defaultViewCount = 2;
const char* viewsCount = getenv("VIEW_COUNT");
if (viewsCount != nullptr) {
defaultViewCount = atoi(viewsCount);
}
for (int i = 0; i < defaultViewCount; ++i) {
viewListeners.push_back(new MyViewListener(this));
}
}

int main(int argc, char** argv)
{
#ifdef MOZ_WIDGET_QT
Expand Down

0 comments on commit 6fd383b

Please sign in to comment.