Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / resources / bookmark_manager / js / bmm_test.html
blob00d410867d987991810a5e01533ec3d7a648af6a
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 <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>
11 <script>
13 goog.require('goog.testing.jsunit');
14 goog.require('goog.testing.AsyncTestCase');
16 </script>
17 </head>
18 <body>
19 <script>
21 var asyncTestCase = goog.testing.AsyncTestCase.createAndInstall(document.title);
23 var tree = {
24 id: 0,
25 children: [
27 id: 1,
28 children: [
29 {id: 2},
30 {id: 3, children: []}
33 {id: 4},
34 {id: 5}
38 // Mock chrome.bookmarkManagerPrivate.getSubtree
39 chrome = chrome || {};
40 chrome.bookmarkManagerPrivate = chrome.bookmarkManagerPrivate || {};
42 var callbacks = {};
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 ''.
52 var id = node.id;
53 if (id == tree.id)
54 id = '';
55 for (var i = 0; i < callbacks[id].length; i++) {
56 callbacks[id][i].call(null, [node]);
60 function continueTesting() {
61 asyncTestCase.continueTesting();
64 function testLoad() {
65 var calls1 = 0;
66 var calls2 = 0;
67 function f1(node) {
68 calls1++;
69 assertEquals(tree, node);
71 function f2(node) {
72 calls2++;
73 assertEquals(tree, node);
76 var p = bmm.loadTree();
77 var p2 = bmm.loadTree();
78 var r = [
79 p.then(f1),
80 p2.then(f2),
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);
89 });
92 var calls3 = 0;
93 function f3(node) {
94 calls3++;
95 assertEquals(tree.children[0], node);
98 var p3 = bmm.loadSubtree(1);
99 var s = p3.then(f3);
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);
111 </script>
112 </body>
113 </html>