4 <!-- TODO(arv): Check in Closure unit tests and make this run as part of the
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>
13 goog
.require('goog.testing.jsunit');
35 // Mock chrome.bookmarkManagerPrivate.getSubtree
36 chrome
= chrome
|| {};
37 chrome
.bookmarkManagerPrivate
= chrome
.bookmarkManagerPrivate
|| {};
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 ''.
52 for (var i
= 0; i
< callbacks
[id
].length
; i
++) {
53 callbacks
[id
][i
].call(null, [node
]);
61 function testLoadSingle() {
65 assertEquals(tree
, node
);
67 var p
= bmm
.loadTree();
70 chrome
.bookmarkManagerPrivate
.getSubtree
.load(tree
);
72 assertEquals(1, calls
);
73 assertEquals(1, callbacks
[''].$calls
);
76 function testLoadMultiple() {
81 assertEquals(tree
, node
);
85 assertEquals(tree
, node
);
88 var p
= bmm
.loadTree();
89 var p2
= bmm
.loadTree();
93 chrome
.bookmarkManagerPrivate
.getSubtree
.load(tree
);
95 assertEquals(1, calls1
);
96 assertEquals(1, calls2
);
97 assertEquals(1, callbacks
[''].$calls
);
100 function testLoadSubtree() {
104 assertEquals(tree
.children
[0], node
);
106 var p
= bmm
.loadSubtree(1);
109 chrome
.bookmarkManagerPrivate
.getSubtree
.load(tree
.children
[0]);
111 assertEquals(1, calls
);
112 assertEquals(1, callbacks
[1].$calls
);