Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / dom / Geolocation / script-tests / argument-types.js
1 description("Tests the acceptable types for arguments to Geolocation methods.");
2
3 function shouldNotThrow(expression)
4 {
5   try {
6     eval(expression);
7     testPassed(expression + " did not throw exception.");
8   } catch(e) {
9     testFailed(expression + " should not throw exception. Threw exception " + e);
10   }
11 }
12
13 function test(expression, expressionShouldThrow, expectedException) {
14     if (expressionShouldThrow) {
15         if (expectedException)
16             shouldThrow(expression, '(function() { return "' + expectedException + '"; })();');
17         else
18             shouldThrow(expression);
19     } else {
20         shouldNotThrow(expression);
21     }
22 }
23
24 var emptyFunction = function() {};
25
26 function ObjectThrowingException() {};
27 ObjectThrowingException.prototype.valueOf = function() {
28     throw new Error('valueOf threw exception');
29 }
30 ObjectThrowingException.prototype.__defineGetter__("enableHighAccuracy", function() {
31     throw new Error('enableHighAccuracy getter exception');
32 });
33 var objectThrowingException = new ObjectThrowingException();
34
35
36 test('navigator.geolocation.getCurrentPosition()', true);
37
38 test('navigator.geolocation.getCurrentPosition(undefined)', true);
39 test('navigator.geolocation.getCurrentPosition(null)', true);
40 test('navigator.geolocation.getCurrentPosition({})', true);
41 test('navigator.geolocation.getCurrentPosition(objectThrowingException)', true);
42 test('navigator.geolocation.getCurrentPosition(emptyFunction)', false);
43 test('navigator.geolocation.getCurrentPosition(Math.abs)', false);
44 test('navigator.geolocation.getCurrentPosition(true)', true);
45 test('navigator.geolocation.getCurrentPosition(42)', true);
46 test('navigator.geolocation.getCurrentPosition(Infinity)', true);
47 test('navigator.geolocation.getCurrentPosition(-Infinity)', true);
48 test('navigator.geolocation.getCurrentPosition("string")', true);
49
50 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined)', false);
51 test('navigator.geolocation.getCurrentPosition(emptyFunction, null)', false);
52 test('navigator.geolocation.getCurrentPosition(emptyFunction, {})', true);
53 test('navigator.geolocation.getCurrentPosition(emptyFunction, objectThrowingException)', true);
54 test('navigator.geolocation.getCurrentPosition(emptyFunction, emptyFunction)', false);
55 test('navigator.geolocation.getCurrentPosition(emptyFunction, Math.abs)', false);
56 test('navigator.geolocation.getCurrentPosition(emptyFunction, true)', true);
57 test('navigator.geolocation.getCurrentPosition(emptyFunction, 42)', true);
58 test('navigator.geolocation.getCurrentPosition(emptyFunction, Infinity)', true);
59 test('navigator.geolocation.getCurrentPosition(emptyFunction, -Infinity)', true);
60 test('navigator.geolocation.getCurrentPosition(emptyFunction, "string")', true);
61
62 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, undefined)', false);
63 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, null)', false);
64 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {})', false);
65 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, objectThrowingException)', true, 'Error: enableHighAccuracy getter exception');
66 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, emptyFunction)', false);
67 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, true)', true);
68 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, 42)', true);
69 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, Infinity)', true);
70 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, -Infinity)', true);
71 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, "string")', true);
72
73 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:undefined})', false);
74 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:null})', false);
75 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:{}})', false);
76 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:objectThrowingException})', false);
77 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:emptyFunction})', false);
78 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:true})', false);
79 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:42})', false);
80 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:Infinity})', false);
81 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:-Infinity})', false);
82 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:"string"})', false);
83
84 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:undefined})', false);
85 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:null})', false);
86 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:{}})', false);
87 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:objectThrowingException})', false);
88 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:emptyFunction})', false);
89 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:true})', false);
90 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:42})', false);
91 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:Infinity})', false);
92 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:-Infinity})', false);
93 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:"string"})', false);
94
95 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:undefined})', false);
96 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:null})', false);
97 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:{}})', false);
98 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:objectThrowingException})', true, 'Error: valueOf threw exception');
99 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:emptyFunction})', false);
100 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:true})', false);
101 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:42})', false);
102 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:Infinity})', false);
103 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:-Infinity})', false);
104 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:"string"})', false);
105
106 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:undefined})', false);
107 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:null})', false);
108 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:{}})', false);
109 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:objectThrowingException})', true, 'Error: valueOf threw exception');
110 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:emptyFunction})', false);
111 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:true})', false);
112 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:42})', false);
113 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:Infinity})', false);
114 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:-Infinity})', false);
115 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:"string"})', false);
116
117 window.jsTestIsAsync = false;
118