4 <!-- TODO(arv): Check in Closure unit tests and make this run as part of the
6 <link rel=
"stylesheet" href=
"chrome://resources/css/text_defaults.css">
7 <script src=
"https://cdn.rawgit.com/google/closure-library/master/closure/goog/base.js"></script>
8 <script src=
"../../../../../ui/webui/resources/js/cr.js"></script>
9 <script src=
"bmm.js"></script>
10 <title>Bookmark Manager Loading Test
</title>
13 goog
.require('goog.testing.jsunit');
14 goog
.require('goog.testing.AsyncTestCase');
21 var asyncTestCase
= goog
.testing
.AsyncTestCase
.createAndInstall(document
.title
);
38 // Mock chrome.bookmarkManagerPrivate.getSubtree
39 chrome
= chrome
|| {};
40 chrome
.bookmarkManagerPrivate
= chrome
.bookmarkManagerPrivate
|| {};
44 chrome
.bookmarkManagerPrivate
.getSubtree = function(id
, foldersOnly
, callback
) {
45 callbacks
[id
] = callbacks
[id
] || [];
46 callbacks
[id
].push(callback
);
47 callbacks
[id
].$calls
= callbacks
[id
].$calls
? callbacks
[id
].$calls
++ : 1;
50 chrome
.bookmarkManagerPrivate
.getSubtree
.load = function(node
) {
51 // getSubtree gets the root tree when id is ''.
55 for (var i
= 0; i
< callbacks
[id
].length
; i
++) {
56 callbacks
[id
][i
].call(null, [node
]);
60 function continueTesting() {
61 asyncTestCase
.continueTesting();
69 assertEquals(tree
, node
);
73 assertEquals(tree
, node
);
76 var p
= bmm
.loadTree();
77 var p2
= bmm
.loadTree();
83 chrome
.bookmarkManagerPrivate
.getSubtree
.load(tree
);
85 var root
= Promise
.all(r
).then(function() {
86 assertEquals(1, calls1
);
87 assertEquals(1, calls2
);
88 assertEquals(1, callbacks
[''].$calls
);
95 assertEquals(tree
.children
[0], node
);
98 var p3
= bmm
.loadSubtree(1);
101 chrome
.bookmarkManagerPrivate
.getSubtree
.load(tree
.children
[0]);
103 var subtree
= s
.then(function() {
104 assertEquals(1, calls3
);
105 assertEquals(1, callbacks
[1].$calls
);
108 Promise
.all([root
, subtree
]).then(continueTesting
);