OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // bookmarks api test | 5 // bookmarks api test |
6 // browser_tests.exe --gtest_filter=ExtensionApiTest.Bookmarks | 6 // browser_tests.exe --gtest_filter=ExtensionApiTest.Bookmarks |
7 | 7 |
8 // This is global state that is maintained across tests as a reference | 8 // This is global state that is maintained across tests as a reference |
9 // to compare against what's fetched from the browser (using compareTrees). | 9 // to compare against what's fetched from the browser (using compareTrees). |
10 // TODO(erikkay) It would be better if each test was self-contained and | 10 // TODO(erikkay) It would be better if each test was self-contained and |
(...skipping 18 matching lines...) Expand all Loading... |
29 function bookmarksBar() { return expected[0].children[0]; } | 29 function bookmarksBar() { return expected[0].children[0]; } |
30 function otherBookmarks() { return expected[0].children[1]; } | 30 function otherBookmarks() { return expected[0].children[1]; } |
31 | 31 |
32 // Some variables that are used across multiple tests. | 32 // Some variables that are used across multiple tests. |
33 var node1 = {parentId:"1", title:"bar baz", | 33 var node1 = {parentId:"1", title:"bar baz", |
34 url:"http://www.example.com/hello"}; | 34 url:"http://www.example.com/hello"}; |
35 var node2 = {parentId:"1", title:"foo quux", | 35 var node2 = {parentId:"1", title:"foo quux", |
36 url:"http://www.example.com/bar"}; | 36 url:"http://www.example.com/bar"}; |
37 var node3 = {parentId:"1", title:"Foo bar baz", | 37 var node3 = {parentId:"1", title:"Foo bar baz", |
38 url:"http://www.google.com/hello/quux"}; | 38 url:"http://www.google.com/hello/quux"}; |
39 var quota_node1 = {parentId:"1", title:"Dave", | |
40 url:"http://www.dmband.com/"}; | |
41 var quota_node2 = {parentId:"1", title:"UW", | |
42 url:"http://www.uwaterloo.ca/"}; | |
43 var quota_node3 = {parentId:"1", title:"Whistler", | |
44 url:"http://www.whistlerblackcomb.com/"}; | |
45 | 39 |
46 var pass = chrome.test.callbackPass; | 40 var pass = chrome.test.callbackPass; |
47 var fail = chrome.test.callbackFail; | 41 var fail = chrome.test.callbackFail; |
48 | 42 |
49 function compareNode(left, right) { | 43 function compareNode(left, right) { |
50 //chrome.test.log("compareNode()"); | 44 //chrome.test.log("compareNode()"); |
51 //chrome.test.log(JSON.stringify(left, null, 2)); | 45 //chrome.test.log(JSON.stringify(left, null, 2)); |
52 //chrome.test.log(JSON.stringify(right, null, 2)); | 46 //chrome.test.log(JSON.stringify(right, null, 2)); |
53 // TODO(erikkay): do some comparison of dateAdded | 47 // TODO(erikkay): do some comparison of dateAdded |
54 if (left.id != right.id) | 48 if (left.id != right.id) |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 }, | 456 }, |
463 | 457 |
464 function searchRemovedTree() { | 458 function searchRemovedTree() { |
465 // Search for deleted folder and enclosed node3 | 459 // Search for deleted folder and enclosed node3 |
466 chrome.bookmarks.search("foo bar", pass(function(results) { | 460 chrome.bookmarks.search("foo bar", pass(function(results) { |
467 // Does not match anything since folder was removed with node3 in it | 461 // Does not match anything since folder was removed with node3 in it |
468 chrome.test.assertEq(0, results.length); | 462 chrome.test.assertEq(0, results.length); |
469 })); | 463 })); |
470 }, | 464 }, |
471 | 465 |
472 function quotaLimitedCreate() { | |
473 var node = {parentId:"1", title:"quotacreate", url:"http://www.quota.com/"}; | |
474 for (i = 0; i < 100; i++) { | |
475 chrome.bookmarks.create(node, pass(function(results) { | |
476 expected[0].children[0].children.push(results); | |
477 })); | |
478 } | |
479 chrome.bookmarks.create( | |
480 node, | |
481 fail("This request exceeds the MAX_WRITE_OPERATIONS_PER_HOUR quota.")); | |
482 | |
483 chrome.test.resetQuota(); | |
484 | |
485 // Also, test that > 100 creations of different items is fine. | |
486 for (i = 0; i < 101; i++) { | |
487 var changer = {parentId:"1", title:"" + i, url:"http://www.quota.com/"}; | |
488 chrome.bookmarks.create(changer, pass(function(results) { | |
489 expected[0].children[0].children.push(results); | |
490 })); | |
491 } | |
492 }, | |
493 | |
494 function quotaSetup() { | |
495 createNodes(bookmarksBar(), | |
496 [quota_node1, quota_node2, quota_node3], | |
497 pass(function() { | |
498 verifyTreeIsExpected(pass()); | |
499 })); | |
500 }, | |
501 | |
502 function quotaLimitedUpdate() { | |
503 var title = "hello, world!"; | |
504 for (i = 0; i < 100; i++) { | |
505 chrome.bookmarks.update(quota_node1.id, {"title": title}, | |
506 pass(function(results) { | |
507 chrome.test.assertEq(title, results.title); | |
508 } | |
509 )); | |
510 } | |
511 chrome.bookmarks.update(quota_node1.id, {"title": title}, | |
512 fail("This request exceeds the MAX_WRITE_OPERATIONS_PER_HOUR quota.")); | |
513 | |
514 chrome.test.resetQuota(); | |
515 }, | |
516 | |
517 function getRecentSetup() { | 466 function getRecentSetup() { |
518 // Clean up tree | 467 // Clean up tree |
519 ["1", "2"].forEach(function(id) { | 468 ["1", "2"].forEach(function(id) { |
520 chrome.bookmarks.getChildren(id, pass(function(children) { | 469 chrome.bookmarks.getChildren(id, pass(function(children) { |
521 children.forEach(function(child, i) { | 470 children.forEach(function(child, i) { |
522 chrome.bookmarks.removeTree(child.id, pass(function() {})); | 471 chrome.bookmarks.removeTree(child.id, pass(function() {})); |
523 // When we have removed the last child we can continue. | 472 // When we have removed the last child we can continue. |
524 if (id == "2" && i == children.length - 1) | 473 if (id == "2" && i == children.length - 1) |
525 afterRemove(); | 474 afterRemove(); |
526 }); | 475 }); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 function(result) { | 535 function(result) { |
587 chrome.test.assertEq(newTitle, result.title); | 536 chrome.test.assertEq(newTitle, result.title); |
588 chrome.test.assertFalse('url' in result) | 537 chrome.test.assertFalse('url' in result) |
589 })); | 538 })); |
590 }); | 539 }); |
591 } | 540 } |
592 ]); | 541 ]); |
593 } | 542 } |
594 | 543 |
595 run(); | 544 run(); |
OLD | NEW |