Chromium Code Reviews| Index: chrome/browser/extensions/ad_view_browsertest.cc |
| diff --git a/chrome/browser/extensions/ad_view_browsertest.cc b/chrome/browser/extensions/ad_view_browsertest.cc |
| index 4a70524d7600e530925692b884fdcae56a545410..0cd612daa3944f92d9c85ce9d7b88ff5533c8f80 100644 |
| --- a/chrome/browser/extensions/ad_view_browsertest.cc |
| +++ b/chrome/browser/extensions/ad_view_browsertest.cc |
| @@ -5,6 +5,9 @@ |
| #include "chrome/browser/extensions/extension_test_message_listener.h" |
| #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| #include "chrome/common/chrome_switches.h" |
| +#include "content/test/net/url_request_prepackaged_interceptor.h" |
| +#include "net/url_request/url_fetcher.h" |
| + |
| class AdViewTest : public extensions::PlatformAppBrowserTest { |
| protected: |
| @@ -15,28 +18,145 @@ class AdViewTest : public extensions::PlatformAppBrowserTest { |
| } |
| }; |
| -IN_PROC_BROWSER_TEST_F(AdViewTest, LoadEventIsCalled) { |
| +// This test checks the "loadcommit" event is called when the page inside an |
| +// <adview> is loaded. |
| +IN_PROC_BROWSER_TEST_F(AdViewTest, LoadCommitEventIsCalled) { |
| ASSERT_TRUE(StartTestServer()); |
| ExtensionTestMessageListener listener("guest-loaded", false); |
| - LoadAndLaunchPlatformApp("ad_view/load_event"); |
| + LoadAndLaunchPlatformApp("ad_view/loadcommit_event"); |
|
benwells
2013/03/28 00:16:48
Any reason not to use RunPaltformAppTest? You won'
|
| ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| } |
| -IN_PROC_BROWSER_TEST_F(AdViewTest, AdNetworkIsLoaded) { |
| +// This test checks the "loadabort" event is called when the "src" attribute |
| +// of an <adview> is an invalid URL. |
| +IN_PROC_BROWSER_TEST_F(AdViewTest, LoadAbortEventIsCalled) { |
| ASSERT_TRUE(StartTestServer()); |
| - ExtensionTestMessageListener listener("ad-network-loaded", false); |
| - LoadAndLaunchPlatformApp("ad_view/ad_network_loaded"); |
| + ExtensionTestMessageListener listener("loadabort-received", false); |
| + LoadAndLaunchPlatformApp("ad_view/loadabort_event"); |
| ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| } |
| -// This test currently fails on trybots because it requires new binary file |
| -// (image315.png). The test will be enabled once the binary files are committed. |
| -IN_PROC_BROWSER_TEST_F(AdViewTest, DISABLED_DisplayFirstAd) { |
| +// This test checks the page loaded inside an <adview> has the ability to |
| +// 1) receive "message" events from the application, and 2) use |
| +// "window.postMessage" to post back a message to the application. |
| +IN_PROC_BROWSER_TEST_F(AdViewTest, CommitMessageFromAdNetwork) { |
| + ASSERT_TRUE(StartTestServer()); |
| + |
| + ExtensionTestMessageListener listener("onloadcommit-ack-message", false); |
| + LoadAndLaunchPlatformApp("ad_view/onloadcommit_ack"); |
| + ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| +} |
| + |
| +// This test checks the page running inside an <adview> has the ability to load |
| +// and display an image inside an <iframe>. |
| +IN_PROC_BROWSER_TEST_F(AdViewTest, DisplayFirstAd) { |
| ASSERT_TRUE(StartTestServer()); |
| ExtensionTestMessageListener listener("ad-displayed", false); |
| LoadAndLaunchPlatformApp("ad_view/display_first_ad"); |
| ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| } |
| + |
| +// This test checks that <adview> attributes are also exposed as properties |
| +// (with the same name and value). |
| +IN_PROC_BROWSER_TEST_F(AdViewTest, PropertiesAreInSyncWithAttributes) { |
| + ASSERT_TRUE(StartTestServer()); |
| + |
| + ExtensionTestMessageListener listener("test-finished", false); |
| + LoadAndLaunchPlatformApp("ad_view/properties_exposed"); |
| + ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| +} |
| + |
| +// This test checks an <adview> element has no behavior when the "adview" |
| +// permission is missing from the application manifest. |
| +IN_PROC_BROWSER_TEST_F(AdViewTest, AdViewPermissionIsRequired) { |
| + ASSERT_TRUE(StartTestServer()); |
| + |
| + ExtensionTestMessageListener listener("test-finished", false); |
| + LoadAndLaunchPlatformApp("ad_view/permission_required"); |
| + ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| +} |
| + |
| +// This test checks that 1) it is possible change the value of the "ad-network" |
| +// attribute of an <adview> element and 2) changing the value will reset the |
| +// "src" attribute. |
| +IN_PROC_BROWSER_TEST_F(AdViewTest, ChangeAdNetworkValue) { |
| + ASSERT_TRUE(StartTestServer()); |
| + |
| + ExtensionTestMessageListener listener("test-finished", false); |
| + LoadAndLaunchPlatformApp("ad_view/change_ad_network"); |
| + ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| +} |
| + |
| + |
| +class AdViewNoSrcTest : public extensions::PlatformAppBrowserTest { |
| + protected: |
| + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| + extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| + command_line->AppendSwitch(switches::kEnableAdview); |
| + //Note: The "kEnableAdviewSrcAttribute" flag is not here! |
| + } |
| +}; |
| + |
| +// This test checks an invalid "ad-network" value (i.e. not whitelisted) |
| +// is ignored. |
| +IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, InvalidAdNetworkIsIgnored) { |
| + ASSERT_TRUE(StartTestServer()); |
| + |
| + ExtensionTestMessageListener listener("test-finished", false); |
| + LoadAndLaunchPlatformApp("ad_view/invalid_ad_network"); |
| + ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| +} |
| + |
| +// This test checks the "src" attribute is ignored when the |
| +// "kEnableAdviewSrcAttribute" is missing. |
| +IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, EnableAdviewSrcAttributeFlagRequired) { |
| + ASSERT_TRUE(StartTestServer()); |
| + |
| + ExtensionTestMessageListener listener("test-finished", false); |
| + LoadAndLaunchPlatformApp("ad_view/src_flag_required"); |
| + ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| +} |
| + |
| +// This test checks an <adview> works end-to-end (i.e. page is loaded) when |
| +// using a whitelisted ad-network. |
| +IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, SrcNotExposed) { |
| + base::FilePath file_path = test_data_dir_ |
| + .AppendASCII("platform_apps") |
| + .AppendASCII("ad_view/src_not_exposed") |
| + .AppendASCII("ad_network_fake_website.html"); |
| + |
| + // Note: The following URL is identical to the whitelisted url |
| + // for "admob" (see ad_view.js). |
| + GURL url = GURL("https://admob-sdk.doubleclick.net/chromeapps"); |
| + std::string scheme = url.scheme(); |
| + std::string hostname = url.host(); |
| + |
| + content::URLRequestPrepackagedInterceptor interceptor(scheme, hostname); |
| + interceptor.SetResponse(url, file_path); |
| + |
| + ExtensionTestMessageListener listener("test-finished", false); |
| + LoadAndLaunchPlatformApp("ad_view/src_not_exposed"); |
| + ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| + ASSERT_EQ(1, interceptor.GetHitCount()); |
| +} |
| + |
| +class AdViewNotEnabledTest : public extensions::PlatformAppBrowserTest { |
| + protected: |
| + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| + extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| + //Note: The "kEnableAdview" flag is not here! |
| + } |
| +}; |
| + |
| +// This test checks an <adview> element has no behavior when the "kEnableAdview" |
| +// flag is missing. |
| +IN_PROC_BROWSER_TEST_F(AdViewNotEnabledTest, EnableAdviewFlagRequired) { |
| + ASSERT_TRUE(StartTestServer()); |
| + |
| + ExtensionTestMessageListener listener("test-finished", false); |
| + LoadAndLaunchPlatformApp("ad_view/flag_required"); |
| + ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| +} |