1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test IndexedDB's KeyRange.");
8 function checkSingleKeyRange(value)
10 keyRange = evalAndLog("IDBKeyRange.only(" + value + ")");
11 shouldBe("keyRange.lower", "" + value);
12 shouldBe("keyRange.upper", "" + value);
13 shouldBeFalse("keyRange.lowerOpen");
14 shouldBeFalse("keyRange.upperOpen");
17 function checkLowerBoundKeyRange(value, open)
19 keyRange = evalAndLog("IDBKeyRange.lowerBound(" + value + "," + open + ")");
20 shouldBe("keyRange.lower", "" + value);
21 if (open === undefined)
23 shouldBe("keyRange.lowerOpen", "" + open);
24 shouldBeUndefined("keyRange.upper");
25 shouldBeTrue("keyRange.upperOpen");
28 function checkUpperBoundKeyRange(value, open)
30 keyRange = evalAndLog("IDBKeyRange.upperBound(" + value + "," + open + ")");
31 shouldBe("keyRange.upper", "" + value);
32 if (open === undefined)
34 shouldBe("keyRange.upperOpen", "" + open);
35 shouldBeUndefined("keyRange.lower");
36 shouldBeTrue("keyRange.lowerOpen");
39 function checkBoundKeyRange(lower, upper, lowerOpen, upperOpen)
41 keyRange = evalAndLog("IDBKeyRange.bound(" + lower + "," + upper + ", " + lowerOpen + ", " + upperOpen + ")");
42 shouldBe("keyRange.lower", "" + lower);
43 shouldBe("keyRange.upper", "" + upper);
44 if (lowerOpen === undefined)
46 if (upperOpen === undefined)
48 shouldBe("keyRange.lowerOpen", "" + lowerOpen);
49 shouldBe("keyRange.upperOpen", "" + upperOpen);
54 shouldBeFalse("'lower' in IDBKeyRange");
55 shouldBeFalse("'upper' in IDBKeyRange");
56 shouldBeFalse("'lowerOpen' in IDBKeyRange");
57 shouldBeFalse("'upperOpen' in IDBKeyRange");
58 shouldBeTrue("'only' in IDBKeyRange");
59 shouldBeTrue("'lowerBound' in IDBKeyRange");
60 shouldBeTrue("'upperBound' in IDBKeyRange");
61 shouldBeTrue("'bound' in IDBKeyRange");
65 var instance = evalAndLog("instance = IDBKeyRange.only(1)");
66 shouldBeTrue("'lower' in instance");
67 shouldBeTrue("'upper' in instance");
68 shouldBeTrue("'lowerOpen' in instance");
69 shouldBeTrue("'upperOpen' in instance");
70 shouldBeFalse("'only' in instance");
71 shouldBeFalse("'lowerBound' in instance");
72 shouldBeFalse("'upperBound' in instance");
73 shouldBeFalse("'bound' in instance");
77 checkSingleKeyRange(1);
78 checkSingleKeyRange(3.14);
79 checkSingleKeyRange("'a'");
81 checkLowerBoundKeyRange(10, true);
82 checkLowerBoundKeyRange(11, false);
83 checkLowerBoundKeyRange(12);
84 checkLowerBoundKeyRange(10.1, true);
85 checkLowerBoundKeyRange(11.2, false);
86 checkLowerBoundKeyRange(12.3);
87 checkLowerBoundKeyRange("'aa'", true);
88 checkLowerBoundKeyRange("'ab'", false);
89 checkLowerBoundKeyRange("'ac'");
91 checkUpperBoundKeyRange(20, true);
92 checkUpperBoundKeyRange(21, false);
93 checkUpperBoundKeyRange(22);
94 checkUpperBoundKeyRange(20.2, true);
95 checkUpperBoundKeyRange(21.3, false);
96 checkUpperBoundKeyRange(22.4);
97 checkUpperBoundKeyRange("'ba'", true);
98 checkUpperBoundKeyRange("'bb'", false);
99 checkUpperBoundKeyRange("'bc'");
101 checkBoundKeyRange(30, 40);
102 checkBoundKeyRange(31, 41, false, false);
103 checkBoundKeyRange(32, 42, false, true);
104 checkBoundKeyRange(33, 43, true, false);
105 checkBoundKeyRange(34, 44, true, true);
107 checkBoundKeyRange(30.1, 40.2);
108 checkBoundKeyRange(31.3, 41.4, false, false);
109 checkBoundKeyRange(32.5, 42.6, false, true);
110 checkBoundKeyRange(33.7, 43.8, true, false);
111 checkBoundKeyRange(34.9, 44.0, true, true);
113 checkBoundKeyRange("'aaa'", "'aba'", false, false);
114 checkBoundKeyRange("'aab'", "'abb'");
115 checkBoundKeyRange("'aac'", "'abc'", false, false);
116 checkBoundKeyRange("'aad'", "'abd'", false, true);
117 checkBoundKeyRange("'aae'", "'abe'", true, false);
118 checkBoundKeyRange("'aaf'", "'abf'", true, true);
120 debug("Passing an invalid key into only({})");
121 evalAndExpectException("IDBKeyRange.only({})", "0", "'DataError'");
123 debug("Passing an invalid key into upperBound({})");
124 evalAndExpectException("IDBKeyRange.upperBound({})", "0", "'DataError'");
126 debug("Passing an invalid key into lowerBound({})");
127 evalAndExpectException("IDBKeyRange.lowerBound({})", "0", "'DataError'");
129 debug("Passing an invalid key into bound(null, {})");
130 evalAndExpectException("IDBKeyRange.bound(null, {})", "0", "'DataError'");
132 debug("Passing an invalid key into bound({},null)");
133 evalAndExpectException("IDBKeyRange.bound({}, null)", "0", "'DataError'");
135 debug("Passing an invalid key into bound({}, {})");
136 evalAndExpectException("IDBKeyRange.bound({}, {})", "0", "'DataError'");
138 debug("Lower key greater than higher key, bound(4, 3)");
139 evalAndExpectException("IDBKeyRange.bound(4, 3)", "0", "'DataError'");
141 debug("Equal keys, either of the bounds is open, bound(4, 4, true, false)");
142 evalAndExpectException("IDBKeyRange.bound(4, 4, true, false)", "0", "'DataError'");
144 debug("Equal keys, either of the bounds is open, bound(4, 4, false, true)");
145 evalAndExpectException("IDBKeyRange.bound(4, 4, false, true)", "0", "'DataError'");
147 debug("Equal keys, either of the bounds is open, bound(4, 4, true, true)");
148 evalAndExpectException("IDBKeyRange.bound(4, 4, true, true)", "0", "'DataError'");
150 debug("Equal keys, none of the bounds is open, bound(4, 4, false, false)");
151 IDBKeyRange.bound(4, 4, false, false);