OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // proxy api test | 5 // proxy api test |
6 // browser_tests.exe --gtest_filter=ProxySettingsApiTest.ProxyEvents | 6 // browser_tests.exe --gtest_filter=ProxySettingsApiTest.ProxyEvents |
7 | 7 |
8 var captured_events = []; | 8 var captured_events = []; |
9 var expected_events = [ | 9 var expected_events = [ |
10 { | 10 { |
11 error: "net::ERR_PROXY_CONNECTION_FAILED", | 11 error: "net::ERR_PROXY_CONNECTION_FAILED", |
12 details: "", | 12 details: "", |
13 fatal: true | 13 fatal: true |
14 }, | 14 }, |
15 { | 15 { |
16 error: "net::ERR_PROXY_CONNECTION_FAILED", | 16 error: "net::ERR_PROXY_CONNECTION_FAILED", |
17 details: "", | 17 details: "", |
18 fatal: true | 18 fatal: true |
19 }, | 19 }, |
20 { | 20 { |
21 error: "net::ERR_PAC_SCRIPT_FAILED", | 21 error: "net::ERR_PAC_SCRIPT_FAILED", |
22 details: "line: 1: Uncaught SyntaxError: Unexpected token !", | 22 details: "line: 1: Uncaught SyntaxError: Unexpected token !", |
23 fatal: false | 23 fatal: false |
24 } | 24 } |
25 ]; | 25 ]; |
26 | 26 |
27 chrome.experimental.proxy.onProxyError.addListener(function (error) { | 27 chrome.proxy.onProxyError.addListener(function (error) { |
28 captured_events.push(error); | 28 captured_events.push(error); |
29 if (captured_events.length < expected_events.length) | 29 if (captured_events.length < expected_events.length) |
30 return; | 30 return; |
31 chrome.test.assertEq(expected_events, captured_events); | 31 chrome.test.assertEq(expected_events, captured_events); |
32 chrome.test.notifyPass(); | 32 chrome.test.notifyPass(); |
33 }); | 33 }); |
34 | 34 |
35 function pacTest(e) { | 35 function pacTest(e) { |
36 var config = { | 36 var config = { |
37 mode: "pac_script", | 37 mode: "pac_script", |
38 pacScript: { | 38 pacScript: { |
39 data: "trash!", | 39 data: "trash!", |
40 mandatory: false | 40 mandatory: false |
41 } | 41 } |
42 }; | 42 }; |
43 chrome.experimental.proxy.settings.set({'value': config}); | 43 chrome.proxy.settings.set({'value': config}); |
44 } | 44 } |
45 | 45 |
46 var rules = { | 46 var rules = { |
47 singleProxy: { host: "does.not.exist" } | 47 singleProxy: { host: "does.not.exist" } |
48 }; | 48 }; |
49 | 49 |
50 var config = { rules: rules, mode: "fixed_servers" }; | 50 var config = { rules: rules, mode: "fixed_servers" }; |
51 chrome.experimental.proxy.settings.set({'value': config}, function () { | 51 chrome.proxy.settings.set({'value': config}, function () { |
52 var req = new XMLHttpRequest(); | 52 var req = new XMLHttpRequest(); |
53 req.open("GET", "http://127.0.0.1/", true); | 53 req.open("GET", "http://127.0.0.1/", true); |
54 req.onload = function () { | 54 req.onload = function () { |
55 chrome.test.notifyFail("proxy settings should not work"); | 55 chrome.test.notifyFail("proxy settings should not work"); |
56 } | 56 } |
57 req.onerror = pacTest; | 57 req.onerror = pacTest; |
58 req.send(null); | 58 req.send(null); |
59 }); | 59 }); |
OLD | NEW |