| OLD | NEW |
| 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 // This is global state that is maintained across tests as a reference | 4 // This is global state that is maintained across tests as a reference |
| 5 // to compare against what's fetched from the browser (using compareTrees). | 5 // to compare against what's fetched from the browser (using compareTrees). |
| 6 // TODO(erikkay) It would be better if each test was self-contained and | 6 // TODO(erikkay) It would be better if each test was self-contained and |
| 7 // didn't depend on global state. | 7 // didn't depend on global state. |
| 8 var expected = [ | 8 var expected = [ |
| 9 {"children": [ | 9 {"children": [ |
| 10 {children:[], id:"1", parentId:"0", index:0, title:"Bookmarks bar"}, | 10 {children:[], id:"1", parentId:"0", index:0, title:"Bookmarks bar"}, |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 })); | 215 })); |
| 216 // Insert node3 at index 1 rather than at the end. This should result in | 216 // Insert node3 at index 1 rather than at the end. This should result in |
| 217 // an order of node1, node3, node2. | 217 // an order of node1, node3, node2. |
| 218 chrome.bookmarks.move(node3.id, {parentId:folder.id, index:1}, | 218 chrome.bookmarks.move(node3.id, {parentId:folder.id, index:1}, |
| 219 pass(function(results) { | 219 pass(function(results) { |
| 220 chrome.test.assertEq(results.parentId, folder.id); | 220 chrome.test.assertEq(results.parentId, folder.id); |
| 221 chrome.test.assertEq(results.index, 1); | 221 chrome.test.assertEq(results.index, 1); |
| 222 node3.parentId = results.parentId; | 222 node3.parentId = results.parentId; |
| 223 node3.index = 1; | 223 node3.index = 1; |
| 224 node2.index = 2; | 224 node2.index = 2; |
| 225 | 225 |
| 226 // update expected to match | 226 // update expected to match |
| 227 expected[0].children[0].children.pop(); | 227 expected[0].children[0].children.pop(); |
| 228 expected[0].children[0].children.pop(); | 228 expected[0].children[0].children.pop(); |
| 229 expected[0].children[0].children.pop(); | 229 expected[0].children[0].children.pop(); |
| 230 folder.children.push(node1); | 230 folder.children.push(node1); |
| 231 folder.children.push(node3); | 231 folder.children.push(node3); |
| 232 folder.children.push(node2); | 232 folder.children.push(node2); |
| 233 | 233 |
| 234 verifyTreeIsExpected(pass()); | 234 verifyTreeIsExpected(pass()); |
| 235 })); | 235 })); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 276 |
| 277 function update() { | 277 function update() { |
| 278 var title = "hello world"; | 278 var title = "hello world"; |
| 279 chrome.test.listenOnce(chrome.bookmarks.onChanged, function(id, changes) { | 279 chrome.test.listenOnce(chrome.bookmarks.onChanged, function(id, changes) { |
| 280 chrome.test.assertEq(title, changes.title); | 280 chrome.test.assertEq(title, changes.title); |
| 281 }); | 281 }); |
| 282 chrome.bookmarks.update(node1.id, {"title": title}, pass(function(results) { | 282 chrome.bookmarks.update(node1.id, {"title": title}, pass(function(results) { |
| 283 chrome.test.assertEq(title, results.title); | 283 chrome.test.assertEq(title, results.title); |
| 284 })); | 284 })); |
| 285 | 285 |
| 286 var url = "http://example.com/hello" | 286 var url = "http://example.com/hello"; |
| 287 chrome.bookmarks.update(node1.id, {"url": url}, pass(function(results) { | 287 chrome.bookmarks.update(node1.id, {"url": url}, pass(function(results) { |
| 288 // Make sure that leaving out the title does not set the title to empty. | 288 // Make sure that leaving out the title does not set the title to empty. |
| 289 chrome.test.assertEq(title, results.title); | 289 chrome.test.assertEq(title, results.title); |
| 290 chrome.test.assertEq(url, results.url); | 290 chrome.test.assertEq(url, results.url); |
| 291 |
| 292 // Empty or invalid URLs should not change the URL. |
| 293 var bad_url = ""; |
| 294 chrome.bookmarks.update(node1.id, {"url": bad_url}, |
| 295 pass(function(results) { |
| 296 chrome.bookmarks.get(node1.id, pass(function(results) { |
| 297 chrome.test.assertEq(url, results[0].url); |
| 298 chrome.test.log("URL UNCHANGED"); |
| 299 })); |
| 300 }) |
| 301 ); |
| 302 |
| 303 // Invalid URLs also generate an error. |
| 304 bad_url = "I am not an URL"; |
| 305 chrome.bookmarks.update(node1.id, {"url": bad_url}, fail("Invalid URL.", |
| 306 function(results) { |
| 307 chrome.bookmarks.get(node1.id, pass(function(results) { |
| 308 chrome.test.assertEq(url, results[0].url); |
| 309 chrome.test.log("URL UNCHANGED"); |
| 310 })); |
| 311 }) |
| 312 ); |
| 291 })); | 313 })); |
| 292 }, | 314 }, |
| 293 | 315 |
| 294 function remove() { | 316 function remove() { |
| 295 var parentId = node1.parentId; | 317 var parentId = node1.parentId; |
| 296 chrome.test.listenOnce(chrome.bookmarks.onRemoved, | 318 chrome.test.listenOnce(chrome.bookmarks.onRemoved, |
| 297 function(id, removeInfo) { | 319 function(id, removeInfo) { |
| 298 chrome.test.assertEq(id, node1.id); | 320 chrome.test.assertEq(id, node1.id); |
| 299 chrome.test.assertEq(removeInfo.parentId, parentId); | 321 chrome.test.assertEq(removeInfo.parentId, parentId); |
| 300 chrome.test.assertEq(removeInfo.index, node1.index); | 322 chrome.test.assertEq(removeInfo.index, node1.index); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 "Should only get the last 2 bookmarks"); | 448 "Should only get the last 2 bookmarks"); |
| 427 | 449 |
| 428 chrome.test.assertTrue(compareNode(node3, results[0])); | 450 chrome.test.assertTrue(compareNode(node3, results[0])); |
| 429 chrome.test.assertTrue(compareNode(node2, results[1])); | 451 chrome.test.assertTrue(compareNode(node2, results[1])); |
| 430 })); | 452 })); |
| 431 } | 453 } |
| 432 ]); | 454 ]); |
| 433 } | 455 } |
| 434 | 456 |
| 435 run(); | 457 run(); |
| OLD | NEW |