diff options
author | rpaquay@chromium.org <rpaquay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-24 05:10:08 +0000 |
---|---|---|
committer | rpaquay@chromium.org <rpaquay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-24 05:10:08 +0000 |
commit | 98c1d817896f8723dcf348d6e6d292c42f9a6c13 (patch) | |
tree | 87c532f5b302008255ec94f2bd7bb150b778cb37 | |
parent | 5b3ffa0cb78f4ce63633bddff2b8be03a2f18f93 (diff) | |
download | chromium_src-98c1d817896f8723dcf348d6e6d292c42f9a6c13.zip chromium_src-98c1d817896f8723dcf348d6e6d292c42f9a6c13.tar.gz chromium_src-98c1d817896f8723dcf348d6e6d292c42f9a6c13.tar.bz2 |
Improve <adview> implementation and add tests.
The first CL for bug 180618 contained initial support for the <adview> tag. This is a follow up CL to
* fix issues related to various combinations of flags, permissions and property/attributes behavior,
* add corresponding tests,
* and improve code readability of "ad_view.js"
BUG=226125
TBR=asargent@chromium.org (for trivial changes in chrome/browser/component_updater/test/component_updater_service_unittest.cc)
Review URL: https://chromiumcodereview.appspot.com/12967016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196036 0039d316-1c4b-4281-b951-d872f2087c98
61 files changed, 1351 insertions, 252 deletions
diff --git a/chrome/browser/component_updater/test/component_updater_service_unittest.cc b/chrome/browser/component_updater/test/component_updater_service_unittest.cc index 6689e49..ce85ad1 100644 --- a/chrome/browser/component_updater/test/component_updater_service_unittest.cc +++ b/chrome/browser/component_updater/test/component_updater_service_unittest.cc @@ -294,7 +294,7 @@ TEST_F(ComponentUpdaterTest, CheckCrxSleep) { io_thread.StartIOThread(); file_thread.Start(); - content::URLRequestPrepackagedInterceptor interceptor; + content::URLLocalHostRequestPrepackagedInterceptor interceptor; CrxComponent com; EXPECT_EQ(ComponentUpdateService::kOk, @@ -373,7 +373,7 @@ TEST_F(ComponentUpdaterTest, InstallCrx) { io_thread.StartIOThread(); file_thread.Start(); - content::URLRequestPrepackagedInterceptor interceptor; + content::URLLocalHostRequestPrepackagedInterceptor interceptor; CrxComponent com1; RegisterComponent(&com1, kTestComponent_jebg, Version("0.9")); @@ -438,7 +438,7 @@ TEST_F(ComponentUpdaterTest, InstallCrxTwoSources) { io_thread.StartIOThread(); file_thread.Start(); - content::URLRequestPrepackagedInterceptor interceptor; + content::URLLocalHostRequestPrepackagedInterceptor interceptor; CrxComponent com1; RegisterComponent(&com1, kTestComponent_abag, Version("2.2")); @@ -510,7 +510,7 @@ TEST_F(ComponentUpdaterTest, ProdVersionCheck) { io_thread.StartIOThread(); file_thread.Start(); - content::URLRequestPrepackagedInterceptor interceptor; + content::URLLocalHostRequestPrepackagedInterceptor interceptor; CrxComponent com; RegisterComponent(&com, kTestComponent_jebg, Version("0.9")); @@ -550,7 +550,7 @@ TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) { io_thread.StartIOThread(); file_thread.Start(); - content::URLRequestPrepackagedInterceptor interceptor; + content::URLLocalHostRequestPrepackagedInterceptor interceptor; CrxComponent com1; RegisterComponent(&com1, kTestComponent_abag, Version("2.2")); @@ -666,7 +666,7 @@ TEST_F(ComponentUpdaterTest, CheckReRegistration) { io_thread.StartIOThread(); file_thread.Start(); - content::URLRequestPrepackagedInterceptor interceptor; + content::URLLocalHostRequestPrepackagedInterceptor interceptor; CrxComponent com1; RegisterComponent(&com1, kTestComponent_jebg, Version("0.9")); diff --git a/chrome/browser/extensions/ad_view_browsertest.cc b/chrome/browser/extensions/ad_view_browsertest.cc index bb6310a..0391268 100644 --- a/chrome/browser/extensions/ad_view_browsertest.cc +++ b/chrome/browser/extensions/ad_view_browsertest.cc @@ -1,10 +1,12 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #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,34 +17,143 @@ 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"); - ASSERT_TRUE(listener.WaitUntilSatisfied()); + ASSERT_TRUE(RunPlatformAppTest( + "platform_apps/ad_view/loadcommit_event")) << message_; } +// 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()); + + ASSERT_TRUE(RunPlatformAppTest( + "platform_apps/ad_view/loadabort_event")) << message_; +} + +// 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. #if defined(OS_WIN) // Flaky, or takes too long time on Win7. (http://crbug.com/230271) -#define MAYBE_AdNetworkIsLoaded DISABLED_AdNetworkIsLoaded +#define MAYBE_CommitMessageFromAdNetwork DISABLED_CommitMessageFromAdNetwork #else -#define MAYBE_AdNetworkIsLoaded AdNetworkIsLoaded +#define MAYBE_CommitMessageFromAdNetwork CommitMessageFromAdNetwork #endif -IN_PROC_BROWSER_TEST_F(AdViewTest, MAYBE_AdNetworkIsLoaded) { +IN_PROC_BROWSER_TEST_F(AdViewTest, MAYBE_CommitMessageFromAdNetwork) { ASSERT_TRUE(StartTestServer()); - ExtensionTestMessageListener listener("ad-network-loaded", false); - LoadAndLaunchPlatformApp("ad_view/ad_network_loaded"); - ASSERT_TRUE(listener.WaitUntilSatisfied()); + ASSERT_TRUE(RunPlatformAppTest( + "platform_apps/ad_view/onloadcommit_ack")) << message_; } -// 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. +// This test checks the page running inside an <adview> has the ability to load +// and display an image inside an <iframe>. +// Note: Disabled for initial checkin because the test depends on a binary +// file (image035.png) which the trybots don't process correctly when +// first checked-in. IN_PROC_BROWSER_TEST_F(AdViewTest, DISABLED_DisplayFirstAd) { ASSERT_TRUE(StartTestServer()); - ExtensionTestMessageListener listener("ad-displayed", false); - LoadAndLaunchPlatformApp("ad_view/display_first_ad"); - ASSERT_TRUE(listener.WaitUntilSatisfied()); + ASSERT_TRUE(RunPlatformAppTest( + "platform_apps/ad_view/display_first_ad")) << message_; +} + +// 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()); + + ASSERT_TRUE(RunPlatformAppTest( + "platform_apps/ad_view/properties_exposed")) << message_; +} + +// 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()); + + ASSERT_TRUE(RunPlatformAppTest( + "platform_apps/ad_view/permission_required")) << message_; +} + +// 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()); + + ASSERT_TRUE(RunPlatformAppTest( + "platform_apps/ad_view/change_ad_network")) << message_; +} + +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()); + + ASSERT_TRUE(RunPlatformAppTest( + "platform_apps/ad_view/invalid_ad_network")) << message_; +} + +// This test checks the "src" attribute is ignored when the +// "kEnableAdviewSrcAttribute" is missing. +IN_PROC_BROWSER_TEST_F(AdViewNoSrcTest, EnableAdviewSrcAttributeFlagRequired) { + ASSERT_TRUE(StartTestServer()); + + ASSERT_TRUE(RunPlatformAppTest( + "platform_apps/ad_view/src_flag_required")) << message_; +} + +// This test checks 1) an <adview> works end-to-end (i.e. page is loaded) when +// using a whitelisted ad-network, and 2) the "src" attribute is never exposed +// to the application. +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); + + ASSERT_TRUE(RunPlatformAppTest( + "platform_apps/ad_view/src_not_exposed")) << message_; + 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()); + + ASSERT_TRUE(RunPlatformAppTest( + "platform_apps/ad_view/flag_required")) << message_; } diff --git a/chrome/browser/extensions/api/management/management_browsertest.cc b/chrome/browser/extensions/api/management/management_browsertest.cc index b2dc049..03b0514 100644 --- a/chrome/browser/extensions/api/management/management_browsertest.cc +++ b/chrome/browser/extensions/api/management/management_browsertest.cc @@ -250,7 +250,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, MAYBE_AutoUpdate) { NotificationListener notification_listener; base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); // Note: This interceptor gets requests on the IO thread. - content::URLRequestPrepackagedInterceptor interceptor; + content::URLLocalHostRequestPrepackagedInterceptor interceptor; net::URLFetcher::SetEnableInterceptionForTests(true); interceptor.SetResponseIgnoreQuery( @@ -336,7 +336,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, NotificationListener notification_listener; base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); // Note: This interceptor gets requests on the IO thread. - content::URLRequestPrepackagedInterceptor interceptor; + content::URLLocalHostRequestPrepackagedInterceptor interceptor; net::URLFetcher::SetEnableInterceptionForTests(true); interceptor.SetResponseIgnoreQuery( @@ -412,7 +412,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, MAYBE_ExternalUrlUpdate) { base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); // Note: This interceptor gets requests on the IO thread. - content::URLRequestPrepackagedInterceptor interceptor; + content::URLLocalHostRequestPrepackagedInterceptor interceptor; net::URLFetcher::SetEnableInterceptionForTests(true); interceptor.SetResponseIgnoreQuery( @@ -498,7 +498,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalPolicyRefresh) { base::FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); // Note: This interceptor gets requests on the IO thread. - content::URLRequestPrepackagedInterceptor interceptor; + content::URLLocalHostRequestPrepackagedInterceptor interceptor; net::URLFetcher::SetEnableInterceptionForTests(true); interceptor.SetResponseIgnoreQuery( @@ -573,7 +573,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ASSERT_TRUE(service->disabled_extensions()->is_empty()); // Note: This interceptor gets requests on the IO thread. - content::URLRequestPrepackagedInterceptor interceptor; + content::URLLocalHostRequestPrepackagedInterceptor interceptor; net::URLFetcher::SetEnableInterceptionForTests(true); interceptor.SetResponseIgnoreQuery( diff --git a/chrome/browser/extensions/extension_disabled_ui_browsertest.cc b/chrome/browser/extensions/extension_disabled_ui_browsertest.cc index 215ef7d..7c8934a 100644 --- a/chrome/browser/extensions/extension_disabled_ui_browsertest.cc +++ b/chrome/browser/extensions/extension_disabled_ui_browsertest.cc @@ -189,7 +189,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, InstallIncreasingPermissionExtensionV1(); // Note: This interceptor gets requests on the IO thread. - content::URLRequestPrepackagedInterceptor interceptor; + content::URLLocalHostRequestPrepackagedInterceptor interceptor; net::URLFetcher::SetEnableInterceptionForTests(true); interceptor.SetResponseIgnoreQuery( GURL("http://localhost/autoupdate/updates.xml"), diff --git a/chrome/renderer/resources/extensions/ad_view.js b/chrome/renderer/resources/extensions/ad_view.js index 84c7008..0a7aab4 100644 --- a/chrome/renderer/resources/extensions/ad_view.js +++ b/chrome/renderer/resources/extensions/ad_view.js @@ -1,4 +1,4 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -15,99 +15,86 @@ var chrome = requireNative('chrome').GetChrome(); var forEach = require('utils').forEach; var watchForTag = require('tagWatcher').watchForTag; - +/** + * Define "allowCustomAdNetworks" function such that it returns "true" if the + * "adViewCustom" module was injected. This is so that the + * "kEnableAdviewSrcAttribute" flag is respected. + */ var allowCustomAdNetworks = (function(allow){ return function() { return Boolean(allow); } })(adViewCustom ? adViewCustom.enabled : false); - -// List of attribute names to "blindly" sync between <adview> tag and internal -// browser plugin. +/** + * List of attribute names to "blindly" sync between <adview> tag and internal + * browser plugin. + */ var AD_VIEW_ATTRIBUTES = [ 'name', ]; -// List of custom attributes (and their behavior) -// -// name: attribute name. -// onInit(adview): callback invoked when the <adview> element is created. -// onMutate(adview, mutation): callback invoked when attribute is mutated. +/** + * List of custom attributes (and their behavior). + * + * name: attribute name. + * onMutation(adview, mutation): callback invoked when attribute is mutated. + * isProperty: True if the attribute should be exposed as a property. + */ var AD_VIEW_CUSTOM_ATTRIBUTES = [ { - 'name': "ad-network", - 'onInit': function(adview) { - if (adview.node_.hasAttribute(this.name)) { - var value = adview.node_.getAttribute(this.name); - var item = getAdNetworkInfo(value); - if (item) { - adview.objectNode_.setAttribute("src", item.url); - } - else if (allowCustomAdNetworks()) { - console.log('The ad-network \"' + value + '\" is not recognized, ' + - 'but custom ad-networks are enabled.'); - } - else { - console.error('The ad-network \"' + value + '\" is not recognized.'); - } - } + name: 'ad-network', + onMutation: function(adview, mutation) { + adview.handleAdNetworkMutation(mutation); + }, + isProperty: function() { + return true; } }, { - 'name': "src", - 'onInit': function(adview) { - if (allowCustomAdNetworks()) { - if (adview.node_.hasAttribute(this.name)) { - var newValue = adview.node_.getAttribute(this.name); - adview.objectNode_.setAttribute("src", newValue); - } - } + name: 'src', + onMutation: function(adview, mutation) { + adview.handleSrcMutation(mutation); }, - 'onMutation': function(adview, mutation) { - if (allowCustomAdNetworks()) { - if (adview.node_.hasAttribute(this.name)) { - var newValue = adview.node_.getAttribute(this.name); - // Note: setAttribute does not work as intended here. - //adview.objectNode_.setAttribute(this.name, newValue); - adview.objectNode_[this.name] = newValue; - } - else { - // If an attribute is removed from the BrowserPlugin, then remove it - // from the <adview> as well. - this.objectNode_.removeAttribute(this.name); - } - } + isProperty: function() { + return allowCustomAdNetworks(); } } ]; -// List of api methods. These are forwarded to the browser plugin. +/** + * List of api methods. These are forwarded to the browser plugin. + */ var AD_VIEW_API_METHODS = [ // Empty for now. ]; -// List of events to blindly forward from the browser plugin to the <adview>. +/** + * List of events to blindly forward from the browser plugin to the <adview>. + */ var AD_VIEW_EVENTS = { - 'loadcommit' : [], + 'loadabort' : ['url', 'isTopLevel', 'reason'], + 'loadcommit' : ['url', 'isTopLevel'], 'sizechanged': ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'], }; -// List of supported ad-networks. -// -// name: identifier of the ad-network, corresponding to a valid value -// of the "ad-network" attribute of an <adview> element. -// url: url to navigate to when initially displaying the <adview>. -// origin: origin of urls the <adview> is allowed navigate to. +/** + * List of supported ad-networks. + * + * name: identifier of the ad-network, corresponding to a valid value + * of the "ad-network" attribute of an <adview> element. + * url: url to navigate to when initially displaying the <adview>. + * origin: origin of urls the <adview> is allowed navigate to. + */ var AD_VIEW_AD_NETWORKS_WHITELIST = [ { - 'name': 'admob', - 'url': 'https://admob-sdk.doubleclick.net/chromeapps', - 'origin': 'https://double.net' + name: 'admob', + url: 'https://admob-sdk.doubleclick.net/chromeapps', + origin: 'https://double.net' }, ]; -// -// Return the whitelisted ad-network entry named |name|. -// +/** + * Return the whitelisted ad-network entry named |name|. + */ function getAdNetworkInfo(name) { var result = null; forEach(AD_VIEW_AD_NETWORKS_WHITELIST, function(i, item) { @@ -120,133 +107,194 @@ function getAdNetworkInfo(name) { /** * @constructor */ -function AdView(node) { - this.node_ = node; - var shadowRoot = node.webkitCreateShadowRoot(); +function AdView(adviewNode) { + this.adviewNode_ = adviewNode; + this.browserPluginNode_ = this.createBrowserPluginNode_(); + var shadowRoot = this.adviewNode_.webkitCreateShadowRoot(); + shadowRoot.appendChild(this.browserPluginNode_); + + this.setupCustomAttributes_(); + this.setupAdviewNodeObservers_(); + this.setupAdviewNodeMethods_(); + this.setupAdviewNodeProperties_(); + this.setupAdviewNodeEvents_(); + this.setupBrowserPluginNodeObservers_(); +} - this.objectNode_ = document.createElement('object'); - this.objectNode_.type = 'application/browser-plugin'; +/** + * @private + */ +AdView.prototype.createBrowserPluginNode_ = function() { + var browserPluginNode = document.createElement('object'); + browserPluginNode.type = 'application/browser-plugin'; // The <object> node fills in the <adview> container. - this.objectNode_.style.width = '100%'; - this.objectNode_.style.height = '100%'; + browserPluginNode.style.width = '100%'; + browserPluginNode.style.height = '100%'; forEach(AD_VIEW_ATTRIBUTES, function(i, attributeName) { // Only copy attributes that have been assigned values, rather than copying // a series of undefined attributes to BrowserPlugin. - if (this.node_.hasAttribute(attributeName)) { - this.objectNode_.setAttribute( - attributeName, this.node_.getAttribute(attributeName)); + if (this.adviewNode_.hasAttribute(attributeName)) { + browserPluginNode.setAttribute( + attributeName, this.adviewNode_.getAttribute(attributeName)); } }, this); + return browserPluginNode; +} + +/** + * @private + */ +AdView.prototype.setupCustomAttributes_ = function() { forEach(AD_VIEW_CUSTOM_ATTRIBUTES, function(i, attributeInfo) { - if (attributeInfo.onInit) { - attributeInfo.onInit(this); + if (attributeInfo.onMutation) { + attributeInfo.onMutation(this); } }, this); +} - shadowRoot.appendChild(this.objectNode_); - - // this.objectNode_[apiMethod] are not necessarily defined immediately after - // the shadow object is appended to the shadow root. +/** + * @private + */ +AdView.prototype.setupAdviewNodeMethods_ = function() { + // this.browserPluginNode_[apiMethod] are not necessarily defined immediately + // after the shadow object is appended to the shadow root. var self = this; forEach(AD_VIEW_API_METHODS, function(i, apiMethod) { - node[apiMethod] = function(var_args) { - return self.objectNode_[apiMethod].apply(self.objectNode_, arguments); + self.adviewNode_[apiMethod] = function(var_args) { + return self.browserPluginNode_[apiMethod].apply( + self.browserPluginNode_, arguments); }; }, this); +} +/** + * @private + */ +AdView.prototype.setupAdviewNodeObservers_ = function() { // Map attribute modifications on the <adview> tag to property changes in // the underlying <object> node. var handleMutation = function(i, mutation) { - this.handleMutation_(mutation); + this.handleAdviewAttributeMutation_(mutation); }.bind(this); var observer = new WebKitMutationObserver(function(mutations) { forEach(mutations, handleMutation); }); observer.observe( - this.node_, + this.adviewNode_, {attributes: true, attributeFilter: AD_VIEW_ATTRIBUTES}); - var handleObjectMutation = function(i, mutation) { - this.handleObjectMutation_(mutation); - }.bind(this); - var objectObserver = new WebKitMutationObserver(function(mutations) { - forEach(mutations, handleObjectMutation); - }); - objectObserver.observe( - this.objectNode_, - {attributes: true, attributeFilter: AD_VIEW_ATTRIBUTES}); + this.setupAdviewNodeCustomObservers_(); +} - // Map custom attribute modifications on the <adview> tag to property changes - // in the underlying <object> node. - var handleCustomMutation = function(i, mutation) { - this.handleCustomMutation_(mutation); +/** + * @private + */ +AdView.prototype.setupAdviewNodeCustomObservers_ = function() { + var handleMutation = function(i, mutation) { + this.handleAdviewCustomAttributeMutation_(mutation); }.bind(this); var observer = new WebKitMutationObserver(function(mutations) { - forEach(mutations, handleCustomMutation); + forEach(mutations, handleMutation); }); var customAttributeNames = AD_VIEW_CUSTOM_ATTRIBUTES.map(function(item) { return item.name; }); observer.observe( - this.node_, + this.adviewNode_, {attributes: true, attributeFilter: customAttributeNames}); +} - var objectNode = this.objectNode_; +/** + * @private + */ +AdView.prototype.setupBrowserPluginNodeObservers_ = function() { + var handleMutation = function(i, mutation) { + this.handleBrowserPluginAttributeMutation_(mutation); + }.bind(this); + var objectObserver = new WebKitMutationObserver(function(mutations) { + forEach(mutations, handleMutation); + }); + objectObserver.observe( + this.browserPluginNode_, + {attributes: true, attributeFilter: AD_VIEW_ATTRIBUTES}); +} + +/** + * @private + */ +AdView.prototype.setupAdviewNodeProperties_ = function() { + var browserPluginNode = this.browserPluginNode_; // Expose getters and setters for the attributes. forEach(AD_VIEW_ATTRIBUTES, function(i, attributeName) { - Object.defineProperty(this.node_, attributeName, { + Object.defineProperty(this.adviewNode_, attributeName, { get: function() { - return objectNode[attributeName]; + return browserPluginNode[attributeName]; }, set: function(value) { - objectNode[attributeName] = value; + browserPluginNode[attributeName] = value; }, enumerable: true }); }, this); + // Expose getters and setters for the custom attributes. + var adviewNode = this.adviewNode_; + forEach(AD_VIEW_CUSTOM_ATTRIBUTES, function(i, attributeInfo) { + if (attributeInfo.isProperty()) { + var attributeName = attributeInfo.name; + Object.defineProperty(this.adviewNode_, attributeName, { + get: function() { + return adviewNode.getAttribute(attributeName); + }, + set: function(value) { + adviewNode.setAttribute(attributeName, value); + }, + enumerable: true + }); + } + }, this); + + this.setupAdviewContentWindowProperty_(); +} + +/** + * @private + */ +AdView.prototype.setupAdviewContentWindowProperty_ = function() { + var browserPluginNode = this.browserPluginNode_; // We cannot use {writable: true} property descriptor because we want dynamic // getter value. - Object.defineProperty(this.node_, 'contentWindow', { + Object.defineProperty(this.adviewNode_, 'contentWindow', { get: function() { // TODO(fsamuel): This is a workaround to enable // contentWindow.postMessage until http://crbug.com/152006 is fixed. - if (objectNode.contentWindow) - return objectNode.contentWindow.self; + if (browserPluginNode.contentWindow) + return browserPluginNode.contentWindow.self; console.error('contentWindow is not available at this time. ' + 'It will become available when the page has finished loading.'); }, // No setter. enumerable: true }); - - for (var eventName in AD_VIEW_EVENTS) { - this.setupEvent_(eventName, AD_VIEW_EVENTS[eventName]); - } } /** * @private */ -AdView.prototype.handleMutation_ = function(mutation) { +AdView.prototype.handleAdviewAttributeMutation_ = function(mutation) { // This observer monitors mutations to attributes of the <adview> and // updates the BrowserPlugin properties accordingly. In turn, updating // a BrowserPlugin property will update the corresponding BrowserPlugin // attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more // details. - this.objectNode_[mutation.attributeName] = - this.node_.getAttribute(mutation.attributeName); + this.browserPluginNode_[mutation.attributeName] = + this.adviewNode_.getAttribute(mutation.attributeName); }; /** * @private */ -AdView.prototype.handleCustomMutation_ = function(mutation) { - // This observer monitors mutations to attributes of the <adview> and - // updates the BrowserPlugin properties accordingly. In turn, updating - // a BrowserPlugin property will update the corresponding BrowserPlugin - // attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more - // details. +AdView.prototype.handleAdviewCustomAttributeMutation_ = function(mutation) { forEach(AD_VIEW_CUSTOM_ATTRIBUTES, function(i, item) { if (mutation.attributeName.toUpperCase() == item.name.toUpperCase()) { if (item.onMutation) { @@ -259,13 +307,13 @@ AdView.prototype.handleCustomMutation_ = function(mutation) { /** * @private */ -AdView.prototype.handleObjectMutation_ = function(mutation) { +AdView.prototype.handleBrowserPluginAttributeMutation_ = function(mutation) { // This observer monitors mutations to attributes of the BrowserPlugin and // updates the <adview> attributes accordingly. - if (!this.objectNode_.hasAttribute(mutation.attributeName)) { + if (!this.browserPluginNode_.hasAttribute(mutation.attributeName)) { // If an attribute is removed from the BrowserPlugin, then remove it // from the <adview> as well. - this.node_.removeAttribute(mutation.attributeName); + this.adviewNode_.removeAttribute(mutation.attributeName); } else { // Update the <adview> attribute to match the BrowserPlugin attribute. // Note: Calling setAttribute on <adview> will trigger its mutation @@ -274,10 +322,10 @@ AdView.prototype.handleObjectMutation_ = function(mutation) { // again (such as navigation when crashed), this could end up in an infinite // loop. Thus, we avoid this loop by only updating the <adview> attribute // if the BrowserPlugin attributes differs from it. - var oldValue = this.node_.getAttribute(mutation.attributeName); - var newValue = this.objectNode_.getAttribute(mutation.attributeName); + var oldValue = this.adviewNode_.getAttribute(mutation.attributeName); + var newValue = this.browserPluginNode_.getAttribute(mutation.attributeName); if (newValue != oldValue) { - this.node_.setAttribute(mutation.attributeName, newValue); + this.adviewNode_.setAttribute(mutation.attributeName, newValue); } } }; @@ -285,23 +333,144 @@ AdView.prototype.handleObjectMutation_ = function(mutation) { /** * @private */ +AdView.prototype.navigateToUrl_ = function(url) { + var newValue = url; + var oldValue = this.browserPluginNode_.getAttribute('src'); + + if (newValue === oldValue) + return; + + if (url != null) { + // Note: Setting the 'src' property directly, as calling setAttribute has no + // effect due to implementation details of BrowserPlugin. + this.browserPluginNode_['src'] = url; + if (allowCustomAdNetworks()) { + this.adviewNode_.setAttribute('src', url); + } + } + else { + // Note: Setting the 'src' property directly, as calling setAttribute has no + // effect due to implementation details of BrowserPlugin. + // TODO(rpaquay): Due to another implementation detail of BrowserPlugin, + // this line will leave the "src" attribute value untouched. + this.browserPluginNode_['src'] = null; + if (allowCustomAdNetworks()) { + this.adviewNode_.removeAttribute('src'); + } + } +} + +/** + * @public + */ +AdView.prototype.handleAdNetworkMutation = function(mutation) { + if (this.adviewNode_.hasAttribute('ad-network')) { + var value = this.adviewNode_.getAttribute('ad-network'); + var item = getAdNetworkInfo(value); + if (item) { + this.navigateToUrl_(item.url); + } + else if (allowCustomAdNetworks()) { + console.log('The ad-network "' + value + '" is not recognized, ' + + 'but custom ad-networks are enabled.'); + + if (mutation) { + this.navigateToUrl_(''); + } + } + else { + // Ignore the new attribute value and set it to empty string. + // Avoid infinite loop by checking for empty string as new value. + if (value != '') { + console.error('The ad-network "' + value + '" is not recognized.'); + this.adviewNode_.setAttribute('ad-network', ''); + } + this.navigateToUrl_(''); + } + } + else { + this.navigateToUrl_(''); + } +} + +/** + * @public + */ +AdView.prototype.handleSrcMutation = function(mutation) { + if (allowCustomAdNetworks()) { + if (this.adviewNode_.hasAttribute('src')) { + var newValue = this.adviewNode_.getAttribute('src'); + // Note: Setting the 'src' property directly, as calling setAttribute has + // no effect due to implementation details of BrowserPlugin. + this.browserPluginNode_['src'] = newValue; + } + else { + // If an attribute is removed from the <adview>, then remove it + // from the BrowserPlugin as well. + // Note: Setting the 'src' property directly, as calling setAttribute has + // no effect due to implementation details of BrowserPlugin. + // TODO(rpaquay): Due to another implementation detail of BrowserPlugin, + // this line will leave the "src" attribute value untouched. + this.browserPluginNode_['src'] = null; + } + } + else { + if (this.adviewNode_.hasAttribute('src')) { + var value = this.adviewNode_.getAttribute('src'); + // Ignore the new attribute value and set it to empty string. + // Avoid infinite loop by checking for empty string as new value. + if (value != '') { + console.error('Setting the "src" attribute of an <adview> ' + + 'element is not supported. Use the "ad-network" attribute ' + + 'instead.'); + this.adviewNode_.setAttribute('src', ''); + } + } + } +} + +/** + * @private + */ +AdView.prototype.setupAdviewNodeEvents_ = function() { + for (var eventName in AD_VIEW_EVENTS) { + this.setupEvent_(eventName, AD_VIEW_EVENTS[eventName]); + } +} + +/** + * @private + */ AdView.prototype.setupEvent_ = function(eventname, attribs) { - var node = this.node_; - this.objectNode_.addEventListener('-internal-' + eventname, function(e) { + var adviewNode = this.adviewNode_; + var internalname = '-internal-' + eventname; + this.browserPluginNode_.addEventListener(internalname, function(e) { var evt = new Event(eventname, { bubbles: true }); var detail = e.detail ? JSON.parse(e.detail) : {}; forEach(attribs, function(i, attribName) { evt[attribName] = detail[attribName]; }); - node.dispatchEvent(evt); + adviewNode.dispatchEvent(evt); }); } +/** + * @public + */ +AdView.prototype.dispatchEvent = function(eventname, detail) { + // Create event object. + var evt = new Event(eventname, { bubbles: true }); + for(var item in detail) { + evt[item] = detail[item]; + } + + // Dispatch event. + this.adviewNode_.dispatchEvent(evt); +} + // // Hook up <adview> tag creation in DOM. // -var watchForTag = require("tagWatcher").watchForTag; - window.addEventListener('DOMContentLoaded', function() { watchForTag('ADVIEW', function(addedNode) { new AdView(addedNode); }); }); diff --git a/chrome/test/data/extensions/platform_apps/ad_view/ad_network/ads/image316.png b/chrome/test/data/extensions/platform_apps/ad_view/ad_network/ads/image316.png deleted file mode 100644 index e69de29..0000000 --- a/chrome/test/data/extensions/platform_apps/ad_view/ad_network/ads/image316.png +++ /dev/null diff --git a/chrome/test/data/extensions/platform_apps/ad_view/ad_network/ads/image317.png b/chrome/test/data/extensions/platform_apps/ad_view/ad_network/ads/image317.png deleted file mode 100644 index e69de29..0000000 --- a/chrome/test/data/extensions/platform_apps/ad_view/ad_network/ads/image317.png +++ /dev/null diff --git a/chrome/test/data/extensions/platform_apps/ad_view/ad_network/ads/image318.png b/chrome/test/data/extensions/platform_apps/ad_view/ad_network/ads/image318.png deleted file mode 100644 index e69de29..0000000 --- a/chrome/test/data/extensions/platform_apps/ad_view/ad_network/ads/image318.png +++ /dev/null diff --git a/chrome/test/data/extensions/platform_apps/ad_view/ad_network/ads/image319.png b/chrome/test/data/extensions/platform_apps/ad_view/ad_network/ads/image319.png deleted file mode 100644 index e69de29..0000000 --- a/chrome/test/data/extensions/platform_apps/ad_view/ad_network/ads/image319.png +++ /dev/null diff --git a/chrome/test/data/extensions/platform_apps/ad_view/ad_network_loaded/chrometest.js b/chrome/test/data/extensions/platform_apps/ad_view/ad_network_loaded/chrometest.js deleted file mode 100644 index f4f4f59..0000000 --- a/chrome/test/data/extensions/platform_apps/ad_view/ad_network_loaded/chrometest.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -chrome.test.getConfig(function(config) { - var guestURL = 'http://localhost:' + config.testServer.port + - '/files/extensions/platform_apps/ad_view/ad_network/testsdk.html'; - - var adview = document.getElementsByTagName("adview")[0]; - - adview.addEventListener("loadcommit", function() { - adview.contentWindow.postMessage({ - message: "onloadcommit", - data: "data" - }, "*"); - }) - - adview.setAttribute("src", guestURL); - - window.addEventListener("message", function(event) { - if (event.data.message == "onloadcommit-ack") { - chrome.test.sendMessage("ad-network-loaded"); - } - }) -}); diff --git a/chrome/test/data/extensions/platform_apps/ad_view/ad_network/ads/image315.png b/chrome/test/data/extensions/platform_apps/ad_view/ad_network_site/ads/image315.png index e69de29..e69de29 100644 --- a/chrome/test/data/extensions/platform_apps/ad_view/ad_network/ads/image315.png +++ b/chrome/test/data/extensions/platform_apps/ad_view/ad_network_site/ads/image315.png diff --git a/chrome/test/data/extensions/platform_apps/ad_view/ad_network/testsdk.html b/chrome/test/data/extensions/platform_apps/ad_view/ad_network_site/testsdk.html index 36a74f61..e404882 100644 --- a/chrome/test/data/extensions/platform_apps/ad_view/ad_network/testsdk.html +++ b/chrome/test/data/extensions/platform_apps/ad_view/ad_network_site/testsdk.html @@ -1,5 +1,5 @@ <!-- - * Copyright (c) 2013 The Chromium Authors. All rights reserved. Use of this + * Copyright 2013 The Chromium Authors. All rights reserved. Use of this * source code is governed by a BSD-style license that can be found in the * LICENSE file. --> @@ -20,5 +20,5 @@ <iframe id="ad-frame" style="visibility:hidden; height: 0px; width: 0px"></iframe> </div> </fieldset> -</<body> +</body> </html> diff --git a/chrome/test/data/extensions/platform_apps/ad_view/ad_network/testsdk.js b/chrome/test/data/extensions/platform_apps/ad_view/ad_network_site/testsdk.js index 85f08fe..6d5a180 100644 --- a/chrome/test/data/extensions/platform_apps/ad_view/ad_network/testsdk.js +++ b/chrome/test/data/extensions/platform_apps/ad_view/ad_network_site/testsdk.js @@ -1,4 +1,4 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. (function() { diff --git a/chrome/test/data/extensions/platform_apps/ad_view/change_ad_network/chrometest.js b/chrome/test/data/extensions/platform_apps/ad_view/change_ad_network/chrometest.js new file mode 100644 index 0000000..6f9ed3d --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/change_ad_network/chrometest.js @@ -0,0 +1,65 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// 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. + +function onLoadCommit(adview, guestURL) { + console.log('onLoadCommit("' + adview.getAttribute('ad-network') + '")'); + // First callback: assert and run another callback + if (adview.getAttribute('ad-network') == 'test') { + // Check 'src' and 'ad-network' attributes/properties + chrome.test.assertEq('test', adview.getAttribute('ad-network')); + chrome.test.assertEq('test', adview['ad-network']); + chrome.test.assertEq(guestURL, adview.getAttribute('src')); + chrome.test.assertEq(guestURL, adview.src); + + adview['ad-network'] = ''; + // Timeout is necessary to give the mutation observers a chance to fire. + // http://lists.w3.org/Archives/Public/public-webapps/2011JulSep/1622.html + setTimeout(function() { + // Check 'src' and 'ad-network' attributes/properties + chrome.test.assertEq('', adview.getAttribute('ad-network')); + chrome.test.assertEq('', adview['ad-network']); + chrome.test.assertEq('', adview.getAttribute('src')); + chrome.test.assertEq('', adview.src); + + // Assigning a new value to raise a 2nd "loadcommit" event + adview['ad-network'] = 'test2'; + }, 0); + } + // Second callback: assert and finish test + else if (adview.getAttribute('ad-network') == 'test2') { + // Check 'src' and 'ad-network' attributes/properties + chrome.test.assertEq('test2', adview.getAttribute('ad-network')); + chrome.test.assertEq('test2', adview['ad-network']); + chrome.test.assertEq('', adview.getAttribute('src')); + chrome.test.assertEq('', adview['src']); + + console.log('Test finished correctly.'); + chrome.test.succeed(); + } +}; + +function runTests(guestURL) { + chrome.test.runTests([ + function test() { + var adview = document.getElementsByTagName('adview')[0]; + + adview.addEventListener('loadcommit', function(event) { + onLoadCommit(adview, guestURL); + }); + adview.setAttribute("src", guestURL); + } + ]); +} + +window.onload = function() { + chrome.test.getConfig(function(config) { + var guestURL = 'http://localhost:' + config.testServer.port + + '/files/extensions/platform_apps/ad_view/ad_network_site/testsdk.html'; + runTests(guestURL); + }); +} diff --git a/chrome/test/data/extensions/platform_apps/ad_view/load_event/index.html b/chrome/test/data/extensions/platform_apps/ad_view/change_ad_network/index.html index 79f45a2..f5d2ddc 100644 --- a/chrome/test/data/extensions/platform_apps/ad_view/load_event/index.html +++ b/chrome/test/data/extensions/platform_apps/ad_view/change_ad_network/index.html @@ -1,5 +1,5 @@ <!-- - * Copyright (c) 2013 The Chromium Authors. All rights reserved. Use of this + * Copyright 2013 The Chromium Authors. All rights reserved. Use of this * source code is governed by a BSD-style license that can be found in the * LICENSE file. --> @@ -12,5 +12,5 @@ </head> <body> <adview id="my-adview" class="adview-element" ad-network="test"></adview> -</<body> +</body> </html> diff --git a/chrome/test/data/extensions/platform_apps/ad_view/ad_network_loaded/main.js b/chrome/test/data/extensions/platform_apps/ad_view/change_ad_network/main.js index 0b4074a..3392c0d 100644 --- a/chrome/test/data/extensions/platform_apps/ad_view/ad_network_loaded/main.js +++ b/chrome/test/data/extensions/platform_apps/ad_view/change_ad_network/main.js @@ -1,4 +1,4 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,4 +11,4 @@ chrome.app.runtime.onLaunched.addListener(function() { chrome.app.window.create('index.html', {top:0, left: 0, width: 900, height: 800}); -});
\ No newline at end of file +}); diff --git a/chrome/test/data/extensions/platform_apps/ad_view/ad_network_loaded/manifest.json b/chrome/test/data/extensions/platform_apps/ad_view/change_ad_network/manifest.json index 8d70688..8d70688 100644 --- a/chrome/test/data/extensions/platform_apps/ad_view/ad_network_loaded/manifest.json +++ b/chrome/test/data/extensions/platform_apps/ad_view/change_ad_network/manifest.json diff --git a/chrome/test/data/extensions/platform_apps/ad_view/display_first_ad/chrometest.js b/chrome/test/data/extensions/platform_apps/ad_view/display_first_ad/chrometest.js index de95a6c..d5dab08 100644 --- a/chrome/test/data/extensions/platform_apps/ad_view/display_first_ad/chrometest.js +++ b/chrome/test/data/extensions/platform_apps/ad_view/display_first_ad/chrometest.js @@ -1,25 +1,38 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -chrome.test.getConfig(function(config) { - var guestURL = 'http://localhost:' + config.testServer.port + - '/files/extensions/platform_apps/ad_view/ad_network/testsdk.html'; - var adview = document.getElementsByTagName("adview")[0]; +// This test checks the page running inside an <adview> has the ability to load +// and display an image inside an <iframe>. - adview.addEventListener("loadcommit", function() { - adview.contentWindow.postMessage({ - message: "display-first-ad", - publisherData: "data" - }, "*"); - }) +function runTests(guestURL) { + chrome.test.runTests([ + function test() { + var adview = document.getElementsByTagName("adview")[0]; - window.addEventListener("message", function(event) { - if (event.data.message == "ad-displayed") { - console.log("ad-displayed: " + event.data.data.adSize.height); - chrome.test.sendMessage("ad-displayed"); + adview.addEventListener("loadcommit", function() { + adview.contentWindow.postMessage({ + message: "display-first-ad", + publisherData: "data" + }, "*"); + }) + + window.addEventListener("message", function(event) { + if (event.data.message == "ad-displayed") { + console.log("ad-displayed: " + event.data.data.adSize.height); + chrome.test.succeed(); + } + }) + + adview.setAttribute("src", guestURL); } - }) + ]); +} - adview.setAttribute("src", guestURL); -}); +window.onload = function() { + chrome.test.getConfig(function(config) { + var guestURL = 'http://localhost:' + config.testServer.port + + '/files/extensions/platform_apps/ad_view/ad_network_site/testsdk.html'; + runTests(guestURL); + }); +} diff --git a/chrome/test/data/extensions/platform_apps/ad_view/display_first_ad/index.html b/chrome/test/data/extensions/platform_apps/ad_view/display_first_ad/index.html index 79f45a2..f5d2ddc 100644 --- a/chrome/test/data/extensions/platform_apps/ad_view/display_first_ad/index.html +++ b/chrome/test/data/extensions/platform_apps/ad_view/display_first_ad/index.html @@ -1,5 +1,5 @@ <!-- - * Copyright (c) 2013 The Chromium Authors. All rights reserved. Use of this + * Copyright 2013 The Chromium Authors. All rights reserved. Use of this * source code is governed by a BSD-style license that can be found in the * LICENSE file. --> @@ -12,5 +12,5 @@ </head> <body> <adview id="my-adview" class="adview-element" ad-network="test"></adview> -</<body> +</body> </html> diff --git a/chrome/test/data/extensions/platform_apps/ad_view/display_first_ad/main.js b/chrome/test/data/extensions/platform_apps/ad_view/display_first_ad/main.js index 0b4074a..3392c0d 100644 --- a/chrome/test/data/extensions/platform_apps/ad_view/display_first_ad/main.js +++ b/chrome/test/data/extensions/platform_apps/ad_view/display_first_ad/main.js @@ -1,4 +1,4 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,4 +11,4 @@ chrome.app.runtime.onLaunched.addListener(function() { chrome.app.window.create('index.html', {top:0, left: 0, width: 900, height: 800}); -});
\ No newline at end of file +}); diff --git a/chrome/test/data/extensions/platform_apps/ad_view/flag_required/chrometest.js b/chrome/test/data/extensions/platform_apps/ad_view/flag_required/chrometest.js new file mode 100644 index 0000000..49cd82c --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/flag_required/chrometest.js @@ -0,0 +1,54 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This test checks an <adview> element has no behavior when the "kEnableAdview" +// flag is missing. + +function runTests() { + chrome.test.runTests([ + function test() { + var assertInactive = function(adview) { + chrome.test.assertEq(undefined, adview['src']); + chrome.test.assertEq(undefined, adview['ad-network']); + chrome.test.assertEq(undefined, adview['name']); + + chrome.test.assertEq(false, adview.hasAttribute('src')); + // 'ad-network' is initially set in index.html. + chrome.test.assertEq(true, adview.hasAttribute('ad-network')); + chrome.test.assertEq(false, adview.hasAttribute('name')); + + console.log("Properties and attributes are inactive."); + }; + + var adview = document.getElementsByTagName("adview")[0]; + adview.addEventListener("loadcommit", function() { + chrome.test.fail('Ad network should not be loaded if adview command ' + + 'line flag is not set.'); + }) + + adview.addEventListener("loadabort", function() { + chrome.test.fail('Ad network should not be loaded if adview command ' + + 'line flag is not set.'); + }) + + // Checks that static "ad-network" attribute value has no effect. + assertInactive(adview); + + // Checks that setting the "ad-network" attribute value has no effect. + adview.setAttribute('ad-network', 'test'); + // Timeout is necessary to give the mutation observers a chance to fire. + // http://lists.w3.org/Archives/Public/public-webapps/2011JulSep/1622.html + setTimeout(function() { + assertInactive(adview); + chrome.test.succeed(); + }, 0); + } + ]); +} + +window.onload = function() { + chrome.test.getConfig(function(config) { + runTests(); + }); +} diff --git a/chrome/test/data/extensions/platform_apps/ad_view/flag_required/index.html b/chrome/test/data/extensions/platform_apps/ad_view/flag_required/index.html new file mode 100644 index 0000000..d3a6137 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/flag_required/index.html @@ -0,0 +1,16 @@ +<!-- + * Copyright 2013 The Chromium Authors. All rights reserved. Use of this + * source code is governed by a BSD-style license that can be found in the + * LICENSE file. +--> +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title><adview> Sample</title> +</head> +<body> + <adview id="adview1" ad-network="admob"></adview> + <script src="chrometest.js"></script> +</body> +</html> diff --git a/chrome/test/data/extensions/platform_apps/ad_view/load_event/main.js b/chrome/test/data/extensions/platform_apps/ad_view/flag_required/main.js index 0b4074a..3392c0d 100644 --- a/chrome/test/data/extensions/platform_apps/ad_view/load_event/main.js +++ b/chrome/test/data/extensions/platform_apps/ad_view/flag_required/main.js @@ -1,4 +1,4 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,4 +11,4 @@ chrome.app.runtime.onLaunched.addListener(function() { chrome.app.window.create('index.html', {top:0, left: 0, width: 900, height: 800}); -});
\ No newline at end of file +}); diff --git a/chrome/test/data/extensions/platform_apps/ad_view/flag_required/manifest.json b/chrome/test/data/extensions/platform_apps/ad_view/flag_required/manifest.json new file mode 100644 index 0000000..3aa8cf7 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/flag_required/manifest.json @@ -0,0 +1,14 @@ +{ + "manifest_version": 2, + "name": "Adview Sample", + "version": "0.1", + "minimum_chrome_version": "27", + "app": { + "background": { + "scripts": ["main.js"] + } + }, + "permissions": [ + "adview" + ] +} diff --git a/chrome/test/data/extensions/platform_apps/ad_view/invalid_ad_network/chrometest.js b/chrome/test/data/extensions/platform_apps/ad_view/invalid_ad_network/chrometest.js new file mode 100644 index 0000000..77f594c --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/invalid_ad_network/chrometest.js @@ -0,0 +1,77 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This test checks an invalid "ad-network" value (i.e. not whitelisted) +// is ignored. + +var adview1 = "adview1"; +var adview2 = "adview2"; +var adview3 = "adview3"; + +/** + * Verify setting invalid ad-network value is ignored in immediate Javascript + * code (i.e. before document is fully loaded) on a static <adview> element. + */ +function runTest1() { + var adview = document.getElementById(adview1); + + adview.setAttribute("ad-network", "invalidAdNetwork"); + + // Timeout is necessary to give the mutation observers a chance to fire. + // http://lists.w3.org/Archives/Public/public-webapps/2011JulSep/1622.html + setTimeout(function() { + chrome.test.assertEq("", adview.getAttribute("ad-network")); + console.log("test1 succeeded."); + }, 0); +} + +/** + * Verify setting invalid ad-network value is ignored at "document load" time. + */ +function runTest2(nextTest) { + var adview = document.createElement("adview"); + adview.id = adview2; + document.body.appendChild(adview); + + adview.setAttribute("ad-network", "invalidAdNetwork2"); + + // Timeout is necessary to give the mutation observers a chance to fire. + // http://lists.w3.org/Archives/Public/public-webapps/2011JulSep/1622.html + setTimeout(function() { + chrome.test.assertEq("", adview.getAttribute("ad-network")); + console.log("test2 succeeded."); + nextTest(); + }, 0); +} + +/** + * Verify setting invalid ad-network value is ignored even after document + * is fully loaded. + */ +function runTest3() { + // Timeout to ensure the code runs after the "loaded" event. + setTimeout(function() { + var adview = document.createElement("adview"); + adview.id = adview3; + document.body.appendChild(adview); + + adview.setAttribute("ad-network", "invalidAdNetwork3"); + + // Timeout is necessary to give the mutation observers a chance to fire. + // http://lists.w3.org/Archives/Public/public-webapps/2011JulSep/1622.html + setTimeout(function() { + chrome.test.assertEq("", adview.getAttribute("ad-network")); + console.log("test3 succeeded."); + chrome.test.succeed(); + }, 0); + }, 0); +} + +runTest1(); + +window.addEventListener('DOMContentLoaded', function() { + // Pass "runTest3" as "nextTest" to ensure runTest2 fully finishes + // before test3 is started. + runTest2(runTest3); +}); diff --git a/chrome/test/data/extensions/platform_apps/ad_view/invalid_ad_network/index.html b/chrome/test/data/extensions/platform_apps/ad_view/invalid_ad_network/index.html new file mode 100644 index 0000000..cb4da1d --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/invalid_ad_network/index.html @@ -0,0 +1,16 @@ +<!-- + * Copyright 2013 The Chromium Authors. All rights reserved. Use of this + * source code is governed by a BSD-style license that can be found in the + * LICENSE file. +--> +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title><adview> Sample</title> +</head> +<body> + <adview id="adview1" ad-network="invalidAdNetwork1"></adview> + <script src="chrometest.js"></script> +</body> +</html> diff --git a/chrome/test/data/extensions/platform_apps/ad_view/invalid_ad_network/main.js b/chrome/test/data/extensions/platform_apps/ad_view/invalid_ad_network/main.js new file mode 100644 index 0000000..3392c0d --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/invalid_ad_network/main.js @@ -0,0 +1,14 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * Listens for the app launching then creates the window + * + * @see http://developer.chrome.com/trunk/apps/app.runtime.html + * @see http://developer.chrome.com/trunk/apps/app.window.html + */ +chrome.app.runtime.onLaunched.addListener(function() { + chrome.app.window.create('index.html', + {top:0, left: 0, width: 900, height: 800}); +}); diff --git a/chrome/test/data/extensions/platform_apps/ad_view/load_event/manifest.json b/chrome/test/data/extensions/platform_apps/ad_view/invalid_ad_network/manifest.json index 8d70688..8d70688 100644 --- a/chrome/test/data/extensions/platform_apps/ad_view/load_event/manifest.json +++ b/chrome/test/data/extensions/platform_apps/ad_view/invalid_ad_network/manifest.json diff --git a/chrome/test/data/extensions/platform_apps/ad_view/load_event/chrometest.js b/chrome/test/data/extensions/platform_apps/ad_view/load_event/chrometest.js deleted file mode 100644 index 0886f55..0000000 --- a/chrome/test/data/extensions/platform_apps/ad_view/load_event/chrometest.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -chrome.test.getConfig(function(config) { - var guestURL = 'http://localhost:' + config.testServer.port + - '/files/extensions/platform_apps/ad_view/ad_network/testsdk.html'; - var adview = document.getElementsByTagName("adview")[0]; - - adview.addEventListener("loadcommit", function() { - chrome.test.sendMessage('guest-loaded'); - }) - - adview.setAttribute("src", guestURL); -}); diff --git a/chrome/test/data/extensions/platform_apps/ad_view/loadabort_event/chrometest.js b/chrome/test/data/extensions/platform_apps/ad_view/loadabort_event/chrometest.js new file mode 100644 index 0000000..afb362d --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/loadabort_event/chrometest.js @@ -0,0 +1,32 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This test checks the "loadabort" event is called when the "src" attribute +// of an <adview> is an invalid URL. + +function runTests(guestURL) { + chrome.test.runTests([ + function test() { + var adview = document.getElementsByTagName("adview")[0]; + + adview.addEventListener("loadabort", function(event) { + var url = event.url; + var isTopLevel = event.isTopLevel; + chrome.test.assertEq(guestURL, url); + chrome.test.assertEq(true, isTopLevel); + console.log("loadabort event called: url=" + url); + chrome.test.succeed(); + }) + + adview.setAttribute("src", guestURL); + } + ]); +} + +window.onload = function() { + chrome.test.getConfig(function(config) { + var guestURL = 'http://255.255.255.255/fake_file.html'; + runTests(guestURL); + }); +} diff --git a/chrome/test/data/extensions/platform_apps/ad_view/loadabort_event/index.html b/chrome/test/data/extensions/platform_apps/ad_view/loadabort_event/index.html new file mode 100644 index 0000000..f5d2ddc --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/loadabort_event/index.html @@ -0,0 +1,16 @@ +<!-- + * Copyright 2013 The Chromium Authors. All rights reserved. Use of this + * source code is governed by a BSD-style license that can be found in the + * LICENSE file. +--> +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title><adview> Sample</title> + <script src="chrometest.js"></script> +</head> +<body> + <adview id="my-adview" class="adview-element" ad-network="test"></adview> +</body> +</html> diff --git a/chrome/test/data/extensions/platform_apps/ad_view/loadabort_event/main.js b/chrome/test/data/extensions/platform_apps/ad_view/loadabort_event/main.js new file mode 100644 index 0000000..3392c0d --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/loadabort_event/main.js @@ -0,0 +1,14 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * Listens for the app launching then creates the window + * + * @see http://developer.chrome.com/trunk/apps/app.runtime.html + * @see http://developer.chrome.com/trunk/apps/app.window.html + */ +chrome.app.runtime.onLaunched.addListener(function() { + chrome.app.window.create('index.html', + {top:0, left: 0, width: 900, height: 800}); +}); diff --git a/chrome/test/data/extensions/platform_apps/ad_view/loadabort_event/manifest.json b/chrome/test/data/extensions/platform_apps/ad_view/loadabort_event/manifest.json new file mode 100644 index 0000000..8d70688 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/loadabort_event/manifest.json @@ -0,0 +1,14 @@ +{ + "manifest_version": 2, + "name": "Adview Sample", + "version": "0.1", + "minimum_chrome_version": "27", + "app": { + "background": { + "scripts": ["main.js"] + } + }, + "permissions": [ + "adview" + ] +}
\ No newline at end of file diff --git a/chrome/test/data/extensions/platform_apps/ad_view/loadcommit_event/chrometest.js b/chrome/test/data/extensions/platform_apps/ad_view/loadcommit_event/chrometest.js new file mode 100644 index 0000000..b7d65c1 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/loadcommit_event/chrometest.js @@ -0,0 +1,33 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This test checks the "loadcommit" event is called when the page inside an +// <adview> is loaded. + +function runTests(guestURL) { + chrome.test.runTests([ + function test() { + var adview = document.getElementsByTagName("adview")[0]; + + adview.addEventListener("loadcommit", function(event) { + var url = event.url; + var isTopLevel = event.isTopLevel; + chrome.test.assertEq(guestURL, url); + chrome.test.assertEq(true, isTopLevel); + console.log("loadcommit event called: url=" + url); + chrome.test.succeed(); + }) + + adview.setAttribute("src", guestURL); + } + ]); +} + +window.onload = function() { + chrome.test.getConfig(function(config) { + var guestURL = 'http://localhost:' + config.testServer.port + + '/files/extensions/platform_apps/ad_view/ad_network_site/testsdk.html'; + runTests(guestURL); + }); +} diff --git a/chrome/test/data/extensions/platform_apps/ad_view/loadcommit_event/index.html b/chrome/test/data/extensions/platform_apps/ad_view/loadcommit_event/index.html new file mode 100644 index 0000000..f5d2ddc --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/loadcommit_event/index.html @@ -0,0 +1,16 @@ +<!-- + * Copyright 2013 The Chromium Authors. All rights reserved. Use of this + * source code is governed by a BSD-style license that can be found in the + * LICENSE file. +--> +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title><adview> Sample</title> + <script src="chrometest.js"></script> +</head> +<body> + <adview id="my-adview" class="adview-element" ad-network="test"></adview> +</body> +</html> diff --git a/chrome/test/data/extensions/platform_apps/ad_view/loadcommit_event/main.js b/chrome/test/data/extensions/platform_apps/ad_view/loadcommit_event/main.js new file mode 100644 index 0000000..3392c0d --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/loadcommit_event/main.js @@ -0,0 +1,14 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * Listens for the app launching then creates the window + * + * @see http://developer.chrome.com/trunk/apps/app.runtime.html + * @see http://developer.chrome.com/trunk/apps/app.window.html + */ +chrome.app.runtime.onLaunched.addListener(function() { + chrome.app.window.create('index.html', + {top:0, left: 0, width: 900, height: 800}); +}); diff --git a/chrome/test/data/extensions/platform_apps/ad_view/loadcommit_event/manifest.json b/chrome/test/data/extensions/platform_apps/ad_view/loadcommit_event/manifest.json new file mode 100644 index 0000000..8d70688 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/loadcommit_event/manifest.json @@ -0,0 +1,14 @@ +{ + "manifest_version": 2, + "name": "Adview Sample", + "version": "0.1", + "minimum_chrome_version": "27", + "app": { + "background": { + "scripts": ["main.js"] + } + }, + "permissions": [ + "adview" + ] +}
\ No newline at end of file diff --git a/chrome/test/data/extensions/platform_apps/ad_view/onloadcommit_ack/chrometest.js b/chrome/test/data/extensions/platform_apps/ad_view/onloadcommit_ack/chrometest.js new file mode 100644 index 0000000..2be96d4 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/onloadcommit_ack/chrometest.js @@ -0,0 +1,39 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// 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. + +function runTests(guestURL) { + chrome.test.runTests([ + function test() { + var adview = document.getElementsByTagName("adview")[0]; + + adview.addEventListener("loadcommit", function() { + adview.contentWindow.postMessage({ + message: "onloadcommit", + data: "data" + }, "*"); + }); + + window.addEventListener("message", function(event) { + if (event.data.message == "onloadcommit-ack") { + console.log("onloadcommit-ack message received."); + chrome.test.succeed(); + } + }); + + adview.setAttribute("src", guestURL); + } + ]); +} + +window.onload = function() { + chrome.test.getConfig(function(config) { + var guestURL = 'http://localhost:' + config.testServer.port + + '/files/extensions/platform_apps/ad_view/ad_network_site/testsdk.html'; + runTests(guestURL); + }); +} diff --git a/chrome/test/data/extensions/platform_apps/ad_view/ad_network_loaded/displayad.js b/chrome/test/data/extensions/platform_apps/ad_view/onloadcommit_ack/displayad.js index e71d974..e8df4a3 100644 --- a/chrome/test/data/extensions/platform_apps/ad_view/ad_network_loaded/displayad.js +++ b/chrome/test/data/extensions/platform_apps/ad_view/onloadcommit_ack/displayad.js @@ -1,4 +1,4 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. (function() { diff --git a/chrome/test/data/extensions/platform_apps/ad_view/ad_network_loaded/index.html b/chrome/test/data/extensions/platform_apps/ad_view/onloadcommit_ack/index.html index d675f97..b16f27a 100644 --- a/chrome/test/data/extensions/platform_apps/ad_view/ad_network_loaded/index.html +++ b/chrome/test/data/extensions/platform_apps/ad_view/onloadcommit_ack/index.html @@ -1,5 +1,5 @@ <!-- - * Copyright (c) 2013 The Chromium Authors. All rights reserved. Use of this + * Copyright 2013 The Chromium Authors. All rights reserved. Use of this * source code is governed by a BSD-style license that can be found in the * LICENSE file. --> @@ -23,5 +23,5 @@ <input id="display-ad" type="button" value="(loading adview...)" disabled="true"/> <p id="my-status"></p> </div> -</<body> +</body> </html> diff --git a/chrome/test/data/extensions/platform_apps/ad_view/onloadcommit_ack/main.js b/chrome/test/data/extensions/platform_apps/ad_view/onloadcommit_ack/main.js new file mode 100644 index 0000000..3392c0d --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/onloadcommit_ack/main.js @@ -0,0 +1,14 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * Listens for the app launching then creates the window + * + * @see http://developer.chrome.com/trunk/apps/app.runtime.html + * @see http://developer.chrome.com/trunk/apps/app.window.html + */ +chrome.app.runtime.onLaunched.addListener(function() { + chrome.app.window.create('index.html', + {top:0, left: 0, width: 900, height: 800}); +}); diff --git a/chrome/test/data/extensions/platform_apps/ad_view/onloadcommit_ack/manifest.json b/chrome/test/data/extensions/platform_apps/ad_view/onloadcommit_ack/manifest.json new file mode 100644 index 0000000..8d70688 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/onloadcommit_ack/manifest.json @@ -0,0 +1,14 @@ +{ + "manifest_version": 2, + "name": "Adview Sample", + "version": "0.1", + "minimum_chrome_version": "27", + "app": { + "background": { + "scripts": ["main.js"] + } + }, + "permissions": [ + "adview" + ] +}
\ No newline at end of file diff --git a/chrome/test/data/extensions/platform_apps/ad_view/permission_required/chrometest.js b/chrome/test/data/extensions/platform_apps/ad_view/permission_required/chrometest.js new file mode 100644 index 0000000..2feee67c --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/permission_required/chrometest.js @@ -0,0 +1,39 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This test checks an <adview> element has no behavior when the "adview" +// permission is missing from the application manifest. + +function runTests(guestURL) { + chrome.test.runTests([ + function test() { + var adview = document.getElementsByTagName('adview')[0]; + var adnetwork = adview.getAttribute('ad-network'); + + adview.setAttribute('src', guestURL); + + // Timeout is necessary to give the mutation observers a chance to fire. + // http://lists.w3.org/Archives/Public/public-webapps/2011JulSep/1622.html + setTimeout(function() { + chrome.test.assertEq(true, adview.hasAttribute('src')); + chrome.test.assertEq(guestURL, adview.getAttribute('src')); + chrome.test.assertEq(undefined, adview['src']); + + chrome.test.assertEq(adnetwork, adview.getAttribute('ad-network')); + chrome.test.assertEq(undefined, adview['ad-network']); + + console.log("Properties and attributes are inactive."); + chrome.test.succeed(); + }, 0); + } + ]); +} + +window.onload = function() { + chrome.test.getConfig(function(config) { + var guestURL = 'http://localhost:' + config.testServer.port + + '/files/extensions/platform_apps/ad_view/ad_network_site/testsdk.html'; + runTests(guestURL); + }); +} diff --git a/chrome/test/data/extensions/platform_apps/ad_view/permission_required/index.html b/chrome/test/data/extensions/platform_apps/ad_view/permission_required/index.html new file mode 100644 index 0000000..f5d2ddc --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/permission_required/index.html @@ -0,0 +1,16 @@ +<!-- + * Copyright 2013 The Chromium Authors. All rights reserved. Use of this + * source code is governed by a BSD-style license that can be found in the + * LICENSE file. +--> +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title><adview> Sample</title> + <script src="chrometest.js"></script> +</head> +<body> + <adview id="my-adview" class="adview-element" ad-network="test"></adview> +</body> +</html> diff --git a/chrome/test/data/extensions/platform_apps/ad_view/permission_required/main.js b/chrome/test/data/extensions/platform_apps/ad_view/permission_required/main.js new file mode 100644 index 0000000..3392c0d --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/permission_required/main.js @@ -0,0 +1,14 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * Listens for the app launching then creates the window + * + * @see http://developer.chrome.com/trunk/apps/app.runtime.html + * @see http://developer.chrome.com/trunk/apps/app.window.html + */ +chrome.app.runtime.onLaunched.addListener(function() { + chrome.app.window.create('index.html', + {top:0, left: 0, width: 900, height: 800}); +}); diff --git a/chrome/test/data/extensions/platform_apps/ad_view/permission_required/manifest.json b/chrome/test/data/extensions/platform_apps/ad_view/permission_required/manifest.json new file mode 100644 index 0000000..e78cfc3 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/permission_required/manifest.json @@ -0,0 +1,14 @@ +{ + "manifest_version": 2, + "name": "Adview Sample", + "version": "0.1", + "minimum_chrome_version": "27", + "app": { + "background": { + "scripts": ["main.js"] + } + }, + "permissions": [ + // Note: No "adview" permission here! + ] +} diff --git a/chrome/test/data/extensions/platform_apps/ad_view/properties_exposed/chrometest.js b/chrome/test/data/extensions/platform_apps/ad_view/properties_exposed/chrometest.js new file mode 100644 index 0000000..4631275 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/properties_exposed/chrometest.js @@ -0,0 +1,38 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This test checks that <adview> attributes are also exposed as properties +// (with the same name and value). + +function runTests(guestURL) { + chrome.test.runTests([ + function test() { + var adview = document.getElementsByTagName('adview')[0]; + var adnetwork = adview.getAttribute('ad-network'); + + adview.setAttribute('src', guestURL); + + // Timeout is necessary to give the mutation observers a chance to fire. + // http://lists.w3.org/Archives/Public/public-webapps/2011JulSep/1622.html + setTimeout(function() { + chrome.test.assertEq(guestURL, adview.getAttribute('src')); + chrome.test.assertEq(guestURL, adview['src']); + + chrome.test.assertEq(adnetwork, adview.getAttribute('ad-network')); + chrome.test.assertEq(adnetwork, adview['ad-network']); + + console.log("Properties verified."); + chrome.test.succeed(); + }, 0); + } + ]); +} + +window.onload = function() { + chrome.test.getConfig(function(config) { + var guestURL = 'http://localhost:' + config.testServer.port + + '/files/extensions/platform_apps/ad_view/ad_network_site/testsdk.html'; + runTests(guestURL); + }); +} diff --git a/chrome/test/data/extensions/platform_apps/ad_view/properties_exposed/index.html b/chrome/test/data/extensions/platform_apps/ad_view/properties_exposed/index.html new file mode 100644 index 0000000..f5d2ddc --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/properties_exposed/index.html @@ -0,0 +1,16 @@ +<!-- + * Copyright 2013 The Chromium Authors. All rights reserved. Use of this + * source code is governed by a BSD-style license that can be found in the + * LICENSE file. +--> +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title><adview> Sample</title> + <script src="chrometest.js"></script> +</head> +<body> + <adview id="my-adview" class="adview-element" ad-network="test"></adview> +</body> +</html> diff --git a/chrome/test/data/extensions/platform_apps/ad_view/properties_exposed/main.js b/chrome/test/data/extensions/platform_apps/ad_view/properties_exposed/main.js new file mode 100644 index 0000000..3392c0d --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/properties_exposed/main.js @@ -0,0 +1,14 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * Listens for the app launching then creates the window + * + * @see http://developer.chrome.com/trunk/apps/app.runtime.html + * @see http://developer.chrome.com/trunk/apps/app.window.html + */ +chrome.app.runtime.onLaunched.addListener(function() { + chrome.app.window.create('index.html', + {top:0, left: 0, width: 900, height: 800}); +}); diff --git a/chrome/test/data/extensions/platform_apps/ad_view/properties_exposed/manifest.json b/chrome/test/data/extensions/platform_apps/ad_view/properties_exposed/manifest.json new file mode 100644 index 0000000..8d70688 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/properties_exposed/manifest.json @@ -0,0 +1,14 @@ +{ + "manifest_version": 2, + "name": "Adview Sample", + "version": "0.1", + "minimum_chrome_version": "27", + "app": { + "background": { + "scripts": ["main.js"] + } + }, + "permissions": [ + "adview" + ] +}
\ No newline at end of file diff --git a/chrome/test/data/extensions/platform_apps/ad_view/src_flag_required/chrometest.js b/chrome/test/data/extensions/platform_apps/ad_view/src_flag_required/chrometest.js new file mode 100644 index 0000000..5085bc3 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/src_flag_required/chrometest.js @@ -0,0 +1,34 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This test checks the "src" attribute is ignored when the +// "kEnableAdviewSrcAttribute" is missing. + +function runTests(guestURL) { + chrome.test.runTests([ + function test() { + var adview = document.getElementsByTagName("adview")[0]; + + adview.setAttribute("src", guestURL); + + // Timeout is necessary to give the mutation observers a chance to fire. + // http://lists.w3.org/Archives/Public/public-webapps/2011JulSep/1622.html + setTimeout(function() { + chrome.test.assertEq("", adview.getAttribute("src")); + chrome.test.assertEq(undefined, adview['src']); + chrome.test.assertEq(undefined, adview.src); + console.log("Properties and attributes are inactive."); + chrome.test.succeed(); + }, 0); + } + ]); +} + +window.onload = function() { + chrome.test.getConfig(function(config) { + var guestURL = 'http://localhost:' + config.testServer.port + + '/files/extensions/platform_apps/ad_view/ad_network_site/testsdk.html'; + runTests(guestURL); + }); +} diff --git a/chrome/test/data/extensions/platform_apps/ad_view/src_flag_required/index.html b/chrome/test/data/extensions/platform_apps/ad_view/src_flag_required/index.html new file mode 100644 index 0000000..f5d2ddc --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/src_flag_required/index.html @@ -0,0 +1,16 @@ +<!-- + * Copyright 2013 The Chromium Authors. All rights reserved. Use of this + * source code is governed by a BSD-style license that can be found in the + * LICENSE file. +--> +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title><adview> Sample</title> + <script src="chrometest.js"></script> +</head> +<body> + <adview id="my-adview" class="adview-element" ad-network="test"></adview> +</body> +</html> diff --git a/chrome/test/data/extensions/platform_apps/ad_view/src_flag_required/main.js b/chrome/test/data/extensions/platform_apps/ad_view/src_flag_required/main.js new file mode 100644 index 0000000..3392c0d --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/src_flag_required/main.js @@ -0,0 +1,14 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * Listens for the app launching then creates the window + * + * @see http://developer.chrome.com/trunk/apps/app.runtime.html + * @see http://developer.chrome.com/trunk/apps/app.window.html + */ +chrome.app.runtime.onLaunched.addListener(function() { + chrome.app.window.create('index.html', + {top:0, left: 0, width: 900, height: 800}); +}); diff --git a/chrome/test/data/extensions/platform_apps/ad_view/src_flag_required/manifest.json b/chrome/test/data/extensions/platform_apps/ad_view/src_flag_required/manifest.json new file mode 100644 index 0000000..8d70688 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/src_flag_required/manifest.json @@ -0,0 +1,14 @@ +{ + "manifest_version": 2, + "name": "Adview Sample", + "version": "0.1", + "minimum_chrome_version": "27", + "app": { + "background": { + "scripts": ["main.js"] + } + }, + "permissions": [ + "adview" + ] +}
\ No newline at end of file diff --git a/chrome/test/data/extensions/platform_apps/ad_view/src_not_exposed/ad_network_fake_website.html b/chrome/test/data/extensions/platform_apps/ad_view/src_not_exposed/ad_network_fake_website.html new file mode 100644 index 0000000..0f9a0b2 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/src_not_exposed/ad_network_fake_website.html @@ -0,0 +1,15 @@ +<!-- + * Copyright 2013 The Chromium Authors. All rights reserved. Use of this + * source code is governed by a BSD-style license that can be found in the + * LICENSE file. +--> +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title><adview> test</title> +</head> +<body> + <p>Ad network test file.</p> +</body> +</html> diff --git a/chrome/test/data/extensions/platform_apps/ad_view/src_not_exposed/chrometest.js b/chrome/test/data/extensions/platform_apps/ad_view/src_not_exposed/chrometest.js new file mode 100644 index 0000000..f6bf10d --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/src_not_exposed/chrometest.js @@ -0,0 +1,30 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This test checks 1) an <adview> works end-to-end (i.e. page is loaded) when +// using a whitelisted ad-network, and 2) the "src" attribute is never exposed +// to the application. + +function runTests() { + chrome.test.runTests([ + function test() { + var adview = document.getElementsByTagName("adview")[0]; + adview.addEventListener("loadcommit", function(e){ + chrome.test.assertEq(false, adview.hasAttribute("src")); + chrome.test.assertEq(null, adview.getAttribute("src")); + chrome.test.assertEq(undefined, adview['src']); + chrome.test.assertEq(undefined, adview.src); + console.log("Properties and attributes are inactive."); + chrome.test.succeed(); + }); + adview.setAttribute('ad-network', 'admob'); + } + ]); +} + +window.onload = function() { + chrome.test.getConfig(function(config) { + runTests(); + }); +} diff --git a/chrome/test/data/extensions/platform_apps/ad_view/src_not_exposed/index.html b/chrome/test/data/extensions/platform_apps/ad_view/src_not_exposed/index.html new file mode 100644 index 0000000..61d533a --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/src_not_exposed/index.html @@ -0,0 +1,16 @@ +<!-- + * Copyright 2013 The Chromium Authors. All rights reserved. Use of this + * source code is governed by a BSD-style license that can be found in the + * LICENSE file. +--> +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title><adview> Sample</title> + <script src="chrometest.js"></script> +</head> +<body> + <adview id="my-adview" class="adview-element"></adview> +</body> +</html> diff --git a/chrome/test/data/extensions/platform_apps/ad_view/src_not_exposed/main.js b/chrome/test/data/extensions/platform_apps/ad_view/src_not_exposed/main.js new file mode 100644 index 0000000..3392c0d --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/src_not_exposed/main.js @@ -0,0 +1,14 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * Listens for the app launching then creates the window + * + * @see http://developer.chrome.com/trunk/apps/app.runtime.html + * @see http://developer.chrome.com/trunk/apps/app.window.html + */ +chrome.app.runtime.onLaunched.addListener(function() { + chrome.app.window.create('index.html', + {top:0, left: 0, width: 900, height: 800}); +}); diff --git a/chrome/test/data/extensions/platform_apps/ad_view/src_not_exposed/manifest.json b/chrome/test/data/extensions/platform_apps/ad_view/src_not_exposed/manifest.json new file mode 100644 index 0000000..3aa8cf7 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/ad_view/src_not_exposed/manifest.json @@ -0,0 +1,14 @@ +{ + "manifest_version": 2, + "name": "Adview Sample", + "version": "0.1", + "minimum_chrome_version": "27", + "app": { + "background": { + "scripts": ["main.js"] + } + }, + "permissions": [ + "adview" + ] +} diff --git a/content/test/net/url_request_prepackaged_interceptor.cc b/content/test/net/url_request_prepackaged_interceptor.cc index f8603ef..9150a7e 100644 --- a/content/test/net/url_request_prepackaged_interceptor.cc +++ b/content/test/net/url_request_prepackaged_interceptor.cc @@ -38,23 +38,26 @@ class URLRequestPrepackagedJob : public net::URLRequestFileJob { class URLRequestPrepackagedInterceptor::Delegate : public net::URLRequestJobFactory::ProtocolHandler { public: - Delegate() : hit_count_(0) {} + Delegate(const std::string& scheme, const std::string& hostname) + : scheme_(scheme), hostname_(hostname), hit_count_(0) {} virtual ~Delegate() {} void Register() { net::URLRequestFilter::GetInstance()->AddHostnameProtocolHandler( - "http", "localhost", + scheme_, hostname_, scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>(this)); } - static void Unregister() { - net::URLRequestFilter::GetInstance()->RemoveHostnameHandler("http", - "localhost"); + static void Unregister( + const std::string& scheme, + const std::string& hostname) { + net::URLRequestFilter::GetInstance()->RemoveHostnameHandler(scheme, + hostname); } // When requests for |url| arrive, respond with the contents of |path|. The - // hostname of |url| must be "localhost" to avoid DNS lookups, and the scheme - // must be "http". + // hostname and scheme of |url| must match the corresponding parameters + // passed as constructor arguments. void SetResponse(const GURL& url, const base::FilePath& path, bool ignore_query) { @@ -84,8 +87,8 @@ class URLRequestPrepackagedInterceptor::Delegate net::URLRequest* request, net::NetworkDelegate* network_delegate) const OVERRIDE { CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - if (request->url().scheme() != "http" || - request->url().host() != "localhost") { + if (request->url().scheme() != scheme_ || + request->url().host() != hostname_) { return NULL; } @@ -112,6 +115,9 @@ class URLRequestPrepackagedInterceptor::Delegate it->second); } + const std::string scheme_; + const std::string hostname_; + ResponseMap responses_; ResponseMap ignore_query_responses_; @@ -122,8 +128,12 @@ class URLRequestPrepackagedInterceptor::Delegate }; -URLRequestPrepackagedInterceptor::URLRequestPrepackagedInterceptor() - : delegate_(new Delegate) { +URLRequestPrepackagedInterceptor::URLRequestPrepackagedInterceptor( + const std::string& scheme, + const std::string& hostname) + : scheme_(scheme), + hostname_(hostname), + delegate_(new Delegate(scheme, hostname)) { BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind(&Delegate::Register, base::Unretained(delegate_))); @@ -131,13 +141,16 @@ URLRequestPrepackagedInterceptor::URLRequestPrepackagedInterceptor() URLRequestPrepackagedInterceptor::~URLRequestPrepackagedInterceptor() { BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, - base::Bind(&Delegate::Unregister)); + base::Bind(&Delegate::Unregister, + scheme_, + hostname_)); } -void URLRequestPrepackagedInterceptor::SetResponse(const GURL& url, - const base::FilePath& path) { - CHECK_EQ("http", url.scheme()); - CHECK_EQ("localhost", url.host()); +void URLRequestPrepackagedInterceptor::SetResponse( + const GURL& url, + const base::FilePath& path) { + CHECK_EQ(scheme_, url.scheme()); + CHECK_EQ(hostname_, url.host()); BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind(&Delegate::SetResponse, base::Unretained(delegate_), url, path, @@ -147,8 +160,8 @@ void URLRequestPrepackagedInterceptor::SetResponse(const GURL& url, void URLRequestPrepackagedInterceptor::SetResponseIgnoreQuery( const GURL& url, const base::FilePath& path) { - CHECK_EQ("http", url.scheme()); - CHECK_EQ("localhost", url.host()); + CHECK_EQ(scheme_, url.scheme()); + CHECK_EQ(hostname_, url.host()); BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind(&Delegate::SetResponse, base::Unretained(delegate_), url, path, @@ -159,4 +172,10 @@ int URLRequestPrepackagedInterceptor::GetHitCount() { return delegate_->GetHitCount(); } + +URLLocalHostRequestPrepackagedInterceptor + ::URLLocalHostRequestPrepackagedInterceptor() + : URLRequestPrepackagedInterceptor("http", "localhost") { +} + } // namespace content diff --git a/content/test/net/url_request_prepackaged_interceptor.h b/content/test/net/url_request_prepackaged_interceptor.h index edb65c5..cc5736d 100644 --- a/content/test/net/url_request_prepackaged_interceptor.h +++ b/content/test/net/url_request_prepackaged_interceptor.h @@ -5,6 +5,8 @@ #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_INTERCEPTOR_H_ #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_INTERCEPTOR_H_ +#include <string> + #include "base/basictypes.h" class GURL; @@ -20,12 +22,15 @@ namespace content { // occurs while the URLRequestPrepackagedInterceptor is alive. class URLRequestPrepackagedInterceptor { public: - URLRequestPrepackagedInterceptor(); + // Registers an interceptor for urls using |scheme| and |hostname|. Urls + // passed to "SetResponse" are required to use |scheme| and |hostname|. + URLRequestPrepackagedInterceptor(const std::string& scheme, + const std::string& hostname); virtual ~URLRequestPrepackagedInterceptor(); // When requests for |url| arrive, respond with the contents of |path|. The - // hostname of |url| must be "localhost" to avoid DNS lookups, and the scheme - // must be "http". + // hostname and scheme of |url| must match the corresponding parameters + // passed as constructor arguments. void SetResponse(const GURL& url, const base::FilePath& path); // Identical to SetResponse except that query parameters are ignored on @@ -38,6 +43,9 @@ class URLRequestPrepackagedInterceptor { private: class Delegate; + const std::string scheme_; + const std::string hostname_; + // After creation, |delegate_| lives on the IO thread, and a task to delete // it is posted from ~URLRequestPrepackagedInterceptor(). Delegate* delegate_; @@ -45,6 +53,17 @@ class URLRequestPrepackagedInterceptor { DISALLOW_COPY_AND_ASSIGN(URLRequestPrepackagedInterceptor); }; +// Specialization of URLRequestPrepackagedInterceptor where scheme is "http" and +// hostname is "localhost". +class URLLocalHostRequestPrepackagedInterceptor + : public URLRequestPrepackagedInterceptor { + public: + URLLocalHostRequestPrepackagedInterceptor(); + + private: + DISALLOW_COPY_AND_ASSIGN(URLLocalHostRequestPrepackagedInterceptor); +}; + } // namespace content #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_INTERCEPTOR_H_ |