Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / resources / bookmark_manager / js / bmm_test.html
blob88e8cbee91eb782d180bff2939966fab14f7d3f8
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <!-- TODO(arv): Check in Closure unit tests and make this run as part of the
5 tests -->
6 <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"></script>
7 <script src="cr.js"></script>
8 <script src="cr/promise.js"></script>
9 <script src="bmm/treeiterator.js"></script>
10 <script src="bmm.js"></script>
11 <script>
13 goog.require('goog.testing.jsunit');
15 </script>
16 </head>
17 <body>
18 <script>
20 var tree = {
21 id: 0,
22 children: [
24 id: 1,
25 children: [
26 {id: 2},
27 {id: 3, children: []}
30 {id: 4},
31 {id: 5}
35 // Mock chrome.bookmarkManagerPrivate.getSubtree
36 chrome = chrome || {};
37 chrome.bookmarkManagerPrivate = chrome.bookmarkManagerPrivate || {};
39 var callbacks = {};
41 chrome.bookmarkManagerPrivate.getSubtree = function(id, foldersOnly, callback) {
42 callbacks[id] = callbacks[id] || [];
43 callbacks[id].push(callback);
44 callbacks[id].$calls = callbacks[id].$calls ? callbacks[id].$calls++ : 1;
47 chrome.bookmarkManagerPrivate.getSubtree.load = function(node) {
48 // getSubtree gets the root tree when id is ''.
49 var id = node.id;
50 if (id == tree.id)
51 id = '';
52 for (var i = 0; i < callbacks[id].length; i++) {
53 callbacks[id][i].call(null, [node]);
57 function setUp() {
58 callbacks = {}
61 function testLoadSingle() {
62 var calls = 0;
63 function f(node) {
64 calls++;
65 assertEquals(tree, node);
67 var p = bmm.loadTree();
68 p.addListener(f);
70 chrome.bookmarkManagerPrivate.getSubtree.load(tree);
72 assertEquals(1, calls);
73 assertEquals(1, callbacks[''].$calls);
76 function testLoadMultiple() {
77 var calls1 = 0;
78 var calls2 = 0;
79 function f1(node) {
80 calls1++;
81 assertEquals(tree, node);
83 function f2(node) {
84 calls2++;
85 assertEquals(tree, node);
88 var p = bmm.loadTree();
89 var p2 = bmm.loadTree();
90 p.addListener(f1);
91 p2.addListener(f2);
93 chrome.bookmarkManagerPrivate.getSubtree.load(tree);
95 assertEquals(1, calls1);
96 assertEquals(1, calls2);
97 assertEquals(1, callbacks[''].$calls);
100 function testLoadSubtree() {
101 var calls = 0;
102 function f(node) {
103 calls++;
104 assertEquals(tree.children[0], node);
106 var p = bmm.loadSubtree(1);
107 p.addListener(f);
109 chrome.bookmarkManagerPrivate.getSubtree.load(tree.children[0]);
111 assertEquals(1, calls);
112 assertEquals(1, callbacks[1].$calls);
115 </script>
116 </body>
117 </html>