OLD | NEW |
1 // Copyright (c) 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" |
| 9 #include "net/url_request/url_fetcher.h" |
8 | 10 |
9 class AdViewTest : public extensions::PlatformAppBrowserTest { | 11 class AdViewTest : public extensions::PlatformAppBrowserTest { |
10 protected: | 12 protected: |
11 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 13 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
12 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); | 14 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); |
13 command_line->AppendSwitch(switches::kEnableAdview); | 15 command_line->AppendSwitch(switches::kEnableAdview); |
14 command_line->AppendSwitch(switches::kEnableAdviewSrcAttribute); | 16 command_line->AppendSwitch(switches::kEnableAdviewSrcAttribute); |
15 } | 17 } |
16 }; | 18 }; |
17 | 19 |
18 IN_PROC_BROWSER_TEST_F(AdViewTest, LoadEventIsCalled) { | 20 // This test checks the "loadcommit" event is called when the page inside an |
| 21 // <adview> is loaded. |
| 22 IN_PROC_BROWSER_TEST_F(AdViewTest, LoadCommitEventIsCalled) { |
19 ASSERT_TRUE(StartTestServer()); | 23 ASSERT_TRUE(StartTestServer()); |
20 | 24 |
21 ExtensionTestMessageListener listener("guest-loaded", false); | 25 ASSERT_TRUE(RunPlatformAppTest( |
22 LoadAndLaunchPlatformApp("ad_view/load_event"); | 26 "platform_apps/ad_view/loadcommit_event")) << message_; |
23 ASSERT_TRUE(listener.WaitUntilSatisfied()); | |
24 } | 27 } |
25 | 28 |
26 IN_PROC_BROWSER_TEST_F(AdViewTest, AdNetworkIsLoaded) { | 29 // This test checks the "loadabort" event is called when the "src" attribute |
| 30 // of an <adview> is an invalid URL. |
| 31 IN_PROC_BROWSER_TEST_F(AdViewTest, LoadAbortEventIsCalled) { |
27 ASSERT_TRUE(StartTestServer()); | 32 ASSERT_TRUE(StartTestServer()); |
28 | 33 |
29 ExtensionTestMessageListener listener("ad-network-loaded", false); | 34 ASSERT_TRUE(RunPlatformAppTest( |
30 LoadAndLaunchPlatformApp("ad_view/ad_network_loaded"); | 35 "platform_apps/ad_view/loadabort_event")) << message_; |
31 ASSERT_TRUE(listener.WaitUntilSatisfied()); | |
32 } | 36 } |
33 | 37 |
34 // This test currently fails on trybots because it requires new binary file | 38 // This test checks the page loaded inside an <adview> has the ability to |
35 // (image315.png). The test will be enabled once the binary files are committed. | 39 // 1) receive "message" events from the application, and 2) use |
36 IN_PROC_BROWSER_TEST_F(AdViewTest, DISABLED_DisplayFirstAd) { | 40 // "window.postMessage" to post back a message to the application. |
| 41 IN_PROC_BROWSER_TEST_F(AdViewTest, CommitMessageFromAdNetwork) { |
37 ASSERT_TRUE(StartTestServer()); | 42 ASSERT_TRUE(StartTestServer()); |
38 | 43 |
39 ExtensionTestMessageListener listener("ad-displayed", false); | 44 ASSERT_TRUE(RunPlatformAppTest( |
40 LoadAndLaunchPlatformApp("ad_view/display_first_ad"); | 45 "platform_apps/ad_view/onloadcommit_ack")) << message_; |
41 ASSERT_TRUE(listener.WaitUntilSatisfied()); | |
42 } | 46 } |
| 47 |
| 48 // This test checks the page running inside an <adview> has the ability to load |
| 49 // and display an image inside an <iframe>. |
| 50 IN_PROC_BROWSER_TEST_F(AdViewTest, DisplayFirstAd) { |
| 51 ASSERT_TRUE(StartTestServer()); |
| 52 |
| 53 ASSERT_TRUE(RunPlatformAppTest( |
| 54 "platform_apps/ad_view/display_first_ad")) << message_; |
| 55 } |
| 56 |
| 57 // This test checks that <adview> attributes are also exposed as properties |
| 58 // (with the same name and value). |
| 59 IN_PROC_BROWSER_TEST_F(AdViewTest, PropertiesAreInSyncWithAttributes) { |
| 60 ASSERT_TRUE(StartTestServer()); |
| 61 |
| 62 ASSERT_TRUE(RunPlatformAppTest( |
| 63 "platform_apps/ad_view/properties_exposed")) << message_; |
| 64 } |
| 65 |
| 66 // This test checks an <adview> element has no behavior when the "adview" |
| 67 // permission is missing from the application manifest. |
| 68 IN_PROC_BROWSER_TEST_F(AdViewTest, AdViewPermissionIsRequired) { |
| 69 ASSERT_TRUE(StartTestServer()); |
| 70 |
| 71 ASSERT_TRUE(RunPlatformAppTest( |
| 72 "platform_apps/ad_view/permission_required")) << message_; |
| 73 } |
| 74 |
| 75 // This test checks that 1) it is possible change the value of the "ad-network" |
| 76 // attribute of an <adview> element and 2) changing the value will reset the |
| 77 // "src" attribute. |
| 78 IN_PROC_BROWSER_TEST_F(AdViewTest, ChangeAdNetworkValue) { |
| 79 ASSERT_TRUE(StartTestServer()); |
| 80 |
| 81 ASSERT_TRUE(RunPlatformAppTest( |
| 82 "platform_apps/ad_view/change_ad_network")) << message_; |
| 83 } |
| 84 |
| 85 class AdViewNoSrcTest : public extensions::PlatformAppBrowserTest { |
| 86 protected: |
| 87 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 88 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 89 command_line->AppendSwitch(switches::kEnableAdview); |
| 90 //Note: The "kEnableAdviewSrcAttribute" flag is not here! |
| 91 } |
| 92 }; |
| 93 |
| 94 // This test checks an invalid "ad-network" value (i.e. not whitelisted) |
| 95 // is ignored. |
| 96 IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, InvalidAdNetworkIsIgnored) { |
| 97 ASSERT_TRUE(StartTestServer()); |
| 98 |
| 99 ASSERT_TRUE(RunPlatformAppTest( |
| 100 "platform_apps/ad_view/invalid_ad_network")) << message_; |
| 101 } |
| 102 |
| 103 // This test checks the "src" attribute is ignored when the |
| 104 // "kEnableAdviewSrcAttribute" is missing. |
| 105 IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, EnableAdviewSrcAttributeFlagRequired) { |
| 106 ASSERT_TRUE(StartTestServer()); |
| 107 |
| 108 ASSERT_TRUE(RunPlatformAppTest( |
| 109 "platform_apps/ad_view/src_flag_required")) << message_; |
| 110 } |
| 111 |
| 112 // This test checks 1) an <adview> works end-to-end (i.e. page is loaded) when |
| 113 // using a whitelisted ad-network, and 2) the "src" attribute is never exposed |
| 114 // to the application. |
| 115 IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, SrcNotExposed) { |
| 116 base::FilePath file_path = test_data_dir_ |
| 117 .AppendASCII("platform_apps") |
| 118 .AppendASCII("ad_view/src_not_exposed") |
| 119 .AppendASCII("ad_network_fake_website.html"); |
| 120 |
| 121 // Note: The following URL is identical to the whitelisted url |
| 122 // for "admob" (see ad_view.js). |
| 123 GURL url = GURL("https://admob-sdk.doubleclick.net/chromeapps"); |
| 124 std::string scheme = url.scheme(); |
| 125 std::string hostname = url.host(); |
| 126 |
| 127 content::URLRequestPrepackagedInterceptor interceptor(scheme, hostname); |
| 128 interceptor.SetResponse(url, file_path); |
| 129 |
| 130 ASSERT_TRUE(RunPlatformAppTest( |
| 131 "platform_apps/ad_view/src_not_exposed")) << message_; |
| 132 ASSERT_EQ(1, interceptor.GetHitCount()); |
| 133 } |
| 134 |
| 135 class AdViewNotEnabledTest : public extensions::PlatformAppBrowserTest { |
| 136 protected: |
| 137 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 138 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 139 //Note: The "kEnableAdview" flag is not here! |
| 140 } |
| 141 }; |
| 142 |
| 143 // This test checks an <adview> element has no behavior when the "kEnableAdview" |
| 144 // flag is missing. |
| 145 IN_PROC_BROWSER_TEST_F(AdViewNotEnabledTest, EnableAdviewFlagRequired) { |
| 146 ASSERT_TRUE(StartTestServer()); |
| 147 |
| 148 ASSERT_TRUE(RunPlatformAppTest( |
| 149 "platform_apps/ad_view/flag_required")) << message_; |
| 150 } |
OLD | NEW |