diff options
author | fsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-05 22:39:49 +0000 |
---|---|---|
committer | fsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-05 22:39:49 +0000 |
commit | ead6751a4a41f35c3cc4ba72f0519610ba6b2f08 (patch) | |
tree | 0c44cccce725421144cc50c109716f9828d7649c /chrome | |
parent | 63be12d09ac1bb18048ec80f626e94bf877465ad (diff) | |
download | chromium_src-ead6751a4a41f35c3cc4ba72f0519610ba6b2f08.zip chromium_src-ead6751a4a41f35c3cc4ba72f0519610ba6b2f08.tar.gz chromium_src-ead6751a4a41f35c3cc4ba72f0519610ba6b2f08.tar.bz2 |
Move WebRequest API to request object and add existence test
BUG=171421
Test=WebViewTest.Shim_TestWebRequestAPI, WebViewInteractiveTest.NewWindow_WebRequest, WebViewTest.Shim_TestWebRequestAPIExistence
Review URL: https://chromiumcodereview.appspot.com/22249002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215713 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
3 files changed, 83 insertions, 17 deletions
diff --git a/chrome/browser/extensions/web_view_browsertest.cc b/chrome/browser/extensions/web_view_browsertest.cc index 8c2166e..9dd1903 100644 --- a/chrome/browser/extensions/web_view_browsertest.cc +++ b/chrome/browser/extensions/web_view_browsertest.cc @@ -501,6 +501,15 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAPIMethodExistence) { "web_view/shim"); } +// Tests the existence of WebRequest API event objects on the request +// object, on the webview element, and hanging directly off webview. +IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPIExistence) { + TestHelper("testWebRequestAPIExistence", + "DoneShimTest.PASSED", + "DoneShimTest.FAILED", + "web_view/shim"); +} + IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestEventName) { TestHelper("testEventName", "DoneShimTest.PASSED", diff --git a/chrome/renderer/resources/extensions/web_view_experimental.js b/chrome/renderer/resources/extensions/web_view_experimental.js index d1e1fa0..7c366b2 100644 --- a/chrome/renderer/resources/extensions/web_view_experimental.js +++ b/chrome/renderer/resources/extensions/web_view_experimental.js @@ -29,27 +29,53 @@ WebView.prototype.maybeSetupExperimentalAPI_ = function() { */ WebView.prototype.setupWebRequestEvents_ = function() { var self = this; + var request = {}; + var createWebRequestEvent = function(webRequestEvent) { + return function() { + if (!self[webRequestEvent.name + '_']) { + self[webRequestEvent.name + '_'] = + new WebRequestEvent( + 'webview.' + webRequestEvent.name, + webRequestEvent.parameters, + webRequestEvent.extraParameters, null, + self.browserPluginNode_.getInstanceId()); + } + return self[webRequestEvent.name + '_']; + } + }; + // Populate the WebRequest events from the API definition. for (var i = 0; i < webRequestSchema.events.length; ++i) { - Object.defineProperty(self.webviewNode_, - webRequestSchema.events[i].name, { - get: function(webRequestEvent) { - return function() { - if (!self[webRequestEvent.name + '_']) { - self[webRequestEvent.name + '_'] = - new WebRequestEvent( - 'webview.' + webRequestEvent.name, - webRequestEvent.parameters, - webRequestEvent.extraParameters, null, - self.browserPluginNode_.getInstanceId()); - } - return self[webRequestEvent.name + '_']; + var webRequestEvent = createWebRequestEvent(webRequestSchema.events[i]); + Object.defineProperty( + request, + webRequestSchema.events[i].name, + { + get: webRequestEvent, + configuable: false, + enumerable: true } - }(webRequestSchema.events[i]), - // No setter. - enumerable: true - }); + ); + Object.defineProperty( + this.webviewNode_, + webRequestSchema.events[i].name, + { + get: webRequestEvent, + configuable: false, + enumerable: true + } + ); } + Object.defineProperty( + this.webviewNode_, + 'request', + { + value: request, + configurable: false, + enumerable: true, + writable: false + } + ); }; /** diff --git a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js index ba846bf..2d86c65 100644 --- a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js +++ b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js @@ -151,6 +151,36 @@ function testAPIMethodExistence() { document.body.appendChild(webview); } +function testWebRequestAPIExistence() { + var apiPropertiesToCheck = [ + 'onBeforeRequest', + 'onBeforeSendHeaders', + 'onSendHeaders', + 'onHeadersReceived', + 'onAuthRequired', + 'onBeforeRedirect', + 'onResponseStarted', + 'onCompleted', + 'onErrorOccurred' + ]; + var webview = document.createElement('webview'); + webview.setAttribute('partition', arguments.callee.name); + webview.addEventListener('loadstop', function(e) { + for (var i = 0; i < apiPropertiesToCheck.length; ++i) { + embedder.test.assertEq('object', + typeof webview[apiPropertiesToCheck[i]]); + embedder.test.assertEq( + 'function', typeof webview[apiPropertiesToCheck[i]].addListener); + embedder.test.assertEq(webview[apiPropertiesToCheck[i]], + webview.request[apiPropertiesToCheck[i]]); + } + + embedder.test.succeed(); + }); + webview.setAttribute('src', 'data:text/html,webview check api'); + document.body.appendChild(webview); +} + // This test verifies that the loadstart, loadstop, and exit events fire as // expected. function testEventName() { @@ -647,6 +677,7 @@ function testRemoveWebviewOnExit() { embedder.test.testList = { 'testSize': testSize, 'testAPIMethodExistence': testAPIMethodExistence, + 'testWebRequestAPIExistence': testWebRequestAPIExistence, 'testEventName': testEventName, 'testDestroyOnEventListener': testDestroyOnEventListener, 'testCannotMutateEventName': testCannotMutateEventName, |