2 <p>Test the behavior of DOMApplicationCache methods related to dynamic entries when the context
3 is not associated with any cache.</p>
4 <div id="result"></div>
7 testRunner.dumpAsText();
11 document.getElementById("result").innerHTML += message + "<br>";
15 function isResultCorrect(_actual, _expected)
18 return _actual === _expected && (1/_actual) === (1/_expected);
19 if (_actual === _expected)
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");
30 function shouldBe(_a, _b)
32 if (typeof _a != "string" || typeof _b != "string")
33 log("WARN: shouldBe() expects string arguments");
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) + ".");
50 log("FAIL: " + _a + " should be " + _bv + " (of type " + typeof _bv + "). Was " + _av + " (of type " + typeof _av + ").");
54 shouldBe("applicationCache.items.length", "0");
55 shouldBe("applicationCache.items.item(0)", "null");
56 shouldBe("applicationCache.items.item(1)", "null");
57 shouldBe("applicationCache.items.item(0xffffffff)", "null");
58 shouldBe("applicationCache.items.item(0xfffffffe)", "null");
59 shouldBe("applicationCache.items.item(-1)", "null");
60 shouldBe("applicationCache.items.item(-2)", "null");
62 shouldBe("applicationCache.items[0xfffffffe]", "undefined");
63 shouldBe("applicationCache.items[0xffffffff]", "undefined");
65 // The below index access tests give different results in WebKit and Firefox 3.1b2 (undefined vs. empty string).
66 shouldBe("applicationCache.items['0']", "undefined");
67 shouldBe("applicationCache.items['']", "undefined");
68 shouldBe("applicationCache.items[0]", "undefined");
69 shouldBe("applicationCache.items[1]", "undefined");
70 shouldBe("applicationCache.items[-1]", "undefined");
71 shouldBe("applicationCache.items[-2]", "undefined");
72 applicationCache.items[100] = "foobar";
73 applicationCache.items['100'] = "foobar";
74 applicationCache.items['foo'] = "bar";
75 shouldBe("applicationCache.items[100]", "undefined");
76 shouldBe("applicationCache.items['100']", "undefined");
78 shouldBe("applicationCache.items['foo']", "undefined");
79 shouldBe("applicationCache.items[0.1]", "undefined");
82 applicationCache.hasItem('foo');
83 log("FAIL: hasItem didn't raise an exception");
86 log("PASS: hasItem raised INVALID_STATE_ERR");
88 log("FAIL: hasItem raised unexpected exception " + ex);
92 applicationCache.add('foo');
93 log("FAIL: add didn't raise an exception");
96 log("PASS: add raised INVALID_STATE_ERR");
98 log("FAIL: add raised unexpected exception " + ex);
102 applicationCache.remove('bar');
103 log("FAIL: remove didn't raise an exception");
106 log("PASS: remove raised INVALID_STATE_ERR");
108 log("FAIL: remove raised unexpected exception " + ex);
111 shouldBe("applicationCache.items.length", "0");