| 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 cr.define('md_history.history_item_test', function() { |
| 6 function registerTests() { | 6 function registerTests() { |
| 7 suite('history-item', function() { | 7 suite('history-item', function() { |
| 8 var element; | 8 var element; |
| 9 var TEST_HISTORY_RESULTS; | 9 var TEST_HISTORY_RESULTS; |
| 10 var SEARCH_HISTORY_RESULTS; | 10 var SEARCH_HISTORY_RESULTS; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 SEARCH_HISTORY_RESULTS = [ | 23 SEARCH_HISTORY_RESULTS = [ |
| 24 createSearchEntry('2016-03-16', "http://www.google.com"), | 24 createSearchEntry('2016-03-16', "http://www.google.com"), |
| 25 createSearchEntry('2016-03-14 11:00', "http://calendar.google.com"), | 25 createSearchEntry('2016-03-14 11:00', "http://calendar.google.com"), |
| 26 createSearchEntry('2016-03-14 10:00', "http://mail.google.com") | 26 createSearchEntry('2016-03-14 10:00', "http://mail.google.com") |
| 27 ]; | 27 ]; |
| 28 }); | 28 }); |
| 29 | 29 |
| 30 test('basic separator insertion', function() { | 30 test('basic separator insertion', function() { |
| 31 element.addNewResults(TEST_HISTORY_RESULTS); | 31 element.addNewResults(TEST_HISTORY_RESULTS); |
| 32 return flush().then(function() { | 32 return PolymerTest.flushTasks().then(function() { |
| 33 // Check that the correct number of time gaps are inserted. | 33 // Check that the correct number of time gaps are inserted. |
| 34 var items = | 34 var items = |
| 35 Polymer.dom(element.root).querySelectorAll('history-item'); | 35 Polymer.dom(element.root).querySelectorAll('history-item'); |
| 36 | 36 |
| 37 assertTrue(items[0].hasTimeGap); | 37 assertTrue(items[0].hasTimeGap); |
| 38 assertTrue(items[1].hasTimeGap); | 38 assertTrue(items[1].hasTimeGap); |
| 39 assertFalse(items[2].hasTimeGap); | 39 assertFalse(items[2].hasTimeGap); |
| 40 assertTrue(items[3].hasTimeGap); | 40 assertTrue(items[3].hasTimeGap); |
| 41 assertFalse(items[4].hasTimeGap); | 41 assertFalse(items[4].hasTimeGap); |
| 42 assertFalse(items[5].hasTimeGap); | 42 assertFalse(items[5].hasTimeGap); |
| 43 }); | 43 }); |
| 44 }); | 44 }); |
| 45 | 45 |
| 46 test('separator insertion for search', function() { | 46 test('separator insertion for search', function() { |
| 47 element.addNewResults(SEARCH_HISTORY_RESULTS); | 47 element.addNewResults(SEARCH_HISTORY_RESULTS); |
| 48 element.searchedTerm = 'search'; | 48 element.searchedTerm = 'search'; |
| 49 | 49 |
| 50 return flush().then(function() { | 50 return PolymerTest.flushTasks().then(function() { |
| 51 var items = | 51 var items = |
| 52 Polymer.dom(element.root).querySelectorAll('history-item'); | 52 Polymer.dom(element.root).querySelectorAll('history-item'); |
| 53 | 53 |
| 54 assertTrue(items[0].hasTimeGap); | 54 assertTrue(items[0].hasTimeGap); |
| 55 assertFalse(items[1].hasTimeGap); | 55 assertFalse(items[1].hasTimeGap); |
| 56 assertFalse(items[2].hasTimeGap); | 56 assertFalse(items[2].hasTimeGap); |
| 57 }); | 57 }); |
| 58 }); | 58 }); |
| 59 | 59 |
| 60 test('separator insertion after deletion', function() { | 60 test('separator insertion after deletion', function() { |
| 61 element.addNewResults(TEST_HISTORY_RESULTS); | 61 element.addNewResults(TEST_HISTORY_RESULTS); |
| 62 return flush().then(function() { | 62 return PolymerTest.flushTasks().then(function() { |
| 63 var items = | 63 var items = |
| 64 Polymer.dom(element.root).querySelectorAll('history-item'); | 64 Polymer.dom(element.root).querySelectorAll('history-item'); |
| 65 | 65 |
| 66 element.removeItemsByPath(['historyData_.3']); | 66 element.removeItemsByPath(['historyData_.3']); |
| 67 assertEquals(5, element.historyData_.length); | 67 assertEquals(5, element.historyData_.length); |
| 68 | 68 |
| 69 // Checks that a new time gap separator has been inserted. | 69 // Checks that a new time gap separator has been inserted. |
| 70 assertTrue(items[2].hasTimeGap); | 70 assertTrue(items[2].hasTimeGap); |
| 71 | 71 |
| 72 element.removeItemsByPath(['historyData_.3']); | 72 element.removeItemsByPath(['historyData_.3']); |
| 73 | 73 |
| 74 // Checks time gap separator is removed. | 74 // Checks time gap separator is removed. |
| 75 assertFalse(items[2].hasTimeGap); | 75 assertFalse(items[2].hasTimeGap); |
| 76 }); | 76 }); |
| 77 }); | 77 }); |
| 78 | 78 |
| 79 test('remove bookmarks', function() { | 79 test('remove bookmarks', function() { |
| 80 element.addNewResults(TEST_HISTORY_RESULTS); | 80 element.addNewResults(TEST_HISTORY_RESULTS); |
| 81 return flush().then(function() { | 81 return PolymerTest.flushTasks().then(function() { |
| 82 element.set('historyData_.1.starred', true); | 82 element.set('historyData_.1.starred', true); |
| 83 element.set('historyData_.5.starred', true); | 83 element.set('historyData_.5.starred', true); |
| 84 return flush(); | 84 return PolymerTest.flushTasks(); |
| 85 }).then(function() { | 85 }).then(function() { |
| 86 | 86 |
| 87 items = Polymer.dom(element.root).querySelectorAll('history-item'); | 87 items = Polymer.dom(element.root).querySelectorAll('history-item'); |
| 88 | 88 |
| 89 items[1].$$('#bookmark-star').focus(); | 89 items[1].$$('#bookmark-star').focus(); |
| 90 MockInteractions.tap(items[1].$$('#bookmark-star')); | 90 MockInteractions.tap(items[1].$$('#bookmark-star')); |
| 91 | 91 |
| 92 // Check that focus is shifted to overflow menu icon. | 92 // Check that focus is shifted to overflow menu icon. |
| 93 assertEquals(items[1].root.activeElement, items[1].$['menu-button']); | 93 assertEquals(items[1].root.activeElement, items[1].$['menu-button']); |
| 94 // Check that all items matching this url are unstarred. | 94 // Check that all items matching this url are unstarred. |
| 95 assertEquals(element.historyData_[1].starred, false); | 95 assertEquals(element.historyData_[1].starred, false); |
| 96 assertEquals(element.historyData_[5].starred, false); | 96 assertEquals(element.historyData_[5].starred, false); |
| 97 }); | 97 }); |
| 98 }); | 98 }); |
| 99 | 99 |
| 100 teardown(function() { | 100 teardown(function() { |
| 101 element.historyData_ = []; | 101 element.historyData_ = []; |
| 102 element.searchedTerm = ''; | 102 element.searchedTerm = ''; |
| 103 }); | 103 }); |
| 104 }); | 104 }); |
| 105 } | 105 } |
| 106 return { | 106 return { |
| 107 registerTests: registerTests | 107 registerTests: registerTests |
| 108 }; | 108 }; |
| 109 }); | 109 }); |
| OLD | NEW |