OLD | NEW |
| 1 // Copyright (c) 2014 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 |
1 // This should output "PROXY success:80" if all the tests pass. | 5 // This should output "PROXY success:80" if all the tests pass. |
2 // Otherwise it will output "PROXY failure:<num-failures>". | 6 // Otherwise it will output "PROXY failure:<num-failures>". |
3 // | 7 // |
4 // This aims to unit-test the PAC library functions, which are | 8 // This aims to unit-test the PAC library functions, which are |
5 // exposed in the PAC's execution environment. (Namely, dnsDomainLevels, | 9 // exposed in the PAC's execution environment. (Namely, dnsDomainLevels, |
6 // timeRange, etc.) | 10 // timeRange, etc.) |
7 | 11 |
8 function FindProxyForURL(url, host) { | 12 function FindProxyForURL(url, host) { |
9 var numTestsFailed = 0; | 13 var numTestsFailed = 0; |
10 | 14 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 t.expectTrue(isInNet("192.89.132.25", "192.89.0.0", "255.255.0.0")); | 58 t.expectTrue(isInNet("192.89.132.25", "192.89.0.0", "255.255.0.0")); |
55 t.expectFalse(isInNet("193.89.132.25", "192.89.0.0", "255.255.0.0")); | 59 t.expectFalse(isInNet("193.89.132.25", "192.89.0.0", "255.255.0.0")); |
56 | 60 |
57 t.expectFalse( | 61 t.expectFalse( |
58 isInNet("192.89.132.a", "192.89.0.0", "255.255.0.0")); | 62 isInNet("192.89.132.a", "192.89.0.0", "255.255.0.0")); |
59 }; | 63 }; |
60 | 64 |
61 Tests.testIsPlainHostName = function(t) { | 65 Tests.testIsPlainHostName = function(t) { |
62 t.expectTrue(isPlainHostName("google")); | 66 t.expectTrue(isPlainHostName("google")); |
63 t.expectFalse(isPlainHostName("google.com")); | 67 t.expectFalse(isPlainHostName("google.com")); |
| 68 t.expectFalse(isPlainHostName("192.168.1.1")); |
| 69 t.expectFalse(isPlainHostName(".")); |
| 70 t.expectFalse(isPlainHostName(".:")); |
| 71 |
| 72 // Valid IPv6 address |
| 73 t.expectFalse(isPlainHostName("::1")); |
| 74 |
| 75 // Not a valid IPv6 address |
| 76 t.expectTrue(isPlainHostName("foopy::1")); |
| 77 t.expectTrue(isPlainHostName("foo:112")); |
| 78 t.expectTrue(isPlainHostName(":")); |
| 79 t.expectTrue(isPlainHostName("[:]")); |
| 80 |
| 81 // Not considered a valid IPv6 address because of surrounding brackets. |
| 82 t.expectTrue(isPlainHostName("[::1]")); |
| 83 |
| 84 // Calling with more than 1 argument is allowed. |
| 85 t.expectTrue(isPlainHostName("foo", "foo", "foo")); |
| 86 |
| 87 // Calling with no arguments is an error. |
| 88 try { |
| 89 isPlainHostName(); |
| 90 t.expectTrue(false); // Not reached. |
| 91 } catch (e) { |
| 92 t.expectEquals('TypeError: Requires 1 string parameter', e.toString()); |
| 93 } |
| 94 |
| 95 // Calling with the wrong argument type is an error. |
| 96 try { |
| 97 isPlainHostName(null); |
| 98 t.expectTrue(false); // Not reached. |
| 99 } catch (e) { |
| 100 t.expectEquals('TypeError: Requires 1 string parameter', e.toString()); |
| 101 } |
| 102 |
| 103 // Calling with the wrong argument type is an error. |
| 104 try { |
| 105 isPlainHostName(1); |
| 106 t.expectTrue(false); // Not reached. |
| 107 } catch (e) { |
| 108 t.expectEquals('TypeError: Requires 1 string parameter', e.toString()); |
| 109 } |
| 110 |
| 111 // Calling with the wrong argument type is an error. |
| 112 try { |
| 113 isPlainHostName(function() {}); |
| 114 t.expectTrue(false); // Not reached. |
| 115 } catch (e) { |
| 116 t.expectEquals('TypeError: Requires 1 string parameter', e.toString()); |
| 117 } |
64 }; | 118 }; |
65 | 119 |
66 Tests.testLocalHostOrDomainIs = function(t) { | 120 Tests.testLocalHostOrDomainIs = function(t) { |
67 t.expectTrue(localHostOrDomainIs("www.google.com", "www.google.com")); | 121 t.expectTrue(localHostOrDomainIs("www.google.com", "www.google.com")); |
68 t.expectTrue(localHostOrDomainIs("www", "www.google.com")); | 122 t.expectTrue(localHostOrDomainIs("www", "www.google.com")); |
69 t.expectFalse(localHostOrDomainIs("maps.google.com", "www.google.com")); | 123 t.expectFalse(localHostOrDomainIs("maps.google.com", "www.google.com")); |
70 }; | 124 }; |
71 | 125 |
72 Tests.testShExpMatch = function(t) { | 126 Tests.testShExpMatch = function(t) { |
73 t.expectTrue(shExpMatch("foo.jpg", "*.jpg")); | 127 t.expectTrue(shExpMatch("foo.jpg", "*.jpg")); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 "toGMTString", "toUTCString", "getYear", "setYear" | 411 "toGMTString", "toUTCString", "getYear", "setYear" |
358 ]; | 412 ]; |
359 | 413 |
360 MockDate.setCurrent = function(currentDateString) { | 414 MockDate.setCurrent = function(currentDateString) { |
361 MockDate.currentDateString_ = currentDateString; | 415 MockDate.currentDateString_ = currentDateString; |
362 } | 416 } |
363 | 417 |
364 // Bind the methods to proxy requests to the wrapped Date(). | 418 // Bind the methods to proxy requests to the wrapped Date(). |
365 MockDate.init(); | 419 MockDate.init(); |
366 | 420 |
OLD | NEW |