diff options
-rw-r--r-- | chrome/browser/extensions/cross_origin_xhr_apitest.cc | 11 | ||||
-rw-r--r-- | chrome/chrome.gyp | 2 | ||||
-rw-r--r-- | chrome/test/data/extensions/api_test/cross_origin_xhr/manifest.json | 7 | ||||
-rw-r--r-- | chrome/test/data/extensions/api_test/cross_origin_xhr/test.html | 54 | ||||
-rw-r--r-- | chrome/test/data/extensions/test_file.txt | 1 |
5 files changed, 75 insertions, 0 deletions
diff --git a/chrome/browser/extensions/cross_origin_xhr_apitest.cc b/chrome/browser/extensions/cross_origin_xhr_apitest.cc new file mode 100644 index 0000000..5a98322 --- /dev/null +++ b/chrome/browser/extensions/cross_origin_xhr_apitest.cc @@ -0,0 +1,11 @@ +// Copyright (c) 2009 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. + +#include "chrome/browser/extensions/extension_apitest.h" + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, CrossOriginXHR) { + host_resolver()->AddRule("*.com", "127.0.0.1"); + StartHTTPServer(); + ASSERT_TRUE(RunExtensionTest("cross_origin_xhr")) << message_; +} diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index cc56d34..185f65c 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -59,6 +59,7 @@ 'browser/gtk/bookmark_manager_browsertest.cc', 'browser/gtk/view_id_util_browsertest.cc', 'browser/ssl/ssl_browser_tests.cc', + 'browser/extensions/cross_origin_xhr_apitest.cc', 'browser/extensions/extension_apitest.cc', 'browser/extensions/extension_apitest.h', 'browser/extensions/extension_bookmarks_apitest.cc', @@ -89,6 +90,7 @@ 'browser/task_manager_browsertest.cc', ], 'browser_tests_sources_exclude_on_mac': [ + 'browser/extensions/cross_origin_xhr_apitest.cc', 'browser/extensions/extension_apitest.cc', 'browser/extensions/extension_apitest.h', 'browser/extensions/extension_bookmarks_apitest.cc', diff --git a/chrome/test/data/extensions/api_test/cross_origin_xhr/manifest.json b/chrome/test/data/extensions/api_test/cross_origin_xhr/manifest.json new file mode 100644 index 0000000..7da00ed --- /dev/null +++ b/chrome/test/data/extensions/api_test/cross_origin_xhr/manifest.json @@ -0,0 +1,7 @@ +{ + "name": "cross origin xhr tests", + "version": "0.1", + "description": "Sanity check that cross-origin XHR works for extensions. The majority of this is implemented (and tested) in WebKit, but we have a sanity test here just to make sure the integration with Chromium keeps working.", + "background_page": "test.html", + "permissions": ["http://a.com/", "http://*.b.com/"] +} diff --git a/chrome/test/data/extensions/api_test/cross_origin_xhr/test.html b/chrome/test/data/extensions/api_test/cross_origin_xhr/test.html new file mode 100644 index 0000000..52a8a33 --- /dev/null +++ b/chrome/test/data/extensions/api_test/cross_origin_xhr/test.html @@ -0,0 +1,54 @@ +<script> +function doReq(domain, expectSuccess) { + var req = new XMLHttpRequest(); + var url = domain + ":1337/files/extensions/test_file.txt"; + + chrome.test.log("Requesting url: " + url); + req.open("GET", url, true); + + + if (expectSuccess) { + req.onload = function() { + chrome.test.assertEq(200, req.status); + 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 domain: " + domain); + } + } else { + req.onload = function() { + chrome.test.fail("Unexpected success for domain: " + domain); + } + req.onerror = function() { + chrome.test.assertEq(0, req.status); + chrome.test.runNextTest(); + } + } + + req.send(null); +} + +chrome.test.runTests([ + function allowedOrigin() { + doReq("http://a.com", true); + }, + function diallowedOrigin() { + doReq("http://c.com", false); + }, + function allowedSubdomain() { + doReq("http://foo.b.com", true); + }, + function noSubdomain() { + doReq("http://b.com", true); + }, + function disallowedSubdomain() { + doReq("http://foob.com", false); + }, + function disallowedSSL() { + doReq("https://a.com", false); + } +]); +</script> diff --git a/chrome/test/data/extensions/test_file.txt b/chrome/test/data/extensions/test_file.txt new file mode 100644 index 0000000..05a682b --- /dev/null +++ b/chrome/test/data/extensions/test_file.txt @@ -0,0 +1 @@ +Hello!
\ No newline at end of file |