| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 suite('<bookmarks-toolbar>', function() { | 5 suite('<bookmarks-toolbar>', function() { |
| 6 var toolbar; | 6 var toolbar; |
| 7 var store; | 7 var store; |
| 8 var commandManager; | 8 var commandManager; |
| 9 | 9 |
| 10 suiteSetup(function() { | 10 suiteSetup(function() { |
| 11 chrome.bookmarkManagerPrivate.removeTrees = function() {}; | 11 chrome.bookmarkManagerPrivate.removeTrees = function() {}; |
| 12 }); | 12 }); |
| 13 | 13 |
| 14 setup(function() { | 14 setup(function() { |
| 15 store = new bookmarks.TestStore({ | 15 store = new bookmarks.TestStore({ |
| 16 nodes: testTree(createFolder('1', [ | 16 nodes: testTree(createFolder( |
| 17 createItem('2'), | 17 '1', |
| 18 createItem('3'), | 18 [ |
| 19 ])), | 19 createItem('2'), |
| 20 createItem('3'), |
| 21 createFolder('4', [], {unmodifiable: 'managed'}), |
| 22 ])), |
| 20 selection: { | 23 selection: { |
| 21 items: new Set(), | 24 items: new Set(), |
| 22 anchor: null, | 25 anchor: null, |
| 23 }, | 26 }, |
| 24 }); | 27 }); |
| 25 store.replaceSingleton(); | 28 store.replaceSingleton(); |
| 26 | 29 |
| 27 toolbar = document.createElement('bookmarks-toolbar'); | 30 toolbar = document.createElement('bookmarks-toolbar'); |
| 28 replaceBody(toolbar); | 31 replaceBody(toolbar); |
| 29 | 32 |
| 30 commandManager = new TestCommandManager(); | 33 commandManager = new TestCommandManager(); |
| 31 document.body.appendChild(commandManager); | 34 document.body.appendChild(commandManager); |
| 32 }); | 35 }); |
| 33 | 36 |
| 34 test('selecting multiple items shows toolbar overlay', function() { | 37 test('selecting multiple items shows toolbar overlay', function() { |
| 35 assertFalse(toolbar.showSelectionOverlay); | 38 assertFalse(toolbar.showSelectionOverlay); |
| 36 | 39 |
| 37 store.data.selection.items = new Set(['2']); | 40 store.data.selection.items = new Set(['2']); |
| 38 store.notifyObservers(); | 41 store.notifyObservers(); |
| 39 assertFalse(toolbar.showSelectionOverlay); | 42 assertFalse(toolbar.showSelectionOverlay); |
| 40 | 43 |
| 41 store.data.selection.items = new Set(['2', '3']); | 44 store.data.selection.items = new Set(['2', '3']); |
| 42 store.notifyObservers(); | 45 store.notifyObservers(); |
| 43 assertTrue(toolbar.showSelectionOverlay); | 46 assertTrue(toolbar.showSelectionOverlay); |
| 44 }); | 47 }); |
| 45 | 48 |
| 49 test('overlay does not show when editing is disabled', function() { |
| 50 store.data.prefs.canEdit = false |
| 51 store.data.selection.items = new Set(['2', '3']); |
| 52 store.notifyObservers(); |
| 53 assertFalse(toolbar.showSelectionOverlay); |
| 54 }); |
| 55 |
| 46 test('clicking overlay delete button triggers a delete command', function() { | 56 test('clicking overlay delete button triggers a delete command', function() { |
| 47 store.data.selection.items = new Set(['2', '3']); | 57 store.data.selection.items = new Set(['2', '3']); |
| 48 store.notifyObservers(); | 58 store.notifyObservers(); |
| 49 | 59 |
| 50 Polymer.dom.flush(); | 60 Polymer.dom.flush(); |
| 51 MockInteractions.tap( | 61 var button = toolbar.$$('cr-toolbar-selection-overlay').deleteButton; |
| 52 toolbar.$$('cr-toolbar-selection-overlay').deleteButton); | 62 assertFalse(button.disabled); |
| 63 MockInteractions.tap(button); |
| 53 | 64 |
| 54 commandManager.assertLastCommand(Command.DELETE, ['2', '3']); | 65 commandManager.assertLastCommand(Command.DELETE, ['2', '3']); |
| 55 }); | 66 }); |
| 56 | 67 |
| 57 test('commands do not trigger from the search field', function() { | 68 test('commands do not trigger from the search field', function() { |
| 58 store.data.selection.items = new Set(['2']); | 69 store.data.selection.items = new Set(['2']); |
| 59 store.notifyObservers(); | 70 store.notifyObservers(); |
| 60 | 71 |
| 61 var input = toolbar.$$('cr-toolbar').getSearchField().getSearchInput(); | 72 var input = toolbar.$$('cr-toolbar').getSearchField().getSearchInput(); |
| 62 var modifier = cr.isMac ? 'meta' : 'ctrl'; | 73 var modifier = cr.isMac ? 'meta' : 'ctrl'; |
| 63 MockInteractions.pressAndReleaseKeyOn(input, 67, modifier, 'c'); | 74 MockInteractions.pressAndReleaseKeyOn(input, 67, modifier, 'c'); |
| 64 | 75 |
| 65 commandManager.assertLastCommand(null); | 76 commandManager.assertLastCommand(null); |
| 66 }); | 77 }); |
| 78 |
| 79 test('delete button is disabled when items are unmodifiable', function() { |
| 80 store.data.nodes['3'].unmodifiable = 'managed'; |
| 81 store.data.selection.items = new Set(['2', '3']); |
| 82 store.notifyObservers(); |
| 83 Polymer.dom.flush(); |
| 84 |
| 85 assertTrue(toolbar.showSelectionOverlay); |
| 86 assertTrue( |
| 87 toolbar.$$('cr-toolbar-selection-overlay').deleteButton.disabled); |
| 88 }); |
| 89 |
| 90 test('overflow menu options are disabled when appropriate', function() { |
| 91 store.data.selectedFolder = '1'; |
| 92 store.notifyObservers(); |
| 93 |
| 94 assertFalse(toolbar.$.addBookmarkButton.disabled); |
| 95 |
| 96 store.data.selectedFolder = '4'; |
| 97 store.notifyObservers(); |
| 98 |
| 99 assertTrue(toolbar.$.addBookmarkButton.disabled); |
| 100 assertFalse(toolbar.$.importBookmarkButton.disabled); |
| 101 |
| 102 store.data.prefs.canEdit = false; |
| 103 store.notifyObservers(); |
| 104 |
| 105 assertTrue(toolbar.$.addBookmarkButton.disabled); |
| 106 assertTrue(toolbar.$.importBookmarkButton.disabled); |
| 107 }); |
| 67 }); | 108 }); |
| OLD | NEW |