| 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 cr.define('md_history.history_item_test', function() { | 5 var TEST_HISTORY_RESULTS = [ |
| 6 function registerTests() { | 6 createHistoryEntry('2016-03-16 10:00', 'http://www.google.com'), |
| 7 var TEST_HISTORY_RESULTS = [ | 7 createHistoryEntry('2016-03-16 9:00', 'http://www.example.com'), |
| 8 createHistoryEntry('2016-03-16 10:00', 'http://www.google.com'), | 8 createHistoryEntry('2016-03-16 7:01', 'http://www.badssl.com'), |
| 9 createHistoryEntry('2016-03-16 9:00', 'http://www.example.com'), | 9 createHistoryEntry('2016-03-16 7:00', 'http://www.website.com'), |
| 10 createHistoryEntry('2016-03-16 7:01', 'http://www.badssl.com'), | 10 createHistoryEntry('2016-03-16 4:00', 'http://www.website.com'), |
| 11 createHistoryEntry('2016-03-16 7:00', 'http://www.website.com'), | 11 createHistoryEntry('2016-03-15 11:00', 'http://www.example.com'), |
| 12 createHistoryEntry('2016-03-16 4:00', 'http://www.website.com'), | 12 ]; |
| 13 createHistoryEntry('2016-03-15 11:00', 'http://www.example.com'), | |
| 14 ]; | |
| 15 | 13 |
| 16 var SEARCH_HISTORY_RESULTS = [ | 14 var SEARCH_HISTORY_RESULTS = [ |
| 17 createSearchEntry('2016-03-16', "http://www.google.com"), | 15 createSearchEntry('2016-03-16', "http://www.google.com"), |
| 18 createSearchEntry('2016-03-14 11:00', "http://calendar.google.com"), | 16 createSearchEntry('2016-03-14 11:00', "http://calendar.google.com"), |
| 19 createSearchEntry('2016-03-14 10:00', "http://mail.google.com") | 17 createSearchEntry('2016-03-14 10:00', "http://mail.google.com") |
| 20 ]; | 18 ]; |
| 21 | 19 |
| 22 suite('<history-item> unit test', function() { | 20 suite('<history-item> unit test', function() { |
| 23 var item; | 21 var item; |
| 24 | 22 |
| 25 setup(function() { | 23 setup(function() { |
| 26 item = document.createElement('history-item'); | 24 item = document.createElement('history-item'); |
| 27 item.item = TEST_HISTORY_RESULTS[0]; | 25 item.item = TEST_HISTORY_RESULTS[0]; |
| 28 replaceBody(item); | 26 replaceBody(item); |
| 29 }); | 27 }); |
| 30 | 28 |
| 31 test('click targets for selection', function() { | 29 test('click targets for selection', function() { |
| 32 var selectionCount = 0; | 30 var selectionCount = 0; |
| 33 item.addEventListener('history-checkbox-select', function() { | 31 item.addEventListener('history-checkbox-select', function() { |
| 34 selectionCount++; | 32 selectionCount++; |
| 35 }); | |
| 36 | |
| 37 // Checkbox should trigger selection. | |
| 38 MockInteractions.tap(item.$.checkbox); | |
| 39 assertEquals(1, selectionCount); | |
| 40 | |
| 41 // Non-interactive text should trigger selection. | |
| 42 MockInteractions.tap(item.$['time-accessed']); | |
| 43 assertEquals(2, selectionCount); | |
| 44 | |
| 45 // Menu button should not trigger selection. | |
| 46 MockInteractions.tap(item.$['menu-button']); | |
| 47 assertEquals(2, selectionCount); | |
| 48 }); | |
| 49 | |
| 50 test('refocus checkbox on click', function() { | |
| 51 return PolymerTest.flushTasks().then(function() { | |
| 52 item.$['menu-button'].focus(); | |
| 53 assertEquals(item.$['menu-button'], item.root.activeElement); | |
| 54 | |
| 55 MockInteractions.tap(item.$['time-accessed']); | |
| 56 assertEquals(item.$['checkbox'], item.root.activeElement); | |
| 57 }); | |
| 58 }); | |
| 59 }); | 33 }); |
| 60 | 34 |
| 61 suite('<history-item> integration test', function() { | 35 // Checkbox should trigger selection. |
| 62 var element; | 36 MockInteractions.tap(item.$.checkbox); |
| 37 assertEquals(1, selectionCount); |
| 63 | 38 |
| 64 setup(function() { | 39 // Non-interactive text should trigger selection. |
| 65 element = replaceApp().$['history'].$['infinite-list']; | 40 MockInteractions.tap(item.$['time-accessed']); |
| 66 }); | 41 assertEquals(2, selectionCount); |
| 67 | 42 |
| 68 test('basic separator insertion', function() { | 43 // Menu button should not trigger selection. |
| 69 element.addNewResults(TEST_HISTORY_RESULTS); | 44 MockInteractions.tap(item.$['menu-button']); |
| 70 return PolymerTest.flushTasks().then(function() { | 45 assertEquals(2, selectionCount); |
| 71 // Check that the correct number of time gaps are inserted. | 46 }); |
| 72 var items = | |
| 73 Polymer.dom(element.root).querySelectorAll('history-item'); | |
| 74 | 47 |
| 75 assertTrue(items[0].hasTimeGap); | 48 test('refocus checkbox on click', function() { |
| 76 assertTrue(items[1].hasTimeGap); | 49 return PolymerTest.flushTasks().then(function() { |
| 77 assertFalse(items[2].hasTimeGap); | 50 item.$['menu-button'].focus(); |
| 78 assertTrue(items[3].hasTimeGap); | 51 assertEquals(item.$['menu-button'], item.root.activeElement); |
| 79 assertFalse(items[4].hasTimeGap); | |
| 80 assertFalse(items[5].hasTimeGap); | |
| 81 }); | |
| 82 }); | |
| 83 | 52 |
| 84 test('separator insertion for search', function() { | 53 MockInteractions.tap(item.$['time-accessed']); |
| 85 element.addNewResults(SEARCH_HISTORY_RESULTS); | 54 assertEquals(item.$['checkbox'], item.root.activeElement); |
| 86 element.searchedTerm = 'search'; | 55 }); |
| 56 }); |
| 57 }); |
| 87 | 58 |
| 88 return PolymerTest.flushTasks().then(function() { | 59 suite('<history-item> integration test', function() { |
| 89 var items = | 60 var element; |
| 90 Polymer.dom(element.root).querySelectorAll('history-item'); | |
| 91 | 61 |
| 92 assertTrue(items[0].hasTimeGap); | 62 setup(function() { |
| 93 assertFalse(items[1].hasTimeGap); | 63 element = replaceApp().$['history'].$['infinite-list']; |
| 94 assertFalse(items[2].hasTimeGap); | 64 }); |
| 95 }); | |
| 96 }); | |
| 97 | 65 |
| 98 test('separator insertion after deletion', function() { | 66 test('basic separator insertion', function() { |
| 99 element.addNewResults(TEST_HISTORY_RESULTS); | 67 element.addNewResults(TEST_HISTORY_RESULTS); |
| 100 return PolymerTest.flushTasks().then(function() { | 68 return PolymerTest.flushTasks().then(function() { |
| 101 var items = | 69 // Check that the correct number of time gaps are inserted. |
| 102 Polymer.dom(element.root).querySelectorAll('history-item'); | 70 var items = Polymer.dom(element.root).querySelectorAll('history-item'); |
| 103 | 71 |
| 104 element.removeItemsByPath(['historyData_.3']); | 72 assertTrue(items[0].hasTimeGap); |
| 105 assertEquals(5, element.historyData_.length); | 73 assertTrue(items[1].hasTimeGap); |
| 74 assertFalse(items[2].hasTimeGap); |
| 75 assertTrue(items[3].hasTimeGap); |
| 76 assertFalse(items[4].hasTimeGap); |
| 77 assertFalse(items[5].hasTimeGap); |
| 78 }); |
| 79 }); |
| 106 | 80 |
| 107 // Checks that a new time gap separator has been inserted. | 81 test('separator insertion for search', function() { |
| 108 assertTrue(items[2].hasTimeGap); | 82 element.addNewResults(SEARCH_HISTORY_RESULTS); |
| 83 element.searchedTerm = 'search'; |
| 109 | 84 |
| 110 element.removeItemsByPath(['historyData_.3']); | 85 return PolymerTest.flushTasks().then(function() { |
| 86 var items = Polymer.dom(element.root).querySelectorAll('history-item'); |
| 111 | 87 |
| 112 // Checks time gap separator is removed. | 88 assertTrue(items[0].hasTimeGap); |
| 113 assertFalse(items[2].hasTimeGap); | 89 assertFalse(items[1].hasTimeGap); |
| 114 }); | 90 assertFalse(items[2].hasTimeGap); |
| 115 }); | 91 }); |
| 92 }); |
| 116 | 93 |
| 117 test('remove bookmarks', function() { | 94 test('separator insertion after deletion', function() { |
| 118 element.addNewResults(TEST_HISTORY_RESULTS); | 95 element.addNewResults(TEST_HISTORY_RESULTS); |
| 119 return PolymerTest.flushTasks().then(function() { | 96 return PolymerTest.flushTasks().then(function() { |
| 120 element.set('historyData_.1.starred', true); | 97 var items = Polymer.dom(element.root).querySelectorAll('history-item'); |
| 121 element.set('historyData_.5.starred', true); | |
| 122 return PolymerTest.flushTasks(); | |
| 123 }).then(function() { | |
| 124 | 98 |
| 125 items = Polymer.dom(element.root).querySelectorAll('history-item'); | 99 element.removeItemsByPath(['historyData_.3']); |
| 100 assertEquals(5, element.historyData_.length); |
| 126 | 101 |
| 127 items[1].$$('#bookmark-star').focus(); | 102 // Checks that a new time gap separator has been inserted. |
| 128 MockInteractions.tap(items[1].$$('#bookmark-star')); | 103 assertTrue(items[2].hasTimeGap); |
| 129 | 104 |
| 130 // Check that focus is shifted to overflow menu icon. | 105 element.removeItemsByPath(['historyData_.3']); |
| 131 assertEquals(items[1].root.activeElement, items[1].$['menu-button']); | 106 |
| 132 // Check that all items matching this url are unstarred. | 107 // Checks time gap separator is removed. |
| 133 assertEquals(element.historyData_[1].starred, false); | 108 assertFalse(items[2].hasTimeGap); |
| 134 assertEquals(element.historyData_[5].starred, false); | |
| 135 }); | |
| 136 }); | |
| 137 }); | 109 }); |
| 138 } | 110 }); |
| 139 return { | 111 |
| 140 registerTests: registerTests | 112 test('remove bookmarks', function() { |
| 141 }; | 113 element.addNewResults(TEST_HISTORY_RESULTS); |
| 114 return PolymerTest.flushTasks().then(function() { |
| 115 element.set('historyData_.1.starred', true); |
| 116 element.set('historyData_.5.starred', true); |
| 117 return PolymerTest.flushTasks(); |
| 118 }).then(function() { |
| 119 |
| 120 items = Polymer.dom(element.root).querySelectorAll('history-item'); |
| 121 |
| 122 items[1].$$('#bookmark-star').focus(); |
| 123 MockInteractions.tap(items[1].$$('#bookmark-star')); |
| 124 |
| 125 // Check that focus is shifted to overflow menu icon. |
| 126 assertEquals(items[1].root.activeElement, items[1].$['menu-button']); |
| 127 // Check that all items matching this url are unstarred. |
| 128 assertEquals(element.historyData_[1].starred, false); |
| 129 assertEquals(element.historyData_[5].starred, false); |
| 130 }); |
| 131 }); |
| 142 }); | 132 }); |
| OLD | NEW |