1// Try calling the browser-side bound functions with varying (invalid)
2// inputs. There is no notion of "success" for this test, other than
3// verifying the correct C++ bindings were reached with expected values.
4
5function MyObject() {
6  this.x = "3";
7}
8
9MyObject.prototype.toString = function() {
10  throw "exception from calling toString()";
11}
12
13function expectEquals(expectation, actual) {
14  if (!(expectation === actual)) {
15    throw "FAIL: expected: " + expectation + ", actual: " + actual;
16  }
17}
18
19function FindProxyForURL(url, host) {
20  // Call dnsResolve with some wonky arguments.
21  // Those expected to fail (because we have passed a non-string parameter)
22  // will return |null|, whereas those that have called through to the C++
23  // bindings will return '127.0.0.1'.
24  expectEquals(undefined, dnsResolve());
25  expectEquals(undefined, dnsResolve(null));
26  expectEquals(undefined, dnsResolve(undefined));
27  expectEquals('127.0.0.1', dnsResolve(""));
28  expectEquals(undefined, dnsResolve({foo: 'bar'}));
29  expectEquals(undefined, dnsResolve(fn));
30  expectEquals(undefined, dnsResolve(['3']));
31  expectEquals('127.0.0.1', dnsResolve("arg1", "arg2", "arg3", "arg4"));
32
33  // Call alert with some wonky arguments.
34  alert();
35  alert(null);
36  alert(undefined);
37  alert({foo:'bar'});
38
39  // This should throw an exception when we toString() the argument
40  // to alert in the bindings.
41  try {
42    alert(new MyObject());
43  } catch (e) {
44    alert(e);
45  }
46
47  // Call myIpAddress() with wonky arguments
48  myIpAddress(null);
49  myIpAddress(null, null);
50
51  // Call myIpAddressEx() correctly (no arguments).
52  myIpAddressEx();
53
54  // Call dnsResolveEx() (note that isResolvableEx() implicity calls it.)
55  isResolvableEx("is_resolvable");
56  dnsResolveEx("foobar");
57
58  return "DIRECT";
59}
60
61function fn() {}
62
63