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
3 // found in the LICENSE file.
5 #include "chrome/browser/apps/app_browsertest_util.h"
6 #include "chrome/browser/extensions/extension_test_message_listener.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"
11 class AdViewTest
: public extensions::PlatformAppBrowserTest
{
13 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
14 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line
);
15 command_line
->AppendSwitch(switches::kEnableAdview
);
16 command_line
->AppendSwitch(switches::kEnableAdviewSrcAttribute
);
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
) {
23 ASSERT_TRUE(StartEmbeddedTestServer());
25 ASSERT_TRUE(RunPlatformAppTest(
26 "platform_apps/ad_view/loadcommit_event")) << message_
;
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(StartEmbeddedTestServer());
34 ASSERT_TRUE(RunPlatformAppTest(
35 "platform_apps/ad_view/loadabort_event")) << message_
;
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.
42 // Flaky, or takes too long time on Win7. (http://crbug.com/230271)
43 #define MAYBE_CommitMessageFromAdNetwork DISABLED_CommitMessageFromAdNetwork
45 #define MAYBE_CommitMessageFromAdNetwork CommitMessageFromAdNetwork
47 IN_PROC_BROWSER_TEST_F(AdViewTest
, MAYBE_CommitMessageFromAdNetwork
) {
48 ASSERT_TRUE(StartEmbeddedTestServer());
50 ASSERT_TRUE(RunPlatformAppTest(
51 "platform_apps/ad_view/onloadcommit_ack")) << message_
;
54 // This test checks the page running inside an <adview> has the ability to load
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
59 IN_PROC_BROWSER_TEST_F(AdViewTest
, DISABLED_DisplayFirstAd
) {
60 ASSERT_TRUE(StartEmbeddedTestServer());
62 ASSERT_TRUE(RunPlatformAppTest(
63 "platform_apps/ad_view/display_first_ad")) << message_
;
66 // This test checks that <adview> attributes are also exposed as properties
67 // (with the same name and value).
69 // Flaky on Win XP. (http://crbug.com/264362)
70 #define MAYBE_PropertiesAreInSyncWithAttributes \
71 DISABLED_PropertiesAreInSyncWithAttributes
73 #define MAYBE_PropertiesAreInSyncWithAttributes \
74 PropertiesAreInSyncWithAttributes
76 IN_PROC_BROWSER_TEST_F(AdViewTest
, MAYBE_PropertiesAreInSyncWithAttributes
) {
77 ASSERT_TRUE(StartEmbeddedTestServer());
79 ASSERT_TRUE(RunPlatformAppTest(
80 "platform_apps/ad_view/properties_exposed")) << message_
;
83 // This test checks an <adview> element has no behavior when the "adview"
84 // permission is missing from the application manifest.
85 IN_PROC_BROWSER_TEST_F(AdViewTest
, AdViewPermissionIsRequired
) {
86 ASSERT_TRUE(StartEmbeddedTestServer());
88 ASSERT_TRUE(RunPlatformAppTest(
89 "platform_apps/ad_view/permission_required")) << message_
;
92 // This test checks that 1) it is possible change the value of the "ad-network"
93 // attribute of an <adview> element and 2) changing the value will reset the
95 // Broken test: http://crbug.com/257465.
96 IN_PROC_BROWSER_TEST_F(AdViewTest
, DISABLED_ChangeAdNetworkValue
) {
97 ASSERT_TRUE(StartEmbeddedTestServer());
99 ASSERT_TRUE(RunPlatformAppTest(
100 "platform_apps/ad_view/change_ad_network")) << message_
;
103 class AdViewNoSrcTest
: public extensions::PlatformAppBrowserTest
{
105 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
106 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line
);
107 command_line
->AppendSwitch(switches::kEnableAdview
);
108 //Note: The "kEnableAdviewSrcAttribute" flag is not here!
112 // This test checks an invalid "ad-network" value (i.e. not whitelisted)
114 IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest
, InvalidAdNetworkIsIgnored
) {
115 ASSERT_TRUE(StartEmbeddedTestServer());
117 ASSERT_TRUE(RunPlatformAppTest(
118 "platform_apps/ad_view/invalid_ad_network")) << message_
;
121 // This test checks the "src" attribute is ignored when the
122 // "kEnableAdviewSrcAttribute" is missing.
123 IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest
, EnableAdviewSrcAttributeFlagRequired
) {
124 ASSERT_TRUE(StartEmbeddedTestServer());
126 ASSERT_TRUE(RunPlatformAppTest(
127 "platform_apps/ad_view/src_flag_required")) << message_
;
130 // This test checks 1) an <adview> works end-to-end (i.e. page is loaded) when
131 // using a whitelisted ad-network, and 2) the "src" attribute is never exposed
132 // to the application.
133 IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest
, SrcNotExposed
) {
134 base::FilePath file_path
= test_data_dir_
135 .AppendASCII("platform_apps")
136 .AppendASCII("ad_view/src_not_exposed")
137 .AppendASCII("ad_network_fake_website.html");
139 // Note: The following URL is identical to the whitelisted url
140 // for "admob" (see ad_view.js).
141 GURL url
= GURL("https://admob-sdk.doubleclick.net/chromeapps");
142 std::string scheme
= url
.scheme();
143 std::string hostname
= url
.host();
145 content::URLRequestPrepackagedInterceptor
interceptor(scheme
, hostname
);
146 interceptor
.SetResponse(url
, file_path
);
148 ASSERT_TRUE(RunPlatformAppTest(
149 "platform_apps/ad_view/src_not_exposed")) << message_
;
150 ASSERT_EQ(1, interceptor
.GetHitCount());
153 class AdViewNotEnabledTest
: public extensions::PlatformAppBrowserTest
{
155 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
156 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line
);
157 //Note: The "kEnableAdview" flag is not here!
161 // This test checks an <adview> element has no behavior when the "kEnableAdview"
163 IN_PROC_BROWSER_TEST_F(AdViewNotEnabledTest
, EnableAdviewFlagRequired
) {
164 ASSERT_TRUE(StartEmbeddedTestServer());
166 ASSERT_TRUE(RunPlatformAppTest(
167 "platform_apps/ad_view/flag_required")) << message_
;