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 |
| 14 /** |
| 15 * Initialize a tree for UI testing. This performs the same initialization as |
| 16 * `setUpStore_` in <bookmarks-store>, but without the need for a store element |
| 17 * in the test. |
| 18 * @param {BookmarkTreeNode} rootNode |
| 19 */ |
| 20 function setupTreeForUITests(rootNode){ |
| 21 if (!rootNode.path) |
| 22 rootNode.path = 'rootNode'; |
| 23 |
| 24 BookmarksStore.generatePaths(rootNode, 0); |
| 25 BookmarksStore.initNodes(rootNode); |
| 26 } |
| 27 |
| 28 /** |
| 29 * Creates a folder with given properties. |
| 30 * @param {string} id |
| 31 * @param {Array<BookmarkTreeNode>} children |
| 32 * @param {Object=} config |
| 33 * @return {BookmarkTreeNode} |
| 34 */ |
| 35 function createFolder(id, children, config) { |
| 36 var newFolder = { |
| 37 id: id, |
| 38 children: children, |
| 39 title: '', |
| 40 }; |
| 41 if (config) { |
| 42 for (var key in config) |
| 43 newFolder[key] = config[key]; |
| 44 } |
| 45 if (children.length) { |
| 46 for (var i = 0; i < children.length; i++) { |
| 47 children[i].index = i; |
| 48 children[i].parentId = newFolder.id; |
| 49 } |
| 50 } |
| 51 return newFolder; |
| 52 } |
| 53 |
| 54 /** |
| 55 * Creates a bookmark with given properties. |
| 56 * @param {string} id |
| 57 * @param {Object=} config |
| 58 * @return {BookmarkTreeNode} |
| 59 */ |
| 60 function createItem(id, config) { |
| 61 var newItem = { |
| 62 id: id, |
| 63 title: '', |
| 64 url: 'http://www.google.com/', |
| 65 }; |
| 66 if (config) { |
| 67 for (var key in config) |
| 68 newItem[key] = config[key]; |
| 69 } |
| 70 return newItem; |
| 71 } |
OLD | NEW |