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

Side by Side Diff: chrome/test/data/extensions/api_test/settings/split_incognito/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 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
« no previous file with comments | « chrome/test/data/extensions/api_test/settings/simple_test/background.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <script> 1 <script>
2 var settings = chrome.experimental.settings; 2 var api = chrome.experimental.settings;
3 var assertEq = chrome.test.assertEq; 3 var assertEq = chrome.test.assertEq;
4 var inIncognitoContext = chrome.extension.inIncognitoContext; 4 var inIncognitoContext = chrome.extension.inIncognitoContext;
5 5
6 // All notifications received. 6 ['sync', 'local'].forEach(function(namespace) {
7 var notifications = []; 7 api[namespace].notifications = [];
8 settings.onChanged.addListener(function(changes) { 8 api.onChanged.addListener(function(changes, event_namespace) {
9 changes.forEach(function(change) { 9 if (event_namespace == namespace) {
10 notifications.push(change); 10 changes.forEach(function(change) {
11 api[namespace].notifications.push(change);
12 });
13 }
11 }); 14 });
12 }); 15 });
13 16
14 // The test from C++ runs "actions", where each action is defined here. 17 // The test from C++ runs "actions", where each action is defined here.
15 // This allows the test to be tightly controlled between incognito and 18 // This allows the test to be tightly controlled between incognito and
16 // non-incognito modes. 19 // non-incognito modes.
17 // Each function accepts a callback which should be run when the settings 20 // Each function accepts a callback which should be run when the settings
18 // operation fully completes. 21 // operation fully completes.
19 var testActions = { 22 var testActions = {
20 noop: function(callback) { 23 noop: function(callback) {
21 settings.get("", callback); 24 this.get("", callback);
22 }, 25 },
23 assertEmpty: function(callback) { 26 assertEmpty: function(callback) {
24 settings.get(null, function(settings) { 27 this.get(null, function(settings) {
25 chrome.test.assertEq({}, settings); 28 chrome.test.assertEq({}, settings);
26 callback(); 29 callback();
27 }); 30 });
28 }, 31 },
29 assertFoo: function(callback) { 32 assertFoo: function(callback) {
30 settings.get(null, function(settings) { 33 this.get(null, function(settings) {
31 chrome.test.assertEq({foo: "bar"}, settings); 34 chrome.test.assertEq({foo: "bar"}, settings);
32 callback(); 35 callback();
33 }); 36 });
34 }, 37 },
35 setFoo: function(callback) { 38 setFoo: function(callback) {
36 settings.set({foo: "bar"}, callback); 39 this.set({foo: "bar"}, callback);
37 }, 40 },
38 removeFoo: function(callback) { 41 removeFoo: function(callback) {
39 settings.remove("foo", callback); 42 this.remove("foo", callback);
40 }, 43 },
41 clear: function(callback) { 44 clear: function(callback) {
42 settings.clear(callback); 45 this.clear(callback);
43 }, 46 },
44 assertNoNotifications: function(callback) { 47 assertNoNotifications: function(callback) {
45 assertEq([], notifications); 48 assertEq([], this.notifications);
46 callback(); 49 callback();
47 }, 50 },
48 clearNotifications: function(callback) { 51 clearNotifications: function(callback) {
49 notifications = []; 52 this.notifications.length = 0;
50 callback(); 53 callback();
51 }, 54 },
52 assertAddFooNotification: function(callback) { 55 assertAddFooNotification: function(callback) {
53 assertEq(1, notifications.length); 56 assertEq([{ key: 'foo', newValue: 'bar' }], this.notifications);
54 assertEq("foo", notifications[0].key);
55 assertEq(undefined, notifications[0].oldValue);
56 assertEq("bar", notifications[0].newValue);
57 callback(); 57 callback();
58 }, 58 },
59 assertDeleteFooNotification: function(callback) { 59 assertDeleteFooNotification: function(callback) {
60 assertEq(1, notifications.length); 60 assertEq([{ key: 'foo', oldValue: 'bar' }], this.notifications);
61 assertEq("foo", notifications[0].key);
62 assertEq("bar", notifications[0].oldValue);
63 assertEq(undefined, notifications[0].newValue);
64 callback(); 61 callback();
65 } 62 }
66 }; 63 };
67 64
68 // The only test we run. Runs "actions" (as defined above) until told 65 // The only test we run. Runs "actions" (as defined above) until told
69 // to stop (when the message has isFinalAction set to true). 66 // to stop (when the message has isFinalAction set to true).
70 function testEverything() { 67 function testEverything() {
71 function next() { 68 function next() {
72 var waiting = inIncognitoContext ? "waiting_incognito" : "waiting"; 69 var waiting = inIncognitoContext ? "waiting_incognito" : "waiting";
73 chrome.test.sendMessage(waiting, function(messageJson) { 70 chrome.test.sendMessage(waiting, function(messageJson) {
74 var message = JSON.parse(messageJson); 71 var message = JSON.parse(messageJson);
75 var action = testActions[message.action]; 72 var action = testActions[message.action];
76 action(message.isFinalAction ? chrome.test.succeed : next); 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);
77 }); 79 });
78 } 80 }
79 next(); 81 next();
80 } 82 }
81 83
82 chrome.test.runTests([testEverything]); 84 chrome.test.runTests([testEverything]);
83 </script> 85 </script>
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/settings/simple_test/background.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698