OLD | NEW |
1 <script> | 1 <!-- |
2 var api = chrome.experimental.storage; | 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this |
3 var assertEq = chrome.test.assertEq; | 3 * source code is governed by a BSD-style license that can be found in the |
4 var inIncognitoContext = chrome.extension.inIncognitoContext; | 4 * LICENSE file. |
5 | 5 --> |
6 ['sync', 'local'].forEach(function(namespace) { | 6 <script src="background.js"></script> |
7 api[namespace].notifications = []; | |
8 api.onChanged.addListener(function(changes, event_namespace) { | |
9 if (event_namespace == namespace) { | |
10 changes.forEach(function(change) { | |
11 api[namespace].notifications.push(change); | |
12 }); | |
13 } | |
14 }); | |
15 }); | |
16 | |
17 // The test from C++ runs "actions", where each action is defined here. | |
18 // This allows the test to be tightly controlled between incognito and | |
19 // non-incognito modes. | |
20 // Each function accepts a callback which should be run when the settings | |
21 // operation fully completes. | |
22 var testActions = { | |
23 noop: function(callback) { | |
24 this.get("", callback); | |
25 }, | |
26 assertEmpty: function(callback) { | |
27 this.get(null, function(settings) { | |
28 chrome.test.assertEq({}, settings); | |
29 callback(); | |
30 }); | |
31 }, | |
32 assertFoo: function(callback) { | |
33 this.get(null, function(settings) { | |
34 chrome.test.assertEq({foo: "bar"}, settings); | |
35 callback(); | |
36 }); | |
37 }, | |
38 setFoo: function(callback) { | |
39 this.set({foo: "bar"}, callback); | |
40 }, | |
41 removeFoo: function(callback) { | |
42 this.remove("foo", callback); | |
43 }, | |
44 clear: function(callback) { | |
45 this.clear(callback); | |
46 }, | |
47 assertNoNotifications: function(callback) { | |
48 assertEq([], this.notifications); | |
49 callback(); | |
50 }, | |
51 clearNotifications: function(callback) { | |
52 this.notifications.length = 0; | |
53 callback(); | |
54 }, | |
55 assertAddFooNotification: function(callback) { | |
56 assertEq([{ key: 'foo', newValue: 'bar' }], this.notifications); | |
57 callback(); | |
58 }, | |
59 assertDeleteFooNotification: function(callback) { | |
60 assertEq([{ key: 'foo', oldValue: 'bar' }], this.notifications); | |
61 callback(); | |
62 } | |
63 }; | |
64 | |
65 // The only test we run. Runs "actions" (as defined above) until told | |
66 // to stop (when the message has isFinalAction set to true). | |
67 function testEverything() { | |
68 function next() { | |
69 var waiting = inIncognitoContext ? "waiting_incognito" : "waiting"; | |
70 chrome.test.sendMessage(waiting, function(messageJson) { | |
71 var message = JSON.parse(messageJson); | |
72 var action = testActions[message.action]; | |
73 if (!action) { | |
74 chrome.test.fail("Unknown action: " + message.action); | |
75 return; | |
76 } | |
77 action.bind(api[message.namespace])( | |
78 message.isFinalAction ? chrome.test.succeed : next); | |
79 }); | |
80 } | |
81 next(); | |
82 } | |
83 | |
84 chrome.test.runTests([testEverything]); | |
85 </script> | |
OLD | NEW |