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

Unified Diff: chrome/test/data/webui/md_history/history_card_manager_test.js

Issue 1643693003: MD History: Implement search functionality. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch_to_be_uploaded
Patch Set: Rebase and address reviewer comments. Created 4 years, 10 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
« no previous file with comments | « chrome/browser/ui/webui/md_history_ui.cc ('k') | chrome/test/data/webui/md_history/history_toolbar_test.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webui/md_history/history_card_manager_test.js
diff --git a/chrome/test/data/webui/md_history/history_card_manager_test.js b/chrome/test/data/webui/md_history/history_card_manager_test.js
new file mode 100644
index 0000000000000000000000000000000000000000..5a5491230ba54f3e3c8acd50dffc0fb2f016b00a
--- /dev/null
+++ b/chrome/test/data/webui/md_history/history_card_manager_test.js
@@ -0,0 +1,248 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+cr.define('md_history.history_card_manager_test', function() {
+ // Array of test history data.
+ var TEST_HISTORY_RESULTS = [
+ {
+ "dateRelativeDay": "Today - Wednesday, December 9, 2015",
+ "title": "Google",
+ "url": "https://www.google.com",
+ "allTimestamps": "1",
+ },
+ {
+ "dateRelativeDay": "Yesterday - Tuesday, December 8, 2015",
+ "title": "Wikipedia",
+ "url": "https://en.wikipedia.com",
+ "allTimestamps": "2"
+ },
+ {
+ "dateRelativeDay": "Monday, December 7, 2015",
+ "title": "Example",
+ "url": "https://www.example.com",
+ "allTimestamps": "3"
+ },
+ {
+ "dateRelativeDay": "Monday, December 7, 2015",
+ "title": "Google",
+ "url": "https://www.google.com",
+ "allTimestamps": "4"
+ }
+ ];
+
+ var ADDITIONAL_RESULTS = [
+ {
+ "dateRelativeDay": "Monday, December 7, 2015",
+ "url": "https://en.wikipedia.com"
+ },
+ {
+ "dateRelativeDay": "Monday, December 7, 2015",
+ "url": "https://www.youtube.com"
+ },
+ {
+ "dateRelativeDay": "Sunday, December 6, 2015",
+ "url": "https://www.google.com"
+ },
+ {
+ "dateRelativeDay": "Saturday, December 5, 2015",
+ "url": "https://www.example.com"
+ }
+ ];
+
+ function registerTests() {
+ suite('history-card-manager', function() {
+ var element;
+ var toolbar;
+ var items;
+
+ suiteSetup(function() {
+ element = $('history-card-manager');
+ toolbar = $('toolbar');
+ items = [];
+ });
+
+ test('splitting items by day', function() {
+ element.addNewResults(TEST_HISTORY_RESULTS, '');
+ assertEquals(3, element.historyDataByDay_.length);
+
+ // Ensure that the output is in reversed date order.
+ assertEquals("Today - Wednesday, December 9, 2015",
+ element.historyDataByDay_[0].date);
+ assertEquals("Yesterday - Tuesday, December 8, 2015",
+ element.historyDataByDay_[1].date);
+ assertEquals("Monday, December 7, 2015",
+ element.historyDataByDay_[2].date);
+ assertEquals("https://www.example.com",
+ element.historyDataByDay_[2].historyItems[0].url);
+ assertEquals("https://www.google.com",
+ element.historyDataByDay_[2].historyItems[1].url);
+ });
+
+ test('cancelling selection of multiple items', function(done) {
+ element.addNewResults(TEST_HISTORY_RESULTS, '');
+ flush(function() {
+ var cards = Polymer.dom(element.root)
+ .querySelectorAll('history-card');
+ items = Polymer.dom(cards[2].root)
+ .querySelectorAll('history-item');
+
+ MockInteractions.tap(items[0].$.checkbox);
+ MockInteractions.tap(items[1].$.checkbox);
+
+ // Make sure that the array of data that determines whether or not an
+ // item is selected is what we expect after selecting the two items.
+ assertFalse(element.historyDataByDay_[0].historyItems[0].selected);
+ assertFalse(element.historyDataByDay_[1].historyItems[0].selected);
+ assertTrue(element.historyDataByDay_[2].historyItems[0].selected);
+ assertTrue(element.historyDataByDay_[2].historyItems[1].selected);
+
+ toolbar.onClearSelectionTap_();
+
+ // Make sure that clearing the selection updates both the array and
+ // the actual history-items affected.
+ assertFalse(element.historyDataByDay_[0].historyItems[0].selected);
+ assertFalse(element.historyDataByDay_[1].historyItems[0].selected);
+ assertFalse(element.historyDataByDay_[2].historyItems[0].selected);
+ assertFalse(element.historyDataByDay_[2].historyItems[1].selected);
+
+ assertFalse(items[0].$.checkbox.checked);
+ assertFalse(items[1].$.checkbox.checked);
+
+ done();
+ });
+ });
+
+ test('updating history results', function() {
+ element.addNewResults(TEST_HISTORY_RESULTS, '');
+ element.addNewResults(ADDITIONAL_RESULTS, '');
+
+ assertEquals(5, element.historyDataByDay_.length);
+
+ // Ensure that the output is still in reverse order.
+ assertEquals("Monday, December 7, 2015",
+ element.historyDataByDay_[2].date);
+ assertEquals("Sunday, December 6, 2015",
+ element.historyDataByDay_[3].date);
+ assertEquals("Saturday, December 5, 2015",
+ element.historyDataByDay_[4].date);
+
+ // Ensure that the correct items have been appended to the list.
+ assertEquals("https://en.wikipedia.com",
+ element.historyDataByDay_[2].historyItems[2].url);
+ assertEquals("https://www.youtube.com",
+ element.historyDataByDay_[2].historyItems[3].url);
+ assertEquals("https://www.google.com",
+ element.historyDataByDay_[3].historyItems[0].url);
+ assertEquals("https://www.example.com",
+ element.historyDataByDay_[4].historyItems[0].url);
+ });
+
+ test('removeVisits for multiple items', function(done) {
+ element.addNewResults(TEST_HISTORY_RESULTS, '');
+ // Ensure that the correct identifying data is being used for removal.
+ registerMessageCallback('removeVisits', this, function (toBeRemoved) {
+ assertEquals(toBeRemoved[0].url,
+ element.historyDataByDay_[2].historyItems[0].url);
+ assertEquals(toBeRemoved[1].url,
+ element.historyDataByDay_[2].historyItems[1].url);
+ assertEquals(toBeRemoved[0].timestamps,
+ element.historyDataByDay_[2].historyItems[0]
+ .allTimestamps);
+ assertEquals(toBeRemoved[1].timestamps,
+ element.historyDataByDay_[2].historyItems[1]
+ .allTimestamps);
+ done();
+ });
+
+ flush(function() {
+ var cards = Polymer.dom(element.root)
+ .querySelectorAll('history-card');
+ items = Polymer.dom(cards[2].root)
+ .querySelectorAll('history-item');
+
+ MockInteractions.tap(items[0].$['checkbox']);
+ MockInteractions.tap(items[1].$['checkbox']);
+
+ toolbar.onDeleteTap_();
+ });
+ });
+
+ test('deleting multiple items from view', function(done) {
+ element.addNewResults(TEST_HISTORY_RESULTS, '');
+ flush(function() {
+ var cards = Polymer.dom(element.root)
+ .querySelectorAll('history-card');
+ items = Polymer.dom(cards[2].root)
+ .querySelectorAll('history-item');
+
+ MockInteractions.tap(items[0].$['checkbox']);
+ MockInteractions.tap(items[1].$['checkbox']);
+
+ element.removeDeletedHistory(2);
+
+ flush(function() {
+ var cards = Polymer.dom(element.root)
+ .querySelectorAll('history-card');
+ items = Polymer.dom(cards[2].root)
+ .querySelectorAll('history-item');
+
+ assertEquals(element.historyDataByDay_.length, 2);
+ assertEquals(element.historyDataByDay_[0].date,
+ "Today - Wednesday, December 9, 2015");
+ assertEquals(element.historyDataByDay_[1].date,
+ "Yesterday - Tuesday, December 8, 2015");
+ assertEquals(items.length, 0);
+ done();
+ });
+ });
+ });
+
+ test('search results display with correct item title', function(done) {
+ element.addNewResults(TEST_HISTORY_RESULTS, 'Google');
+
+ flush(function() {
+ var heading =
+ element.$$('history-card').$$('#date-accessed').textContent;
+ var title = element.$$('history-card').$$('history-item').$.title;
+
+ // Check that the card title displays the search term somewhere.
+ var index = heading.indexOf('Google');
+ assertTrue(index != -1);
+
+ // Check that the search term is bolded correctly in the history-item.
+ assertEquals(title.innerHTML, '<b>Google</b>');
+ done();
+ });
+ });
+
+ test('correct display message when no history available', function(done) {
+ element.addNewResults([], '');
+
+ flush(function() {
+ assertFalse(element.$['no-results'].hidden);
+ assertTrue(element.$['infinite-list'].hidden);
+
+ element.addNewResults(TEST_HISTORY_RESULTS, '');
+
+ flush(function() {
+ assertTrue(element.$['no-results'].hidden);
+ assertFalse(element.$['infinite-list'].hidden);
+ done();
+ });
+ });
+ });
+
+ teardown(function() {
+ for (var i = 0; i < items.length; i++) {
+ items[i].selected = false;
+ }
+ element.historyDataByDay_ = [];
+ toolbar.count = 0;
+ });
+ });
+ }
+ return {
+ registerTests: registerTests
+ };
+});
« no previous file with comments | « chrome/browser/ui/webui/md_history_ui.cc ('k') | chrome/test/data/webui/md_history/history_toolbar_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698