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

Side by Side Diff: chrome/test/data/extensions/api_test/bookmarks/test.js

Issue 183020: more bookmark tests, plus fix a couple of API bugs (Closed)
Patch Set: cleanup from review comments (plus merge fallout) Created 11 years, 3 months 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
« no previous file with comments | « chrome/common/extensions/api/extension_api.json ('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 // bookmarks api test 1 // bookmarks api test
2 // browser_tests.exe --gtest_filter=ExtensionApiTest.Bookmarks 2 // browser_tests.exe --gtest_filter=ExtensionApiTest.Bookmarks
3 3
4 var expected = [ 4 var expected = [
5 {"children": [ 5 {"children": [
6 {"children": [], "id": "1", "parentId": "0", "index": 0, "title":"Bookmarks bar"}, 6 {children:[], id:"1", parentId:"0", index:0, title:"Bookmarks bar"},
7 {"children": [], "id": "2", "parentId": "0", "index": 1, "title":"Other book marks"} 7 {children:[], id:"2", parentId:"0", index:1, title:"Other bookmarks"}
8 ], 8 ],
9 "id": "0", "title": "" 9 id:"0", title:""
10 } 10 }
11 ]; 11 ];
12 12
13 // Some variables that are used across multiple tests.
14 var node1 = {parentId:"1", title:"Foo bar baz",
15 url:"http://www.example.com/hello"};
16 var node2 = {parentId:"1", title:"foo quux",
17 url:"http://www.example.com/bar"};
18 var node3 = {parentId:"1", title:"bar baz",
19 url:"http://www.google.com/hello/quux"};
20
13 var testCallback = chrome.test.testCallback; 21 var testCallback = chrome.test.testCallback;
14 22
15 function compareNode(left, right) { 23 function compareNode(left, right) {
16 //console.log(JSON.stringify(left)); 24 //chrome.test.log(JSON.stringify(left));
17 //console.log(JSON.stringify(right)); 25 //chrome.test.log(JSON.stringify(right));
18 // TODO(erikkay): do some comparison of dateAdded 26 // TODO(erikkay): do some comparison of dateAdded
19 if (left.id != right.id) 27 if (left.id != right.id)
20 return "id mismatch: " + left.id + " != " + right.id; 28 return "id mismatch: " + left.id + " != " + right.id;
21 if (left.title != right.title) 29 if (left.title != right.title)
22 return "title mismatch: " + left.title + " != " + right.title; 30 return "title mismatch: " + left.title + " != " + right.title;
23 if (left.url != right.url) 31 if (left.url != right.url)
24 return "url mismatch: " + left.url + " != " + right.url; 32 return "url mismatch: " + left.url + " != " + right.url;
25 if (left.index != right.index) 33 if (left.index != right.index)
26 return "index mismatch: " + left.index + " != " + right.index; 34 return "index mismatch: " + left.index + " != " + right.index;
27 return true; 35 return true;
28 } 36 }
29 37
30 function compareTrees(left, right) { 38 function compareTrees(left, right) {
31 //console.log(JSON.stringify(left)); 39 //chrome.test.log(JSON.stringify(left) || "<null>");
32 //console.log(JSON.stringify(right)); 40 //chrome.test.log(JSON.stringify(right) || "<null>");
33 if (left == null && right == null) { 41 if (left == null && right == null) {
34 console.log("both left and right are NULL"); 42 console.log("both left and right are NULL");
35 return true; 43 return true;
36 } 44 }
37 if (left == null || right == null) 45 if (left == null || right == null)
38 return left + " !+ " + right; 46 return left + " !+ " + right;
39 if (left.length != right.length) 47 if (left.length != right.length)
40 return "count mismatch: " + left.length + " != " + right.length; 48 return "count mismatch: " + left.length + " != " + right.length;
41 for (var i = 0; i < left.length; i++) { 49 for (var i = 0; i < left.length; i++) {
42 var result = compareNode(left[i], right[i]); 50 var result = compareNode(left[i], right[i]);
43 if (result !== true) { 51 if (result !== true) {
44 console.log(JSON.stringify(left)); 52 console.log(JSON.stringify(left));
45 console.log(JSON.stringify(right)); 53 console.log(JSON.stringify(right));
46 return result; 54 return result;
47 } 55 }
48 result = compareTrees(left[i].children, right[i].children); 56 result = compareTrees(left[i].children, right[i].children);
49 if (result !== true) 57 if (result !== true)
50 return result; 58 return result;
51 } 59 }
52 return true; 60 return true;
53 } 61 }
54 62
55 chrome.test.runTests([ 63 chrome.test.runTests([
56 function getTree() { 64 function getTree() {
57 chrome.bookmarks.getTree(testCallback(true, function(results) { 65 chrome.bookmarks.getTree(testCallback(true, function(results) {
58 chrome.test.assertTrue(compareTrees(results, expected), 66 chrome.test.assertTrue(compareTrees(results, expected),
59 "getTree() result != expected"); 67 "getTree() result != expected");
60 expected = results; 68 expected = results;
61 })); 69 }));
62 }, 70 },
63 71
64 function get() { 72 function get() {
65 chrome.bookmarks.get("1", testCallback(true, function(results) { 73 chrome.bookmarks.get("1", testCallback(true, function(results) {
66 chrome.test.assertTrue(compareNode(results[0], expected[0].children[0])); 74 chrome.test.assertTrue(compareNode(results[0], expected[0].children[0]));
67 })); 75 }));
68 }, 76 },
69 77
70 function getArray() { 78 function getArray() {
71 chrome.bookmarks.get(["1", "2"], testCallback(true, function(results) { 79 chrome.bookmarks.get(["1", "2"], testCallback(true, function(results) {
72 chrome.test.assertTrue(compareNode(results[0], expected[0].children[0]), 80 chrome.test.assertTrue(compareNode(results[0], expected[0].children[0]),
73 "get() result != expected"); 81 "get() result != expected");
74 chrome.test.assertTrue(compareNode(results[1], expected[0].children[1]), 82 chrome.test.assertTrue(compareNode(results[1], expected[0].children[1]),
75 "get() result != expected"); 83 "get() result != expected");
76 })); 84 }));
77 }, 85 },
78 86
79 function getChildren() { 87 function getChildren() {
80 chrome.bookmarks.getChildren("0", testCallback(true, function(results) { 88 chrome.bookmarks.getChildren("0", testCallback(true, function(results) {
81 chrome.test.assertTrue(compareNode(results[0], expected[0].children[0]), 89 chrome.test.assertTrue(compareNode(results[0], expected[0].children[0]),
82 "getChildren() result != expected"); 90 "getChildren() result != expected");
83 chrome.test.assertTrue(compareNode(results[1], expected[0].children[1]), 91 chrome.test.assertTrue(compareNode(results[1], expected[0].children[1]),
84 "getChildren() result != expected"); 92 "getChildren() result != expected");
85 })); 93 }));
86 }, 94 },
87 95
88 function create() { 96 function create() {
89 var node = {parentId: "1", title:"google", url:"http://www.google.com/"}; 97 var node = {parentId:"1", title:"google", url:"http://www.google.com/"};
90 chrome.bookmarks.create(node, testCallback(true, function(results) { 98 chrome.bookmarks.create(node, testCallback(true, function(results) {
91 node.id = results.id; // since we couldn't know this going in 99 node.id = results.id; // since we couldn't know this going in
92 node.index = 0; 100 node.index = 0;
93 chrome.test.assertTrue(compareNode(node, results), 101 chrome.test.assertTrue(compareNode(node, results),
94 "created node != source"); 102 "created node != source");
103 expected[0].children[0].children.push(node);
95 })); 104 }));
96 }, 105 },
106
107 function createFolder() {
108 var node = {parentId:"1", title:"foo bar"}; // folder
109 chrome.bookmarks.create(node, testCallback(true, function(results) {
110 node.id = results.id; // since we couldn't know this going in
111 node.index = 1;
112 node.children = [];
113 chrome.test.assertTrue(compareNode(node, results),
114 "created node != source");
115 expected[0].children[0].children.push(node);
116 }));
117 },
118
119 function move_setup() {
120 chrome.bookmarks.create(node1, testCallback(false, function(results) {
121 node1.id = results.id;
122 node1.index = results.index;
123 expected[0].children[0].children.push(node1);
124 }));
125 chrome.bookmarks.create(node2, testCallback(false, function(results) {
126 node2.id = results.id;
127 node2.index = results.index;
128 expected[0].children[0].children.push(node2);
129 }));
130 chrome.bookmarks.create(node3, testCallback(false, function(results) {
131 node3.id = results.id;
132 node3.index = results.index;
133 expected[0].children[0].children.push(node3);
134 }));
135 chrome.bookmarks.getTree(testCallback(true, function(results) {
136 chrome.test.assertTrue(compareTrees(expected, results),
137 "getTree() result != expected");
138 expected = results;
139 }));
140 },
141
142 function move() {
143 // Move node1, node2, and node3 from their current location (the bookmark
144 // bar) to be under the "other bookmarks" folder instead.
145 var other = expected[0].children[1];
146 //var folder = expected[0].children[0].children[1];
147 //console.log(JSON.stringify(node1));
148 chrome.bookmarks.move(node1.id, {parentId:other.id},
149 testCallback(false, function(results) {
150 chrome.test.assertEq(results.parentId, other.id);
151 node1.parentId = results.parentId;
152 }));
153 chrome.bookmarks.move(node2.id, {parentId:other.id},
154 testCallback(false, function(results) {
155 chrome.test.assertEq(results.parentId, other.id);
156 node3.parentId = results.parentId;
157 }));
158 // Insert node3 at index 1 rather than at the end. This should result in
159 // an order of node1, node3, node2.
160 chrome.bookmarks.move(node3.id, {parentId:other.id, index:1},
161 testCallback(true, function(results) {
162 chrome.test.assertEq(results.parentId, other.id);
163 chrome.test.assertEq(results.index, 1);
164 node3.parentId = results.parentId;
165 node3.index = 1;
166 }));
167 },
168
169 function search() {
170 chrome.bookmarks.search("baz bar", testCallback(false, function(results) {
171 // matches node1 & node3
172 console.log(JSON.stringify(results));
173 chrome.test.assertEq(2, results.length);
174 }));
175 chrome.bookmarks.search("www hello", testCallback(false, function(results) {
176 // matches node1 & node3
177 chrome.test.assertEq(2, results.length);
178 }));
179 chrome.bookmarks.search("bar example",
180 testCallback(false, function(results) {
181 // matches node2
182 chrome.test.assertEq(1, results.length);
183 }));
184 chrome.bookmarks.search("foo bar", testCallback(false, function(results) {
185 // matches node1
186 chrome.test.assertEq(1, results.length);
187 }));
188 chrome.bookmarks.search("quux", testCallback(true, function(results) {
189 // matches node2 & node3
190 chrome.test.assertEq(2, results.length);
191 }));
192 },
193
194 function update() {
195 chrome.bookmarks.update(node1.id, {"title": "hello world"},
196 testCallback(true, function(results) {
197 chrome.test.assertEq("hello world", results.title);
198 }));
199 },
200
201 function remove() {
202 chrome.test.succeed();
203 },
204
205 function removeTree() {
206 chrome.test.succeed();
207 },
97 ]); 208 ]);
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/extension_api.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698