OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 function test(stage0) { |
| 6 var apis = [ |
| 7 chrome.experimental.storage.sync, |
| 8 chrome.experimental.storage.local |
| 9 ]; |
| 10 apis.forEach(function(api) { |
| 11 api.succeed = chrome.test.callbackPass(api.clear.bind(api)); |
| 12 stage0.call(api); |
| 13 }); |
| 14 } |
| 15 |
| 16 chrome.test.runTests([ |
| 17 function getWhenEmpty() { |
| 18 function stage0() { |
| 19 this.get('foo', stage1.bind(this)); |
| 20 } |
| 21 function stage1(settings) { |
| 22 chrome.test.assertEq({}, settings); |
| 23 this.get(['foo', 'bar'], stage2.bind(this)); |
| 24 } |
| 25 function stage2(settings) { |
| 26 chrome.test.assertEq({}, settings); |
| 27 this.get(undefined, stage3.bind(this)); |
| 28 } |
| 29 function stage3(settings) { |
| 30 chrome.test.assertEq({}, settings); |
| 31 this.succeed(); |
| 32 } |
| 33 test(stage0); |
| 34 }, |
| 35 |
| 36 function getWhenNonempty() { |
| 37 function stage0() { |
| 38 this.set({ |
| 39 'foo' : 'bar', |
| 40 'baz' : 'qux', |
| 41 'hello': 'world' |
| 42 }, stage1.bind(this)); |
| 43 } |
| 44 function stage1() { |
| 45 this.get(['foo', 'baz'], stage2.bind(this)); |
| 46 } |
| 47 function stage2(settings) { |
| 48 chrome.test.assertEq({ |
| 49 'foo': 'bar', |
| 50 'baz': 'qux' |
| 51 }, settings); |
| 52 this.get(['nothing', 'baz', 'hello', 'ignore'], stage3.bind(this)); |
| 53 } |
| 54 function stage3(settings) { |
| 55 chrome.test.assertEq({ |
| 56 'baz' : 'qux', |
| 57 'hello': 'world' |
| 58 }, settings); |
| 59 this.get(null, stage4.bind(this)); |
| 60 } |
| 61 function stage4(settings) { |
| 62 chrome.test.assertEq({ |
| 63 'foo' : 'bar', |
| 64 'baz' : 'qux', |
| 65 'hello': 'world' |
| 66 }, settings); |
| 67 this.succeed(); |
| 68 } |
| 69 test(stage0); |
| 70 }, |
| 71 |
| 72 function removeWhenEmpty() { |
| 73 function stage0() { |
| 74 this.remove('foo', stage1.bind(this)); |
| 75 } |
| 76 function stage1() { |
| 77 this.remove(['foo', 'bar'], this.succeed); |
| 78 } |
| 79 test(stage0); |
| 80 }, |
| 81 |
| 82 function removeWhenNonempty() { |
| 83 function stage0() { |
| 84 this.set({ |
| 85 'foo' : 'bar', |
| 86 'baz' : 'qux', |
| 87 'hello': 'world' |
| 88 }, stage1.bind(this)); |
| 89 } |
| 90 function stage1() { |
| 91 this.remove('foo', stage2.bind(this)); |
| 92 } |
| 93 function stage2() { |
| 94 this.get(null, stage3.bind(this)); |
| 95 } |
| 96 function stage3(settings) { |
| 97 chrome.test.assertEq({ |
| 98 'baz' : 'qux', |
| 99 'hello': 'world' |
| 100 }, settings); |
| 101 this.remove(['baz', 'nothing'], stage4.bind(this)); |
| 102 } |
| 103 function stage4() { |
| 104 this.get(null, stage5.bind(this)); |
| 105 } |
| 106 function stage5(settings) { |
| 107 chrome.test.assertEq({ |
| 108 'hello': 'world' |
| 109 }, settings); |
| 110 this.remove('hello', stage6.bind(this)); |
| 111 } |
| 112 function stage6() { |
| 113 this.get(null, stage7.bind(this)); |
| 114 } |
| 115 function stage7(settings) { |
| 116 chrome.test.assertEq({}, settings); |
| 117 this.succeed(); |
| 118 } |
| 119 test(stage0); |
| 120 }, |
| 121 |
| 122 function setWhenOverwriting() { |
| 123 function stage0() { |
| 124 this.set({ |
| 125 'foo' : 'bar', |
| 126 'baz' : 'qux', |
| 127 'hello': 'world' |
| 128 }, stage1.bind(this)); |
| 129 } |
| 130 function stage1() { |
| 131 this.set({ |
| 132 'foo' : 'otherBar', |
| 133 'baz' : 'otherQux' |
| 134 }, stage2.bind(this)); |
| 135 } |
| 136 function stage2() { |
| 137 this.get(null, stage3.bind(this)); |
| 138 } |
| 139 function stage3(settings) { |
| 140 chrome.test.assertEq({ |
| 141 'foo' : 'otherBar', |
| 142 'baz' : 'otherQux', |
| 143 'hello': 'world' |
| 144 }, settings); |
| 145 this.set({ |
| 146 'baz' : 'anotherQux', |
| 147 'hello': 'otherWorld', |
| 148 'some' : 'value' |
| 149 }, stage4.bind(this)); |
| 150 } |
| 151 function stage4() { |
| 152 this.get(null, stage5.bind(this)); |
| 153 } |
| 154 function stage5(settings) { |
| 155 chrome.test.assertEq({ |
| 156 'foo' : 'otherBar', |
| 157 'baz' : 'anotherQux', |
| 158 'hello': 'otherWorld', |
| 159 'some' : 'value' |
| 160 }, settings); |
| 161 this.succeed(); |
| 162 } |
| 163 test(stage0); |
| 164 }, |
| 165 |
| 166 function clearWhenEmpty() { |
| 167 function stage0() { |
| 168 this.clear(stage1.bind(this)); |
| 169 } |
| 170 function stage1() { |
| 171 this.get(null, stage2.bind(this)); |
| 172 } |
| 173 function stage2(settings) { |
| 174 chrome.test.assertEq({}, settings); |
| 175 this.succeed(); |
| 176 } |
| 177 test(stage0); |
| 178 }, |
| 179 |
| 180 function clearWhenNonempty() { |
| 181 function stage0() { |
| 182 this.set({ |
| 183 'foo' : 'bar', |
| 184 'baz' : 'qux', |
| 185 'hello': 'world' |
| 186 }, stage1.bind(this)); |
| 187 } |
| 188 function stage1() { |
| 189 this.clear(stage2.bind(this)); |
| 190 } |
| 191 function stage2() { |
| 192 this.get(null, stage3.bind(this)); |
| 193 } |
| 194 function stage3(settings) { |
| 195 chrome.test.assertEq({}, settings); |
| 196 this.succeed(); |
| 197 } |
| 198 test(stage0); |
| 199 }, |
| 200 |
| 201 function keysWithDots() { |
| 202 function stage0() { |
| 203 this.set({ |
| 204 'foo.bar' : 'baz', |
| 205 'one' : {'two': 'three'} |
| 206 }, stage1.bind(this)); |
| 207 } |
| 208 function stage1() { |
| 209 this.get(['foo.bar', 'one'], stage2.bind(this)); |
| 210 } |
| 211 function stage2(settings) { |
| 212 chrome.test.assertEq({ |
| 213 'foo.bar' : 'baz', |
| 214 'one' : {'two': 'three'} |
| 215 }, settings); |
| 216 this.get('one.two', stage3.bind(this)); |
| 217 } |
| 218 function stage3(settings) { |
| 219 chrome.test.assertEq({}, settings); |
| 220 this.remove(['foo.bar', 'one.two'], stage4.bind(this)); |
| 221 } |
| 222 function stage4() { |
| 223 this.get(null, stage5.bind(this)); |
| 224 } |
| 225 function stage5(settings) { |
| 226 chrome.test.assertEq({ |
| 227 'one' : {'two': 'three'} |
| 228 }, settings); |
| 229 this.succeed(); |
| 230 } |
| 231 test(stage0); |
| 232 }, |
| 233 |
| 234 function getWithDefaultValues() { |
| 235 function stage0() { |
| 236 this.get({ |
| 237 'foo': 'defaultBar', |
| 238 'baz': [1, 2, 3] |
| 239 }, stage1.bind(this)); |
| 240 } |
| 241 function stage1(settings) { |
| 242 chrome.test.assertEq({ |
| 243 'foo': 'defaultBar', |
| 244 'baz': [1, 2, 3] |
| 245 }, settings); |
| 246 this.get(null, stage2.bind(this)); |
| 247 } |
| 248 function stage2(settings) { |
| 249 chrome.test.assertEq({}, settings); |
| 250 this.set({'foo': 'bar'}, stage3.bind(this)); |
| 251 } |
| 252 function stage3() { |
| 253 this.get({ |
| 254 'foo': 'defaultBar', |
| 255 'baz': [1, 2, 3] |
| 256 }, stage4.bind(this)); |
| 257 } |
| 258 function stage4(settings) { |
| 259 chrome.test.assertEq({ |
| 260 'foo': 'bar', |
| 261 'baz': [1, 2, 3] |
| 262 }, settings); |
| 263 this.set({'baz': {}}, stage5.bind(this)); |
| 264 } |
| 265 function stage5() { |
| 266 this.get({ |
| 267 'foo': 'defaultBar', |
| 268 'baz': [1, 2, 3] |
| 269 }, stage6.bind(this)); |
| 270 } |
| 271 function stage6(settings) { |
| 272 chrome.test.assertEq({ |
| 273 'foo': 'bar', |
| 274 'baz': {} |
| 275 }, settings); |
| 276 this.remove('foo', stage7.bind(this)); |
| 277 } |
| 278 function stage7() { |
| 279 this.get({ |
| 280 'foo': 'defaultBar', |
| 281 'baz': [1, 2, 3] |
| 282 }, stage8.bind(this)); |
| 283 } |
| 284 function stage8(settings) { |
| 285 chrome.test.assertEq({ |
| 286 'foo': 'defaultBar', |
| 287 'baz': {} |
| 288 }, settings); |
| 289 this.succeed(); |
| 290 } |
| 291 test(stage0); |
| 292 }, |
| 293 |
| 294 function throttling() { |
| 295 // We can only really test one of the namespaces since they will all get |
| 296 // throttled together. |
| 297 var api = chrome.experimental.storage.sync; |
| 298 |
| 299 // Should get throttled after 1000 calls. |
| 300 var maxRequests = 1001; |
| 301 |
| 302 function next() { |
| 303 api.clear((--maxRequests > 0) ? next : done); |
| 304 } |
| 305 function done() { |
| 306 chrome.test.assertEq( |
| 307 "This request exceeds available quota.", |
| 308 chrome.extension.lastError.message); |
| 309 chrome.test.succeed(); |
| 310 } |
| 311 api.clear(next); |
| 312 } |
| 313 ]); |
OLD | NEW |