Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2542)

Unified Diff: chrome/test/data/webui/md_bookmarks/store_test.js

Issue 2613683002: [MD Bookmarks] Add Delete and Copy URL for Material Bookmarks. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/webui/md_bookmarks/store_test.js
diff --git a/chrome/test/data/webui/md_bookmarks/store_test.js b/chrome/test/data/webui/md_bookmarks/store_test.js
index d92fe1d10613ba643efa5d11cb47645c17a9cbb6..220b3a9e58cea2b8defbe05dfafa9eba830360a1 100644
--- a/chrome/test/data/webui/md_bookmarks/store_test.js
+++ b/chrome/test/data/webui/md_bookmarks/store_test.js
@@ -4,9 +4,12 @@
suite('<bookmarks-store>', function() {
var store;
- var TEST_TREE = {
- id: '0',
- children: [
+ var TEST_TREE;
+
+ setup(function() {
+ TEST_TREE = {
+ id: '0',
+ children: [
{
id: '1',
children: [
@@ -19,9 +22,7 @@ suite('<bookmarks-store>', function() {
]
};
- setup(function() {
store = document.createElement('bookmarks-store');
- store.isTesting_ = true;
replaceBody(store);
store.setupStore_(TEST_TREE);
});
@@ -53,11 +54,11 @@ suite('<bookmarks-store>', function() {
test('correct paths generated for nodes', function() {
var TEST_PATHS = {
'0': 'rootNode',
- '1': 'rootNode.children.0',
- '2': 'rootNode.children.0.children.0',
- '3': 'rootNode.children.0.children.1',
- '4': 'rootNode.children.1',
- '5': 'rootNode.children.2',
+ '1': 'rootNode.children.#0',
+ '2': 'rootNode.children.#0.children.#0',
+ '3': 'rootNode.children.#0.children.#1',
+ '4': 'rootNode.children.#1',
+ '5': 'rootNode.children.#2',
};
for (var id in store.idToNodeMap_)
@@ -110,4 +111,64 @@ suite('<bookmarks-store>', function() {
assertTrue(store.idToNodeMap_['1'].isSelected);
assertFalse(store.idToNodeMap_['3'].isSelected);
});
+
+ test('deleting a node updates the tree', function() {
+ // Remove an empty folder/bookmark.
+ store.onBookmarkRemoved_('4', {parentId: '0', index: '1'});
+
+ // Check the tree is correct.
+ assertEquals('5', store.rootNode.children[1].id);
+
+ // idToNodeMap_ has been updated.
+ assertEquals(undefined, store.idToNodeMap_['4']);
+ assertEquals(store.rootNode.children[1], store.idToNodeMap_['5']);
+
+ // paths have been updated.
calamity 2017/01/04 06:57:44 Capitalization.
jiaxi 2017/01/04 22:44:01 Done.
+ var TEST_PATHS = {
+ '0': 'rootNode',
+ '1': 'rootNode.children.#0',
+ '2': 'rootNode.children.#0.children.#0',
+ '3': 'rootNode.children.#0.children.#1',
+ '5': 'rootNode.children.#1',
+ };
+
+ for (var id in store.idToNodeMap_)
+ assertEquals(TEST_PATHS[id], store.idToNodeMap_[id].path);
+
+ // Remove a folder with children.
+ store.onBookmarkRemoved_('1', {parentId: '0', index: '0'});
+
+ // Check the tree is correct.
+ assertEquals('5', store.rootNode.children[0].id);
+
+ // idToNodeMap_ has been updated.
+ assertEquals(undefined, store.idToNodeMap_['1']);
+ assertEquals(undefined, store.idToNodeMap_['2']);
+ assertEquals(undefined, store.idToNodeMap_['3']);
+ assertEquals(undefined, store.idToNodeMap_['4']);
+ assertEquals(store.rootNode.children[0], store.idToNodeMap_['5']);
+
+ // paths have been updated.
calamity 2017/01/04 06:57:44 Capitalization.
jiaxi 2017/01/04 22:44:01 Done.
+ TEST_PATHS = {
+ '0': 'rootNode',
+ '5': 'rootNode.children.#0',
+ };
+
+ for (var id in store.idToNodeMap_)
+ assertEquals(TEST_PATHS[id], store.idToNodeMap_[id].path);
+ });
+
+ test('selectedId updates after removing a selected folder', function() {
+ // Selected folder gets removed.
+ store.selectedId = '2';
+ store.onBookmarkRemoved_('2', {parentId:'1', index:'0'});
+ assertTrue(store.idToNodeMap_['1'].isSelected);
+ assertEquals('1', store.selectedId);
+
+ // A folder with selected folder in it gets removed.
+ store.selectedId = '3';
+ store.onBookmarkRemoved_('1', {parentId:'0', index:'0'});
+ assertTrue(store.idToNodeMap_['0'].isSelected);
+ assertEquals('0', store.selectedId);
+ });
});

Powered by Google App Engine
This is Rietveld 408576698