1 <html> 2 <head> 3 <link rel="stylesheet" href="../../fast/js/resources/js-test-style.css"> 4 <script src="../../fast/js/resources/js-test-pre.js"></script> 5 <script src="../../fast/js/resources/js-test-post-function.js"></script> 6 <script src="resources/shared.js"></script> 7 </head> 8 <body> 9 <p id="description"></p> 10 <div id="console"></div> 11 <script> 12 13 description("Test IndexedDB's KeyRange."); 14 if (window.layoutTestController) 15 layoutTestController.waitUntilDone(); 16 17 function checkSingleKeyRange(value) 18 { 19 keyRange = evalAndLog("webkitIDBKeyRange.only(" + value + ")"); 20 shouldBe("keyRange.lower", "" + value); 21 shouldBe("keyRange.upper", "" + value); 22 shouldBeFalse("keyRange.lowerOpen"); 23 shouldBeFalse("keyRange.upperOpen"); 24 } 25 26 function checkLowerBoundKeyRange(value, open) 27 { 28 keyRange = evalAndLog("webkitIDBKeyRange.lowerBound(" + value + "," + open + ")"); 29 shouldBe("keyRange.lower", "" + value); 30 if (open === undefined) 31 open = false; 32 shouldBe("keyRange.lowerOpen", "" + open); 33 shouldBeNull("keyRange.upper"); 34 shouldBeFalse("keyRange.upperOpen"); 35 } 36 37 function checkUpperBoundKeyRange(value, open) 38 { 39 keyRange = evalAndLog("webkitIDBKeyRange.upperBound(" + value + "," + open + ")"); 40 shouldBe("keyRange.upper", "" + value); 41 if (open === undefined) 42 open = false; 43 shouldBe("keyRange.upperOpen", "" + open); 44 shouldBeNull("keyRange.lower"); 45 shouldBeFalse("keyRange.lowerOpen"); 46 } 47 48 function checkBoundKeyRange(lower, upper, lowerOpen, upperOpen) 49 { 50 keyRange = evalAndLog("webkitIDBKeyRange.bound(" + lower + "," + upper + ", " + lowerOpen + ", " + upperOpen + ")"); 51 shouldBe("keyRange.lower", "" + lower); 52 shouldBe("keyRange.upper", "" + upper); 53 if (lowerOpen === undefined) 54 lowerOpen = false; 55 if (upperOpen === undefined) 56 upperOpen = false; 57 shouldBe("keyRange.lowerOpen", "" + lowerOpen); 58 shouldBe("keyRange.upperOpen", "" + upperOpen); 59 } 60 61 function test() 62 { 63 shouldBeFalse("'lower' in webkitIDBKeyRange"); 64 shouldBeFalse("'upper' in webkitIDBKeyRange"); 65 shouldBeFalse("'lowerOpen' in webkitIDBKeyRange"); 66 shouldBeFalse("'upperOpen' in webkitIDBKeyRange"); 67 shouldBeTrue("'only' in webkitIDBKeyRange"); 68 shouldBeTrue("'lowerBound' in webkitIDBKeyRange"); 69 shouldBeTrue("'upperBound' in webkitIDBKeyRange"); 70 shouldBeTrue("'bound' in webkitIDBKeyRange"); 71 72 debug(""); 73 74 var instance = evalAndLog("instance = webkitIDBKeyRange.only(1)"); 75 shouldBeTrue("'lower' in instance"); 76 shouldBeTrue("'upper' in instance"); 77 shouldBeTrue("'lowerOpen' in instance"); 78 shouldBeTrue("'upperOpen' in instance"); 79 shouldBeFalse("'only' in instance"); 80 shouldBeFalse("'lowerBound' in instance"); 81 shouldBeFalse("'upperBound' in instance"); 82 shouldBeFalse("'bound' in instance"); 83 84 debug(""); 85 86 checkSingleKeyRange(1); 87 checkSingleKeyRange(3.14); 88 checkSingleKeyRange("'a'"); 89 90 checkLowerBoundKeyRange(10, true); 91 checkLowerBoundKeyRange(11, false); 92 checkLowerBoundKeyRange(12); 93 checkLowerBoundKeyRange(10.1, true); 94 checkLowerBoundKeyRange(11.2, false); 95 checkLowerBoundKeyRange(12.3); 96 checkLowerBoundKeyRange("'aa'", true); 97 checkLowerBoundKeyRange("'ab'", false); 98 checkLowerBoundKeyRange("'ac'"); 99 100 checkUpperBoundKeyRange(20, true); 101 checkUpperBoundKeyRange(21, false); 102 checkUpperBoundKeyRange(22); 103 checkUpperBoundKeyRange(20.2, true); 104 checkUpperBoundKeyRange(21.3, false); 105 checkUpperBoundKeyRange(22.4); 106 checkUpperBoundKeyRange("'ba'", true); 107 checkUpperBoundKeyRange("'bb'", false); 108 checkUpperBoundKeyRange("'bc'"); 109 110 checkBoundKeyRange(30, 40); 111 checkBoundKeyRange(31, 41, false, false); 112 checkBoundKeyRange(32, 42, false, true); 113 checkBoundKeyRange(33, 43, true, false); 114 checkBoundKeyRange(34, 44, true, true); 115 116 checkBoundKeyRange(30.1, 40.2); 117 checkBoundKeyRange(31.3, 41.4, false, false); 118 checkBoundKeyRange(32.5, 42.6, false, true); 119 checkBoundKeyRange(33.7, 43.8, true, false); 120 checkBoundKeyRange(34.9, 44.0, true, true); 121 122 checkBoundKeyRange("'aaa'", "'aba'", false, false); 123 checkBoundKeyRange("'aab'", "'abb'"); 124 checkBoundKeyRange("'aac'", "'abc'", false, false); 125 checkBoundKeyRange("'aad'", "'abd'", false, true); 126 checkBoundKeyRange("'aae'", "'abe'", true, false); 127 checkBoundKeyRange("'aaf'", "'abf'", true, true); 128 129 try { 130 debug("Passing an invalid key into only([])"); 131 webkitIDBKeyRange.only([]); 132 testFailed("No exception thrown"); 133 } catch (e) { 134 testPassed("Caught exception: " + e.toString()); 135 } 136 137 try { 138 debug("Passing an invalid key into upperBound([])"); 139 webkitIDBKeyRange.upperBound([]); 140 testFailed("No exception thrown"); 141 } catch (e) { 142 testPassed("Caught exception: " + e.toString()); 143 } 144 145 try { 146 debug("Passing an invalid key into lowerBound([])"); 147 webkitIDBKeyRange.lowerBound([]); 148 testFailed("No exception thrown"); 149 } catch (e) { 150 testPassed("Caught exception: " + e.toString()); 151 } 152 153 try { 154 debug("Passing an invalid key into bound(null, [])"); 155 webkitIDBKeyRange.bound(null, []); 156 testFailed("No exception thrown"); 157 } catch (e) { 158 testPassed("Caught exception: " + e.toString()); 159 } 160 161 try { 162 debug("Passing an invalid key into bound([],null)"); 163 webkitIDBKeyRange.bound([], null); 164 testFailed("No exception thrown"); 165 } catch (e) { 166 testPassed("Caught exception: " + e.toString()); 167 } 168 169 try { 170 debug("Passing an invalid key into bound([], [])"); 171 webkitIDBKeyRange.bound([], []); 172 testFailed("No exception thrown"); 173 } catch (e) { 174 testPassed("Caught exception: " + e.toString()); 175 } 176 } 177 178 test(); 179 180 var successfullyParsed = true; 181 done(); 182 183 </script> 184 </body> 185 </html> 186