1 // Copyright (c) 2012 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.
5 var assertEq = chrome.test.assertEq;
6 var assertTrue = chrome.test.assertTrue;
7 var succeed = chrome.test.succeed;
9 function test(stage0) {
14 apis.forEach(function(api) {
15 api.succeed = chrome.test.callbackPass(api.clear.bind(api));
20 chrome.test.runTests([
21 function getWhenEmpty() {
23 this.get('foo', stage1.bind(this));
25 function stage1(settings) {
26 assertEq({}, settings);
27 this.get(['foo', 'bar'], stage2.bind(this));
29 function stage2(settings) {
30 assertEq({}, settings);
31 this.get(undefined, stage3.bind(this));
33 function stage3(settings) {
34 assertEq({}, settings);
40 function getWhenNonempty() {
46 }, stage1.bind(this));
49 this.get(['foo', 'baz'], stage2.bind(this));
51 function stage2(settings) {
56 this.get(['nothing', 'baz', 'hello', 'ignore'], stage3.bind(this));
58 function stage3(settings) {
63 this.get(null, stage4.bind(this));
65 function stage4(settings) {
76 function removeWhenEmpty() {
78 this.remove('foo', stage1.bind(this));
81 this.remove(['foo', 'bar'], this.succeed);
86 function removeWhenNonempty() {
92 }, stage1.bind(this));
95 this.remove('foo', stage2.bind(this));
98 this.get(null, stage3.bind(this));
100 function stage3(settings) {
105 this.remove(['baz', 'nothing'], stage4.bind(this));
108 this.get(null, stage5.bind(this));
110 function stage5(settings) {
114 this.remove('hello', stage6.bind(this));
117 this.get(null, stage7.bind(this));
119 function stage7(settings) {
120 assertEq({}, settings);
126 function setWhenOverwriting() {
132 }, stage1.bind(this));
138 }, stage2.bind(this));
141 this.get(null, stage3.bind(this));
143 function stage3(settings) {
150 'baz' : 'anotherQux',
151 'hello': 'otherWorld',
153 }, stage4.bind(this));
156 this.get(null, stage5.bind(this));
158 function stage5(settings) {
161 'baz' : 'anotherQux',
162 'hello': 'otherWorld',
170 function clearWhenEmpty() {
172 this.clear(stage1.bind(this));
175 this.get(null, stage2.bind(this));
177 function stage2(settings) {
178 assertEq({}, settings);
184 function clearWhenNonempty() {
190 }, stage1.bind(this));
193 this.clear(stage2.bind(this));
196 this.get(null, stage3.bind(this));
198 function stage3(settings) {
199 assertEq({}, settings);
205 function keysWithDots() {
209 'one' : {'two': 'three'}
210 }, stage1.bind(this));
213 this.get(['foo.bar', 'one'], stage2.bind(this));
215 function stage2(settings) {
218 'one' : {'two': 'three'}
220 this.get('one.two', stage3.bind(this));
222 function stage3(settings) {
223 assertEq({}, settings);
224 this.remove(['foo.bar', 'one.two'], stage4.bind(this));
227 this.get(null, stage5.bind(this));
229 function stage5(settings) {
231 'one' : {'two': 'three'}
238 function getWithDefaultValues() {
243 }, stage1.bind(this));
245 function stage1(settings) {
250 this.get(null, stage2.bind(this));
252 function stage2(settings) {
253 assertEq({}, settings);
254 this.set({'foo': 'bar'}, stage3.bind(this));
260 }, stage4.bind(this));
262 function stage4(settings) {
267 this.set({'baz': {}}, stage5.bind(this));
273 }, stage6.bind(this));
275 function stage6(settings) {
280 this.remove('foo', stage7.bind(this));
286 }, stage8.bind(this));
288 function stage8(settings) {
300 // Just check that the constants are defined; no need to be forced to
301 // update them here as well if/when they change.
302 assertTrue(chrome.storage.sync.QUOTA_BYTES > 0);
303 assertTrue(chrome.storage.sync.QUOTA_BYTES_PER_ITEM > 0);
304 assertTrue(chrome.storage.sync.MAX_ITEMS > 0);
306 assertTrue(chrome.storage.local.QUOTA_BYTES > 0);
307 assertEq('undefined', typeof chrome.storage.local.QUOTA_BYTES_PER_ITEM);
308 assertEq('undefined', typeof chrome.storage.local.MAX_ITEMS);
310 var area = chrome.storage.sync;
312 area.getBytesInUse(null, stage1);
314 function stage1(bytesInUse) {
315 assertEq(0, bytesInUse);
316 area.set({ a: 42, b: 43, c: 44 }, stage2);
319 area.getBytesInUse(null, stage3);
321 function stage3(bytesInUse) {
322 assertEq(9, bytesInUse);
323 area.getBytesInUse('a', stage4);
325 function stage4(bytesInUse) {
326 assertEq(3, bytesInUse);
327 area.getBytesInUse(['a', 'b'], stage5);
329 function stage5(bytesInUse) {
330 assertEq(6, bytesInUse);
336 function nullsInArgs() {
337 var area = chrome.storage.local;
345 function stage1(values) {
354 }, area.get.bind(area, stage2));
356 function stage2(values) {