Chromium Code Reviews| 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 IN_PROC_BROWSER_TEST_F(AdViewTest, LoadCommitEventIsCalled) { |
| 19 ASSERT_TRUE(StartTestServer()); | 22 ASSERT_TRUE(StartTestServer()); |
| 20 | 23 |
| 21 ExtensionTestMessageListener listener("guest-loaded", false); | 24 ExtensionTestMessageListener listener("guest-loaded", false); |
| 22 LoadAndLaunchPlatformApp("ad_view/load_event"); | 25 LoadAndLaunchPlatformApp("ad_view/loadcommit_event"); |
| 23 ASSERT_TRUE(listener.WaitUntilSatisfied()); | 26 ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| 24 } | 27 } |
| 25 | 28 |
| 26 IN_PROC_BROWSER_TEST_F(AdViewTest, AdNetworkIsLoaded) { | 29 IN_PROC_BROWSER_TEST_F(AdViewTest, LoadAbortEventIsCalled) { |
| 27 ASSERT_TRUE(StartTestServer()); | 30 ASSERT_TRUE(StartTestServer()); |
| 28 | 31 |
| 29 ExtensionTestMessageListener listener("ad-network-loaded", false); | 32 ExtensionTestMessageListener listener("loadabort-received", false); |
| 30 LoadAndLaunchPlatformApp("ad_view/ad_network_loaded"); | 33 LoadAndLaunchPlatformApp("ad_view/loadabort_event"); |
| 34 ASSERT_TRUE(listener.WaitUntilSatisfied()); | |
| 35 } | |
| 36 | |
| 37 IN_PROC_BROWSER_TEST_F(AdViewTest, CommitMessageFromAdNetwork) { | |
| 38 ASSERT_TRUE(StartTestServer()); | |
| 39 | |
| 40 ExtensionTestMessageListener listener("onloadcommit-ack-message", false); | |
| 41 LoadAndLaunchPlatformApp("ad_view/onloadcommit_ack"); | |
| 31 ASSERT_TRUE(listener.WaitUntilSatisfied()); | 42 ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| 32 } | 43 } |
| 33 | 44 |
| 34 // This test currently fails on trybots because it requires new binary file | 45 // This test currently fails on trybots because it requires new binary file |
| 35 // (image315.png). The test will be enabled once the binary files are committed. | 46 // (image315.png). The test will be enabled once the binary files are committed. |
|
benwells
2013/03/27 21:43:05
Is this comment out of date now?
rpaquay
2013/03/27 22:57:25
Yes, I removed it. Note that I actually expect thi
| |
| 36 IN_PROC_BROWSER_TEST_F(AdViewTest, DISABLED_DisplayFirstAd) { | 47 IN_PROC_BROWSER_TEST_F(AdViewTest, DisplayFirstAd) { |
| 37 ASSERT_TRUE(StartTestServer()); | 48 ASSERT_TRUE(StartTestServer()); |
| 38 | 49 |
| 39 ExtensionTestMessageListener listener("ad-displayed", false); | 50 ExtensionTestMessageListener listener("ad-displayed", false); |
| 40 LoadAndLaunchPlatformApp("ad_view/display_first_ad"); | 51 LoadAndLaunchPlatformApp("ad_view/display_first_ad"); |
| 41 ASSERT_TRUE(listener.WaitUntilSatisfied()); | 52 ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| 42 } | 53 } |
| 54 | |
| 55 IN_PROC_BROWSER_TEST_F(AdViewTest, PropertiesAreInSyncWithAttributes) { | |
| 56 ASSERT_TRUE(StartTestServer()); | |
| 57 | |
| 58 ExtensionTestMessageListener listener("test-finished", false); | |
| 59 LoadAndLaunchPlatformApp("ad_view/properties_exposed"); | |
| 60 ASSERT_TRUE(listener.WaitUntilSatisfied()); | |
| 61 } | |
| 62 | |
| 63 IN_PROC_BROWSER_TEST_F(AdViewTest, AdViewPermissionIsRequired) { | |
| 64 ASSERT_TRUE(StartTestServer()); | |
| 65 | |
| 66 ExtensionTestMessageListener listener("test-finished", false); | |
| 67 LoadAndLaunchPlatformApp("ad_view/permission_required"); | |
| 68 ASSERT_TRUE(listener.WaitUntilSatisfied()); | |
| 69 } | |
| 70 | |
| 71 IN_PROC_BROWSER_TEST_F(AdViewTest, ChangeAdNetworkValue) { | |
| 72 ASSERT_TRUE(StartTestServer()); | |
| 73 | |
| 74 ExtensionTestMessageListener listener("test-finished", false); | |
| 75 LoadAndLaunchPlatformApp("ad_view/change_ad_network"); | |
| 76 ASSERT_TRUE(listener.WaitUntilSatisfied()); | |
| 77 } | |
| 78 | |
| 79 | |
| 80 class AdViewNoSrcTest : public extensions::PlatformAppBrowserTest { | |
| 81 protected: | |
| 82 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 83 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); | |
| 84 command_line->AppendSwitch(switches::kEnableAdview); | |
| 85 //Note: The "kEnableAdviewSrcAttribute" flag is not here! | |
| 86 } | |
| 87 }; | |
| 88 | |
| 89 IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, InvalidAdNetworkIsIgnored) { | |
| 90 // The point of this test is to ensure an invalid (i.e. not whitelisted) | |
|
benwells
2013/03/27 21:43:05
These comments are helpful. Could you add them to
rpaquay
2013/03/27 22:57:25
Done.
| |
| 91 // value of "ad-network" attribute is ignored. | |
| 92 ASSERT_TRUE(StartTestServer()); | |
| 93 | |
| 94 ExtensionTestMessageListener listener("test-finished", false); | |
| 95 LoadAndLaunchPlatformApp("ad_view/invalid_ad_network"); | |
| 96 ASSERT_TRUE(listener.WaitUntilSatisfied()); | |
| 97 } | |
| 98 | |
| 99 IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, EnableAdviewSrcAttributeFlagRequired) { | |
| 100 // The point of this test is to ensure there are no HTTP request made | |
| 101 // to a non-whitelisted ad-network if the "src" attribute is set | |
| 102 // on an <adview> element. | |
| 103 ASSERT_TRUE(StartTestServer()); | |
| 104 | |
| 105 ExtensionTestMessageListener listener("test-finished", false); | |
| 106 LoadAndLaunchPlatformApp("ad_view/src_flag_required"); | |
| 107 ASSERT_TRUE(listener.WaitUntilSatisfied()); | |
| 108 } | |
| 109 | |
| 110 IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, SrcNotExposed) { | |
| 111 base::FilePath file_path = test_data_dir_ | |
| 112 .AppendASCII("platform_apps") | |
| 113 .AppendASCII("ad_view/src_not_exposed") | |
| 114 .AppendASCII("ad_network_fake_website.html"); | |
| 115 | |
| 116 // Note: The following URL is identical to the whitelisted url | |
| 117 // for "admob" (see ad_view.js). | |
| 118 GURL url = GURL("https://admob-sdk.doubleclick.net/chromeapps"); | |
| 119 std::string scheme = url.scheme(); | |
| 120 std::string hostname = url.host(); | |
| 121 | |
| 122 content::URLRequestPrepackagedInterceptor interceptor(scheme, hostname); | |
|
benwells
2013/03/27 21:43:05
Why does this test use an interceptor and the othe
rpaquay
2013/03/27 22:57:25
Because I thought it would be good to have a test
benwells
2013/03/28 00:16:48
That makes sense. I'm wondering if using the inter
| |
| 123 interceptor.SetResponse(url, file_path); | |
| 124 | |
| 125 ExtensionTestMessageListener listener("test-finished", false); | |
| 126 LoadAndLaunchPlatformApp("ad_view/src_not_exposed"); | |
| 127 ASSERT_TRUE(listener.WaitUntilSatisfied()); | |
| 128 ASSERT_EQ(1, interceptor.GetHitCount()); | |
| 129 } | |
| 130 | |
| 131 class AdViewNotEnabledTest : public extensions::PlatformAppBrowserTest { | |
| 132 protected: | |
| 133 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 134 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); | |
| 135 //Note: The "kEnableAdview" flag is not here! | |
| 136 } | |
| 137 }; | |
| 138 | |
| 139 IN_PROC_BROWSER_TEST_F(AdViewNotEnabledTest, EnableAdviewFlagRequired) { | |
| 140 // The point of this test is to ensure the <adview> tag does not do anything | |
| 141 // when the "kEnableAdview" flag is not set. | |
| 142 ASSERT_TRUE(StartTestServer()); | |
| 143 | |
| 144 ExtensionTestMessageListener listener("test-finished", false); | |
| 145 LoadAndLaunchPlatformApp("ad_view/flag_required"); | |
| 146 ASSERT_TRUE(listener.WaitUntilSatisfied()); | |
| 147 } | |
| OLD | NEW |