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

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

Issue 1802013003: MD History: Refactor how data is created in tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update param type Created 4 years, 9 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/test/data/webui/md_history/history_toolbar_test.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webui/md_history/test_util.js
diff --git a/chrome/test/data/webui/md_history/test_util.js b/chrome/test/data/webui/md_history/test_util.js
index acb77f4d03142d9242589f033837ae2174594dd1..d0a3fc433140dc1161ffcea40af71e00f5ffab85 100644
--- a/chrome/test/data/webui/md_history/test_util.js
+++ b/chrome/test/data/webui/md_history/test_util.js
@@ -10,3 +10,48 @@ function flush(callback) {
Polymer.dom.flush();
window.setTimeout(callback, 0);
}
+
+/**
+ * Create a fake history result with the given timestamp.
+ * @param {number|string} timestamp Timestamp of the entry, as a number in ms or
+ * a string which can be parsed by Date.parse().
+ * @param {string} urlStr The URL to set on this entry.
+ * @return {!HistoryEntry} An object representing a history entry.
+ */
+function createHistoryEntry(timestamp, urlStr) {
+ if (typeof timestamp === 'string')
+ timestamp += ' UTC';
+
+ var d = new Date(timestamp);
+ var url = new URL(urlStr);
+ var domain = url.host;
+ return {
+ allTimestamps: [timestamp],
+ // Formatting the relative day is too hard, will instead display
+ // YYYY-MM-DD.
+ dateRelativeDay: d.toISOString().split('T')[0],
+ dateTimeOfDay: d.getUTCHours() + ':' + d.getUTCMinutes(),
+ domain: domain,
+ starred: false,
+ time: d.getTime(),
+ title: urlStr,
+ url: urlStr
+ };
+}
+
+/**
+ * Create a fake history search result with the given timestamp. Replaces fields
+ * from createHistoryEntry to look like a search result.
+ * @param {number|string} timestamp Timestamp of the entry, as a number in ms or
+ * a string which can be parsed by Date.parse().
+ * @param {string} urlStr The URL to set on this entry.
+ * @return {!HistoryEntry} An object representing a history entry.
+ */
+function createSearchEntry(timestamp, urlStr) {
+ var entry = createHistoryEntry(timestamp, urlStr);
+ entry.dateShort = entry.dateRelativeDay;
+ entry.dateTimeOfDay = '';
+ entry.dateRelativeDay = '';
+
+ return entry;
+}
« no previous file with comments | « chrome/test/data/webui/md_history/history_toolbar_test.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698