diff options
author | peter@chromium.org <peter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-19 12:01:42 +0000 |
---|---|---|
committer | peter@chromium.org <peter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-19 12:01:42 +0000 |
commit | c48fece0c35a6bfdf73ee9ba6e6f18263d0748d8 (patch) | |
tree | 5f76db37d370bf3d07d8bd7ba548732c00adc769 /content/shell | |
parent | 80b11694c00a7ed19e29b03cb00696f4e6b66752 (diff) | |
download | chromium_src-c48fece0c35a6bfdf73ee9ba6e6f18263d0748d8.zip chromium_src-c48fece0c35a6bfdf73ee9ba6e6f18263d0748d8.tar.gz chromium_src-c48fece0c35a6bfdf73ee9ba6e6f18263d0748d8.tar.bz2 |
content_shell: Move BrowserTestSystemMessageHandler and use it in layout tests
for Android
Android needs to use a nested message loop in order to execute the
layout tests. We have an implementation of this for content_browsertests
as BrowserTestSystemMessageHandler, but this lives in /content/test/
which content_shell cannot depend on.
Move it to /content/public/test/ as NestedSystemMessageHandler and
update content_browsertests to depend on that instead. For content_shell,
implement support of starting the nested loop, and use it when running
layout tests.
BUG=232044
Review URL: https://chromiumcodereview.appspot.com/17076008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207215 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/shell')
3 files changed, 32 insertions, 132 deletions
diff --git a/content/shell/android/browsertests_apk/content_browser_tests_android.cc b/content/shell/android/browsertests_apk/content_browser_tests_android.cc index d8319c4..b923538 100644 --- a/content/shell/android/browsertests_apk/content_browser_tests_android.cc +++ b/content/shell/android/browsertests_apk/content_browser_tests_android.cc @@ -23,10 +23,10 @@ #include "content/public/app/android_library_loader_hooks.h" #include "content/public/app/content_main.h" #include "content/public/common/content_switches.h" +#include "content/public/test/nested_message_pump_android.h" #include "content/public/test/test_launcher.h" #include "content/shell/android/shell_jni_registrar.h" #include "content/shell/app/shell_main_delegate.h" -#include "content/test/browser_test_message_pump_android.h" #include "jni/ContentBrowserTestsActivity_jni.h" #include "testing/android/native_test_util.h" @@ -106,7 +106,7 @@ JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { if (!content::android::RegisterShellJni(env)) return -1; - if (!content::BrowserTestMessagePumpAndroid::RegisterJni(env)) + if (!content::NestedMessagePumpAndroid::RegisterJni(env)) return -1; if (!content::RegisterNativesImpl(env)) diff --git a/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/BrowserTestSystemMessageHandler.java b/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/BrowserTestSystemMessageHandler.java deleted file mode 100644 index 2ba7e94..0000000 --- a/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/BrowserTestSystemMessageHandler.java +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package org.chromium.content_browsertests_apk; - -import android.os.Handler; -import android.os.Looper; -import android.os.Message; -import android.os.MessageQueue; -import android.util.Log; - -import org.chromium.base.CalledByNative; -import org.chromium.base.JNINamespace; -import java.lang.reflect.Method; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; - -/** - * Handles processing messages in nested run loops. - * - * Android does not support nested message loops by default. While running - * in nested mode, we use reflection to retreive messages from the MessageQueue - * and dispatch them. - */ -@JNINamespace("content") -class BrowserTestSystemMessageHandler { - // See org.chromium.base.SystemMessageHandler for more message ids. - // The id here should not conflict with the ones in SystemMessageHandler. - private static final int QUIT_MESSAGE = 10; - private static final Handler mHandler = new Handler(); - - private BrowserTestSystemMessageHandler() { - } - - /** - * Processes messages from the current MessageQueue till the queue becomes idle. - */ - @SuppressWarnings("unused") - @CalledByNative - private boolean runNestedLoopTillIdle() { - boolean quitLoop = false; - - MessageQueue queue = Looper.myQueue(); - queue.addIdleHandler(new MessageQueue.IdleHandler() { - @Override - public boolean queueIdle() { - mHandler.sendMessage(mHandler.obtainMessage(QUIT_MESSAGE)); - return false; - } - }); - - Class<?> messageQueueClazz = queue.getClass(); - Method nextMethod = null; - try { - nextMethod = messageQueueClazz.getDeclaredMethod("next"); - } catch (SecurityException e) { - e.printStackTrace(); - return false; - } catch (NoSuchMethodException e) { - e.printStackTrace(); - return false; - } - nextMethod.setAccessible(true); - - while (!quitLoop) { - Message msg = null; - try { - msg = (Message)nextMethod.invoke(queue); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - return false; - } catch (IllegalAccessException e) { - e.printStackTrace(); - return false; - } catch (InvocationTargetException e) { - e.printStackTrace(); - return false; - } - - if (msg != null) { - if (msg.what == QUIT_MESSAGE) { - quitLoop = true; - } - Class messageClazz = msg.getClass(); - Field targetFiled = null; - try { - targetFiled = messageClazz.getDeclaredField("target"); - } catch (SecurityException e) { - e.printStackTrace(); - return false; - } catch (NoSuchFieldException e) { - e.printStackTrace(); - return false; - } - targetFiled.setAccessible(true); - - Handler target = null; - try { - target = (Handler) targetFiled.get(msg); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - return false; - } catch (IllegalAccessException e) { - e.printStackTrace(); - return false; - } - - if (target == null) { - // No target is a magic identifier for the quit message. - quitLoop = true; - } - - target.dispatchMessage(msg); - msg.recycle(); - } else { - quitLoop = true; - } - } - return true; - } - - @SuppressWarnings("unused") - @CalledByNative - private static BrowserTestSystemMessageHandler create() { - return new BrowserTestSystemMessageHandler(); - } -} diff --git a/content/shell/shell_browser_main.cc b/content/shell/shell_browser_main.cc index d2b43b5..b1f0e9f 100644 --- a/content/shell/shell_browser_main.cc +++ b/content/shell/shell_browser_main.cc @@ -24,6 +24,12 @@ #include "net/base/net_util.h" #include "webkit/support/webkit_support.h" +#if defined(OS_ANDROID) +#include "base/android/jni_android.h" +#include "base/run_loop.h" +#include "content/public/test/nested_message_pump_android.h" +#endif + namespace { #if defined(OS_ANDROID) @@ -33,6 +39,11 @@ const char kAndroidLayoutTestPath[] = // The base URL from which layout tests are being served on Android. const char kAndroidLayoutTestBase[] = "http://127.0.0.1:8000/all-tests/"; + +base::MessagePump* CreateMessagePumpForUI() { + return new content::NestedMessagePumpAndroid(); +} + #endif GURL GetURLForLayoutTest(const std::string& test_name, @@ -125,14 +136,23 @@ int ShellBrowserMain(const content::MainFunctionParams& parameters, CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree); base::ScopedTempDir browser_context_path_for_layout_tests; - // TODO(beverloo): Create the FIFOs required for Android layout tests. - if (layout_test_mode) { CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); CommandLine::ForCurrentProcess()->AppendSwitchASCII( switches::kContentShellDataPath, browser_context_path_for_layout_tests.path().MaybeAsASCII()); + +#if defined(OS_ANDROID) + // TODO(beverloo): Create the FIFOs required for Android layout tests. + + JNIEnv* env = base::android::AttachCurrentThread(); + content::NestedMessagePumpAndroid::RegisterJni(env); + + const bool success = base::MessageLoop::InitMessagePumpForUIFactory( + &CreateMessagePumpForUI); + CHECK(success) << "Unable to initialize the message pump for Android."; +#endif } int exit_code = main_runner->Initialize(parameters); @@ -189,7 +209,15 @@ int ShellBrowserMain(const content::MainFunctionParams& parameters, } ran_at_least_once = true; +#if defined(OS_ANDROID) + // The message loop on Android is provided by the system, and does not + // offer a blocking Run() method. For layout tests, use a nested loop + // together with a base::RunLoop so it can block until a QuitClosure. + base::RunLoop run_loop; + run_loop.Run(); +#else main_runner->Run(); +#endif if (!content::WebKitTestController::Get()->ResetAfterLayoutTest()) break; |