Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / settings / simple_test / background.js
blobf641a6033d0d5b2891ed17137346a856578e3d82
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) {
10 var apis = [
11 chrome.storage.sync,
12 chrome.storage.local
14 apis.forEach(function(api) {
15 api.succeed = chrome.test.callbackPass(api.clear.bind(api));
16 stage0.call(api);
17 });
20 chrome.test.runTests([
21 function getWhenEmpty() {
22 function stage0() {
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);
35 this.succeed();
37 test(stage0);
40 function getWhenNonempty() {
41 function stage0() {
42 this.set({
43 'foo' : 'bar',
44 'baz' : 'qux',
45 'hello': 'world'
46 }, stage1.bind(this));
48 function stage1() {
49 this.get(['foo', 'baz'], stage2.bind(this));
51 function stage2(settings) {
52 assertEq({
53 'foo': 'bar',
54 'baz': 'qux'
55 }, settings);
56 this.get(['nothing', 'baz', 'hello', 'ignore'], stage3.bind(this));
58 function stage3(settings) {
59 assertEq({
60 'baz' : 'qux',
61 'hello': 'world'
62 }, settings);
63 this.get(null, stage4.bind(this));
65 function stage4(settings) {
66 assertEq({
67 'foo' : 'bar',
68 'baz' : 'qux',
69 'hello': 'world'
70 }, settings);
71 this.succeed();
73 test(stage0);
76 function removeWhenEmpty() {
77 function stage0() {
78 this.remove('foo', stage1.bind(this));
80 function stage1() {
81 this.remove(['foo', 'bar'], this.succeed);
83 test(stage0);
86 function removeWhenNonempty() {
87 function stage0() {
88 this.set({
89 'foo' : 'bar',
90 'baz' : 'qux',
91 'hello': 'world'
92 }, stage1.bind(this));
94 function stage1() {
95 this.remove('foo', stage2.bind(this));
97 function stage2() {
98 this.get(null, stage3.bind(this));
100 function stage3(settings) {
101 assertEq({
102 'baz' : 'qux',
103 'hello': 'world'
104 }, settings);
105 this.remove(['baz', 'nothing'], stage4.bind(this));
107 function stage4() {
108 this.get(null, stage5.bind(this));
110 function stage5(settings) {
111 assertEq({
112 'hello': 'world'
113 }, settings);
114 this.remove('hello', stage6.bind(this));
116 function stage6() {
117 this.get(null, stage7.bind(this));
119 function stage7(settings) {
120 assertEq({}, settings);
121 this.succeed();
123 test(stage0);
126 function setWhenOverwriting() {
127 function stage0() {
128 this.set({
129 'foo' : 'bar',
130 'baz' : 'qux',
131 'hello': 'world'
132 }, stage1.bind(this));
134 function stage1() {
135 this.set({
136 'foo' : 'otherBar',
137 'baz' : 'otherQux'
138 }, stage2.bind(this));
140 function stage2() {
141 this.get(null, stage3.bind(this));
143 function stage3(settings) {
144 assertEq({
145 'foo' : 'otherBar',
146 'baz' : 'otherQux',
147 'hello': 'world'
148 }, settings);
149 this.set({
150 'baz' : 'anotherQux',
151 'hello': 'otherWorld',
152 'some' : 'value'
153 }, stage4.bind(this));
155 function stage4() {
156 this.get(null, stage5.bind(this));
158 function stage5(settings) {
159 assertEq({
160 'foo' : 'otherBar',
161 'baz' : 'anotherQux',
162 'hello': 'otherWorld',
163 'some' : 'value'
164 }, settings);
165 this.succeed();
167 test(stage0);
170 function clearWhenEmpty() {
171 function stage0() {
172 this.clear(stage1.bind(this));
174 function stage1() {
175 this.get(null, stage2.bind(this));
177 function stage2(settings) {
178 assertEq({}, settings);
179 this.succeed();
181 test(stage0);
184 function clearWhenNonempty() {
185 function stage0() {
186 this.set({
187 'foo' : 'bar',
188 'baz' : 'qux',
189 'hello': 'world'
190 }, stage1.bind(this));
192 function stage1() {
193 this.clear(stage2.bind(this));
195 function stage2() {
196 this.get(null, stage3.bind(this));
198 function stage3(settings) {
199 assertEq({}, settings);
200 this.succeed();
202 test(stage0);
205 function keysWithDots() {
206 function stage0() {
207 this.set({
208 'foo.bar' : 'baz',
209 'one' : {'two': 'three'}
210 }, stage1.bind(this));
212 function stage1() {
213 this.get(['foo.bar', 'one'], stage2.bind(this));
215 function stage2(settings) {
216 assertEq({
217 'foo.bar' : 'baz',
218 'one' : {'two': 'three'}
219 }, settings);
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));
226 function stage4() {
227 this.get(null, stage5.bind(this));
229 function stage5(settings) {
230 assertEq({
231 'one' : {'two': 'three'}
232 }, settings);
233 this.succeed();
235 test(stage0);
238 function getWithDefaultValues() {
239 function stage0() {
240 this.get({
241 'foo': 'defaultBar',
242 'baz': [1, 2, 3]
243 }, stage1.bind(this));
245 function stage1(settings) {
246 assertEq({
247 'foo': 'defaultBar',
248 'baz': [1, 2, 3]
249 }, settings);
250 this.get(null, stage2.bind(this));
252 function stage2(settings) {
253 assertEq({}, settings);
254 this.set({'foo': 'bar'}, stage3.bind(this));
256 function stage3() {
257 this.get({
258 'foo': 'defaultBar',
259 'baz': [1, 2, 3]
260 }, stage4.bind(this));
262 function stage4(settings) {
263 assertEq({
264 'foo': 'bar',
265 'baz': [1, 2, 3]
266 }, settings);
267 this.set({'baz': {}}, stage5.bind(this));
269 function stage5() {
270 this.get({
271 'foo': 'defaultBar',
272 'baz': [1, 2, 3]
273 }, stage6.bind(this));
275 function stage6(settings) {
276 assertEq({
277 'foo': 'bar',
278 'baz': {}
279 }, settings);
280 this.remove('foo', stage7.bind(this));
282 function stage7() {
283 this.get({
284 'foo': 'defaultBar',
285 'baz': [1, 2, 3]
286 }, stage8.bind(this));
288 function stage8(settings) {
289 assertEq({
290 'foo': 'defaultBar',
291 'baz': {}
292 }, settings);
293 this.succeed();
295 test(stage0);
299 function quota() {
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;
311 function stage0() {
312 area.getBytesInUse(null, stage1);
314 function stage1(bytesInUse) {
315 assertEq(0, bytesInUse);
316 area.set({ a: 42, b: 43, c: 44 }, stage2);
318 function 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);
331 succeed();
333 area.clear(stage0);
336 function nullsInArgs() {
337 var area = chrome.storage.local;
338 function stage0() {
339 area.get({
340 foo: 'foo',
341 bar: null,
342 baz: undefined
343 }, stage1);
345 function stage1(values) {
346 assertEq({
347 foo: 'foo',
348 bar: null,
349 }, values);
350 area.set({
351 foo: 'foo',
352 bar: null,
353 baz: undefined
354 }, area.get.bind(area, stage2));
356 function stage2(values) {
357 assertEq({
358 foo: 'foo',
359 bar: null,
360 }, values);
361 succeed();
363 area.clear(stage0);