summaryrefslogtreecommitdiff
path: root/chromium/net/data/proxy_resolver_v8_unittest/bindings.js
blob: 7cf9f2634653885e77709fcd3437f3667f4388b4 (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
// Try calling the browser-side bound functions with varying (invalid)
// inputs. There is no notion of "success" for this test, other than
// verifying the correct C++ bindings were reached with expected values.

function MyObject() {
  this.x = "3";
}

MyObject.prototype.toString = function() {
  throw "exception from calling toString()";
}

function expectEquals(expectation, actual) {
  if (!(expectation === actual)) {
    throw "FAIL: expected: " + expectation + ", actual: " + actual;
  }
}

function FindProxyForURL(url, host) {
  // Call dnsResolve with some wonky arguments.
  // Those expected to fail (because we have passed a non-string parameter)
  // will return |null|, whereas those that have called through to the C++
  // bindings will return '127.0.0.1'.
  expectEquals(null, dnsResolve());
  expectEquals(null, dnsResolve(null));
  expectEquals(null, dnsResolve(undefined));
  expectEquals('127.0.0.1', dnsResolve(""));
  expectEquals(null, dnsResolve({foo: 'bar'}));
  expectEquals(null, dnsResolve(fn));
  expectEquals(null, dnsResolve(['3']));
  expectEquals('127.0.0.1', dnsResolve("arg1", "arg2", "arg3", "arg4"));

  // Call alert with some wonky arguments.
  alert();
  alert(null);
  alert(undefined);
  alert({foo:'bar'});

  // This should throw an exception when we toString() the argument
  // to alert in the bindings.
  try {
    alert(new MyObject());
  } catch (e) {
    alert(e);
  }

  // Call myIpAddress() with wonky arguments
  myIpAddress(null);
  myIpAddress(null, null);

  // Call myIpAddressEx() correctly (no arguments).
  myIpAddressEx();

  // Call dnsResolveEx() (note that isResolvableEx() implicity calls it.)
  isResolvableEx("is_resolvable");
  dnsResolveEx("foobar");

  return "DIRECT";
}

function fn() {}