| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
| 6 * Replace the current body of the test with a new element. | 6 * Replace the current body of the test with a new element. |
| 7 * @param {Element} element | 7 * @param {Element} element |
| 8 */ | 8 */ |
| 9 function replaceBody(element) { | 9 function replaceBody(element) { |
| 10 PolymerTest.clearBody(); | 10 PolymerTest.clearBody(); |
| 11 document.body.appendChild(element); | 11 document.body.appendChild(element); |
| 12 } | 12 } |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * Initialize a tree for UI testing. This performs the same initialization as | 15 * Convert a tree of bookmark nodes into a normalized lookup table of nodes. |
| 16 * `setUpStore_` in <bookmarks-store>, but without the need for a store element | |
| 17 * in the test. | |
| 18 * @param {BookmarkTreeNode} rootNode | |
| 19 */ | 16 */ |
| 20 function setupTreeForUITests(rootNode){ | 17 function testTree(root) { |
| 21 if (!rootNode.path) | 18 return bookmarks.util.normalizeNodes(root); |
| 22 rootNode.path = 'rootNode'; | |
| 23 | |
| 24 BookmarksStore.generatePaths(rootNode, 0); | |
| 25 BookmarksStore.initNodes(rootNode); | |
| 26 } | 19 } |
| 27 | 20 |
| 28 /** | 21 /** |
| 29 * Creates a folder with given properties. | 22 * Creates a folder with given properties. |
| 30 * @param {string} id | 23 * @param {string} id |
| 31 * @param {Array<BookmarkTreeNode>} children | 24 * @param {Array<BookmarkTreeNode>} children |
| 32 * @param {Object=} config | 25 * @param {Object=} config |
| 33 * @return {BookmarkTreeNode} | 26 * @return {BookmarkTreeNode} |
| 34 */ | 27 */ |
| 35 function createFolder(id, children, config) { | 28 function createFolder(id, children, config) { |
| 36 var newFolder = { | 29 var newFolder = { |
| 37 id: id, | 30 id: id, |
| 38 children: children, | 31 children: children, |
| 39 title: '', | 32 title: '', |
| 40 }; | 33 }; |
| 41 if (config) { | 34 if (config) { |
| 42 for (var key in config) | 35 for (var key in config) |
| 43 newFolder[key] = config[key]; | 36 newFolder[key] = config[key]; |
| 44 } | 37 } |
| 45 if (children.length) { | 38 if (children.length) { |
| 46 for (var i = 0; i < children.length; i++) { | 39 for (var i = 0; i < children.length; i++) { |
| 47 children[i].index = i; | |
| 48 children[i].parentId = newFolder.id; | 40 children[i].parentId = newFolder.id; |
| 49 } | 41 } |
| 50 } | 42 } |
| 51 return newFolder; | 43 return newFolder; |
| 52 } | 44 } |
| 53 | 45 |
| 54 /** | 46 /** |
| 55 * Splices out the item/folder at |index| and adjusts the indices of all the | 47 * Splices out the item/folder at |index| and adjusts the indices of all the |
| 56 * items after that. | 48 * items after that. |
| 57 * @param {BookmarkTreeNode} tree | 49 * @param {BookmarkTreeNode} tree |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 91 |
| 100 if (config) { | 92 if (config) { |
| 101 for (var key in config) | 93 for (var key in config) |
| 102 props[key] = config[key]; | 94 props[key] = config[key]; |
| 103 } | 95 } |
| 104 | 96 |
| 105 element.dispatchEvent(new MouseEvent('mousedown', props)); | 97 element.dispatchEvent(new MouseEvent('mousedown', props)); |
| 106 element.dispatchEvent(new MouseEvent('mouseup', props)); | 98 element.dispatchEvent(new MouseEvent('mouseup', props)); |
| 107 element.dispatchEvent(new MouseEvent('click', props)); | 99 element.dispatchEvent(new MouseEvent('click', props)); |
| 108 } | 100 } |
| OLD | NEW |