aboutsummaryrefslogtreecommitdiff
path: root/test/proxy_test_script.h
blob: 500a57ae5584dc604c18bb06472a89f602ff5843 (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
// This file is auto generated using the following command.
// Do not modify.
// 	./jstocstring.pl js-unittest proxy_test_script.h
#ifndef PROXY_TEST_SCRIPT_H_
#define PROXY_TEST_SCRIPT_H_

#define B_132073833_JS \
  u""\
  "function FindProxyForURL(url, host){\n" \
  "    function opt() {\n" \
  "        opt['x'] = 1.1;\n" \
  "        try {\n" \
  "            Object.create(object);\n" \
  "        } catch (e) {\n" \
  "        }\n" \
  "\n" \
  "        for (let i = 0; i < 100000; i++) {\n" \
  "\n" \
  "        }\n" \
  "    }\n" \
  "\n" \
  "    opt();\n" \
  "    object = opt;\n" \
  "    opt();\n" \
  "\n" \
  "    return \"DIRECT\";\n" \
  "}\n" \
  "\n" \
  "var object;\n" \

#define B_139806216_JS \
  u""\
  "function FindProxyForURL(url, host){\n" \
  "    var x = new ArrayBuffer(1);\n" \
  "    return \"DIRECT\";\n" \
  "}\n" \

#define BINDING_FROM_GLOBAL_JS \
  u""\
  "// Calls a bindings outside of FindProxyForURL(). This causes the code to\n" \
  "// get exercised during initialization.\n" \
  "\n" \
  "var x = myIpAddress();\n" \
  "\n" \
  "function FindProxyForURL(url, host) {\n" \
  "  return \"PROXY \" + x + \":80\";\n" \
  "}\n" \

#define BINDINGS_JS \
  u""\
  "// Try calling the browser-side bound functions with varying (invalid)\n" \
  "// inputs. There is no notion of \"success\" for this test, other than\n" \
  "// verifying the correct C++ bindings were reached with expected values.\n" \
  "\n" \
  "function MyObject() {\n" \
  "  this.x = \"3\";\n" \
  "}\n" \
  "\n" \
  "MyObject.prototype.toString = function() {\n" \
  "  throw \"exception from calling toString()\";\n" \
  "}\n" \
  "\n" \
  "function expectEquals(expectation, actual) {\n" \
  "  if (!(expectation === actual)) {\n" \
  "    throw \"FAIL: expected: \" + expectation + \", actual: \" + actual;\n" \
  "  }\n" \
  "}\n" \
  "\n" \
  "function FindProxyForURL(url, host) {\n" \
  "  // Call dnsResolve with some wonky arguments.\n" \
  "  // Those expected to fail (because we have passed a non-string parameter)\n" \
  "  // will return |null|, whereas those that have called through to the C++\n" \
  "  // bindings will return '127.0.0.1'.\n" \
  "  expectEquals(undefined, dnsResolve());\n" \
  "  expectEquals(undefined, dnsResolve(null));\n" \
  "  expectEquals(undefined, dnsResolve(undefined));\n" \
  "  expectEquals('127.0.0.1', dnsResolve(\"\"));\n" \
  "  expectEquals(undefined, dnsResolve({foo: 'bar'}));\n" \
  "  expectEquals(undefined, dnsResolve(fn));\n" \
  "  expectEquals(undefined, dnsResolve(['3']));\n" \
  "  expectEquals('127.0.0.1', dnsResolve(\"arg1\", \"arg2\", \"arg3\", \"arg4\"));\n" \
  "\n" \
  "  // Call alert with some wonky arguments.\n" \
  "  alert();\n" \
  "  alert(null);\n" \
  "  alert(undefined);\n" \
  "  alert({foo:'bar'});\n" \
  "\n" \
  "  // This should throw an exception when we toString() the argument\n" \
  "  // to alert in the bindings.\n" \
  "  try {\n" \
  "    alert(new MyObject());\n" \
  "  } catch (e) {\n" \
  "    alert(e);\n" \
  "  }\n" \
  "\n" \
  "  // Call myIpAddress() with wonky arguments\n" \
  "  myIpAddress(null);\n" \
  "  myIpAddress(null, null);\n" \
  "\n" \
  "  // Call myIpAddressEx() correctly (no arguments).\n" \
  "  myIpAddressEx();\n" \
  "\n" \
  "  // Call dnsResolveEx() (note that isResolvableEx() implicity calls it.)\n" \
  "  isResolvableEx(\"is_resolvable\");\n" \
  "  dnsResolveEx(\"foobar\");\n" \
  "\n" \
  "  return \"DIRECT\";\n" \
  "}\n" \
  "\n" \
  "function fn() {}\n" \
  "\n" \

#define CHANGE_ELEMENT_KIND_JS \
  u""\
  "// PAC script with getter that changes element kind.\n" \
  "\n" \
  "function FindProxyForURL(url, host) {\n" \
  "  let arr = [];\n" \
  "  arr[1000] = 0x1234;\n" \
  "\n" \
  "  arr.__defineGetter__(256, function () {\n" \
  "    delete arr[256];\n" \
  "    arr.unshift(1.1);\n" \
  "  });\n" \
  "\n" \
  "  let results = Object.entries(arr);\n" \
  "  let str = results.toString();\n" \
  "  return \"DIRECT\";\n" \
  "}\n" \

#define DIRECT_JS \
  u""\
  "function FindProxyForURL(url, host) {\n" \
  "  return \"DIRECT\";\n" \
  "}\n" \
  "\n" \

#define DNS_FAIL_JS \
  u""\
  "// This script should be run in an environment where all DNS resolution are\n" \
  "// failing. It tests that functions return the expected values.\n" \
  "//\n" \
  "// Returns \"PROXY success:80\" on success.\n" \
  "function FindProxyForURL(url, host) {\n" \
  "  try {\n" \
  "    expectEq(\"127.0.0.1\", myIpAddress());\n" \
  "    expectEq(\"\", myIpAddressEx());\n" \
  "\n" \
  "    expectEq(null, dnsResolve(\"not-found\"));\n" \
  "    expectEq(\"\", dnsResolveEx(\"not-found\"));\n" \
  "\n" \
  "    expectEq(false, isResolvable(\"not-found\"));\n" \
  "    expectEq(false, isResolvableEx(\"not-found\"));\n" \
  "\n" \
  "    return \"PROXY success:80\";\n" \
  "  } catch(e) {\n" \
  "    alert(e);\n" \
  "    return \"PROXY failed:80\";\n" \
  "  }\n" \
  "}\n" \
  "\n" \
  "function expectEq(expected, actual) {\n" \
  "  if (expected != actual)\n" \
  "    throw \"Expected \" + expected + \" but was \" + actual;\n" \
  "}\n" \
  "\n" \

#define ENDS_WITH_COMMENT_JS \
  u""\
  "function FindProxyForURL(url, host) {\n" \
  "  return \"PROXY success:80\";\n" \
  "}\n" \
  "\n" \
  "// We end the script with a comment (and no trailing newline).\n" \
  "// This used to cause problems, because internally ProxyResolverV8\n" \
  "// would append some functions to the script; the first line of\n" \
  "// those extra functions was being considered part of the comment.\n" \

#define ENDS_WITH_STATEMENT_NO_SEMICOLON_JS \
  u""\
  "// Ends with a statement, and no terminal newline.\n" \
  "function FindProxyForURL(url, host) { return \"PROXY success:\" + x; }\n" \
  "x = 3\n" \

#define INTERNATIONAL_DOMAIN_NAMES_JS \
  u""\
  "// Try resolving hostnames containing non-ASCII characters.\n" \
  "\n" \
  "function FindProxyForURL(url, host) {\n" \
  "  // This international hostname has a non-ASCII character. It is represented\n" \
  "  // in punycode as 'xn--bcher-kva.ch'\n" \
  "  var idn = 'B\u00fccher.ch';\n" \
  "\n" \
  "  // We disregard the actual return value -- all we care about is that on\n" \
  "  // the C++ end the bindings were passed the punycode equivalent of this\n" \
  "  // unicode hostname.\n" \
  "  dnsResolve(idn);\n" \
  "  dnsResolveEx(idn);\n" \
  "\n" \
  "  return \"DIRECT\";\n" \
  "}\n" \
  "\n" \

#define MISSING_CLOSE_BRACE_JS \
  u""\
  "// This PAC script is invalid, because there is a missing close brace\n" \
  "// on the function FindProxyForURL().\n" \
  "\n" \
  "function FindProxyForURL(url, host) {\n" \
  "  return \"DIRECT\";\n" \
  "\n" \

#define NO_ENTRYPOINT_JS \
  u""\
  "var x = \"This is an invalid PAC script because it lacks a \" +\n" \
  "        \"FindProxyForURL() function\";\n" \

#define PAC_LIBRARY_UNITTEST_JS \
  u""\
  "// This should output \"PROXY success:80\" if all the tests pass.\n" \
  "// Otherwise it will output \"PROXY failure:<num-failures>\".\n" \
  "//\n" \
  "// This aims to unit-test the PAC library functions, which are\n" \
  "// exposed in the PAC's execution environment. (Namely, dnsDomainLevels,\n" \
  "// timeRange, etc.)\n" \
  "\n" \
  "function FindProxyForURL(url, host) {\n" \
  "  var numTestsFailed = 0;\n" \
  "\n" \
  "  // Run all the tests\n" \
  "  for (var test in Tests) {\n" \
  "    var t = new TestContext(test);\n" \
  "\n" \
  "    // Run the test.\n" \
  "    Tests[test](t);\n" \
  "\n" \
  "    if (t.failed()) {\n" \
  "      numTestsFailed++;\n" \
  "    }\n" \
  "  }\n" \
  "\n" \
  "  if (numTestsFailed == 0) {\n" \
  "    return \"PROXY success:80\";\n" \
  "  }\n" \
  "  return \"PROXY failure:\" + numTestsFailed;\n" \
  "}\n" \
  "\n" \
  "// --------------------------\n" \
  "// Tests\n" \
  "// --------------------------\n" \
  "\n" \
  "var Tests = {};\n" \
  "\n" \
  "Tests.testDnsDomainIs = function(t) {\n" \
  "  t.expectTrue(dnsDomainIs(\"google.com\", \".com\"));\n" \
  "  t.expectTrue(dnsDomainIs(\"google.co.uk\", \".co.uk\"));\n" \
  "  t.expectFalse(dnsDomainIs(\"google.com\", \".co.uk\"));\n" \
  "  t.expectFalse(dnsDomainIs(\"www.adobe.com\", \".ad\"));\n" \
  "};\n" \
  "\n" \
  "Tests.testDnsDomainLevels = function(t) {\n" \
  "  t.expectEquals(0, dnsDomainLevels(\"www\"));\n" \
  "  t.expectEquals(2, dnsDomainLevels(\"www.google.com\"));\n" \
  "  t.expectEquals(3, dnsDomainLevels(\"192.168.1.1\"));\n" \
  "};\n" \
  "\n" \
  "Tests.testIsInNet = function(t) {\n" \
  "  t.expectTrue(\n" \
  "      isInNet(\"192.89.132.25\", \"192.89.132.25\", \"255.255.255.255\"));\n" \
  "  t.expectFalse(\n" \
  "      isInNet(\"193.89.132.25\", \"192.89.132.25\", \"255.255.255.255\"));\n" \
  "\n" \
  "  t.expectTrue(isInNet(\"192.89.132.25\", \"192.89.0.0\", \"255.255.0.0\"));\n" \
  "  t.expectFalse(isInNet(\"193.89.132.25\", \"192.89.0.0\", \"255.255.0.0\"));\n" \
  "\n" \
  "  t.expectFalse(\n" \
  "      isInNet(\"192.89.132.a\", \"192.89.0.0\", \"255.255.0.0\"));\n" \
  "};\n" \
  "\n" \
  "Tests.testIsPlainHostName = function(t) {\n" \
  "  t.expectTrue(isPlainHostName(\"google\"));\n" \
  "  t.expectFalse(isPlainHostName(\"google.com\"));\n" \
  "};\n" \
  "\n" \
  "Tests.testLocalHostOrDomainIs = function(t) {\n" \
  "  t.expectTrue(localHostOrDomainIs(\"www.google.com\", \"www.google.com\"));\n" \
  "  t.expectTrue(localHostOrDomainIs(\"www\", \"www.google.com\"));\n" \
  "  t.expectFalse(localHostOrDomainIs(\"maps.google.com\", \"www.google.com\"));\n" \
  "};\n" \
  "\n" \
  "Tests.testShExpMatch = function(t) {\n" \
  "  t.expectTrue(shExpMatch(\"foo.jpg\", \"*.jpg\"));\n" \
  "  t.expectTrue(shExpMatch(\"foo5.jpg\", \"*o?.jpg\"));\n" \
  "  t.expectFalse(shExpMatch(\"foo.jpg\", \".jpg\"));\n" \
  "  t.expectFalse(shExpMatch(\"foo.jpg\", \"foo\"));\n" \
  "};\n" \
  "\n" \
  "Tests.testSortIpAddressList = function(t) {\n" \
  "  t.expectEquals(\"::1;::2;::3\", sortIpAddressList(\"::2;::3;::1\"));\n" \
  "  t.expectEquals(\n" \
  "      \"2001:4898:28:3:201:2ff:feea:fc14;fe80::5efe:157:9d3b:8b16;157.59.139.22\",\n" \
  "      sortIpAddressList(\"157.59.139.22;\" +\n" \
  "                        \"2001:4898:28:3:201:2ff:feea:fc14;\" +\n" \
  "                        \"fe80::5efe:157:9d3b:8b16\"));\n" \
  "\n" \
  "  // Single IP address (v4 and v6).\n" \
  "  t.expectEquals(\"127.0.0.1\", sortIpAddressList(\"127.0.0.1\"));\n" \
  "  t.expectEquals(\"::1\", sortIpAddressList(\"::1\"))\n" \
  "\n" \
  "  // Verify that IPv6 address is not re-written (not reduced).\n" \
  "  t.expectEquals(\"0:0::1;192.168.1.1\", sortIpAddressList(\"192.168.1.1;0:0::1\"));\n" \
  "\n" \
  "  // Input is already sorted.\n" \
  "  t.expectEquals(\"::1;192.168.1.3\", sortIpAddressList(\"::1;192.168.1.3\"));\n" \
  "\n" \
  "  // Same-valued IP addresses (also tests stability).\n" \
  "  t.expectEquals(\"0::1;::1;0:0::1\", sortIpAddressList(\"0::1;::1;0:0::1\"));\n" \
  "\n" \
  "  // Contains extra semi-colons.\n" \
  "  t.expectEquals(\"127.0.0.1\", sortIpAddressList(\";127.0.0.1;\"));\n" \
  "\n" \
  "  // Contains whitespace (spaces and tabs).\n" \
  "  t.expectEquals(\"192.168.0.1;192.168.0.2\",\n" \
  "      sortIpAddressList(\"192.168.0.1; 192.168.0.2\"));\n" \
  "  t.expectEquals(\"127.0.0.0;127.0.0.1;127.0.0.2\",\n" \
  "      sortIpAddressList(\"127.0.0.1;	127.0.0.2;	 127.0.0.0\"));\n" \
  "\n" \
  "  // Empty lists.\n" \
  "  t.expectFalse(sortIpAddressList(\"\"));\n" \
  "  t.expectFalse(sortIpAddressList(\" \"));\n" \
  "  t.expectFalse(sortIpAddressList(\";\"));\n" \
  "  t.expectFalse(sortIpAddressList(\";;\"));\n" \
  "  t.expectFalse(sortIpAddressList(\" ;  ; \"));\n" \
  "\n" \
  "  // Invalid IP addresses.\n" \
  "  t.expectFalse(sortIpAddressList(\"256.0.0.1\"));\n" \
  "  t.expectFalse(sortIpAddressList(\"192.168.1.1;0:0:0:1;127.0.0.1\"));\n" \
  "\n" \
  "  // Call sortIpAddressList() with wonky arguments.\n" \
  "  t.expectEquals(null, sortIpAddressList());\n" \
  "  t.expectEquals(null, sortIpAddressList(null));\n" \
  "  t.expectEquals(null, sortIpAddressList(null, null));\n" \
  "};\n" \
  "\n" \
  "Tests.testIsInNetEx = function(t) {\n" \
  "  t.expectTrue(isInNetEx(\"198.95.249.79\", \"198.95.249.79/32\"));\n" \
  "  t.expectTrue(isInNetEx(\"198.95.115.10\", \"198.95.0.0/16\"));\n" \
  "  t.expectTrue(isInNetEx(\"198.95.1.1\", \"198.95.0.0/16\"));\n" \
  "  t.expectTrue(isInNetEx(\"198.95.1.1\", \"198.95.3.3/16\"));\n" \
  "  t.expectTrue(isInNetEx(\"0:0:0:0:0:0:7f00:1\", \"0:0:0:0:0:0:7f00:1/32\"));\n" \
  "  t.expectTrue(isInNetEx(\"3ffe:8311:ffff:abcd:1234:dead:beef:101\",\n" \
  "                         \"3ffe:8311:ffff::/48\"));\n" \
  "\n" \
  "  // IPv4 and IPv6 mix.\n" \
  "  t.expectFalse(isInNetEx(\"127.0.0.1\", \"0:0:0:0:0:0:7f00:1/16\"));\n" \
  "  t.expectFalse(isInNetEx(\"192.168.24.3\", \"fe80:0:0:0:0:0:c0a8:1803/32\"));\n" \
  "\n" \
  "  t.expectFalse(isInNetEx(\"198.95.249.78\", \"198.95.249.79/32\"));\n" \
  "  t.expectFalse(isInNetEx(\"198.96.115.10\", \"198.95.0.0/16\"));\n" \
  "  t.expectFalse(isInNetEx(\"3fff:8311:ffff:abcd:1234:dead:beef:101\",\n" \
  "                          \"3ffe:8311:ffff::/48\"));\n" \
  "\n" \
  "  // Call isInNetEx with wonky arguments.\n" \
  "  t.expectEquals(null, isInNetEx());\n" \
  "  t.expectEquals(null, isInNetEx(null));\n" \
  "  t.expectEquals(null, isInNetEx(null, null));\n" \
  "  t.expectEquals(null, isInNetEx(null, null, null));\n" \
  "  t.expectEquals(null, isInNetEx(\"198.95.249.79\"));\n" \
  "\n" \
  "  // Invalid IP address.\n" \
  "  t.expectFalse(isInNetEx(\"256.0.0.1\", \"198.95.249.79\"));\n" \
  "  t.expectFalse(isInNetEx(\"127.0.0.1 \", \"127.0.0.1/32\"));  // Extra space.\n" \
  "\n" \
  "  // Invalid prefix.\n" \
  "  t.expectFalse(isInNetEx(\"198.95.115.10\", \"198.95.0.0/34\"));\n" \
  "  t.expectFalse(isInNetEx(\"127.0.0.1\", \"127.0.0.1\"));  // Missing '/' in prefix.\n" \
  "};\n" \
  "\n" \
  "Tests.testWeekdayRange = function(t) {\n" \
  "  // Test with local time.\n" \
  "  MockDate.setCurrent(\"Tue Mar 03 2009\");\n" \
  "  t.expectEquals(true, weekdayRange(\"MON\", \"FRI\"));\n" \
  "  t.expectEquals(true, weekdayRange(\"TUE\", \"FRI\"));\n" \
  "  t.expectEquals(true, weekdayRange(\"TUE\", \"TUE\"));\n" \
  "  t.expectEquals(true, weekdayRange(\"TUE\"));\n" \
  "  t.expectEquals(false, weekdayRange(\"WED\", \"FRI\"));\n" \
  "  t.expectEquals(false, weekdayRange(\"SUN\", \"MON\"));\n" \
  "  t.expectEquals(false, weekdayRange(\"SAT\"));\n" \
  "  t.expectEquals(false, weekdayRange(\"FRI\", \"MON\"));\n" \
  "\n" \
  "  // Test with GMT time.\n" \
  "  MockDate.setCurrent(\"Tue Mar 03 2009 GMT\");\n" \
  "  t.expectEquals(true, weekdayRange(\"MON\", \"FRI\", \"GMT\"));\n" \
  "  t.expectEquals(true, weekdayRange(\"TUE\", \"FRI\", \"GMT\"));\n" \
  "  t.expectEquals(true, weekdayRange(\"TUE\", \"TUE\", \"GMT\"));\n" \
  "  t.expectEquals(true, weekdayRange(\"TUE\", \"GMT\"));\n" \
  "  t.expectEquals(false, weekdayRange(\"WED\", \"FRI\", \"GMT\"));\n" \
  "  t.expectEquals(false, weekdayRange(\"SUN\", \"MON\", \"GMT\"));\n" \
  "  t.expectEquals(false, weekdayRange(\"SAT\", \"GMT\"));\n" \
  "};\n" \
  "\n" \
  "Tests.testDateRange = function(t) {\n" \
  "  // dateRange(day)\n" \
  "  MockDate.setCurrent(\"Mar 03 2009\");\n" \
  "  t.expectEquals(true, dateRange(3));\n" \
  "  t.expectEquals(false, dateRange(1));\n" \
  "\n" \
  "  // dateRange(day, \"GMT\")\n" \
  "  MockDate.setCurrent(\"Mar 03 2009 GMT\");\n" \
  "  t.expectEquals(true, dateRange(3, \"GMT\"));\n" \
  "  t.expectEquals(false, dateRange(1, \"GMT\"));\n" \
  "\n" \
  "  // dateRange(day1, day2)\n" \
  "  MockDate.setCurrent(\"Mar 03 2009\");\n" \
  "  t.expectEquals(true, dateRange(1, 4));\n" \
  "  t.expectEquals(false, dateRange(4, 20));\n" \
  "\n" \
  "  // dateRange(day, month)\n" \
  "  MockDate.setCurrent(\"Mar 03 2009\");\n" \
  "  t.expectEquals(true, dateRange(3, \"MAR\"));\n" \
  "  MockDate.setCurrent(\"Mar 03 2014\");\n" \
  "  t.expectEquals(true, dateRange(3, \"MAR\"));\n" \
  "  // TODO(eroman):\n" \
  "  //t.expectEquals(false, dateRange(2, \"MAR\"));\n" \
  "  //t.expectEquals(false, dateRange(3, \"JAN\"));\n" \
  "\n" \
  "  // dateRange(day, month, year)\n" \
  "  MockDate.setCurrent(\"Mar 03 2009\");\n" \
  "  t.expectEquals(true, dateRange(3, \"MAR\", 2009));\n" \
  "  t.expectEquals(false, dateRange(4, \"MAR\", 2009));\n" \
  "  t.expectEquals(false, dateRange(3, \"FEB\", 2009));\n" \
  "  MockDate.setCurrent(\"Mar 03 2014\");\n" \
  "  t.expectEquals(false, dateRange(3, \"MAR\", 2009));\n" \
  "\n" \
  "  // dateRange(month1, month2)\n" \
  "  MockDate.setCurrent(\"Mar 03 2009\");\n" \
  "  t.expectEquals(true, dateRange(\"JAN\", \"MAR\"));\n" \
  "  t.expectEquals(true, dateRange(\"MAR\", \"APR\"));\n" \
  "  t.expectEquals(false, dateRange(\"MAY\", \"SEP\"));\n" \
  "\n" \
  "  // dateRange(day1, month1, day2, month2)\n" \
  "  MockDate.setCurrent(\"Mar 03 2009\");\n" \
  "  t.expectEquals(true, dateRange(1, \"JAN\", 3, \"MAR\"));\n" \
  "  t.expectEquals(true, dateRange(3, \"MAR\", 4, \"SEP\"));\n" \
  "  t.expectEquals(false, dateRange(4, \"MAR\", 4, \"SEP\"));\n" \
  "\n" \
  "  // dateRange(month1, year1, month2, year2)\n" \
  "  MockDate.setCurrent(\"Mar 03 2009\");\n" \
  "  t.expectEquals(true, dateRange(\"FEB\", 2009, \"MAR\", 2009));\n" \
  "  MockDate.setCurrent(\"Apr 03 2009\");\n" \
  "  t.expectEquals(true, dateRange(\"FEB\", 2009, \"MAR\", 2010));\n" \
  "  t.expectEquals(false, dateRange(\"FEB\", 2009, \"MAR\", 2009));\n" \
  "\n" \
  "  // dateRange(day1, month1, year1, day2, month2, year2)\n" \
  "  MockDate.setCurrent(\"Mar 03 2009\");\n" \
  "  t.expectEquals(true, dateRange(1, \"JAN\", 2009, 3, \"MAR\", 2009));\n" \
  "  t.expectEquals(true, dateRange(3, \"MAR\", 2009, 4, \"SEP\", 2009));\n" \
  "  t.expectEquals(true, dateRange(3, \"JAN\", 2009, 4, \"FEB\", 2010));\n" \
  "  t.expectEquals(false, dateRange(4, \"MAR\", 2009, 4, \"SEP\", 2009));\n" \
  "};\n" \
  "\n" \
  "Tests.testTimeRange = function(t) {\n" \
  "  // timeRange(hour)\n" \
  "  MockDate.setCurrent(\"Mar 03, 2009 03:34:01\");\n" \
  "  t.expectEquals(true, timeRange(3));\n" \
  "  t.expectEquals(false, timeRange(2));\n" \
  "\n" \
  "  // timeRange(hour1, hour2)\n" \
  "  MockDate.setCurrent(\"Mar 03, 2009 03:34:01\");\n" \
  "  t.expectEquals(true, timeRange(2, 3));\n" \
  "  t.expectEquals(true, timeRange(2, 4));\n" \
  "  t.expectEquals(true, timeRange(3, 5));\n" \
  "  t.expectEquals(false, timeRange(1, 2));\n" \
  "  t.expectEquals(false, timeRange(11, 12));\n" \
  "\n" \
  "  // timeRange(hour1, min1, hour2, min2)\n" \
  "  MockDate.setCurrent(\"Mar 03, 2009 03:34:01\");\n" \
  "  t.expectEquals(true, timeRange(1, 0, 3, 34));\n" \
  "  t.expectEquals(true, timeRange(1, 0, 3, 35));\n" \
  "  t.expectEquals(true, timeRange(3, 34, 5, 0));\n" \
  "  t.expectEquals(false, timeRange(1, 0, 3, 0));\n" \
  "  t.expectEquals(false, timeRange(11, 0, 16, 0));\n" \
  "\n" \
  "  // timeRange(hour1, min1, sec1, hour2, min2, sec2)\n" \
  "  MockDate.setCurrent(\"Mar 03, 2009 03:34:14\");\n" \
  "  t.expectEquals(true, timeRange(1, 0, 0, 3, 34, 14));\n" \
  "  t.expectEquals(false, timeRange(1, 0, 0, 3, 34, 0));\n" \
  "  t.expectEquals(true, timeRange(1, 0, 0, 3, 35, 0));\n" \
  "  t.expectEquals(true, timeRange(3, 34, 0, 5, 0, 0));\n" \
  "  t.expectEquals(false, timeRange(1, 0, 0, 3, 0, 0));\n" \
  "  t.expectEquals(false, timeRange(11, 0, 0, 16, 0, 0));\n" \
  "};\n" \
  "\n" \
  "// --------------------------\n" \
  "// TestContext\n" \
  "// --------------------------\n" \
  "\n" \
  "// |name| is the name of the test being executed, it will be used when logging\n" \
  "// errors.\n" \
  "function TestContext(name) {\n" \
  "  this.numFailures_ = 0;\n" \
  "  this.name_ = name;\n" \
  "};\n" \
  "\n" \
  "TestContext.prototype.failed = function() {\n" \
  "  return this.numFailures_ != 0;\n" \
  "};\n" \
  "\n" \
  "TestContext.prototype.expectEquals = function(expectation, actual) {\n" \
  "  if (!(expectation === actual)) {\n" \
  "    this.numFailures_++;\n" \
  "    this.log(\"FAIL: expected: \" + expectation + \", actual: \" + actual);\n" \
  "  }\n" \
  "};\n" \
  "\n" \
  "TestContext.prototype.expectTrue = function(x) {\n" \
  "  this.expectEquals(true, x);\n" \
  "};\n" \
  "\n" \
  "TestContext.prototype.expectFalse = function(x) {\n" \
  "  this.expectEquals(false, x);\n" \
  "};\n" \
  "\n" \
  "TestContext.prototype.log = function(x) {\n" \
  "  // Prefix with the test name that generated the log.\n" \
  "  try {\n" \
  "    alert(this.name_ + \": \" + x);\n" \
  "  } catch(e) {\n" \
  "    // In case alert() is not defined.\n" \
  "  }\n" \
  "};\n" \
  "\n" \
  "// --------------------------\n" \
  "// MockDate\n" \
  "// --------------------------\n" \
  "\n" \
  "function MockDate() {\n" \
  "  this.wrappedDate_ = new MockDate.super_(MockDate.currentDateString_);\n" \
  "};\n" \
  "\n" \
  "// Setup the MockDate so it forwards methods to \"this.wrappedDate_\" (which is a\n" \
  "// real Date object).  We can't simply chain the prototypes since Date() doesn't\n" \
  "// allow it.\n" \
  "MockDate.init = function() {\n" \
  "  MockDate.super_ = Date;\n" \
  "\n" \
  "  function createProxyMethod(methodName) {\n" \
  "    return function() {\n" \
  "      return this.wrappedDate_[methodName]\n" \
  "          .apply(this.wrappedDate_, arguments);\n" \
  "    }\n" \
  "  };\n" \
  "\n" \
  "  for (i in MockDate.methodNames_) {\n" \
  "    var methodName = MockDate.methodNames_[i];\n" \
  "    // Don't define the closure directly in the loop body, since Javascript's\n" \
  "    // crazy scoping rules mean |methodName| actually bleeds out of the loop!\n" \
  "    MockDate.prototype[methodName] = createProxyMethod(methodName);\n" \
  "  }\n" \
  "\n" \
  "  // Replace the native Date() with our mock.\n" \
  "  Date = MockDate;\n" \
  "};\n" \
  "\n" \
  "// Unfortunately Date()'s methods are non-enumerable, therefore list manually.\n" \
  "MockDate.methodNames_ = [\n" \
  "  \"toString\", \"toDateString\", \"toTimeString\", \"toLocaleString\",\n" \
  "  \"toLocaleDateString\", \"toLocaleTimeString\", \"valueOf\", \"getTime\",\n" \
  "  \"getFullYear\", \"getUTCFullYear\", \"getMonth\", \"getUTCMonth\",\n" \
  "  \"getDate\", \"getUTCDate\", \"getDay\", \"getUTCDay\", \"getHours\", \"getUTCHours\",\n" \
  "  \"getMinutes\", \"getUTCMinutes\", \"getSeconds\", \"getUTCSeconds\",\n" \
  "  \"getMilliseconds\", \"getUTCMilliseconds\", \"getTimezoneOffset\", \"setTime\",\n" \
  "  \"setMilliseconds\", \"setUTCMilliseconds\", \"setSeconds\", \"setUTCSeconds\",\n" \
  "  \"setMinutes\", \"setUTCMinutes\", \"setHours\", \"setUTCHours\", \"setDate\",\n" \
  "  \"setUTCDate\", \"setMonth\", \"setUTCMonth\", \"setFullYear\", \"setUTCFullYear\",\n" \
  "  \"toGMTString\", \"toUTCString\", \"getYear\", \"setYear\"\n" \
  "];\n" \
  "\n" \
  "MockDate.setCurrent = function(currentDateString) {\n" \
  "  MockDate.currentDateString_ = currentDateString;\n" \
  "}\n" \
  "\n" \
  "// Bind the methods to proxy requests to the wrapped Date().\n" \
  "MockDate.init();\n" \
  "\n" \

#define PASSTHROUGH_JS \
  u""\
  "// Return a single-proxy result, which encodes ALL the arguments that were\n" \
  "// passed to FindProxyForURL().\n" \
  "\n" \
  "function FindProxyForURL(url, host) {\n" \
  "  if (arguments.length != 2) {\n" \
  "    throw \"Wrong number of arguments passed to FindProxyForURL!\";\n" \
  "    return \"FAIL\";\n" \
  "  }\n" \
  "\n" \
  "  return \"PROXY \" + makePseudoHost(url + \".\" + host);\n" \
  "}\n" \
  "\n" \
  "// Form a string that kind-of resembles a host. We will replace any\n" \
  "// non-alphanumeric character with a dot, then fix up the oddly placed dots.\n" \
  "function makePseudoHost(str) {\n" \
  "  var result = \"\";\n" \
  "\n" \
  "  for (var i = 0; i < str.length; ++i) {\n" \
  "    var c = str.charAt(i);\n" \
  "    if (!isValidPseudoHostChar(c)) {\n" \
  "      c = '.';  // Replace unsupported characters with a dot.\n" \
  "    }\n" \
  "\n" \
  "    // Take care not to place multiple adjacent dots,\n" \
  "    // a dot at the beginning, or a dot at the end.\n" \
  "    if (c == '.' &&\n" \
  "        (result.length == 0 || \n" \
  "         i == str.length - 1 ||\n" \
  "         result.charAt(result.length - 1) == '.')) {\n" \
  "      continue;\n" \
  "    }\n" \
  "    result += c;\n" \
  "  }\n" \
  "  return result;\n" \
  "}\n" \
  "\n" \
  "function isValidPseudoHostChar(c) {\n" \
  "  if (c >= '0' && c <= '9')\n" \
  "    return true;\n" \
  "  if (c >= 'a' && c <= 'z')\n" \
  "    return true;\n" \
  "  if (c >= 'A' && c <= 'Z')\n" \
  "    return true;\n" \
  "  return false;\n" \
  "}\n" \

#define RETURN_EMPTY_STRING_JS \
  u""\
  "function FindProxyForURL(url, host) {\n" \
  "  return \"\";\n" \
  "}\n" \
  "\n" \

#define RETURN_FUNCTION_JS \
  u""\
  "function FindProxyForURL(url, host) {\n" \
  "  return FindProxyForURL;\n" \
  "}\n" \
  "\n" \

#define RETURN_INTEGER_JS \
  u""\
  "function FindProxyForURL(url, host) {\n" \
  "  return 0;\n" \
  "}\n" \
  "\n" \

#define RETURN_NULL_JS \
  u""\
  "function FindProxyForURL(url, host) {\n" \
  "  return null;\n" \
  "}\n" \
  "\n" \

#define RETURN_OBJECT_JS \
  u""\
  "function FindProxyForURL(url, host) {\n" \
  "  return {result: \"PROXY foo\"};\n" \
  "}\n" \
  "\n" \

#define RETURN_UNDEFINED_JS \
  u""\
  "function FindProxyForURL(url, host) {\n" \
  "  return undefined;\n" \
  "}\n" \
  "\n" \

#define RETURN_UNICODE_JS \
  u""\
  "// U+200B is the codepoint for zero-width-space.\n" \
  "function FindProxyForURL(url, host) {\n" \
  "  return \"PROXY foo.com\u200B\";\n" \
  "}\n" \

#define SIDE_EFFECTS_JS \
  u""\
  "if (!gCounter) {\n" \
  "  // We write it this way so if the script gets loaded twice,\n" \
  "  // gCounter remains dirty.\n" \
  "  var gCounter = 0;\n" \
  "}\n" \
  "\n" \
  "function FindProxyForURL(url, host) {\n" \
  "  return \"PROXY sideffect_\" + gCounter++;\n" \
  "}\n" \
  "\n" \

#define SIMPLE_JS \
  u""\
  "// PAC script which uses isInNet on both IP addresses and hosts, and calls\n" \
  "// isResolvable().\n" \
  "\n" \
  "function FindProxyForURL(url, host) {\n" \
  "  var my_ip = myIpAddress();\n" \
  "\n" \
  "  if (isInNet(my_ip, \"172.16.0.0\", \"255.248.0.0\")) {\n" \
  "    return \"PROXY a:80\";\n" \
  "  }\n" \
  "\n" \
  "  if (url.substring(0, 6) != \"https:\" &&\n" \
  "      isInNet(host, \"10.0.0.0\", \"255.0.0.0\")) {\n" \
  "    return \"PROXY b:80\";\n" \
  "  }\n" \
  "\n" \
  "  if (dnsDomainIs(host, \"foo.bar.baz.com\") || !isResolvable(host)) {\n" \
  "    return \"PROXY c:100\";\n" \
  "  }\n" \
  "\n" \
  "  return \"DIRECT\";\n" \
  "}\n" \

#define STRING_FUNCTIONS_JS \
  u""\
  "function FindProxyForURL(url, host) {\n" \
  "  return \"direct\".toUpperCase();\n" \
  "}\n" \

#define UNHANDLED_EXCEPTION_JS \
  u""\
  "function FindProxyForURL(url, host) {\n" \
  "  // This will throw a runtime exception.\n" \
  "  return \"PROXY x\" + undefined_variable;\n" \
  "}\n" \
  "\n" \

#endif //PROXY_TEST_SCRIPT_H_