diff options
author | jochen <jochen@chromium.org> | 2015-07-14 03:04:45 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-14 10:05:28 +0000 |
commit | 7923c2a2c443d98c432864e361b1d090f0c911ca (patch) | |
tree | 8b621d061efbea0ea7531add4081113bc7be349a | |
parent | a0743be4faeba12784322efb70387bf708308bf6 (diff) | |
download | chromium_src-7923c2a2c443d98c432864e361b1d090f0c911ca.zip chromium_src-7923c2a2c443d98c432864e361b1d090f0c911ca.tar.gz chromium_src-7923c2a2c443d98c432864e361b1d090f0c911ca.tar.bz2 |
Add a test that getModuleSystem() doesn't work cross origin
BUG=504011
R=kalman@chromium.org
TBR=fukino@chromium.org
Review URL: https://codereview.chromium.org/1241443004
Cr-Commit-Position: refs/heads/master@{#338663}
10 files changed, 82 insertions, 20 deletions
diff --git a/chrome/browser/extensions/extension_bindings_apitest.cc b/chrome/browser/extensions/extension_bindings_apitest.cc index c78fb20..9843e7f 100644 --- a/chrome/browser/extensions/extension_bindings_apitest.cc +++ b/chrome/browser/extensions/extension_bindings_apitest.cc @@ -6,7 +6,9 @@ #include "chrome/browser/extensions/api/permissions/permissions_api.h" #include "chrome/browser/extensions/extension_apitest.h" +#include "chrome/browser/net/url_request_mock_util.h" #include "chrome/browser/ui/browser.h" +#include "content/public/browser/browser_thread.h" #include "content/public/test/browser_test_utils.h" #include "extensions/browser/extension_host.h" #include "extensions/browser/process_manager.h" @@ -16,7 +18,14 @@ namespace extensions { namespace { -class ExtensionBindingsApiTest : public ExtensionApiTest {}; +class ExtensionBindingsApiTest : public ExtensionApiTest { + public: + void SetUpOnMainThread() override { + content::BrowserThread::PostTask( + content::BrowserThread::IO, FROM_HERE, + base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); + } +}; IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, UnavailableBindingsNeverRegistered) { @@ -96,5 +105,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, ApiEnums) { ASSERT_TRUE(RunExtensionTest("bindings/api_enums")) << message_; }; +// Regression test for http://crbug.com/504011 - proper access checks on +// getModuleSystem(). +IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, ModuleSystem) { + ASSERT_TRUE(RunExtensionTest("bindings/module_system")) << message_; +} + } // namespace } // namespace extensions diff --git a/chrome/test/data/extensions/api_test/automation/tests/unit/test.js b/chrome/test/data/extensions/api_test/automation/tests/unit/test.js index 95a2cab..cc788ec 100644 --- a/chrome/test/data/extensions/api_test/automation/tests/unit/test.js +++ b/chrome/test/data/extensions/api_test/automation/tests/unit/test.js @@ -2,7 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -chrome.test.runWithModuleSystem(function(moduleSystem) { +chrome.test.runWithNativesEnabled(function() { + var moduleSystem = chrome.test.getModuleSystem(window); window.AutomationRootNode = moduleSystem.require('automationNode').AutomationRootNode; window.privates = moduleSystem.privates; diff --git a/chrome/test/data/extensions/api_test/bindings/module_system/background.js b/chrome/test/data/extensions/api_test/bindings/module_system/background.js new file mode 100644 index 0000000..f646363 --- /dev/null +++ b/chrome/test/data/extensions/api_test/bindings/module_system/background.js @@ -0,0 +1,15 @@ +// Copyright 2015 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.assertTrue(chrome.hasOwnProperty('runtime')); + +var iframe = document.createElement('iframe'); +iframe.src = 'http://mock.http/'; +iframe.onload = function() { + chrome.test.assertTrue(chrome.test.getModuleSystem(window) instanceof Object); + chrome.test.assertEq(undefined, + chrome.test.getModuleSystem(iframe.contentWindow)); + chrome.test.notifyPass(); +}; +document.body.appendChild(iframe); diff --git a/chrome/test/data/extensions/api_test/bindings/module_system/manifest.json b/chrome/test/data/extensions/api_test/bindings/module_system/manifest.json new file mode 100644 index 0000000..b976fcf --- /dev/null +++ b/chrome/test/data/extensions/api_test/bindings/module_system/manifest.json @@ -0,0 +1,8 @@ +{ + "name": "bindings/module_system", + "manifest_version": 2, + "version": "1", + "background": { + "scripts": ["background.js"] + } +} diff --git a/extensions/common/api/test.json b/extensions/common/api/test.json index 440ba26..1b910a9 100644 --- a/extensions/common/api/test.json +++ b/extensions/common/api/test.json @@ -147,10 +147,10 @@ ] }, { - "name": "runWithModuleSystem", + "name": "runWithNativesEnabled", "type": "function", "nocompile": true, - "description": "Gets a module system suitable for use in the context of a test.", + "description": "Runs the given function with access to native methods enabled.", "parameters": [ { "type": "function", @@ -159,6 +159,23 @@ ] }, { + "name": "getModuleSystem", + "type": "function", + "nocompile": true, + "description": "Returns an instance of the module system for the given context.", + "parameters": [ + { + "type": "any", + "name": "context" + } + ], + "returns": { + "type": "any", + "description": "The module system", + "optional": true + } + }, + { "name": "assertTrue", "type": "function", "nocompile": true, diff --git a/extensions/renderer/resources/test_custom_bindings.js b/extensions/renderer/resources/test_custom_bindings.js index 5ffbf6c..ebb3f1b 100644 --- a/extensions/renderer/resources/test_custom_bindings.js +++ b/extensions/renderer/resources/test_custom_bindings.js @@ -14,8 +14,8 @@ var GetAPIFeatures = requireNative('test_features').GetAPIFeatures; var uncaughtExceptionHandler = require('uncaught_exception_handler'); var userGestures = requireNative('user_gestures'); -var RunWithNativesEnabledModuleSystem = - requireNative('v8_context').RunWithNativesEnabledModuleSystem; +var RunWithNativesEnabled = requireNative('v8_context').RunWithNativesEnabled; +var GetModuleSystem = requireNative('v8_context').GetModuleSystem; binding.registerCustomHook(function(api) { var chromeTest = api.compiledApi; @@ -122,8 +122,12 @@ binding.registerCustomHook(function(api) { testDone(); }); - apiFunctions.setHandleRequest('runWithModuleSystem', function(callback) { - RunWithNativesEnabledModuleSystem(callback); + apiFunctions.setHandleRequest('runWithNativesEnabled', function(callback) { + RunWithNativesEnabled(callback); + }); + + apiFunctions.setHandleRequest('getModuleSystem', function(context) { + return GetModuleSystem(context); }); apiFunctions.setHandleRequest('assertTrue', function(test, message) { diff --git a/extensions/renderer/v8_context_native_handler.cc b/extensions/renderer/v8_context_native_handler.cc index 37f052b..7dbc2b8 100644 --- a/extensions/renderer/v8_context_native_handler.cc +++ b/extensions/renderer/v8_context_native_handler.cc @@ -24,8 +24,8 @@ V8ContextNativeHandler::V8ContextNativeHandler(ScriptContext* context, base::Bind(&V8ContextNativeHandler::GetModuleSystem, base::Unretained(this))); RouteFunction( - "RunWithNativesEnabledModuleSystem", - base::Bind(&V8ContextNativeHandler::RunWithNativesEnabledModuleSystem, + "RunWithNativesEnabled", + base::Bind(&V8ContextNativeHandler::RunWithNativesEnabled, base::Unretained(this))); } @@ -58,15 +58,12 @@ void V8ContextNativeHandler::GetModuleSystem( args.GetReturnValue().Set(context->module_system()->NewInstance()); } -void V8ContextNativeHandler::RunWithNativesEnabledModuleSystem( +void V8ContextNativeHandler::RunWithNativesEnabled( const v8::FunctionCallbackInfo<v8::Value>& args) { CHECK_EQ(args.Length(), 1); CHECK(args[0]->IsFunction()); - v8::Local<v8::Value> call_with_args[] = { - context()->module_system()->NewInstance()}; ModuleSystem::NativesEnabledScope natives_enabled(context()->module_system()); - context()->CallFunction(v8::Local<v8::Function>::Cast(args[0]), 1, - call_with_args); + context()->CallFunction(v8::Local<v8::Function>::Cast(args[0])); } } // namespace extensions diff --git a/extensions/renderer/v8_context_native_handler.h b/extensions/renderer/v8_context_native_handler.h index 77f68a6..da5098b 100644 --- a/extensions/renderer/v8_context_native_handler.h +++ b/extensions/renderer/v8_context_native_handler.h @@ -19,8 +19,7 @@ class V8ContextNativeHandler : public ObjectBackedNativeHandler { void GetAvailability(const v8::FunctionCallbackInfo<v8::Value>& args); void GetModuleSystem(const v8::FunctionCallbackInfo<v8::Value>& args); - void RunWithNativesEnabledModuleSystem( - const v8::FunctionCallbackInfo<v8::Value>& args); + void RunWithNativesEnabled(const v8::FunctionCallbackInfo<v8::Value>& args); ScriptContext* context_; Dispatcher* dispatcher_; diff --git a/extensions/test/data/api_test_base_unittest.js b/extensions/test/data/api_test_base_unittest.js index 46641ba..10c4792 100644 --- a/extensions/test/data/api_test_base_unittest.js +++ b/extensions/test/data/api_test_base_unittest.js @@ -55,7 +55,7 @@ unittestBindings.exportTests([ } test.runWithUserGesture(increment); test.runWithoutUserGesture(increment); - test.runWithModuleSystem(increment); + test.runWithNativesEnabled(increment); test.assertEq(3, counter); test.assertFalse(test.isProcessingUserGesture()); test.assertTrue(!!test.getApiFeatures()); diff --git a/ui/file_manager/externs/chrome_test.js b/ui/file_manager/externs/chrome_test.js index 88f9565..b76bbac 100644 --- a/ui/file_manager/externs/chrome_test.js +++ b/ui/file_manager/externs/chrome_test.js @@ -62,10 +62,16 @@ chrome.test.fail = function(message) {}; chrome.test.succeed = function(message) {}; /** - * Gets a module system suitable for use in the context of a test. + * Runs the given function with access to native methods enabled. * @param {Function} callback */ -chrome.test.runWithModuleSystem = function(callback) {}; +chrome.test.runWithNativesEnabled = function(callback) {}; + +/** + * Returns an instance of the ModuleSystem for the given context. + * @param {Object} context + */ +chrome.test.getModuleSystem = function(context) {}; /** * @param {?} test |