Skip to content

Commit

Permalink
Move async tests back to original files
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeshkova committed Oct 19, 2014
1 parent 491497b commit a703809
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 340 deletions.
30 changes: 16 additions & 14 deletions embedding/embedlite/tests/embedLiteCoreInitTest.cpp
Expand Up @@ -5,26 +5,28 @@

#include "mozilla/embedlite/EmbedInitGlue.h"
#include "mozilla/embedlite/EmbedLiteApp.h"
#include "qmessagepump.h"

#ifdef MOZ_WIDGET_QT
#include <QGuiApplication>
#elif defined(MOZ_WIDGET_GTK2)
#include <glib-object.h>
#endif

using namespace mozilla::embedlite;

static bool sDoExit = getenv("NORMAL_EXIT") != 0;
static bool sNoProfile = getenv("NO_PROFILE") != 0;

class MyListener : public EmbedLiteAppListener
{
public:
MyListener(EmbedLiteApp* aApp) : mApp(aApp) {}
MyListener(EmbedLiteApp* aApp) : mApp(aApp) {
}
virtual ~MyListener() { }
virtual void Initialized() {
printf("Embedding initialized, let's make view");
printf("Embedding initialized\n");
mApp->Stop();
printf("Embedding stop finished\n");
}
virtual void Destroyed() {
printf("Embedding destroyed\n");
qApp->quit();
}

private:
Expand All @@ -35,9 +37,6 @@ int main(int argc, char** argv)
{
#ifdef MOZ_WIDGET_QT
QGuiApplication app(argc, argv);
#elif defined(MOZ_WIDGET_GTK2)
g_type_init();
g_thread_init(NULL);
#endif

printf("Load XUL Symbols\n");
Expand All @@ -46,13 +45,16 @@ int main(int argc, char** argv)
EmbedLiteApp* mapp = XRE_GetEmbedLite();
MyListener* listener = new MyListener(mapp);
mapp->SetListener(listener);
if (sNoProfile) {
mapp->SetProfilePath(nullptr);
}
bool res = mapp->Start(EmbedLiteApp::EMBED_THREAD);
MessagePumpQt* mQtPump = new MessagePumpQt(mapp);
bool res = mapp->StartWithCustomPump(EmbedLiteApp::EMBED_THREAD, mQtPump->EmbedLoop());
printf("XUL Symbols loaded: init res:%i\n", res);
app.exec();
delete mQtPump;
printf("Execution stopped\n");
delete listener;
printf("Listener destroyed\n");
delete mapp;
printf("App destroyed\n");
} else {
printf("XUL Symbols failed to load\n");
}
Expand Down
78 changes: 15 additions & 63 deletions embedding/embedlite/tests/embedLiteViewInitTest.cpp
Expand Up @@ -6,30 +6,19 @@
#include "mozilla/embedlite/EmbedInitGlue.h"
#include "mozilla/embedlite/EmbedLiteApp.h"
#include "mozilla/embedlite/EmbedLiteView.h"
#include "qmessagepump.h"

#ifdef MOZ_WIDGET_QT
#include <QGuiApplication>
#if defined(Q_WS_X11) && QT_VERSION < 0x040800
#include <X11/Xlib.h>
#endif
#elif defined(MOZ_WIDGET_GTK2)
#include <glib-object.h>
#include <gtk/gtk.h>
#ifdef MOZ_X11
#include <gdk/gdkx.h>
#endif /* MOZ_X11 */
#endif

using namespace mozilla::embedlite;

static bool sDoExit = getenv("NORMAL_EXIT");
static bool sDoExitSeq = getenv("NORMAL_EXIT_SEQ");
static bool sNoProfile = getenv("NO_PROFILE") != 0;

class MyListener : public EmbedLiteAppListener, public EmbedLiteViewListener
{
public:
MyListener(EmbedLiteApp* aApp) : mApp(aApp), mView(NULL) {}
MyListener(EmbedLiteApp* aApp) : mApp(aApp), mView(NULL) {
}
virtual ~MyListener() { }
virtual void Initialized() {
printf("Embedding initialized, let's make view");
Expand All @@ -42,34 +31,14 @@ class MyListener : public EmbedLiteAppListener, public EmbedLiteViewListener
// then Widget/View not initialized properly and prevent destroy process
mView->SetViewSize(800, 600);
mView->LoadURL("data:text/html,<body bgcolor=red>TestApp</body>");
// mView->LoadURL("http://ya.ru");
}
virtual bool Invalidate() {
printf("Embedding Has something for render\n");
mApp->PostTask(&MyListener::RenderImage, this);
return true;
}
static void RenderImage(void* aData) {
printf("OnRenderImage\n");
MyListener* self = static_cast<MyListener*>(aData);
#if 1
unsigned char* data = (unsigned char*)malloc(960000);
self->mView->RenderToImage(data, 800, 600, 1600, 16);
#else
char* data = self->mView->GetImageAsURL(800, 600);
data[25] = 0;
printf("Embedding render Image: %s\n", data);
#endif
delete data;
}
virtual void Destroyed() {
printf("OnAppDestroyed\n");
printf("Embedding destroyed\n");
qApp->quit();
}
virtual void ViewDestroyed() {
printf("OnViewDestroyed\n");
if (sDoExitSeq) {
mApp->PostTask(&MyListener::DoDestroyApp, this, 100);
}
mApp->PostTask(&MyListener::DoDestroyApp, this, 100);
}
static void DoDestroyApp(void* aData) {
MyListener* self = static_cast<MyListener*>(aData);
Expand All @@ -79,9 +48,7 @@ class MyListener : public EmbedLiteAppListener, public EmbedLiteViewListener
static void DoDestroyView(void* aData) {
MyListener* self = static_cast<MyListener*>(aData);
printf("DoDestroyView\n");
if (sDoExitSeq) {
self->mApp->PostTask(&MyListener::DoDestroyApp, self, 100);
}
self->mApp->DestroyView(self->mView);
}
virtual void OnLocationChanged(const char* aLocation, bool aCanGoBack, bool aCanGoForward) {
printf("OnLocationChanged: loc:%s, canBack:%i, canForw:%i\n", aLocation, aCanGoBack, aCanGoForward);
Expand All @@ -91,11 +58,6 @@ class MyListener : public EmbedLiteAppListener, public EmbedLiteViewListener
}
virtual void OnLoadFinished(void) {
printf("OnLoadFinished\n");
if (sDoExitSeq) {
mApp->PostTask(&MyListener::DoDestroyView, this, 2000);
} else if (sDoExit) {
mApp->PostTask(&MyListener::DoDestroyApp, this, 2000);
}
}
virtual void OnLoadRedirect(void) {
printf("OnLoadRedirect\n");
Expand All @@ -108,6 +70,7 @@ class MyListener : public EmbedLiteAppListener, public EmbedLiteViewListener
}
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 @@ -127,21 +90,7 @@ class MyListener : public EmbedLiteAppListener, public EmbedLiteViewListener
int main(int argc, char** argv)
{
#ifdef MOZ_WIDGET_QT
#if QT_VERSION >= 0x040800
QGuiApplication::setAttribute(Qt::AA_X11InitThreads, true);
#else
XInitThreads();
QGuiApplication::setAttribute(static_cast<Qt::ApplicationAttribute>(10), true);
#endif
QGuiApplication app(argc, argv);
#elif defined(MOZ_WIDGET_GTK2)
g_type_init();
g_thread_init(NULL);
gdk_rgb_set_install(TRUE);
const char* display_name = gdk_get_display_arg_name();
GdkDisplay* mGdkDisplay = gdk_display_open(display_name);
gdk_display_manager_set_default_display (gdk_display_manager_get(), mGdkDisplay);
gtk_widget_set_default_colormap(gdk_rgb_get_colormap());
#endif

printf("Load XUL Symbols\n");
Expand All @@ -150,13 +99,16 @@ int main(int argc, char** argv)
EmbedLiteApp* mapp = XRE_GetEmbedLite();
MyListener* listener = new MyListener(mapp);
mapp->SetListener(listener);
if (sNoProfile) {
mapp->SetProfilePath(nullptr);
}
bool res = mapp->Start(EmbedLiteApp::EMBED_THREAD);
MessagePumpQt* mQtPump = new MessagePumpQt(mapp);
bool res = mapp->StartWithCustomPump(EmbedLiteApp::EMBED_THREAD, mQtPump->EmbedLoop());
printf("XUL Symbols loaded: init res:%i\n", res);
app.exec();
delete mQtPump;
printf("Execution stopped\n");
delete listener;
printf("Listener destroyed\n");
delete mapp;
printf("App destroyed\n");
} else {
printf("XUL Symbols failed to load\n");
}
Expand Down
3 changes: 2 additions & 1 deletion embedding/embedlite/tests/moz.build
Expand Up @@ -3,7 +3,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

DIRS += ['shared', 'qtcoreasync', 'qtviewasync']
DIRS += ['shared']

SimplePrograms([
'embedLiteCoreInitTest',
Expand All @@ -15,6 +15,7 @@ DEFINES['XPCOM_GLUE'] = True
DISABLE_STL_WRAPPING = True

USE_LIBS += [
'qmessagepump',
'xpcomglue',
]

Expand Down
16 changes: 0 additions & 16 deletions embedding/embedlite/tests/qtcoreasync/Makefile.in

This file was deleted.

This file was deleted.

26 changes: 0 additions & 26 deletions embedding/embedlite/tests/qtcoreasync/moz.build

This file was deleted.

16 changes: 0 additions & 16 deletions embedding/embedlite/tests/qtviewasync/Makefile.in

This file was deleted.

0 comments on commit a703809

Please sign in to comment.