summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormihaip@chromium.org <mihaip@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-18 00:32:53 +0000
committermihaip@chromium.org <mihaip@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-18 00:32:53 +0000
commit8f0633691cd10779408642e2ad5eaa9b0c190b0a (patch)
tree24395b8196731886a6e46b87b779d4cf09aba3d9
parentff3e5c4b85e2d4d93410841a4ca31a1707e7dac3 (diff)
downloadchromium_src-8f0633691cd10779408642e2ad5eaa9b0c190b0a.zip
chromium_src-8f0633691cd10779408642e2ad5eaa9b0c190b0a.tar.gz
chromium_src-8f0633691cd10779408642e2ad5eaa9b0c190b0a.tar.bz2
When allowing an extension file:/// URL access, grant its process access to that scheme.
This allows XHRs from the background page to file:/// URLs to succeed. XHRs from content scripts still fail, since they're running in a regular renderer process, and there is currently no mechanism for only whitelisting the isolated world within it for the file: scheme. Also re-enable ExtensionApiTest.CrossOriginXHRContentScript since it doesn't appear to have flaked recently. BUG=104547,96725 R=aa@chromium.org Review URL: http://codereview.chromium.org/8587052 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110614 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/cross_origin_xhr_apitest.cc12
-rw-r--r--chrome/browser/extensions/extension_apitest.cc7
-rw-r--r--chrome/browser/renderer_host/chrome_render_view_host_observer.cc7
-rw-r--r--chrome/common/extensions/api/extension_api.json4
-rw-r--r--chrome/test/data/extensions/api_test/cross_origin_xhr/file_access/manifest.json7
-rw-r--r--chrome/test/data/extensions/api_test/cross_origin_xhr/file_access/test.html25
-rw-r--r--chrome/test/data/extensions/api_test/cross_origin_xhr/no_file_access/manifest.json7
-rw-r--r--chrome/test/data/extensions/api_test/cross_origin_xhr/no_file_access/test.html23
8 files changed, 88 insertions, 4 deletions
diff --git a/chrome/browser/extensions/cross_origin_xhr_apitest.cc b/chrome/browser/extensions/cross_origin_xhr_apitest.cc
index 43fa257..7f67897 100644
--- a/chrome/browser/extensions/cross_origin_xhr_apitest.cc
+++ b/chrome/browser/extensions/cross_origin_xhr_apitest.cc
@@ -17,9 +17,17 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, CrossOriginXHRAllURLs) {
ASSERT_TRUE(RunExtensionTest("cross_origin_xhr/all_urls")) << message_;
}
-// Flaky on the trybots. See http://crbug.com/96725.
-IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FLAKY_CrossOriginXHRContentScript) {
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, CrossOriginXHRContentScript) {
host_resolver()->AddRule("*.com", "127.0.0.1");
ASSERT_TRUE(StartTestServer());
ASSERT_TRUE(RunExtensionTest("cross_origin_xhr/content_script")) << message_;
}
+
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, CrossOriginXHRFileAccess) {
+ ASSERT_TRUE(RunExtensionTest("cross_origin_xhr/file_access")) << message_;
+}
+
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, CrossOriginXHRNoFileAccess) {
+ ASSERT_TRUE(RunExtensionTestNoFileAccess(
+ "cross_origin_xhr/no_file_access")) << message_;
+}
diff --git a/chrome/browser/extensions/extension_apitest.cc b/chrome/browser/extensions/extension_apitest.cc
index 0631151..893a25d 100644
--- a/chrome/browser/extensions/extension_apitest.cc
+++ b/chrome/browser/extensions/extension_apitest.cc
@@ -18,6 +18,7 @@
namespace {
const char kTestServerPort[] = "testServer.port";
+const char kTestDataDirectory[] = "testDataDirectory";
}; // namespace
@@ -93,6 +94,8 @@ void ExtensionApiTest::ResultCatcher::Observe(
void ExtensionApiTest::SetUpInProcessBrowserTestFixture() {
DCHECK(!test_config_.get()) << "Previous test did not clear config state.";
test_config_.reset(new DictionaryValue());
+ test_config_->SetString(kTestDataDirectory,
+ net::FilePathToFileURL(test_data_dir_).spec());
ExtensionTestGetConfigFunction::set_test_config_state(test_config_.get());
}
@@ -233,8 +236,8 @@ bool ExtensionApiTest::StartTestServer() {
return false;
// Build a dictionary of values that tests can use to build URLs that
- // access the test server. Tests can see these values using the extension
- // API function chrome.test.getConfig().
+ // access the test server and local file system. Tests can see these values
+ // using the extension API function chrome.test.getConfig().
test_config_->SetInteger(kTestServerPort,
test_server()->host_port_pair().port());
diff --git a/chrome/browser/renderer_host/chrome_render_view_host_observer.cc b/chrome/browser/renderer_host/chrome_render_view_host_observer.cc
index cb924d3..eb0646c 100644
--- a/chrome/browser/renderer_host/chrome_render_view_host_observer.cc
+++ b/chrome/browser/renderer_host/chrome_render_view_host_observer.cc
@@ -116,6 +116,13 @@ void ChromeRenderViewHostObserver::InitRenderViewForExtensions() {
process->id(), chrome::kChromeUIScheme);
}
+ if (type == Extension::TYPE_EXTENSION &&
+ profile_->GetExtensionService()->extension_prefs()->AllowFileAccess(
+ extension->id())) {
+ ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
+ process->id(), chrome::kFileScheme);
+ }
+
if (type == Extension::TYPE_EXTENSION ||
type == Extension::TYPE_USER_SCRIPT ||
type == Extension::TYPE_PACKAGED_APP ||
diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json
index 0486385..bff9470 100644
--- a/chrome/common/extensions/api/extension_api.json
+++ b/chrome/common/extensions/api/extension_api.json
@@ -6334,6 +6334,10 @@
"maximum": 65535
}
}
+ },
+ "testDataDirectory": {
+ "type": "string",
+ "description": "file:/// URL for the API test data directory."
}
}
}
diff --git a/chrome/test/data/extensions/api_test/cross_origin_xhr/file_access/manifest.json b/chrome/test/data/extensions/api_test/cross_origin_xhr/file_access/manifest.json
new file mode 100644
index 0000000..e243ba5
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/cross_origin_xhr/file_access/manifest.json
@@ -0,0 +1,7 @@
+{
+ "name": "Cross origin XHR to file:/// URLs with access",
+ "version": "1.0",
+ "description": "Tests bug 104547",
+ "background_page": "test.html",
+ "permissions": [ "<all_urls>" ]
+}
diff --git a/chrome/test/data/extensions/api_test/cross_origin_xhr/file_access/test.html b/chrome/test/data/extensions/api_test/cross_origin_xhr/file_access/test.html
new file mode 100644
index 0000000..2aaaab1
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/cross_origin_xhr/file_access/test.html
@@ -0,0 +1,25 @@
+<script>
+chrome.test.getConfig(function(config) {
+ chrome.test.runTests([
+ function fileAccessAllowed() {
+ var req = new XMLHttpRequest();
+
+ var url = config.testDataDirectory + "/../test_file.txt";
+ chrome.test.log("Requesting url: " + url);
+ req.open("GET", url, true);
+
+ req.onload = function() {
+ chrome.test.assertEq("Hello!", req.responseText);
+ chrome.test.runNextTest();
+ }
+ req.onerror = function() {
+ chrome.test.log("status: " + req.status);
+ chrome.test.log("text: " + req.responseText);
+ chrome.test.fail("Unexpected error for url: " + url);
+ }
+
+ req.send(null);
+ }
+ ]);
+});
+</script>
diff --git a/chrome/test/data/extensions/api_test/cross_origin_xhr/no_file_access/manifest.json b/chrome/test/data/extensions/api_test/cross_origin_xhr/no_file_access/manifest.json
new file mode 100644
index 0000000..2dff594
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/cross_origin_xhr/no_file_access/manifest.json
@@ -0,0 +1,7 @@
+{
+ "name": "Cross origin XHR to file:/// URLs without access",
+ "version": "1.0",
+ "description": "Tests bug 104547",
+ "background_page": "test.html",
+ "permissions": [ "<all_urls>" ]
+}
diff --git a/chrome/test/data/extensions/api_test/cross_origin_xhr/no_file_access/test.html b/chrome/test/data/extensions/api_test/cross_origin_xhr/no_file_access/test.html
new file mode 100644
index 0000000..71adbb0
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/cross_origin_xhr/no_file_access/test.html
@@ -0,0 +1,23 @@
+<script>
+chrome.test.getConfig(function(config) {
+ chrome.test.runTests([
+ function fileAccessNotAllowed() {
+ var req = new XMLHttpRequest();
+
+ var url = config.testDataDirectory + "/../test_file.txt";
+ chrome.test.log("Requesting url: " + url);
+ req.open("GET", url, true);
+
+ req.onload = function() {
+ chrome.test.fail("Unexpected success for url: " + url);
+ }
+ req.onerror = function() {
+ chrome.test.assertEq(0, req.status);
+ chrome.test.runNextTest();
+ }
+
+ req.send(null);
+ }
+ ]);
+});
+</script>