| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/extension_test_message_listener.h" | 5 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 6 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | 6 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| 7 #include "chrome/common/chrome_switches.h" | 7 #include "chrome/common/chrome_switches.h" |
| 8 #include "content/test/net/url_request_prepackaged_interceptor.h" | 8 #include "content/test/net/url_request_prepackaged_interceptor.h" |
| 9 #include "net/url_request/url_fetcher.h" | 9 #include "net/url_request/url_fetcher.h" |
| 10 | 10 |
| 11 class AdViewTest : public extensions::PlatformAppBrowserTest { | 11 class AdViewTest : public extensions::PlatformAppBrowserTest { |
| 12 protected: | 12 protected: |
| 13 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 13 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 14 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); | 14 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 15 command_line->AppendSwitch(switches::kEnableAdview); | 15 command_line->AppendSwitch(switches::kEnableAdview); |
| 16 command_line->AppendSwitch(switches::kEnableAdviewSrcAttribute); | 16 command_line->AppendSwitch(switches::kEnableAdviewSrcAttribute); |
| 17 } | 17 } |
| 18 }; | 18 }; |
| 19 | 19 |
| 20 // This test checks the "loadcommit" event is called when the page inside an | 20 // This test checks the "loadcommit" event is called when the page inside an |
| 21 // <adview> is loaded. | 21 // <adview> is loaded. |
| 22 #if defined(OS_MACOSX) | 22 #if defined(OS_MACOSX) |
| 23 // Very flaky on MacOS 10.8. | 23 // Very flaky on MacOS 10.8. |
| 24 #define MAYBE_LoadCommitEventIsCalled DISABLED_LoadCommitEventIsCalled | 24 #define MAYBE_LoadCommitEventIsCalled DISABLED_LoadCommitEventIsCalled |
| 25 #else | 25 #else |
| 26 #define MAYBE_LoadCommitEventIsCalled LoadCommitEventIsCalled | 26 #define MAYBE_LoadCommitEventIsCalled LoadCommitEventIsCalled |
| 27 #endif | 27 #endif |
| 28 IN_PROC_BROWSER_TEST_F(AdViewTest, MAYBE_LoadCommitEventIsCalled) { | 28 IN_PROC_BROWSER_TEST_F(AdViewTest, MAYBE_LoadCommitEventIsCalled) { |
| 29 ASSERT_TRUE(StartTestServer()); | 29 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 30 | 30 |
| 31 ASSERT_TRUE(RunPlatformAppTest( | 31 ASSERT_TRUE(RunPlatformAppTest( |
| 32 "platform_apps/ad_view/loadcommit_event")) << message_; | 32 "platform_apps/ad_view/loadcommit_event")) << message_; |
| 33 } | 33 } |
| 34 | 34 |
| 35 // This test checks the "loadabort" event is called when the "src" attribute | 35 // This test checks the "loadabort" event is called when the "src" attribute |
| 36 // of an <adview> is an invalid URL. | 36 // of an <adview> is an invalid URL. |
| 37 IN_PROC_BROWSER_TEST_F(AdViewTest, LoadAbortEventIsCalled) { | 37 IN_PROC_BROWSER_TEST_F(AdViewTest, LoadAbortEventIsCalled) { |
| 38 ASSERT_TRUE(StartTestServer()); | 38 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 39 | 39 |
| 40 ASSERT_TRUE(RunPlatformAppTest( | 40 ASSERT_TRUE(RunPlatformAppTest( |
| 41 "platform_apps/ad_view/loadabort_event")) << message_; | 41 "platform_apps/ad_view/loadabort_event")) << message_; |
| 42 } | 42 } |
| 43 | 43 |
| 44 // This test checks the page loaded inside an <adview> has the ability to | 44 // This test checks the page loaded inside an <adview> has the ability to |
| 45 // 1) receive "message" events from the application, and 2) use | 45 // 1) receive "message" events from the application, and 2) use |
| 46 // "window.postMessage" to post back a message to the application. | 46 // "window.postMessage" to post back a message to the application. |
| 47 #if defined(OS_WIN) | 47 #if defined(OS_WIN) |
| 48 // Flaky, or takes too long time on Win7. (http://crbug.com/230271) | 48 // Flaky, or takes too long time on Win7. (http://crbug.com/230271) |
| 49 #define MAYBE_CommitMessageFromAdNetwork DISABLED_CommitMessageFromAdNetwork | 49 #define MAYBE_CommitMessageFromAdNetwork DISABLED_CommitMessageFromAdNetwork |
| 50 #else | 50 #else |
| 51 #define MAYBE_CommitMessageFromAdNetwork CommitMessageFromAdNetwork | 51 #define MAYBE_CommitMessageFromAdNetwork CommitMessageFromAdNetwork |
| 52 #endif | 52 #endif |
| 53 IN_PROC_BROWSER_TEST_F(AdViewTest, MAYBE_CommitMessageFromAdNetwork) { | 53 IN_PROC_BROWSER_TEST_F(AdViewTest, MAYBE_CommitMessageFromAdNetwork) { |
| 54 ASSERT_TRUE(StartTestServer()); | 54 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 55 | 55 |
| 56 ASSERT_TRUE(RunPlatformAppTest( | 56 ASSERT_TRUE(RunPlatformAppTest( |
| 57 "platform_apps/ad_view/onloadcommit_ack")) << message_; | 57 "platform_apps/ad_view/onloadcommit_ack")) << message_; |
| 58 } | 58 } |
| 59 | 59 |
| 60 // This test checks the page running inside an <adview> has the ability to load | 60 // This test checks the page running inside an <adview> has the ability to load |
| 61 // and display an image inside an <iframe>. | 61 // and display an image inside an <iframe>. |
| 62 // Note: Disabled for initial checkin because the test depends on a binary | 62 // Note: Disabled for initial checkin because the test depends on a binary |
| 63 // file (image035.png) which the trybots don't process correctly when | 63 // file (image035.png) which the trybots don't process correctly when |
| 64 // first checked-in. | 64 // first checked-in. |
| 65 IN_PROC_BROWSER_TEST_F(AdViewTest, DISABLED_DisplayFirstAd) { | 65 IN_PROC_BROWSER_TEST_F(AdViewTest, DISABLED_DisplayFirstAd) { |
| 66 ASSERT_TRUE(StartTestServer()); | 66 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 67 | 67 |
| 68 ASSERT_TRUE(RunPlatformAppTest( | 68 ASSERT_TRUE(RunPlatformAppTest( |
| 69 "platform_apps/ad_view/display_first_ad")) << message_; | 69 "platform_apps/ad_view/display_first_ad")) << message_; |
| 70 } | 70 } |
| 71 | 71 |
| 72 // This test checks that <adview> attributes are also exposed as properties | 72 // This test checks that <adview> attributes are also exposed as properties |
| 73 // (with the same name and value). | 73 // (with the same name and value). |
| 74 IN_PROC_BROWSER_TEST_F(AdViewTest, PropertiesAreInSyncWithAttributes) { | 74 IN_PROC_BROWSER_TEST_F(AdViewTest, PropertiesAreInSyncWithAttributes) { |
| 75 ASSERT_TRUE(StartTestServer()); | 75 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 76 | 76 |
| 77 ASSERT_TRUE(RunPlatformAppTest( | 77 ASSERT_TRUE(RunPlatformAppTest( |
| 78 "platform_apps/ad_view/properties_exposed")) << message_; | 78 "platform_apps/ad_view/properties_exposed")) << message_; |
| 79 } | 79 } |
| 80 | 80 |
| 81 // This test checks an <adview> element has no behavior when the "adview" | 81 // This test checks an <adview> element has no behavior when the "adview" |
| 82 // permission is missing from the application manifest. | 82 // permission is missing from the application manifest. |
| 83 IN_PROC_BROWSER_TEST_F(AdViewTest, AdViewPermissionIsRequired) { | 83 IN_PROC_BROWSER_TEST_F(AdViewTest, AdViewPermissionIsRequired) { |
| 84 ASSERT_TRUE(StartTestServer()); | 84 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 85 | 85 |
| 86 ASSERT_TRUE(RunPlatformAppTest( | 86 ASSERT_TRUE(RunPlatformAppTest( |
| 87 "platform_apps/ad_view/permission_required")) << message_; | 87 "platform_apps/ad_view/permission_required")) << message_; |
| 88 } | 88 } |
| 89 | 89 |
| 90 // This test checks that 1) it is possible change the value of the "ad-network" | 90 // This test checks that 1) it is possible change the value of the "ad-network" |
| 91 // attribute of an <adview> element and 2) changing the value will reset the | 91 // attribute of an <adview> element and 2) changing the value will reset the |
| 92 // "src" attribute. | 92 // "src" attribute. |
| 93 #if defined(OS_MACOSX) | 93 #if defined(OS_MACOSX) |
| 94 // Very flaky on MacOS 10.8 - crbug.com/253644. | 94 // Very flaky on MacOS 10.8 - crbug.com/253644. |
| 95 #define MAYBE_ChangeAdNetworkValue DISABLED_ChangeAdNetworkValue | 95 #define MAYBE_ChangeAdNetworkValue DISABLED_ChangeAdNetworkValue |
| 96 #else | 96 #else |
| 97 #define MAYBE_ChangeAdNetworkValue ChangeAdNetworkValue | 97 #define MAYBE_ChangeAdNetworkValue ChangeAdNetworkValue |
| 98 #endif | 98 #endif |
| 99 IN_PROC_BROWSER_TEST_F(AdViewTest, ChangeAdNetworkValue) { | 99 IN_PROC_BROWSER_TEST_F(AdViewTest, ChangeAdNetworkValue) { |
| 100 ASSERT_TRUE(StartTestServer()); | 100 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 101 | 101 |
| 102 ASSERT_TRUE(RunPlatformAppTest( | 102 ASSERT_TRUE(RunPlatformAppTest( |
| 103 "platform_apps/ad_view/change_ad_network")) << message_; | 103 "platform_apps/ad_view/change_ad_network")) << message_; |
| 104 } | 104 } |
| 105 | 105 |
| 106 class AdViewNoSrcTest : public extensions::PlatformAppBrowserTest { | 106 class AdViewNoSrcTest : public extensions::PlatformAppBrowserTest { |
| 107 protected: | 107 protected: |
| 108 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 108 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 109 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); | 109 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 110 command_line->AppendSwitch(switches::kEnableAdview); | 110 command_line->AppendSwitch(switches::kEnableAdview); |
| 111 //Note: The "kEnableAdviewSrcAttribute" flag is not here! | 111 //Note: The "kEnableAdviewSrcAttribute" flag is not here! |
| 112 } | 112 } |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 // This test checks an invalid "ad-network" value (i.e. not whitelisted) | 115 // This test checks an invalid "ad-network" value (i.e. not whitelisted) |
| 116 // is ignored. | 116 // is ignored. |
| 117 IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, InvalidAdNetworkIsIgnored) { | 117 IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, InvalidAdNetworkIsIgnored) { |
| 118 ASSERT_TRUE(StartTestServer()); | 118 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 119 | 119 |
| 120 ASSERT_TRUE(RunPlatformAppTest( | 120 ASSERT_TRUE(RunPlatformAppTest( |
| 121 "platform_apps/ad_view/invalid_ad_network")) << message_; | 121 "platform_apps/ad_view/invalid_ad_network")) << message_; |
| 122 } | 122 } |
| 123 | 123 |
| 124 // This test checks the "src" attribute is ignored when the | 124 // This test checks the "src" attribute is ignored when the |
| 125 // "kEnableAdviewSrcAttribute" is missing. | 125 // "kEnableAdviewSrcAttribute" is missing. |
| 126 IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, EnableAdviewSrcAttributeFlagRequired) { | 126 IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, EnableAdviewSrcAttributeFlagRequired) { |
| 127 ASSERT_TRUE(StartTestServer()); | 127 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 128 | 128 |
| 129 ASSERT_TRUE(RunPlatformAppTest( | 129 ASSERT_TRUE(RunPlatformAppTest( |
| 130 "platform_apps/ad_view/src_flag_required")) << message_; | 130 "platform_apps/ad_view/src_flag_required")) << message_; |
| 131 } | 131 } |
| 132 | 132 |
| 133 // This test checks 1) an <adview> works end-to-end (i.e. page is loaded) when | 133 // This test checks 1) an <adview> works end-to-end (i.e. page is loaded) when |
| 134 // using a whitelisted ad-network, and 2) the "src" attribute is never exposed | 134 // using a whitelisted ad-network, and 2) the "src" attribute is never exposed |
| 135 // to the application. | 135 // to the application. |
| 136 IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, SrcNotExposed) { | 136 IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, SrcNotExposed) { |
| 137 base::FilePath file_path = test_data_dir_ | 137 base::FilePath file_path = test_data_dir_ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 157 protected: | 157 protected: |
| 158 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 158 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 159 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); | 159 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 160 //Note: The "kEnableAdview" flag is not here! | 160 //Note: The "kEnableAdview" flag is not here! |
| 161 } | 161 } |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 // This test checks an <adview> element has no behavior when the "kEnableAdview" | 164 // This test checks an <adview> element has no behavior when the "kEnableAdview" |
| 165 // flag is missing. | 165 // flag is missing. |
| 166 IN_PROC_BROWSER_TEST_F(AdViewNotEnabledTest, EnableAdviewFlagRequired) { | 166 IN_PROC_BROWSER_TEST_F(AdViewNotEnabledTest, EnableAdviewFlagRequired) { |
| 167 ASSERT_TRUE(StartTestServer()); | 167 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 168 | 168 |
| 169 ASSERT_TRUE(RunPlatformAppTest( | 169 ASSERT_TRUE(RunPlatformAppTest( |
| 170 "platform_apps/ad_view/flag_required")) << message_; | 170 "platform_apps/ad_view/flag_required")) << message_; |
| 171 } | 171 } |
| OLD | NEW |