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, '(function() { return "Error: TYPE_MISMATCH_ERR: DOM Exception 17"; })();'); 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(layoutTestController.setGeolocationPermission)', false); 45 test('navigator.geolocation.getCurrentPosition(true)', true); 46 test('navigator.geolocation.getCurrentPosition(42)', true); 47 test('navigator.geolocation.getCurrentPosition(Infinity)', true); 48 test('navigator.geolocation.getCurrentPosition(-Infinity)', true); 49 test('navigator.geolocation.getCurrentPosition("string")', true); 50 51 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined)', false); 52 test('navigator.geolocation.getCurrentPosition(emptyFunction, null)', false); 53 test('navigator.geolocation.getCurrentPosition(emptyFunction, {})', true); 54 test('navigator.geolocation.getCurrentPosition(emptyFunction, objectThrowingException)', true); 55 test('navigator.geolocation.getCurrentPosition(emptyFunction, emptyFunction)', false); 56 test('navigator.geolocation.getCurrentPosition(emptyFunction, Math.abs)', false); 57 test('navigator.geolocation.getCurrentPosition(emptyFunction, layoutTestController.setGeolocationPermission)', false); 58 test('navigator.geolocation.getCurrentPosition(emptyFunction, true)', true); 59 test('navigator.geolocation.getCurrentPosition(emptyFunction, 42)', true); 60 test('navigator.geolocation.getCurrentPosition(emptyFunction, Infinity)', true); 61 test('navigator.geolocation.getCurrentPosition(emptyFunction, -Infinity)', true); 62 test('navigator.geolocation.getCurrentPosition(emptyFunction, "string")', true); 63 64 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, undefined)', false); 65 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, null)', false); 66 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {})', false); 67 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, objectThrowingException)', true, 'Error: enableHighAccuracy getter exception'); 68 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, emptyFunction)', false); 69 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, true)', false); 70 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, 42)', false); 71 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, Infinity)', false); 72 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, -Infinity)', false); 73 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, "string")', false); 74 75 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:undefined})', false); 76 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:null})', false); 77 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:{}})', false); 78 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:objectThrowingException})', false); 79 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:emptyFunction})', false); 80 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:true})', false); 81 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:42})', false); 82 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:Infinity})', false); 83 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:-Infinity})', false); 84 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:"string"})', false); 85 86 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:undefined})', false); 87 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:null})', false); 88 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:{}})', false); 89 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:objectThrowingException})', false); 90 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:emptyFunction})', false); 91 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:true})', false); 92 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:42})', false); 93 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:Infinity})', false); 94 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:-Infinity})', false); 95 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:"string"})', false); 96 97 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:undefined})', false); 98 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:null})', false); 99 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:{}})', false); 100 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:objectThrowingException})', true, 'Error: valueOf threw exception'); 101 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:emptyFunction})', false); 102 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:true})', false); 103 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:42})', false); 104 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:Infinity})', false); 105 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:-Infinity})', false); 106 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:"string"})', false); 107 108 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:undefined})', false); 109 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:null})', false); 110 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:{}})', false); 111 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:objectThrowingException})', true, 'Error: valueOf threw exception'); 112 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:emptyFunction})', false); 113 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:true})', false); 114 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:42})', false); 115 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:Infinity})', false); 116 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:-Infinity})', false); 117 test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:"string"})', false); 118 119 window.jsTestIsAsync = false; 120 window.successfullyParsed = true; 121 122