summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-11 19:28:25 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-11 19:28:25 +0000
commit55d2896ebe24dbe13282e78a593698c4d04a2b6c (patch)
tree53f12b27aca26515608964cd71b40f3b437a5a6c /chrome/test
parent5482516e2acb357f73a4a1950579c61f19d69bbc (diff)
downloadchromium_src-55d2896ebe24dbe13282e78a593698c4d04a2b6c.zip
chromium_src-55d2896ebe24dbe13282e78a593698c4d04a2b6c.tar.gz
chromium_src-55d2896ebe24dbe13282e78a593698c4d04a2b6c.tar.bz2
Add api tests for cross-origin XHR.
Review URL: http://codereview.chromium.org/199092 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25994 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/data/extensions/api_test/cross_origin_xhr/manifest.json7
-rw-r--r--chrome/test/data/extensions/api_test/cross_origin_xhr/test.html54
-rw-r--r--chrome/test/data/extensions/test_file.txt1
3 files changed, 62 insertions, 0 deletions
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