Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: chrome/browser/extensions/ad_view_browsertest.cc

Issue 12967016: Improve <adview> implementation and add tests. (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Disable test with dependency on binary file. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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) {
32 ASSERT_TRUE(StartTestServer());
33
34 ASSERT_TRUE(RunPlatformAppTest(
35 "platform_apps/ad_view/loadabort_event")) << message_;
36 }
37
38 // This test checks the page loaded inside an <adview> has the ability to
39 // 1) receive "message" events from the application, and 2) use
40 // "window.postMessage" to post back a message to the application.
26 #if defined(OS_WIN) 41 #if defined(OS_WIN)
27 // Flaky, or takes too long time on Win7. (http://crbug.com/230271) 42 // Flaky, or takes too long time on Win7. (http://crbug.com/230271)
28 #define MAYBE_AdNetworkIsLoaded DISABLED_AdNetworkIsLoaded 43 #define MAYBE_CommitMessageFromAdNetwork DISABLED_CommitMessageFromAdNetwork
29 #else 44 #else
30 #define MAYBE_AdNetworkIsLoaded AdNetworkIsLoaded 45 #define MAYBE_CommitMessageFromAdNetwork CommitMessageFromAdNetwork
31 #endif 46 #endif
32 IN_PROC_BROWSER_TEST_F(AdViewTest, MAYBE_AdNetworkIsLoaded) { 47 IN_PROC_BROWSER_TEST_F(AdViewTest, MAYBE_CommitMessageFromAdNetwork) {
33 ASSERT_TRUE(StartTestServer()); 48 ASSERT_TRUE(StartTestServer());
34 49
35 ExtensionTestMessageListener listener("ad-network-loaded", false); 50 ASSERT_TRUE(RunPlatformAppTest(
36 LoadAndLaunchPlatformApp("ad_view/ad_network_loaded"); 51 "platform_apps/ad_view/onloadcommit_ack")) << message_;
37 ASSERT_TRUE(listener.WaitUntilSatisfied());
38 } 52 }
39 53
40 // This test currently fails on trybots because it requires new binary file 54 // This test checks the page running inside an <adview> has the ability to load
41 // (image315.png). The test will be enabled once the binary files are committed. 55 // and display an image inside an <iframe>.
56 // Note: Disabled for initial checkin because the test depends on a binary
57 // file (image035.png) which the trybots don't process correctly when
58 // first checked-in.
42 IN_PROC_BROWSER_TEST_F(AdViewTest, DISABLED_DisplayFirstAd) { 59 IN_PROC_BROWSER_TEST_F(AdViewTest, DISABLED_DisplayFirstAd) {
43 ASSERT_TRUE(StartTestServer()); 60 ASSERT_TRUE(StartTestServer());
44 61
45 ExtensionTestMessageListener listener("ad-displayed", false); 62 ASSERT_TRUE(RunPlatformAppTest(
46 LoadAndLaunchPlatformApp("ad_view/display_first_ad"); 63 "platform_apps/ad_view/display_first_ad")) << message_;
47 ASSERT_TRUE(listener.WaitUntilSatisfied());
48 } 64 }
65
66 // This test checks that <adview> attributes are also exposed as properties
67 // (with the same name and value).
68 IN_PROC_BROWSER_TEST_F(AdViewTest, PropertiesAreInSyncWithAttributes) {
69 ASSERT_TRUE(StartTestServer());
70
71 ASSERT_TRUE(RunPlatformAppTest(
72 "platform_apps/ad_view/properties_exposed")) << message_;
73 }
74
75 // This test checks an <adview> element has no behavior when the "adview"
76 // permission is missing from the application manifest.
77 IN_PROC_BROWSER_TEST_F(AdViewTest, AdViewPermissionIsRequired) {
78 ASSERT_TRUE(StartTestServer());
79
80 ASSERT_TRUE(RunPlatformAppTest(
81 "platform_apps/ad_view/permission_required")) << message_;
82 }
83
84 // This test checks that 1) it is possible change the value of the "ad-network"
85 // attribute of an <adview> element and 2) changing the value will reset the
86 // "src" attribute.
87 IN_PROC_BROWSER_TEST_F(AdViewTest, ChangeAdNetworkValue) {
88 ASSERT_TRUE(StartTestServer());
89
90 ASSERT_TRUE(RunPlatformAppTest(
91 "platform_apps/ad_view/change_ad_network")) << message_;
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 ASSERT_TRUE(RunPlatformAppTest(
109 "platform_apps/ad_view/invalid_ad_network")) << message_;
110 }
111
112 // This test checks the "src" attribute is ignored when the
113 // "kEnableAdviewSrcAttribute" is missing.
114 IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, EnableAdviewSrcAttributeFlagRequired) {
115 ASSERT_TRUE(StartTestServer());
116
117 ASSERT_TRUE(RunPlatformAppTest(
118 "platform_apps/ad_view/src_flag_required")) << message_;
119 }
120
121 // This test checks 1) an <adview> works end-to-end (i.e. page is loaded) when
122 // using a whitelisted ad-network, and 2) the "src" attribute is never exposed
123 // to the application.
124 IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, SrcNotExposed) {
125 base::FilePath file_path = test_data_dir_
126 .AppendASCII("platform_apps")
127 .AppendASCII("ad_view/src_not_exposed")
128 .AppendASCII("ad_network_fake_website.html");
129
130 // Note: The following URL is identical to the whitelisted url
131 // for "admob" (see ad_view.js).
132 GURL url = GURL("https://admob-sdk.doubleclick.net/chromeapps");
133 std::string scheme = url.scheme();
134 std::string hostname = url.host();
135
136 content::URLRequestPrepackagedInterceptor interceptor(scheme, hostname);
137 interceptor.SetResponse(url, file_path);
138
139 ASSERT_TRUE(RunPlatformAppTest(
140 "platform_apps/ad_view/src_not_exposed")) << message_;
141 ASSERT_EQ(1, interceptor.GetHitCount());
142 }
143
144 class AdViewNotEnabledTest : public extensions::PlatformAppBrowserTest {
145 protected:
146 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
147 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
148 //Note: The "kEnableAdview" flag is not here!
149 }
150 };
151
152 // This test checks an <adview> element has no behavior when the "kEnableAdview"
153 // flag is missing.
154 IN_PROC_BROWSER_TEST_F(AdViewNotEnabledTest, EnableAdviewFlagRequired) {
155 ASSERT_TRUE(StartTestServer());
156
157 ASSERT_TRUE(RunPlatformAppTest(
158 "platform_apps/ad_view/flag_required")) << message_;
159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698