argument-types.js revision 545e470e52f0ac6a3a072bf559c796b42c6066b6
1description("Tests the acceptable types for arguments to Geolocation methods."); 2 3function 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 13function 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 24var emptyFunction = function() {}; 25 26function ObjectThrowingException() {}; 27ObjectThrowingException.prototype.valueOf = function() { 28 throw new Error('valueOf threw exception'); 29} 30ObjectThrowingException.prototype.__defineGetter__("enableHighAccuracy", function() { 31 throw new Error('enableHighAccuracy getter exception'); 32}); 33var objectThrowingException = new ObjectThrowingException(); 34 35 36test('navigator.geolocation.getCurrentPosition()', true); 37 38test('navigator.geolocation.getCurrentPosition(undefined)', true); 39test('navigator.geolocation.getCurrentPosition(null)', true); 40test('navigator.geolocation.getCurrentPosition({})', true); 41test('navigator.geolocation.getCurrentPosition(objectThrowingException)', true); 42test('navigator.geolocation.getCurrentPosition(emptyFunction)', false); 43//test('navigator.geolocation.getCurrentPosition(Math.abs)', false); 44test('navigator.geolocation.getCurrentPosition(true)', true); 45test('navigator.geolocation.getCurrentPosition(42)', true); 46test('navigator.geolocation.getCurrentPosition(Infinity)', true); 47test('navigator.geolocation.getCurrentPosition(-Infinity)', true); 48test('navigator.geolocation.getCurrentPosition("string")', true); 49 50test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined)', false); 51test('navigator.geolocation.getCurrentPosition(emptyFunction, null)', false); 52test('navigator.geolocation.getCurrentPosition(emptyFunction, {})', true); 53test('navigator.geolocation.getCurrentPosition(emptyFunction, objectThrowingException)', true); 54test('navigator.geolocation.getCurrentPosition(emptyFunction, emptyFunction)', false); 55//test('navigator.geolocation.getCurrentPosition(emptyFunction, Math.abs)', false); 56test('navigator.geolocation.getCurrentPosition(emptyFunction, true)', true); 57test('navigator.geolocation.getCurrentPosition(emptyFunction, 42)', true); 58test('navigator.geolocation.getCurrentPosition(emptyFunction, Infinity)', true); 59test('navigator.geolocation.getCurrentPosition(emptyFunction, -Infinity)', true); 60test('navigator.geolocation.getCurrentPosition(emptyFunction, "string")', true); 61 62test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, undefined)', false); 63test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, null)', false); 64test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {})', false); 65test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, objectThrowingException)', true, 'Error: enableHighAccuracy getter exception'); 66test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, emptyFunction)', false); 67test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, true)', false); 68test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, 42)', false); 69test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, Infinity)', false); 70test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, -Infinity)', false); 71test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, "string")', false); 72 73test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:undefined})', false); 74test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:null})', false); 75test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:{}})', false); 76test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:objectThrowingException})', false); 77test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:emptyFunction})', false); 78test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:true})', false); 79test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:42})', false); 80test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:Infinity})', false); 81test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:-Infinity})', false); 82test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {dummyProperty:"string"})', false); 83 84test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:undefined})', false); 85test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:null})', false); 86test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:{}})', false); 87test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:objectThrowingException})', false); 88test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:emptyFunction})', false); 89test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:true})', false); 90test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:42})', false); 91test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:Infinity})', false); 92test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:-Infinity})', false); 93test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {enableHighAccuracy:"string"})', false); 94 95test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:undefined})', false); 96test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:null})', false); 97test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:{}})', false); 98test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:objectThrowingException})', true, 'Error: valueOf threw exception'); 99test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:emptyFunction})', false); 100test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:true})', false); 101test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:42})', false); 102test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:Infinity})', false); 103test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:-Infinity})', false); 104test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {maximumAge:"string"})', false); 105 106test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:undefined})', false); 107test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:null})', false); 108test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:{}})', false); 109test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:objectThrowingException})', true, 'Error: valueOf threw exception'); 110test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:emptyFunction})', false); 111test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:true})', false); 112test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:42})', false); 113test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:Infinity})', false); 114test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:-Infinity})', false); 115test('navigator.geolocation.getCurrentPosition(emptyFunction, undefined, {timeout:"string"})', false); 116 117window.jsTestIsAsync = false; 118window.successfullyParsed = true; 119 120