diff options
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> |