Add a test that getModuleSystem() doesn't work cross origin
BUG=504011
[email protected]
[email protected]
Review URL: https://codereview.chromium.org/1241443004
Cr-Commit-Position: refs/heads/master@{#338663}
diff --git a/chrome/browser/extensions/extension_bindings_apitest.cc b/chrome/browser/extensions/extension_bindings_apitest.cc
index c78fb200..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 @@
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..f646363a
--- /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"]
+ }
+}