| 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; |
| 11 | 11 |
| 12 suiteSetup(function() { | 12 suiteSetup(function() { |
| 13 element = $('history-list'); | 13 element = $('history-list'); |
| 14 TEST_HISTORY_RESULTS = [ | 14 TEST_HISTORY_RESULTS = [ |
| 15 createHistoryEntry('2016-03-16 10:00', 'http://www.google.com'), | 15 createHistoryEntry('2016-03-16 10:00', 'http://www.google.com'), |
| 16 createHistoryEntry('2016-03-16 9:00', 'http://www.example.com'), | 16 createHistoryEntry('2016-03-16 9:00', 'http://www.example.com'), |
| 17 createHistoryEntry('2016-03-16 7:01', 'http://www.badssl.com'), | 17 createHistoryEntry('2016-03-16 7:01', 'http://www.badssl.com'), |
| 18 createHistoryEntry('2016-03-16 7:00', 'http://www.website.com'), | 18 createHistoryEntry('2016-03-16 7:00', 'http://www.website.com'), |
| 19 createHistoryEntry('2016-03-16 4:00', 'http://www.website.com'), | 19 createHistoryEntry('2016-03-16 4:00', 'http://www.website.com'), |
| 20 createHistoryEntry('2016-03-15 11:00', 'http://www.example.com'), | 20 createHistoryEntry('2016-03-15 11:00', 'http://www.example.com'), |
| 21 ]; | 21 ]; |
| 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', "http://calendar.google.com"), | 25 createSearchEntry('2016-03-14', "http://calendar.google.com"), |
| 26 createSearchEntry('2016-03-14', "http://mail.google.com") | 26 createSearchEntry('2016-03-14', "http://mail.google.com") |
| 27 ]; | 27 ]; |
| 28 }); | 28 }); |
| 29 | 29 |
| 30 setup(function() { | 30 test('basic separator insertion', function(done) { |
| 31 element.addNewResults(TEST_HISTORY_RESULTS, ''); | 31 element.addNewResults(TEST_HISTORY_RESULTS, ''); |
| 32 }); | |
| 33 | |
| 34 test('basic separator insertion', function(done) { | |
| 35 flush(function() { | 32 flush(function() { |
| 36 // Check that the correct number of time gaps are inserted. | 33 // Check that the correct number of time gaps are inserted. |
| 37 var items = | 34 var items = |
| 38 Polymer.dom(element.root).querySelectorAll('history-item'); | 35 Polymer.dom(element.root).querySelectorAll('history-item'); |
| 39 | 36 |
| 40 assertTrue(items[0].item.needsTimeGap); | 37 assertTrue(items[0].hasTimeGap); |
| 41 assertTrue(items[1].item.needsTimeGap); | 38 assertTrue(items[1].hasTimeGap); |
| 42 assertFalse(items[2].item.needsTimeGap); | 39 assertFalse(items[2].hasTimeGap); |
| 43 assertTrue(items[3].item.needsTimeGap); | 40 assertTrue(items[3].hasTimeGap); |
| 44 assertFalse(items[4].item.needsTimeGap); | 41 assertFalse(items[4].hasTimeGap); |
| 45 assertFalse(items[5].item.needsTimeGap); | 42 assertFalse(items[5].hasTimeGap); |
| 46 | 43 |
| 47 done(); | 44 done(); |
| 48 }); | 45 }); |
| 49 }); | 46 }); |
| 50 | 47 |
| 51 test('separator insertion for search', function(done) { | 48 test('separator insertion for search', function(done) { |
| 52 element.addNewResults(SEARCH_HISTORY_RESULTS, 'search'); | 49 element.addNewResults(SEARCH_HISTORY_RESULTS, 'search'); |
| 53 flush(function() { | 50 flush(function() { |
| 54 var items = | 51 var items = |
| 55 Polymer.dom(element.root).querySelectorAll('history-item'); | 52 Polymer.dom(element.root).querySelectorAll('history-item'); |
| 56 | 53 |
| 57 assertTrue(items[0].item.needsTimeGap); | 54 assertTrue(items[0].hasTimeGap); |
| 58 assertFalse(items[1].item.needsTimeGap); | 55 assertFalse(items[1].hasTimeGap); |
| 59 assertFalse(items[2].item.needsTimeGap); | 56 assertFalse(items[2].hasTimeGap); |
| 60 | 57 |
| 61 done(); | 58 done(); |
| 62 }); | 59 }); |
| 63 }); | 60 }); |
| 64 | 61 |
| 65 test('separator insertion after deletion', function(done) { | 62 test('separator insertion after deletion', function(done) { |
| 63 element.addNewResults(TEST_HISTORY_RESULTS, ''); |
| 66 flush(function() { | 64 flush(function() { |
| 67 var items = | 65 var items = |
| 68 Polymer.dom(element.root).querySelectorAll('history-item'); | 66 Polymer.dom(element.root).querySelectorAll('history-item'); |
| 69 | 67 |
| 70 element.set('historyData.3.selected', true); | 68 element.set('historyData.3.selected', true); |
| 71 items[3].onCheckboxSelected_(); | 69 items[3].onCheckboxSelected_(); |
| 72 | 70 |
| 73 element.removeDeletedHistory(1); | 71 element.removeDeletedHistory(1); |
| 74 assertEquals(element.historyData.length, 5); | 72 assertEquals(element.historyData.length, 5); |
| 75 | 73 |
| 76 // Checks that a new time gap separator has been inserted. | 74 // Checks that a new time gap separator has been inserted. |
| 77 assertTrue(items[2].item.needsTimeGap); | 75 assertTrue(items[2].hasTimeGap); |
| 78 | 76 |
| 79 element.set('historyData.3.selected', true); | 77 element.set('historyData.3.selected', true); |
| 80 items[3].onCheckboxSelected_(); | 78 items[3].onCheckboxSelected_(); |
| 81 element.removeDeletedHistory(1); | 79 element.removeDeletedHistory(1); |
| 82 | 80 |
| 83 // Checks time gap separator is removed. | 81 // Checks time gap separator is removed. |
| 84 assertFalse(items[2].item.needsTimeGap); | 82 assertFalse(items[2].hasTimeGap); |
| 85 done(); | 83 done(); |
| 86 }); | 84 }); |
| 87 }); | 85 }); |
| 88 | 86 |
| 89 teardown(function() { | 87 teardown(function() { |
| 90 element.historyData = []; | 88 element.historyData = []; |
| 91 }); | 89 }); |
| 92 }); | 90 }); |
| 93 } | 91 } |
| 94 return { | 92 return { |
| 95 registerTests: registerTests | 93 registerTests: registerTests |
| 96 }; | 94 }; |
| 97 }); | 95 }); |
| OLD | NEW |