diff options
author | jaekyun <jaekyun@chromium.org> | 2015-04-22 21:22:48 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-23 04:22:48 +0000 |
commit | 4ba34ff136727244ead91780152b3248fe7ce0fd (patch) | |
tree | 7d92757a191a5873c0dbdfe3579cd0818d26c434 /components | |
parent | c32d8a85648b9e19320368f1dd91ddaca814fd0e (diff) | |
download | chromium_src-4ba34ff136727244ead91780152b3248fe7ce0fd.zip chromium_src-4ba34ff136727244ead91780152b3248fe7ce0fd.tar.gz chromium_src-4ba34ff136727244ead91780152b3248fe7ce0fd.tar.bz2 |
Enable components_browsertests on Android
BUG=465351
Review URL: https://codereview.chromium.org/1075783002
Cr-Commit-Position: refs/heads/master@{#326449}
Diffstat (limited to 'components')
18 files changed, 603 insertions, 63 deletions
diff --git a/components/BUILD.gn b/components/BUILD.gn index 95761c1..01503dc 100644 --- a/components/BUILD.gn +++ b/components/BUILD.gn @@ -334,6 +334,17 @@ repack("components_tests_pak") { ] } +if (is_android) { + import("//build/config/android/rules.gni") + + generate_jni("components_browsertests_jni_headers") { + jni_package = "components_browsertests/shell" + sources = [ + "test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsActivity.java", + ] + } +} + test("components_browsertests") { sources = [ "autofill/content/browser/risk/fingerprint_browsertest.cc", @@ -369,7 +380,18 @@ test("components_browsertests") { data_deps = [ ":components_tests_pak" ] if (is_android) { + sources += [ + "test/android/browsertests_apk/components_browser_tests_android.cc", + "test/android/browsertests_apk/components_browser_tests_android.h", + "test/android/browsertests_apk/components_browser_tests_jni_onload.cc", + ] sources -= [ "autofill/content/browser/risk/fingerprint_browsertest.cc" ] + deps += [ + ":components_browsertests_jni_headers", + "//testing/android/native_test:native_test_util", + ] + + use_launcher = false } if (is_linux) { diff --git a/components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc b/components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc index d4b3f45..6971997 100644 --- a/components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc +++ b/components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc @@ -105,10 +105,19 @@ class PasswordFormBuilder { DISALLOW_COPY_AND_ASSIGN(PasswordFormBuilder); }; -class PasswordFormConversionUtilsTest : public content::RenderViewTest { +// RenderVIewTest-based tests crash on Android +// http://crbug.com/187500 +#if defined(OS_ANDROID) +#define MAYBE_PasswordFormConversionUtilsTest \ + DISABLED_PasswordFormConversionUtilsTest +#else +#define MAYBE_PasswordFormConversionUtilsTest PasswordFormConversionUtilsTest +#endif // defined(OS_ANDROID) + +class MAYBE_PasswordFormConversionUtilsTest : public content::RenderViewTest { public: - PasswordFormConversionUtilsTest() : content::RenderViewTest() {} - ~PasswordFormConversionUtilsTest() override {} + MAYBE_PasswordFormConversionUtilsTest() : content::RenderViewTest() {} + ~MAYBE_PasswordFormConversionUtilsTest() override {} protected: // Loads the given |html|, retrieves the sole WebFormElement from it, and then @@ -138,12 +147,12 @@ class PasswordFormConversionUtilsTest : public content::RenderViewTest { } private: - DISALLOW_COPY_AND_ASSIGN(PasswordFormConversionUtilsTest); + DISALLOW_COPY_AND_ASSIGN(MAYBE_PasswordFormConversionUtilsTest); }; } // namespace -TEST_F(PasswordFormConversionUtilsTest, BasicFormAttributes) { +TEST_F(MAYBE_PasswordFormConversionUtilsTest, BasicFormAttributes) { PasswordFormBuilder builder(kTestFormActionURL); builder.AddUsernameField("username", "johnsmith", NULL); builder.AddSubmitButton("inactive_submit", false); @@ -170,7 +179,7 @@ TEST_F(PasswordFormConversionUtilsTest, BasicFormAttributes) { EXPECT_EQ(PasswordForm::TYPE_MANUAL, password_form->type); } -TEST_F(PasswordFormConversionUtilsTest, DisabledFieldsAreIgnored) { +TEST_F(MAYBE_PasswordFormConversionUtilsTest, DisabledFieldsAreIgnored) { PasswordFormBuilder builder(kTestFormActionURL); builder.AddUsernameField("username", "johnsmith", NULL); builder.AddDisabledUsernameField(); @@ -188,7 +197,7 @@ TEST_F(PasswordFormConversionUtilsTest, DisabledFieldsAreIgnored) { EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); } -TEST_F(PasswordFormConversionUtilsTest, IdentifyingUsernameFields) { +TEST_F(MAYBE_PasswordFormConversionUtilsTest, IdentifyingUsernameFields) { // Each test case consists of a set of parameters to be plugged into the // PasswordFormBuilder below, plus the corresponding expectations. struct TestCase { @@ -273,7 +282,7 @@ TEST_F(PasswordFormConversionUtilsTest, IdentifyingUsernameFields) { } } -TEST_F(PasswordFormConversionUtilsTest, IdentifyingTwoPasswordFields) { +TEST_F(MAYBE_PasswordFormConversionUtilsTest, IdentifyingTwoPasswordFields) { // Each test case consists of a set of parameters to be plugged into the // PasswordFormBuilder below, plus the corresponding expectations. struct TestCase { @@ -328,7 +337,7 @@ TEST_F(PasswordFormConversionUtilsTest, IdentifyingTwoPasswordFields) { } } -TEST_F(PasswordFormConversionUtilsTest, IdentifyingThreePasswordFields) { +TEST_F(MAYBE_PasswordFormConversionUtilsTest, IdentifyingThreePasswordFields) { // Each test case consists of a set of parameters to be plugged into the // PasswordFormBuilder below, plus the corresponding expectations. struct TestCase { @@ -389,7 +398,7 @@ TEST_F(PasswordFormConversionUtilsTest, IdentifyingThreePasswordFields) { } } -TEST_F(PasswordFormConversionUtilsTest, +TEST_F(MAYBE_PasswordFormConversionUtilsTest, IdentifyingPasswordFieldsWithAutocompleteAttributes) { // Each test case consists of a set of parameters to be plugged into the // PasswordFormBuilder below, plus the corresponding expectations. @@ -527,7 +536,7 @@ TEST_F(PasswordFormConversionUtilsTest, } } -TEST_F(PasswordFormConversionUtilsTest, InvalidFormDueToBadActionURL) { +TEST_F(MAYBE_PasswordFormConversionUtilsTest, InvalidFormDueToBadActionURL) { PasswordFormBuilder builder("invalid_target"); builder.AddUsernameField("username", "JohnSmith", NULL); builder.AddSubmitButton("submit", true); @@ -539,7 +548,8 @@ TEST_F(PasswordFormConversionUtilsTest, InvalidFormDueToBadActionURL) { EXPECT_FALSE(password_form); } -TEST_F(PasswordFormConversionUtilsTest, InvalidFormDueToNoPasswordFields) { +TEST_F(MAYBE_PasswordFormConversionUtilsTest, + InvalidFormDueToNoPasswordFields) { PasswordFormBuilder builder(kTestFormActionURL); builder.AddUsernameField("username1", "John", NULL); builder.AddUsernameField("username2", "Smith", NULL); @@ -551,7 +561,7 @@ TEST_F(PasswordFormConversionUtilsTest, InvalidFormDueToNoPasswordFields) { EXPECT_FALSE(password_form); } -TEST_F(PasswordFormConversionUtilsTest, +TEST_F(MAYBE_PasswordFormConversionUtilsTest, InvalidFormsDueToConfusingPasswordFields) { // Each test case consists of a set of parameters to be plugged into the // PasswordFormBuilder below. @@ -582,7 +592,7 @@ TEST_F(PasswordFormConversionUtilsTest, } } -TEST_F(PasswordFormConversionUtilsTest, +TEST_F(MAYBE_PasswordFormConversionUtilsTest, InvalidFormDueToTooManyPasswordFieldsWithoutAutocompleteAttributes) { PasswordFormBuilder builder(kTestFormActionURL); builder.AddUsernameField("username1", "John", NULL); @@ -598,7 +608,7 @@ TEST_F(PasswordFormConversionUtilsTest, EXPECT_FALSE(password_form); } -TEST_F(PasswordFormConversionUtilsTest, LayoutClassificationLogin) { +TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationLogin) { PasswordFormBuilder builder(kTestFormActionURL); builder.AddHiddenField(); builder.AddUsernameField("username", "", nullptr); @@ -612,7 +622,7 @@ TEST_F(PasswordFormConversionUtilsTest, LayoutClassificationLogin) { EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, login_form->layout); } -TEST_F(PasswordFormConversionUtilsTest, LayoutClassificationSignup) { +TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationSignup) { PasswordFormBuilder builder(kTestFormActionURL); builder.AddUsernameField("someotherfield", "", nullptr); builder.AddUsernameField("username", "", nullptr); @@ -628,7 +638,7 @@ TEST_F(PasswordFormConversionUtilsTest, LayoutClassificationSignup) { EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, signup_form->layout); } -TEST_F(PasswordFormConversionUtilsTest, LayoutClassificationChange) { +TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationChange) { PasswordFormBuilder builder(kTestFormActionURL); builder.AddUsernameField("username", "", nullptr); builder.AddPasswordField("old_password", "", nullptr); @@ -644,7 +654,8 @@ TEST_F(PasswordFormConversionUtilsTest, LayoutClassificationChange) { EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, change_form->layout); } -TEST_F(PasswordFormConversionUtilsTest, LayoutClassificationLoginPlusSignup_A) { +TEST_F(MAYBE_PasswordFormConversionUtilsTest, + LayoutClassificationLoginPlusSignup_A) { PasswordFormBuilder builder(kTestFormActionURL); builder.AddUsernameField("username", "", nullptr); builder.AddHiddenField(); @@ -665,7 +676,8 @@ TEST_F(PasswordFormConversionUtilsTest, LayoutClassificationLoginPlusSignup_A) { login_plus_signup_form->layout); } -TEST_F(PasswordFormConversionUtilsTest, LayoutClassificationLoginPlusSignup_B) { +TEST_F(MAYBE_PasswordFormConversionUtilsTest, + LayoutClassificationLoginPlusSignup_B) { PasswordFormBuilder builder(kTestFormActionURL); builder.AddUsernameField("username", "", nullptr); builder.AddHiddenField(); diff --git a/components/components_browsertests.isolate b/components/components_browsertests.isolate index 2dff53a..e60cea1 100644 --- a/components/components_browsertests.isolate +++ b/components/components_browsertests.isolate @@ -34,18 +34,32 @@ ], }, }], + ['OS=="android"', { + 'variables': { + 'files': [ + '<(PRODUCT_DIR)/components_browsertests_apk_shell/assets/components_tests_resources.pak', + '<(PRODUCT_DIR)/components_browsertests_apk_shell/assets/content_shell.pak', + ], + }, + }], ['OS=="linux" or OS=="mac" or OS=="win"', { 'variables': { 'files': [ - 'test/data/', '../testing/test_env.py', - '../third_party/dom_distiller_js/dist/test/data/', '<(PRODUCT_DIR)/components_browsertests<(EXECUTABLE_SUFFIX)', '<(PRODUCT_DIR)/components_tests_resources.pak', '<(PRODUCT_DIR)/content_shell.pak', ], }, }], + ['OS=="android" or OS=="linux" or OS=="mac" or OS=="win"', { + 'variables': { + 'files': [ + 'test/data/', + '../third_party/dom_distiller_js/dist/test/data/', + ], + }, + }], ['OS=="linux"', { 'variables': { 'files': [ diff --git a/components/components_tests.gyp b/components/components_tests.gyp index 64cdc9d..f48690f 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -1123,6 +1123,87 @@ }, ], 'conditions': [ + ['OS == "android"', { + 'variables': { + 'components_browsertests_pak_input_resources': [ + '<(PRODUCT_DIR)/components_tests_resources.pak', + '<(PRODUCT_DIR)/content_shell/assets/content_shell.pak', + ], + 'conditions': [ + ['icu_use_data_file_flag==1', { + 'components_browsertests_pak_input_resources': [ + '<(PRODUCT_DIR)/icudtl.dat', + ], + }], + ['v8_use_external_startup_data==1', { + 'components_browsertests_pak_input_resources': [ + '<(PRODUCT_DIR)/natives_blob.bin', + '<(PRODUCT_DIR)/snapshot_blob.bin', + ], + }], + ], + }, + 'targets': [ + { + 'target_name': 'components_browsertests_paks_copy', + 'type': 'none', + 'dependencies': [ + 'components_browsertests', + ], + 'copies': [ + { + 'destination': '<(PRODUCT_DIR)/components_browsertests_apk_shell/assets', + 'files': [ + '<@(components_browsertests_pak_input_resources)', + ], + } + ], + }, + { + 'target_name': 'components_browsertests_manifest', + 'type': 'none', + 'variables': { + 'jinja_inputs': ['test/android/browsertests_apk/AndroidManifest.xml.jinja2'], + 'jinja_output': '<(SHARED_INTERMEDIATE_DIR)/components_browsertests_manifest/AndroidManifest.xml', + }, + 'includes': [ '../build/android/jinja_template.gypi' ], + }, + { + 'target_name': 'components_browsertests_jni_headers', + 'type': 'none', + 'sources': [ + 'test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsActivity.java', + ], + 'variables': { + 'jni_gen_package': 'content/shell', + }, + 'includes': [ '../build/jni_generator.gypi' ], + }, + { + # TODO(GN) + 'target_name': 'components_browsertests_apk', + 'type': 'none', + 'dependencies': [ + '../content/content.gyp:content_icudata', + '../content/content.gyp:content_java', + '../content/content.gyp:content_v8_external_data', + '../content/content_shell_and_tests.gyp:content_java_test_support', + '../content/content_shell_and_tests.gyp:content_shell_java', + 'components_browsertests_paks_copy', + 'components_browsertests', + ], + 'variables': { + 'apk_name': 'components_browsertests', + 'java_in_dir': 'test/android/browsertests_apk', + 'android_manifest_path': '<(SHARED_INTERMEDIATE_DIR)/components_browsertests_manifest/AndroidManifest.xml', + 'resource_dir': 'test/android/browsertests_apk/res', + 'native_lib_target': 'libcomponents_browsertests', + 'asset_location': '<(PRODUCT_DIR)/components_browsertests_apk_shell/assets', + }, + 'includes': [ '../build/java_apk.gypi' ], + }, + ], + }], ['OS != "ios"', { 'targets': [ { @@ -1204,9 +1285,18 @@ ], 'conditions': [ ['OS == "android"', { + 'sources' : [ + 'test/android/browsertests_apk/components_browser_tests_android.cc', + 'test/android/browsertests_apk/components_browser_tests_android.h', + 'test/android/browsertests_apk/components_browser_tests_jni_onload.cc', + ], 'sources!': [ 'autofill/content/browser/risk/fingerprint_browsertest.cc', ], + 'dependencies': [ + '../testing/android/native_test.gyp:native_test_util', + 'components_browsertests_jni_headers', + ], }], ['OS == "linux"', { 'sources': [ diff --git a/components/dom_distiller/content/distillable_page_utils_browsertest.cc b/components/dom_distiller/content/distillable_page_utils_browsertest.cc index 9525982..c320eed 100644 --- a/components/dom_distiller/content/distillable_page_utils_browsertest.cc +++ b/components/dom_distiller/content/distillable_page_utils_browsertest.cc @@ -50,7 +50,12 @@ class DomDistillerDistillablePageUtilsTest : public content::ContentBrowserTest, void AddComponentsResources() { base::FilePath pak_file; base::FilePath pak_dir; +#if defined(OS_ANDROID) + CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_dir)); + pak_dir = pak_dir.Append(FILE_PATH_LITERAL("paks")); +#else PathService::Get(base::DIR_MODULE, &pak_dir); +#endif // OS_ANDROID pak_file = pak_dir.Append(FILE_PATH_LITERAL("components_tests_resources.pak")); ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( diff --git a/components/dom_distiller/content/distiller_page_web_contents_browsertest.cc b/components/dom_distiller/content/distiller_page_web_contents_browsertest.cc index 79d557a..d1d2dff 100644 --- a/components/dom_distiller/content/distiller_page_web_contents_browsertest.cc +++ b/components/dom_distiller/content/distiller_page_web_contents_browsertest.cc @@ -104,7 +104,12 @@ class DistillerPageWebContentsTest : public ContentBrowserTest { void AddComponentsResources() { base::FilePath pak_file; base::FilePath pak_dir; +#if defined(OS_ANDROID) + CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_dir)); + pak_dir = pak_dir.Append(FILE_PATH_LITERAL("paks")); +#else PathService::Get(base::DIR_MODULE, &pak_dir); +#endif // OS_ANDROID pak_file = pak_dir.Append(FILE_PATH_LITERAL("components_tests_resources.pak")); ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( diff --git a/components/dom_distiller/content/test/dom_distiller_js_browsertest.cc b/components/dom_distiller/content/test/dom_distiller_js_browsertest.cc index 53b37b6..6d26962 100644 --- a/components/dom_distiller/content/test/dom_distiller_js_browsertest.cc +++ b/components/dom_distiller/content/test/dom_distiller_js_browsertest.cc @@ -76,8 +76,14 @@ class DomDistillerJsTest : public content::ContentBrowserTest { void AddComponentsResources() { base::FilePath pak_file; base::FilePath pak_dir; +#if defined(OS_ANDROID) + CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_dir)); + pak_dir = pak_dir.Append(FILE_PATH_LITERAL("paks")); +#else PathService::Get(base::DIR_MODULE, &pak_dir); - pak_file = pak_dir.Append(FILE_PATH_LITERAL("components_resources.pak")); +#endif // OS_ANDROID + pak_file = + pak_dir.Append(FILE_PATH_LITERAL("components_tests_resources.pak")); ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( pak_file, ui::SCALE_FACTOR_NONE); } diff --git a/components/printing/renderer/print_web_view_helper.h b/components/printing/renderer/print_web_view_helper.h index d040dbc..562b1e0 100644 --- a/components/printing/renderer/print_web_view_helper.h +++ b/components/printing/renderer/print_web_view_helper.h @@ -26,6 +26,17 @@ struct PrintMsg_PrintPage_Params; struct PrintMsg_PrintPages_Params; struct PrintHostMsg_SetOptionsFromDocument_Params; +// RenderVIewTest-based tests crash on Android +// http://crbug.com/187500 +#if defined(OS_ANDROID) +#define MAYBE_PrintWebViewHelperTest DISABLED_PrintWebViewHelperTest +#define MAYBE_PrintWebViewHelperPreviewTest \ + DISABLED_PrintWebViewHelperPreviewTest +#else +#define MAYBE_PrintWebViewHelperTest PrintWebViewHelperTest +#define MAYBE_PrintWebViewHelperPreviewTest PrintWebViewHelperPreviewTest +#endif // defined(OS_ANDROID) + namespace base { class DictionaryValue; } @@ -115,16 +126,16 @@ class PrintWebViewHelper private: friend class PrintWebViewHelperTestBase; - FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, + FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintWebViewHelperPreviewTest, BlockScriptInitiatedPrinting); - FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, OnPrintPages); - FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, + FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintWebViewHelperTest, OnPrintPages); + FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintWebViewHelperTest, BlockScriptInitiatedPrinting); - FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, + FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintWebViewHelperTest, BlockScriptInitiatedPrintingFromPopup); #if defined(OS_WIN) || defined(OS_MACOSX) - FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintLayoutTest); - FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintWithIframe); + FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintWebViewHelperTest, PrintLayoutTest); + FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintWebViewHelperTest, PrintWithIframe); #endif // defined(OS_WIN) || defined(OS_MACOSX) enum PrintingResult { diff --git a/components/printing/test/print_web_view_helper_browsertest.cc b/components/printing/test/print_web_view_helper_browsertest.cc index bfdc311..65ecc23 100644 --- a/components/printing/test/print_web_view_helper_browsertest.cc +++ b/components/printing/test/print_web_view_helper_browsertest.cc @@ -248,22 +248,30 @@ class PrintWebViewHelperTestBase : public content::RenderViewTest { DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTestBase); }; -class PrintWebViewHelperTest : public PrintWebViewHelperTestBase { +// RenderVIewTest-based tests crash on Android +// http://crbug.com/187500 +#if defined(OS_ANDROID) +#define MAYBE_PrintWebViewHelperTest DISABLED_PrintWebViewHelperTest +#else +#define MAYBE_PrintWebViewHelperTest PrintWebViewHelperTest +#endif // defined(OS_ANDROID) + +class MAYBE_PrintWebViewHelperTest : public PrintWebViewHelperTestBase { public: - PrintWebViewHelperTest() {} - ~PrintWebViewHelperTest() override {} + MAYBE_PrintWebViewHelperTest() {} + ~MAYBE_PrintWebViewHelperTest() override {} void SetUp() override { PrintWebViewHelperTestBase::SetUp(); } protected: - DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTest); + DISALLOW_COPY_AND_ASSIGN(MAYBE_PrintWebViewHelperTest); }; // This tests only for platforms without print preview. #if !defined(ENABLE_PRINT_PREVIEW) // Tests that the renderer blocks window.print() calls if they occur too // frequently. -TEST_F(PrintWebViewHelperTest, BlockScriptInitiatedPrinting) { +TEST_F(MAYBE_PrintWebViewHelperTest, BlockScriptInitiatedPrinting) { // Pretend user will cancel printing. print_render_thread_->set_print_dialog_user_response(false); // Try to print with window.print() a few times. @@ -287,7 +295,7 @@ TEST_F(PrintWebViewHelperTest, BlockScriptInitiatedPrinting) { // Tests that the renderer always allows window.print() calls if they are user // initiated. -TEST_F(PrintWebViewHelperTest, AllowUserOriginatedPrinting) { +TEST_F(MAYBE_PrintWebViewHelperTest, AllowUserOriginatedPrinting) { // Pretend user will cancel printing. print_render_thread_->set_print_dialog_user_response(false); // Try to print with window.print() a few times. @@ -325,7 +333,7 @@ TEST_F(PrintWebViewHelperTest, AllowUserOriginatedPrinting) { } // Duplicate of OnPrintPagesTest only using javascript to print. -TEST_F(PrintWebViewHelperTest, PrintWithJavascript) { +TEST_F(MAYBE_PrintWebViewHelperTest, PrintWithJavascript) { PrintWithJavaScript(); VerifyPageCount(1); @@ -336,7 +344,7 @@ TEST_F(PrintWebViewHelperTest, PrintWithJavascript) { #if defined(ENABLE_BASIC_PRINTING) // Tests that printing pages work and sending and receiving messages through // that channel all works. -TEST_F(PrintWebViewHelperTest, OnPrintPages) { +TEST_F(MAYBE_PrintWebViewHelperTest, OnPrintPages) { LoadHTML(kHelloWorldHTML); OnPrintPages(); @@ -350,7 +358,7 @@ TEST_F(PrintWebViewHelperTest, OnPrintPages) { // to rip out and replace most of the IPC code if we ever plan to improve // printing, and the comment below by sverrir suggests that it doesn't do much // for us anyway. -TEST_F(PrintWebViewHelperTest, PrintWithIframe) { +TEST_F(MAYBE_PrintWebViewHelperTest, PrintWithIframe) { // Document that populates an iframe. const char html[] = "<html><body>Lorem Ipsum:" @@ -440,7 +448,7 @@ const TestPageData kTestPages[] = { // metafile directly. // Same for printing via PDF on Windows. #if defined(OS_MACOSX) && defined(ENABLE_BASIC_PRINTING) -TEST_F(PrintWebViewHelperTest, PrintLayoutTest) { +TEST_F(MAYBE_PrintWebViewHelperTest, PrintLayoutTest) { bool baseline = false; EXPECT_TRUE(print_render_thread_->printer() != NULL); @@ -496,10 +504,20 @@ TEST_F(PrintWebViewHelperTest, PrintLayoutTest) { // These print preview tests do not work on Chrome OS yet. #if !defined(OS_CHROMEOS) -class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase { + +// RenderVIewTest-based tests crash on Android +// http://crbug.com/187500 +#if defined(OS_ANDROID) +#define MAYBE_PrintWebViewHelperPreviewTest \ + DISABLED_PrintWebViewHelperPreviewTest +#else +#define MAYBE_PrintWebViewHelperPreviewTest PrintWebViewHelperPreviewTest +#endif // defined(OS_ANDROID) + +class MAYBE_PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase { public: - PrintWebViewHelperPreviewTest() {} - ~PrintWebViewHelperPreviewTest() override {} + MAYBE_PrintWebViewHelperPreviewTest() {} + ~MAYBE_PrintWebViewHelperPreviewTest() override {} protected: void VerifyPrintPreviewCancelled(bool did_cancel) { @@ -591,11 +609,11 @@ class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase { } } - DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperPreviewTest); + DISALLOW_COPY_AND_ASSIGN(MAYBE_PrintWebViewHelperPreviewTest); }; #if defined(ENABLE_PRINT_PREVIEW) -TEST_F(PrintWebViewHelperPreviewTest, BlockScriptInitiatedPrinting) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, BlockScriptInitiatedPrinting) { LoadHTML(kHelloWorldHTML); PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_); print_web_view_helper->SetScriptedPrintBlocked(true); @@ -607,7 +625,7 @@ TEST_F(PrintWebViewHelperPreviewTest, BlockScriptInitiatedPrinting) { VerifyPreviewRequest(true); } -TEST_F(PrintWebViewHelperPreviewTest, PrintWithJavaScript) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, PrintWithJavaScript) { LoadHTML(kPrintOnUserAction); gfx::Size new_size(200, 100); Resize(new_size, gfx::Rect(), false); @@ -630,7 +648,7 @@ TEST_F(PrintWebViewHelperPreviewTest, PrintWithJavaScript) { // Tests that print preview work and sending and receiving messages through // that channel all works. -TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintPreview) { LoadHTML(kHelloWorldHTML); // Fill in some dummy values. @@ -646,7 +664,8 @@ TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) { VerifyPagesPrinted(false); } -TEST_F(PrintWebViewHelperPreviewTest, PrintPreviewHTMLWithPageMarginsCss) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, + PrintPreviewHTMLWithPageMarginsCss) { // A simple web page with print margins css. const char kHTMLWithPageMarginsCss[] = "<html><head><style>" @@ -677,7 +696,8 @@ TEST_F(PrintWebViewHelperPreviewTest, PrintPreviewHTMLWithPageMarginsCss) { // Test to verify that print preview ignores print media css when non-default // margin is selected. -TEST_F(PrintWebViewHelperPreviewTest, NonDefaultMarginsSelectedIgnorePrintCss) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, + NonDefaultMarginsSelectedIgnorePrintCss) { LoadHTML(kHTMLWithPageSizeCss); // Fill in some dummy values. @@ -697,7 +717,7 @@ TEST_F(PrintWebViewHelperPreviewTest, NonDefaultMarginsSelectedIgnorePrintCss) { // Test to verify that print preview honor print media size css when // PRINT_TO_PDF is selected and doesn't fit to printer default paper size. -TEST_F(PrintWebViewHelperPreviewTest, PrintToPDFSelectedHonorPrintCss) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, PrintToPDFSelectedHonorPrintCss) { LoadHTML(kHTMLWithPageSizeCss); // Fill in some dummy values. @@ -717,7 +737,8 @@ TEST_F(PrintWebViewHelperPreviewTest, PrintToPDFSelectedHonorPrintCss) { // Test to verify that print preview honor print margin css when PRINT_TO_PDF // is selected and doesn't fit to printer default paper size. -TEST_F(PrintWebViewHelperPreviewTest, PrintToPDFSelectedHonorPageMarginsCss) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, + PrintToPDFSelectedHonorPageMarginsCss) { // A simple web page with print margins css. const char kHTMLWithPageCss[] = "<html><head><style>" @@ -749,7 +770,7 @@ TEST_F(PrintWebViewHelperPreviewTest, PrintToPDFSelectedHonorPageMarginsCss) { // Test to verify that print preview workflow center the html page contents to // fit the page size. -TEST_F(PrintWebViewHelperPreviewTest, PrintPreviewCenterToFitPage) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, PrintPreviewCenterToFitPage) { LoadHTML(kHTMLWithPageSizeCss); // Fill in some dummy values. @@ -768,7 +789,7 @@ TEST_F(PrintWebViewHelperPreviewTest, PrintPreviewCenterToFitPage) { // Test to verify that print preview workflow scale the html page contents to // fit the page size. -TEST_F(PrintWebViewHelperPreviewTest, PrintPreviewShrinkToFitPage) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, PrintPreviewShrinkToFitPage) { // A simple web page with print margins css. const char kHTMLWithPageCss[] = "<html><head><style>" @@ -797,7 +818,7 @@ TEST_F(PrintWebViewHelperPreviewTest, PrintPreviewShrinkToFitPage) { // Test to verify that print preview workflow honor the orientation settings // specified in css. -TEST_F(PrintWebViewHelperPreviewTest, PrintPreviewHonorsOrientationCss) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, PrintPreviewHonorsOrientationCss) { LoadHTML(kHTMLWithLandscapePageCss); // Fill in some dummy values. @@ -815,7 +836,8 @@ TEST_F(PrintWebViewHelperPreviewTest, PrintPreviewHonorsOrientationCss) { // Test to verify that print preview workflow honors the orientation settings // specified in css when PRINT_TO_PDF is selected. -TEST_F(PrintWebViewHelperPreviewTest, PrintToPDFSelectedHonorOrientationCss) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, + PrintToPDFSelectedHonorOrientationCss) { LoadHTML(kHTMLWithLandscapePageCss); // Fill in some dummy values. @@ -833,7 +855,7 @@ TEST_F(PrintWebViewHelperPreviewTest, PrintToPDFSelectedHonorOrientationCss) { // Test to verify that complete metafile is generated for a subset of pages // without creating draft pages. -TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewForSelectedPages) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintPreviewForSelectedPages) { LoadHTML(kMultipageHTML); // Fill in some dummy values. @@ -866,7 +888,7 @@ TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewForSelectedPages) { } // Test to verify that preview generated only for one page. -TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewForSelectedText) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintPreviewForSelectedText) { LoadHTML(kMultipageHTML); GetMainFrame()->selectRange( blink::WebRange::fromDocumentRange(GetMainFrame(), 1, 3)); @@ -887,7 +909,7 @@ TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewForSelectedText) { // Tests that print preview fails and receiving error messages through // that channel all works. -TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewFail) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintPreviewFail) { LoadHTML(kHelloWorldHTML); // An empty dictionary should fail. @@ -902,7 +924,7 @@ TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewFail) { } // Tests that cancelling print preview works. -TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewCancel) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintPreviewCancel) { LoadHTML(kLongPageHTML); const int kCancelPage = 3; @@ -921,7 +943,7 @@ TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewCancel) { // Tests that printing from print preview works and sending and receiving // messages through that channel all works. -TEST_F(PrintWebViewHelperPreviewTest, OnPrintForPrintPreview) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreview) { LoadHTML(kPrintPreviewHTML); // Fill in some dummy values. @@ -935,7 +957,7 @@ TEST_F(PrintWebViewHelperPreviewTest, OnPrintForPrintPreview) { // Tests that printing from print preview fails and receiving error messages // through that channel all works. -TEST_F(PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) { LoadHTML(kPrintPreviewHTML); // An empty dictionary should fail. @@ -947,7 +969,7 @@ TEST_F(PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) { // Tests that when default printer has invalid printer settings, print preview // receives error message. -TEST_F(PrintWebViewHelperPreviewTest, +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintPreviewUsingInvalidPrinterSettings) { LoadHTML(kPrintPreviewHTML); @@ -970,7 +992,8 @@ TEST_F(PrintWebViewHelperPreviewTest, // Tests that when the selected printer has invalid page settings, print preview // receives error message. -TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewUsingInvalidPageSize) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, + OnPrintPreviewUsingInvalidPageSize) { LoadHTML(kPrintPreviewHTML); print_render_thread_->printer()->UseInvalidPageSize(); @@ -989,7 +1012,8 @@ TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewUsingInvalidPageSize) { // Tests that when the selected printer has invalid content settings, print // preview receives error message. -TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewUsingInvalidContentSize) { +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, + OnPrintPreviewUsingInvalidContentSize) { LoadHTML(kPrintPreviewHTML); print_render_thread_->printer()->UseInvalidContentSize(); @@ -1006,7 +1030,7 @@ TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewUsingInvalidContentSize) { VerifyPrintPreviewGenerated(false); } -TEST_F(PrintWebViewHelperPreviewTest, +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewUsingInvalidPrinterSettings) { LoadHTML(kPrintPreviewHTML); diff --git a/components/test/DEPS b/components/test/DEPS index ad35ec8..ec6ab2f 100644 --- a/components/test/DEPS +++ b/components/test/DEPS @@ -2,7 +2,17 @@ include_rules = [ # To initialize the global data of content_settings. "+components/content_settings/core/common", "+components/invalidation/android/component_jni_registrar.h", + "+content/public/android/java/src/org/chromium/content/browser", + "+content/public/app/content_jni_onload.h", + "+content/public/app/content_main.h", + "+content/public/common/content_switches.h", "+content/public/test", + "+content/shell/android/java/src/org/chromium/content_shell", + "+content/shell/android/shell_jni_registrar.h", + "+content/shell/app/shell_main_delegate.h", + "+jni", + "+media/base/media_switches.h", + "+ui/android/java/src/org/chromium/ui/base", "+ui/base/android/ui_base_jni_registrar.h", "+ui/base/resource/resource_bundle.h", "+ui/base/ui_base_paths.h", diff --git a/components/test/android/OWNERS b/components/test/android/OWNERS new file mode 100644 index 0000000..c43b4b3 --- /dev/null +++ b/components/test/android/OWNERS @@ -0,0 +1,3 @@ +jaekyun@chromium.org +sievers@chromium.org +tedchoc@chromium.org diff --git a/components/test/android/browsertests_apk/AndroidManifest.xml.jinja2 b/components/test/android/browsertests_apk/AndroidManifest.xml.jinja2 new file mode 100644 index 0000000..3ac010d --- /dev/null +++ b/components/test/android/browsertests_apk/AndroidManifest.xml.jinja2 @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="utf-8"?> + +<!-- Copyright 2015 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. + --> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="org.chromium.components_browsertests_apk"> + + <application android:name="ComponentsBrowserTestsApplication" + android:label="ComponentsBrowserTests"> + <activity android:name="ComponentsBrowserTestsActivity" + android:launchMode="singleTask" + android:theme="@android:style/Theme.Holo.Light.NoActionBar" + android:configChanges="orientation|keyboardHidden|keyboard|screenSize" + android:hardwareAccelerated="true"> + <intent-filter> + <action android:name="android.intent.action.MAIN"/> + <category android:name="android.intent.category.LAUNCHER"/> + </intent-filter> + </activity> + <!-- The following service entries exist in order to allow us to + start more than one sandboxed process. --> + + <!-- NOTE: If you change the values of "android:process" for any of the below services, + you also need to update kHelperProcessExecutableName in chrome_constants.cc. --> + {% set num_sandboxed_services = 20 %} + <meta-data android:name="org.chromium.content.browser.NUM_SANDBOXED_SERVICES" + android:value="{{ num_sandboxed_services }}"/> + {% for i in range(num_sandboxed_services) %} + <service android:name="org.chromium.content.app.SandboxedProcessService{{ i }}" + android:process=":sandboxed_process{{ i }}" + android:isolatedProcess="true" + android:exported="false" /> + {% endfor %} + + {% set num_privileged_services = 3 %} + <meta-data android:name="org.chromium.content.browser.NUM_PRIVILEGED_SERVICES" + android:value="{{ num_privileged_services }}"/> + {% for i in range(num_privileged_services) %} + <service android:name="org.chromium.content.app.PrivilegedProcessService{{ i }}" + android:process=":privileged_process{{ i }}" + android:isolatedProcess="false" + android:exported="false" /> + {% endfor %} + </application> + + <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="22" /> + <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> + <uses-permission android:name="android.permission.CAMERA" /> + <uses-permission android:name="android.permission.INTERNET"/> + <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/> + <uses-permission android:name="android.permission.RECORD_AUDIO"/> + <uses-permission android:name="android.permission.VIBRATE"/> + <uses-permission android:name="android.permission.WAKE_LOCK"/> + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> +</manifest> diff --git a/components/test/android/browsertests_apk/components_browser_tests_android.cc b/components/test/android/browsertests_apk/components_browser_tests_android.cc new file mode 100644 index 0000000..baf8efe --- /dev/null +++ b/components/test/android/browsertests_apk/components_browser_tests_android.cc @@ -0,0 +1,99 @@ +// Copyright 2015 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. + +// This class sets up the environment for running the content browser tests +// inside an android application. + +#include <android/log.h> +#include <unistd.h> + +#include "base/android/base_jni_registrar.h" +#include "base/android/fifo_utils.h" +#include "base/android/jni_android.h" +#include "base/android/jni_string.h" +#include "base/android/library_loader/library_loader_hooks.h" +#include "base/android/scoped_java_ref.h" +#include "base/base_switches.h" +#include "base/command_line.h" +#include "base/files/file_path.h" +#include "base/logging.h" +#include "base/strings/string_tokenizer.h" +#include "base/strings/string_util.h" +#include "base/strings/stringprintf.h" +#include "content/public/common/content_switches.h" +#include "content/public/test/test_launcher.h" +#include "jni/ComponentsBrowserTestsActivity_jni.h" +#include "media/base/media_switches.h" +#include "testing/android/native_test/native_test_util.h" + +using testing::native_test_util::ArgsToArgv; +using testing::native_test_util::ParseArgsFromCommandLineFile; +using testing::native_test_util::ScopedMainEntryLogger; + +// The main function of the program to be wrapped as an apk. +extern int main(int argc, char** argv); + +namespace { + +// The test runner script writes the command line file in +// "/data/local/tmp". +static const char kCommandLineFilePath[] = + "/data/local/tmp/components-browser-tests-command-line"; + +} // namespace + +namespace components { + +// TODO(jaekyun): Refactor and deduplicate with +// testing/android/native_test/native_test_launcher.cc (http://crbug.com/476410) +static void RunTests(JNIEnv* env, + jobject obj, + jstring jfiles_dir, + jobject app_context) { + // Command line basic initialization, will be fully initialized later. + static const char* const kInitialArgv[] = {"ComponentsBrowserTestsActivity"}; + base::CommandLine::Init(arraysize(kInitialArgv), kInitialArgv); + + // Set the application context in base. + base::android::ScopedJavaLocalRef<jobject> scoped_context( + env, env->NewLocalRef(app_context)); + base::android::InitApplicationContext(env, scoped_context); + base::android::RegisterJni(env); + + std::vector<std::string> args; + ParseArgsFromCommandLineFile(kCommandLineFilePath, &args); + + std::vector<char*> argv; + int argc = ArgsToArgv(args, &argv); + + // Fully initialize command line with arguments. + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + command_line->AppendArguments(base::CommandLine(argc, &argv[0]), false); + + // Append required switches. + command_line->AppendSwitch(content::kSingleProcessTestsFlag); + command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); + command_line->AppendSwitch(switches::kUseFakeUIForMediaStream); + // Specify a socket name to not conflict with the default one used + // in content_shell. + command_line->AppendSwitchASCII(switches::kRemoteDebuggingSocketName, + "components_browsertests_devtools_remote"); + + // Create fifo and redirect stdout and stderr to it. + base::FilePath files_dir( + base::android::ConvertJavaStringToUTF8(env, jfiles_dir)); + base::FilePath fifo_path(files_dir.Append(base::FilePath("test.fifo"))); + base::android::CreateFIFO(fifo_path, 0666); + base::android::RedirectStream(stdout, fifo_path, "w+"); + dup2(STDOUT_FILENO, STDERR_FILENO); + + ScopedMainEntryLogger scoped_main_entry_logger; + main(argc, &argv[0]); +} + +bool RegisterComponentsBrowserTestsAndroid(JNIEnv* env) { + return RegisterNativesImpl(env); +} + +} // namespace components diff --git a/components/test/android/browsertests_apk/components_browser_tests_android.h b/components/test/android/browsertests_apk/components_browser_tests_android.h new file mode 100644 index 0000000..a989706 --- /dev/null +++ b/components/test/android/browsertests_apk/components_browser_tests_android.h @@ -0,0 +1,16 @@ +// Copyright 2015 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. + +#ifndef COMPONENTS_TEST_ANDROID_BROWSERTESTS_APK_COMPONENTS_BROWSER_TESTS_ANDROID_H_ +#define COMPONENTS_TEST_ANDROID_BROWSERTESTS_APK_COMPONENTS_BROWSER_TESTS_ANDROID_H_ + +#include <jni.h> + +namespace components { + +bool RegisterComponentsBrowserTestsAndroid(JNIEnv* env); + +} // namespace components + +#endif // COMPONENTS_TEST_ANDROID_BROWSERTESTS_APK_COMPONENTS_BROWSER_TESTS_ANDROID_H_ diff --git a/components/test/android/browsertests_apk/components_browser_tests_jni_onload.cc b/components/test/android/browsertests_apk/components_browser_tests_jni_onload.cc new file mode 100644 index 0000000..e47b840 --- /dev/null +++ b/components/test/android/browsertests_apk/components_browser_tests_jni_onload.cc @@ -0,0 +1,40 @@ +// Copyright 2015 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. + +#include "base/android/jni_android.h" +#include "base/bind.h" +#include "components/test/android/browsertests_apk/components_browser_tests_android.h" +#include "content/public/app/content_jni_onload.h" +#include "content/public/app/content_main.h" +#include "content/public/test/nested_message_pump_android.h" +#include "content/shell/android/shell_jni_registrar.h" +#include "content/shell/app/shell_main_delegate.h" + +namespace { + +bool RegisterJNI(JNIEnv* env) { + return content::android::RegisterShellJni(env) && + content::NestedMessagePumpAndroid::RegisterJni(env) && + components::RegisterComponentsBrowserTestsAndroid(env); +} + +bool Init() { + content::SetContentMainDelegate(new content::ShellMainDelegate()); + return true; +} + +} // namespace + +// This is called by the VM when the shared library is first loaded. +JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { + std::vector<base::android::RegisterCallback> register_callbacks; + register_callbacks.push_back(base::Bind(&RegisterJNI)); + std::vector<base::android::InitCallback> init_callbacks; + init_callbacks.push_back(base::Bind(&Init)); + if (!content::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) || + !content::android::OnJNIOnLoadInit(init_callbacks)) { + return -1; + } + return JNI_VERSION_1_4; +} diff --git a/components/test/android/browsertests_apk/res/layout/test_activity.xml b/components/test/android/browsertests_apk/res/layout/test_activity.xml new file mode 100644 index 0000000..227ce1f --- /dev/null +++ b/components/test/android/browsertests_apk/res/layout/test_activity.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> + +<!-- Copyright 2015 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. + --> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" android:layout_height="match_parent" + android:orientation="vertical"> + <org.chromium.content_shell.ShellManager + android:id="@+id/shell_container" + android:layout_width="match_parent" + android:layout_height="match_parent" /> +</LinearLayout> diff --git a/components/test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsActivity.java b/components/test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsActivity.java new file mode 100644 index 0000000..bbf2461 --- /dev/null +++ b/components/test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsActivity.java @@ -0,0 +1,75 @@ +// Copyright 2015 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.components_browsertests_apk; + +import android.app.Activity; +import android.content.Context; +import android.os.Bundle; +import android.os.Handler; +import android.util.Log; +import android.view.Window; +import android.view.WindowManager; + +import org.chromium.base.JNINamespace; +import org.chromium.base.annotations.SuppressFBWarnings; +import org.chromium.base.library_loader.LibraryLoader; +import org.chromium.base.library_loader.LibraryProcessType; +import org.chromium.base.library_loader.ProcessInitException; +import org.chromium.content.browser.BrowserStartupController; +import org.chromium.content_shell.ShellManager; +import org.chromium.ui.base.ActivityWindowAndroid; +import org.chromium.ui.base.WindowAndroid; + +/** + * Android activity for running components browser tests + */ +@JNINamespace("components") +public class ComponentsBrowserTestsActivity extends Activity { + private static final String TAG = "ComponentsBrowserTestsActivity"; + + private ShellManager mShellManager; + private WindowAndroid mWindowAndroid; + + @Override + @SuppressFBWarnings("DM_EXIT") + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + try { + LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized(); + } catch (ProcessInitException e) { + Log.i(TAG, "Cannot load components_browsertests:" + e); + System.exit(-1); + } + BrowserStartupController.get(getApplicationContext(), LibraryProcessType.PROCESS_BROWSER) + .initChromiumBrowserProcessForTests(); + + setContentView(R.layout.test_activity); + mShellManager = (ShellManager) findViewById(R.id.shell_container); + mWindowAndroid = new ActivityWindowAndroid(this); + mShellManager.setWindow(mWindowAndroid, false); + + Window wind = this.getWindow(); + wind.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); + wind.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); + wind.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); + + new Handler().post(new Runnable() { + @Override + public void run() { + Log.i(TAG, "Running tests"); + runTests(); + Log.i(TAG, "Tests finished."); + finish(); + } + }); + } + + private void runTests() { + nativeRunTests(getFilesDir().getAbsolutePath(), getApplicationContext()); + } + + private native void nativeRunTests(String filesDir, Context appContext); +} diff --git a/components/test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsApplication.java b/components/test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsApplication.java new file mode 100644 index 0000000..91ee597 --- /dev/null +++ b/components/test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsApplication.java @@ -0,0 +1,32 @@ +// Copyright 2015 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.components_browsertests_apk; + +import android.content.Context; + +import org.chromium.base.BaseChromiumApplication; +import org.chromium.base.PathUtils; +import org.chromium.base.ResourceExtractor; + +/** + * A basic content browser tests {@link android.app.Application}. + */ +public class ComponentsBrowserTestsApplication extends BaseChromiumApplication { + private static final String[] MANDATORY_PAK_FILES = + new String[] {"components_tests_resources.pak", "content_shell.pak", "icudtl.dat", + "natives_blob.bin", "snapshot_blob.bin"}; + private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "components_shell"; + + @Override + public void onCreate() { + super.onCreate(); + initializeApplicationParameters(this); + } + + public static void initializeApplicationParameters(Context context) { + ResourceExtractor.setMandatoryPaksToExtract(MANDATORY_PAK_FILES); + PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, context); + } +} |