1<body> 2<p>Test the behavior of DOMApplicationCache methods related to dynamic entries when the context 3is not associated with any cache.</p> 4<div id="result"></div> 5<script> 6if (window.layoutTestController) 7 layoutTestController.dumpAsText(); 8 9function log(message) 10{ 11 document.getElementById("result").innerHTML += message + "<br>"; 12} 13 14 15function isResultCorrect(_actual, _expected) 16{ 17 if (_expected === 0) 18 return _actual === _expected && (1/_actual) === (1/_expected); 19 if (_actual === _expected) 20 return true; 21 if (typeof(_expected) == "number" && isNaN(_expected)) 22 return typeof(_actual) == "number" && isNaN(_actual); 23 if (Object.prototype.toString.call(_expected) == Object.prototype.toString.call([])) { 24 log("Array comparison is not supported"); 25 return false; 26 } 27 return false; 28} 29 30function shouldBe(_a, _b) 31{ 32 if (typeof _a != "string" || typeof _b != "string") 33 log("WARN: shouldBe() expects string arguments"); 34 var exception; 35 var _av; 36 try { 37 _av = eval(_a); 38 } catch (e) { 39 exception = e; 40 } 41 var _bv = eval(_b); 42 43 if (exception) 44 log("FAIL: " + _a + " should be " + _bv + ". Threw exception " + exception); 45 else if (isResultCorrect(_av, _bv)) 46 log("PASS: " + _a + " is " + _b); 47 else if (typeof(_av) == typeof(_bv)) 48 log("FAIL: " + _a + " should be " + _bv + ". Was " + stringify(_av) + "."); 49 else 50 log("FAIL: " + _a + " should be " + _bv + " (of type " + typeof _bv + "). Was " + _av + " (of type " + typeof _av + ")."); 51} 52 53 54shouldBe("applicationCache.items.length", "0"); 55shouldBe("applicationCache.items.item(0)", "null"); 56shouldBe("applicationCache.items.item(1)", "null"); 57shouldBe("applicationCache.items.item(0xffffffff)", "null"); 58shouldBe("applicationCache.items.item(0xfffffffe)", "null"); 59shouldBe("applicationCache.items.item(-1)", "null"); 60shouldBe("applicationCache.items.item(-2)", "null"); 61 62shouldBe("applicationCache.items[0xfffffffe]", "undefined"); 63shouldBe("applicationCache.items[0xffffffff]", "undefined"); 64 65// The below index access tests give different results in WebKit and Firefox 3.1b2 (undefined vs. empty string). 66shouldBe("applicationCache.items['0']", "undefined"); 67shouldBe("applicationCache.items['']", "undefined"); 68shouldBe("applicationCache.items[0]", "undefined"); 69shouldBe("applicationCache.items[1]", "undefined"); 70shouldBe("applicationCache.items[-1]", "undefined"); 71shouldBe("applicationCache.items[-2]", "undefined"); 72applicationCache.items[100] = "foobar"; 73applicationCache.items['100'] = "foobar"; 74applicationCache.items['foo'] = "bar"; 75shouldBe("applicationCache.items[100]", "undefined"); 76shouldBe("applicationCache.items['100']", "undefined"); 77 78shouldBe("applicationCache.items['foo']", "undefined"); 79shouldBe("applicationCache.items[0.1]", "undefined"); 80 81try { 82 applicationCache.hasItem('foo'); 83 log("FAIL: hasItem didn't raise an exception"); 84} catch (ex) { 85 if (ex.code == 11) 86 log("PASS: hasItem raised INVALID_STATE_ERR"); 87 else 88 log("FAIL: hasItem raised unexpected exception " + ex); 89} 90 91try { 92 applicationCache.add('foo'); 93 log("FAIL: add didn't raise an exception"); 94} catch (ex) { 95 if (ex.code == 11) 96 log("PASS: add raised INVALID_STATE_ERR"); 97 else 98 log("FAIL: add raised unexpected exception " + ex); 99} 100 101try { 102 applicationCache.remove('bar'); 103 log("FAIL: remove didn't raise an exception"); 104} catch (ex) { 105 if (ex.code == 11) 106 log("PASS: remove raised INVALID_STATE_ERR"); 107 else 108 log("FAIL: remove raised unexpected exception " + ex); 109} 110 111shouldBe("applicationCache.items.length", "0"); 112 113 114 115log("DONE"); 116 117</script> 118</head> 119</body> 120