- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / proxy / events / invalid_proxy.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 // proxy api test
6 // browser_tests.exe --gtest_filter=ProxySettingsApiTest.ProxyEventsInvalidProxy
7
8 var expected_error = {
9     error: "net::ERR_PROXY_CONNECTION_FAILED",
10     details: "",
11     fatal: true
12 };
13 var empty_json_url = "";
14
15 function test() {
16   // Install error handler and get the test server config.
17   chrome.proxy.onProxyError.addListener(function (error) {
18     chrome.test.assertEq(expected_error, error);
19     chrome.test.notifyPass();
20   });
21   chrome.test.getConfig(readConfigAndSetProxy);
22 }
23
24 function readConfigAndSetProxy(test_config) {
25   // Construct the URL used for XHRs and set the proxy settings.
26   empty_json_url = "http://127.0.0.1:" +
27       test_config.testServer.port +
28       "/extensions/api_test/proxy/events/empty.json";
29
30   // Set an invalid proxy and fire of a XHR. This should trigger proxy errors.
31   // There may be any number of proxy errors, as systems like safe browsing
32   // might start network traffic as well.
33   var rules = {
34     singleProxy: { host: "does.not.exist" }
35   };
36   var config = { rules: rules, mode: "fixed_servers" };
37   chrome.proxy.settings.set({'value': config}, sendFailingXHR);
38 }
39
40 function sendFailingXHR() {
41   var req = new XMLHttpRequest();
42   req.open("GET", empty_json_url, true);
43   req.onload = function () {
44     chrome.test.notifyFail("proxy settings should not work");
45   }
46   req.onerror = testDone;
47   req.send(null);
48 }
49
50 function testDone() {
51  // Do nothing. The test success/failure is decided in the event handler.
52 }
53
54 test();