- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / cross_origin_xhr / all_urls / test.js
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Tab where the content script has been injected.
6 var testTabId;
7
8 var pass = chrome.test.callbackPass;
9
10 chrome.test.getConfig(function(config) {
11
12   function rewriteURL(url) {
13     return url.replace(/PORT/, config.testServer.port);
14   }
15
16   function doReq(domain, expectSuccess) {
17     var url = rewriteURL(domain + ':PORT/extensions/test_file.txt');
18
19     chrome.tabs.sendRequest(testTabId, url, pass(function(response) {
20       if (expectSuccess) {
21         chrome.test.assertEq('load', response.event);
22         chrome.test.assertEq(200, response.status);
23         chrome.test.assertEq('Hello!', response.text);
24       } else {
25         chrome.test.assertEq(0, response.status);
26       }
27     }));
28   }
29
30   chrome.tabs.create({
31       url: rewriteURL('http://localhost:PORT/extensions/test_file.html')},
32       function(tab) {
33         testTabId = tab.id;
34       });
35
36   chrome.extension.onRequest.addListener(function(message) {
37     chrome.test.assertEq('injected', message);
38
39     chrome.test.runTests([
40       function domainOne() {
41         doReq('http://a.com', true);
42       },
43       function domainTwo() {
44         doReq('http://c.com', true);
45       }
46     ]);
47   });
48 });