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

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

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

Powered by Google App Engine
This is Rietveld 408576698