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