Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/test/data/extensions/api_test/settings/simple_test/background.html

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

Powered by Google App Engine
This is Rietveld 408576698