forked from breakwa11/gfw_whitelist
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
82 lines (74 loc) · 1.7 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var test_cases = [
1, "a.b.c.d.com",
0, "127.0.0.1",
0, "qq.com",
0, "im.qq.com",
0, "www.imqq.com",
1, "qqq.com",
1, "google.com",
0, "localhost"
];
function isPlainHostName(host) {
if ( host.toLowerCase() == 'localhost' )
return true;
return false;
}
function dnsResolve(host) {
return "27.40.0.0";
return "27.50.96.0";
return "27.50.128.0";
}
function isInNet(ip, ipstart, ipmask) {
return false;
}
function shExpMatch(a, b) {
return false;
}
function test(url, host) {
ret = FindProxyForURL(url, host);
if ( typeof(direct) == "undefined" ) {
if ( ret.toLowerCase().indexOf("direct") >= 0 ) {
return 0;
}
return 1;
} else if ( ret === direct )
return 0;
else
return 1;
}
function output_result(out_obj) {
output.value = "";
for (var j = 0; j < test_cases.length; j+=2) {
var test_case = test_cases[j+1];
var test_result = test(test_case, test_case);
var out_line = "" + test_result + " " + test_case + " ";
if ( test_result === test_cases[j] ) {
out_line = out_line + "Pass";
} else {
out_line = out_line + "NOT Pass";
}
out_obj.value = out_obj.value + out_line + "\n";
}
var start = new Date();
if ( test_cases.length > 1 ) {
for (var j = 0; j < 100000; ++j) {
var test_case = test_cases[1];
test(test_case, test_case);
}
}
var end = new Date();
alert(String(end - start) + "ms in 100,000 tests");
}
function begin_test() {
var output = document.getElementById("output");
output_result( output );
}
function test_one() {
var input = document.getElementById("input");
var result_obj = document.getElementById("result");
result = test(input.value, input.value);
if ( result === 1 )
result_obj.value = "Proxy";
else
result_obj.value = "Direct";
}