| OLD | NEW |
| 1 <script> | 1 <!-- |
| 2 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this |
| 3 // Use of this source code is governed by a BSD-style license that can be | 3 * source code is governed by a BSD-style license that can be found in the |
| 4 // found in the LICENSE file. | 4 * LICENSE file. |
| 5 | 5 --> |
| 6 // proxy api test | 6 <script src="invalid_proxy.js"></script> |
| 7 // browser_tests.exe --gtest_filter=ProxySettingsApiTest.ProxyEventsInvalidProxy | |
| 8 | |
| 9 var expected_error = { | |
| 10 error: "net::ERR_PROXY_CONNECTION_FAILED", | |
| 11 details: "", | |
| 12 fatal: true | |
| 13 }; | |
| 14 var empty_json_url = ""; | |
| 15 | |
| 16 function test() { | |
| 17 // Install error handler and get the test server config. | |
| 18 chrome.proxy.onProxyError.addListener(function (error) { | |
| 19 chrome.test.assertEq(expected_error, error); | |
| 20 chrome.test.notifyPass(); | |
| 21 }); | |
| 22 chrome.test.getConfig(readConfigAndSetProxy); | |
| 23 } | |
| 24 | |
| 25 function readConfigAndSetProxy(test_config) { | |
| 26 // Construct the URL used for XHRs and set the proxy settings. | |
| 27 empty_json_url = "http://127.0.0.1:" + | |
| 28 test_config.testServer.port + | |
| 29 "/files/extensions/api_test/proxy/events/empty.json"; | |
| 30 | |
| 31 // Set an invalid proxy and fire of a XHR. This should trigger proxy errors. | |
| 32 // There may be any number of proxy errors, as systems like safe browsing | |
| 33 // might start network traffic as well. | |
| 34 var rules = { | |
| 35 singleProxy: { host: "does.not.exist" } | |
| 36 }; | |
| 37 var config = { rules: rules, mode: "fixed_servers" }; | |
| 38 chrome.proxy.settings.set({'value': config}, sendFailingXHR); | |
| 39 } | |
| 40 | |
| 41 function sendFailingXHR() { | |
| 42 var req = new XMLHttpRequest(); | |
| 43 req.open("GET", empty_json_url, true); | |
| 44 req.onload = function () { | |
| 45 chrome.test.notifyFail("proxy settings should not work"); | |
| 46 } | |
| 47 req.onerror = testDone; | |
| 48 req.send(null); | |
| 49 } | |
| 50 | |
| 51 function testDone() { | |
| 52 // Do nothing. The test success/failure is decided in the event handler. | |
| 53 } | |
| 54 | |
| 55 test(); | |
| 56 </script> | |
| OLD | NEW |