Commit 632d75c2 authored by rbpotter's avatar rbpotter Committed by Commit Bot

History Web UI: Use TestBrowserProxy

Bug: 1022212
Change-Id: I72a0ed7cf5d998199d720b5af1659e05082c0b22
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1938831
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720680}
parent f97e7c64
...@@ -109,11 +109,8 @@ cr.define('history', function() { ...@@ -109,11 +109,8 @@ cr.define('history', function() {
chrome.send('metricsHandler:recordTime', [histogram, time]); chrome.send('metricsHandler:recordTime', [histogram, time]);
} }
/** /** @param {boolean} successful */
* @param {boolean} successful resolveDelete(successful) {
* @private
*/
resolveDelete_(successful) {
if (this.pendingDeleteItems_ == null || if (this.pendingDeleteItems_ == null ||
this.pendingDeletePromise_ == null) { this.pendingDeletePromise_ == null) {
return; return;
...@@ -171,12 +168,12 @@ cr.define('history', function() { ...@@ -171,12 +168,12 @@ cr.define('history', function() {
* Called by the history backend when deletion was succesful. * Called by the history backend when deletion was succesful.
*/ */
function deleteComplete() { function deleteComplete() {
history.BrowserService.getInstance().resolveDelete_(true); history.BrowserService.getInstance().resolveDelete(true);
} }
/** /**
* Called by the history backend when the deletion failed. * Called by the history backend when the deletion failed.
*/ */
function deleteFailed() { function deleteFailed() {
history.BrowserService.getInstance().resolveDelete_(false); history.BrowserService.getInstance().resolveDelete(false);
} }
...@@ -102,6 +102,9 @@ HistoryListTest.prototype = { ...@@ -102,6 +102,9 @@ HistoryListTest.prototype = {
__proto__: HistoryBrowserTest.prototype, __proto__: HistoryBrowserTest.prototype,
extraLibraries: HistoryBrowserTest.prototype.extraLibraries.concat([ extraLibraries: HistoryBrowserTest.prototype.extraLibraries.concat([
'//ui/webui/resources/js/promise_resolver.js',
'../test_browser_proxy.js',
'test_browser_service.js',
'history_list_test.js', 'history_list_test.js',
]), ]),
}; };
...@@ -124,6 +127,8 @@ HistoryMetricsTest.prototype = { ...@@ -124,6 +127,8 @@ HistoryMetricsTest.prototype = {
__proto__: HistoryBrowserTest.prototype, __proto__: HistoryBrowserTest.prototype,
extraLibraries: HistoryBrowserTest.prototype.extraLibraries.concat([ extraLibraries: HistoryBrowserTest.prototype.extraLibraries.concat([
'../test_browser_proxy.js',
'test_browser_service.js',
'history_metrics_test.js', 'history_metrics_test.js',
]), ]),
}; };
...@@ -152,6 +157,8 @@ HistoryRoutingTest.prototype = { ...@@ -152,6 +157,8 @@ HistoryRoutingTest.prototype = {
__proto__: HistoryBrowserTest.prototype, __proto__: HistoryBrowserTest.prototype,
extraLibraries: HistoryBrowserTest.prototype.extraLibraries.concat([ extraLibraries: HistoryBrowserTest.prototype.extraLibraries.concat([
'../test_browser_proxy.js',
'test_browser_service.js',
'history_routing_test.js', 'history_routing_test.js',
]), ]),
}; };
...@@ -200,6 +207,8 @@ HistorySyncedTabsTest.prototype = { ...@@ -200,6 +207,8 @@ HistorySyncedTabsTest.prototype = {
__proto__: HistoryBrowserTest.prototype, __proto__: HistoryBrowserTest.prototype,
extraLibraries: HistoryBrowserTest.prototype.extraLibraries.concat([ extraLibraries: HistoryBrowserTest.prototype.extraLibraries.concat([
'../test_browser_proxy.js',
'test_browser_service.js',
'history_synced_tabs_test.js', 'history_synced_tabs_test.js',
]), ]),
}; };
...@@ -220,17 +229,19 @@ HistorySupervisedUserTest.prototype = { ...@@ -220,17 +229,19 @@ HistorySupervisedUserTest.prototype = {
}, },
extraLibraries: HistoryBrowserTest.prototype.extraLibraries.concat([ extraLibraries: HistoryBrowserTest.prototype.extraLibraries.concat([
'../test_browser_proxy.js',
'test_browser_service.js',
'history_supervised_user_test.js', 'history_supervised_user_test.js',
]), ]),
}; };
GEN('#if defined(OS_MACOSX)'); GEN('#if defined(OS_MACOSX)');
GEN('#define MAYBE_AllTest DISABLED_AllTest'); GEN('#define MAYBE_AllSupervised DISABLED_All');
GEN('#else'); GEN('#else');
GEN('#define MAYBE_AllTest AllTest'); GEN('#define MAYBE_AllSupervised All');
GEN('#endif'); GEN('#endif');
TEST_F('HistorySupervisedUserTest', 'MAYBE_AllTest', function() { TEST_F('HistorySupervisedUserTest', 'MAYBE_AllSupervised', function() {
mocha.run(); mocha.run();
}); });
...@@ -240,6 +251,8 @@ HistoryToolbarTest.prototype = { ...@@ -240,6 +251,8 @@ HistoryToolbarTest.prototype = {
__proto__: HistoryBrowserTest.prototype, __proto__: HistoryBrowserTest.prototype,
extraLibraries: HistoryBrowserTest.prototype.extraLibraries.concat([ extraLibraries: HistoryBrowserTest.prototype.extraLibraries.concat([
'../test_browser_proxy.js',
'test_browser_service.js',
'history_toolbar_test.js', 'history_toolbar_test.js',
]), ]),
}; };
......
...@@ -6,11 +6,9 @@ suite('<history-list>', function() { ...@@ -6,11 +6,9 @@ suite('<history-list>', function() {
let app; let app;
let element; let element;
let toolbar; let toolbar;
let TEST_HISTORY_RESULTS; let testService;
let ADDITIONAL_RESULTS;
suiteSetup(function() { const TEST_HISTORY_RESULTS = [
TEST_HISTORY_RESULTS = [
createHistoryEntry('2016-03-15', 'https://www.google.com'), createHistoryEntry('2016-03-15', 'https://www.google.com'),
createHistoryEntry('2016-03-14 10:00', 'https://www.example.com'), createHistoryEntry('2016-03-14 10:00', 'https://www.example.com'),
createHistoryEntry('2016-03-14 9:00', 'https://www.google.com'), createHistoryEntry('2016-03-14 9:00', 'https://www.google.com'),
...@@ -18,16 +16,22 @@ suite('<history-list>', function() { ...@@ -18,16 +16,22 @@ suite('<history-list>', function() {
]; ];
TEST_HISTORY_RESULTS[2].starred = true; TEST_HISTORY_RESULTS[2].starred = true;
ADDITIONAL_RESULTS = [ const ADDITIONAL_RESULTS = [
createHistoryEntry('2016-03-13 10:00', 'https://en.wikipedia.org'), createHistoryEntry('2016-03-13 10:00', 'https://en.wikipedia.org'),
createHistoryEntry('2016-03-13 9:50', 'https://www.youtube.com'), createHistoryEntry('2016-03-13 9:50', 'https://www.youtube.com'),
createHistoryEntry('2016-03-11', 'https://www.google.com'), createHistoryEntry('2016-03-11', 'https://www.google.com'),
createHistoryEntry('2016-03-10', 'https://www.example.com') createHistoryEntry('2016-03-10', 'https://www.example.com')
]; ];
});
setup(function() { setup(function() {
app = replaceApp(); window.history.replaceState({}, '', '/');
PolymerTest.clearBody();
testService = new TestBrowserService();
history.BrowserService.instance_ = testService;
app = document.createElement('history-app');
document.body.appendChild(app);
element = app.$.history; element = app.$.history;
toolbar = app.$.toolbar; toolbar = app.$.toolbar;
app.queryState_.incremental = true; app.queryState_.incremental = true;
...@@ -53,12 +57,12 @@ suite('<history-list>', function() { ...@@ -53,12 +57,12 @@ suite('<history-list>', function() {
toolbar.deleteSelectedItems(); toolbar.deleteSelectedItems();
return test_util.flushTasks(); return test_util.flushTasks();
}) })
.then(() => new Promise(resolve => { .then(function() {
registerMessageCallback('removeVisits', this, resolve);
const dialog = element.$.dialog.get(); const dialog = element.$.dialog.get();
assertTrue(dialog.open); assertTrue(dialog.open);
element.$$('.action-button').click(); element.$$('.action-button').click();
})) return testService.whenCalled('deleteItems');
})
.then(test_util.flushTasks) .then(test_util.flushTasks)
.then(function() { .then(function() {
deleteComplete(); deleteComplete();
...@@ -304,17 +308,15 @@ suite('<history-list>', function() { ...@@ -304,17 +308,15 @@ suite('<history-list>', function() {
let items; let items;
return test_util.flushTasks() return test_util.flushTasks()
.then(function() { .then(function() {
return new Promise(resolve => {
registerMessageCallback('queryHistory', this, resolve);
Polymer.dom.flush(); Polymer.dom.flush();
items = polymerSelectAll(element, 'history-item'); items = polymerSelectAll(element, 'history-item');
items[0].$['menu-button'].click(); items[0].$['menu-button'].click();
element.$.sharedMenu.get(); element.$.sharedMenu.get();
element.$$('#menuMoreButton').click(); element.$$('#menuMoreButton').click();
}); return testService.whenCalled('queryHistory');
}) })
.then(function(info) { .then(function(query) {
assertEquals('www.google.com', info[0]); assertEquals('www.google.com', query);
app.historyResult( app.historyResult(
createHistoryInfo('www.google.com'), TEST_HISTORY_RESULTS); createHistoryInfo('www.google.com'), TEST_HISTORY_RESULTS);
...@@ -395,20 +397,20 @@ suite('<history-list>', function() { ...@@ -395,20 +397,20 @@ suite('<history-list>', function() {
toolbar.deleteSelectedItems(); toolbar.deleteSelectedItems();
return test_util.flushTasks(); return test_util.flushTasks();
}) })
.then(() => new Promise(resolve => { .then(function() {
registerMessageCallback('removeVisits', this, resolve); testService.resetResolver('deleteItems');
// Confirmation dialog should appear. // Confirmation dialog should appear.
assertTrue(dialog.open); assertTrue(dialog.open);
element.$$('.action-button').click(); element.$$('.action-button').click();
})) return testService.whenCalled('deleteItems');
})
.then(test_util.flushTasks) .then(test_util.flushTasks)
.then(function() { .then(function() {
deleteComplete(); deleteComplete();
return test_util.flushTasks(); return test_util.flushTasks();
}) })
.then(function() { .then(function() {
assertEquals(element.historyData_.length, 5); assertEquals(5, element.historyData_.length);
assertEquals(element.historyData_[0].dateRelativeDay, '2016-03-15'); assertEquals(element.historyData_[0].dateRelativeDay, '2016-03-15');
assertEquals(element.historyData_[2].dateRelativeDay, '2016-03-13'); assertEquals(element.historyData_[2].dateRelativeDay, '2016-03-13');
assertEquals(element.historyData_[4].dateRelativeDay, '2016-03-11'); assertEquals(element.historyData_[4].dateRelativeDay, '2016-03-11');
...@@ -433,15 +435,12 @@ suite('<history-list>', function() { ...@@ -433,15 +435,12 @@ suite('<history-list>', function() {
.then(function() { .then(function() {
Polymer.dom.flush(); Polymer.dom.flush();
items = polymerSelectAll(element, 'history-item'); items = polymerSelectAll(element, 'history-item');
return new Promise(resolve => {
registerMessageCallback('removeVisits', this, resolve);
items[1].$.checkbox.click(); items[1].$.checkbox.click();
items[3].$.checkbox.click(); items[3].$.checkbox.click();
items[1].$['menu-button'].click(); items[1].$['menu-button'].click();
element.$.sharedMenu.get(); element.$.sharedMenu.get();
element.$$('#menuRemoveButton').click(); element.$$('#menuRemoveButton').click();
}); return testService.whenCalled('deleteItems');
}) })
.then(test_util.flushTasks) .then(test_util.flushTasks)
.then(function() { .then(function() {
...@@ -501,11 +500,8 @@ suite('<history-list>', function() { ...@@ -501,11 +500,8 @@ suite('<history-list>', function() {
}) })
.then(function() { .then(function() {
assertTrue(dialog.open); assertTrue(dialog.open);
return new Promise(resolve => {
registerMessageCallback('removeVisits', this, resolve);
element.$$('.action-button').click(); element.$$('.action-button').click();
}); return testService.whenCalled('deleteItems');
}) })
.then(function(toRemove) { .then(function(toRemove) {
assertEquals('https://www.example.com', toRemove[0].url); assertEquals('https://www.example.com', toRemove[0].url);
...@@ -559,21 +555,15 @@ suite('<history-list>', function() { ...@@ -559,21 +555,15 @@ suite('<history-list>', function() {
.then(function() { .then(function() {
Polymer.dom.flush(); Polymer.dom.flush();
const items = polymerSelectAll(element, 'history-item'); const items = polymerSelectAll(element, 'history-item');
return new Promise(resolve => {
registerMessageCallback('navigateToUrl', this, resolve);
items[0].$.link.click(); items[0].$.link.click();
}); return testService.whenCalled('navigateToUrl');
}) })
.then(function(info) { .then(function(url) {
assertEquals(fileURL, info[0]); assertEquals(fileURL, url);
}); });
}); });
teardown(function() { teardown(function() {
registerMessageCallback('removeVisits', this, undefined);
registerMessageCallback('queryHistory', this, function() {});
registerMessageCallback('navigateToUrl', this, undefined);
app.fire('change-query', {search: ''}); app.fire('change-query', {search: ''});
}); });
}); });
...@@ -12,54 +12,21 @@ const TestMetricsBrowserService = function() { ...@@ -12,54 +12,21 @@ const TestMetricsBrowserService = function() {
}; };
suite('Metrics', function() { suite('Metrics', function() {
let service; let testService;
let app; let app;
let histogramMap; let histogramMap;
let actionMap; let actionMap;
suiteSetup(function() { suiteSetup(function() {
disableLinkClicks(); disableLinkClicks();
TestMetricsBrowserService.prototype = {
__proto__: history.BrowserService.prototype,
/** @override */
recordHistogram: function(histogram, value, max) {
assertTrue(value < max);
if (!(histogram in this.histogramMap)) {
this.histogramMap[histogram] = {};
}
if (!(value in this.histogramMap[histogram])) {
this.histogramMap[histogram][value] = 0;
}
this.histogramMap[histogram][value]++;
},
/** @override */
recordAction: function(action) {
if (!(action in this.actionMap)) {
this.actionMap[action] = 0;
}
this.actionMap[action]++;
},
/** @override */
deleteItems: function() {
return test_util.flushTasks();
}
};
}); });
setup(function() { setup(function() {
history.BrowserService.instance_ = new TestMetricsBrowserService(); history.BrowserService.instance_ = new TestBrowserService();
service = history.BrowserService.getInstance(); testService = history.BrowserService.getInstance();
actionMap = service.actionMap; actionMap = testService.actionMap;
histogramMap = service.histogramMap; histogramMap = testService.histogramMap;
app = replaceApp(); app = replaceApp();
updateSignInState(false); updateSignInState(false);
...@@ -158,6 +125,10 @@ suite('Metrics', function() { ...@@ -158,6 +125,10 @@ suite('Metrics', function() {
}) })
.then(() => { .then(() => {
MockInteractions.tap(app.$.history.$$('#menuRemoveButton')); MockInteractions.tap(app.$.history.$$('#menuRemoveButton'));
return testService.whenCalled('deleteItems');
})
.then(() => {
deleteComplete();
return test_util.flushTasks(); return test_util.flushTasks();
}) })
.then(() => { .then(() => {
......
...@@ -91,30 +91,33 @@ cr.define('history.history_routing_test_with_query_param', function() { ...@@ -91,30 +91,33 @@ cr.define('history.history_routing_test_with_query_param', function() {
let app; let app;
let toolbar; let toolbar;
let expectedQuery; let expectedQuery;
let testService;
suiteSetup(function() { suiteSetup(function() {
testService = new TestBrowserService();
history.BrowserService.instance_ = testService;
app = $('history-app'); app = $('history-app');
toolbar = app.$['toolbar']; toolbar = app.$['toolbar'];
expectedQuery = 'query'; expectedQuery = 'query';
}); });
test('search initiated on load', function(done) { test('search initiated on load', function() {
const verifyFunction = function(info) { const verifyFunction = function(info) {
assertEquals(expectedQuery, info[0]); assertEquals(expectedQuery, info[0]);
test_util.flushTasks().then(function() { return test_util.flushTasks().then(function() {
assertEquals( assertEquals(
expectedQuery, expectedQuery,
toolbar.$['main-toolbar'].getSearchField().getValue()); toolbar.$['main-toolbar'].getSearchField().getValue());
done();
}); });
}; };
if (window.historyQueryInfo) { if (window.historyQueryInfo) {
verifyFunction(window.historyQueryInfo); return verifyFunction(window.historyQueryInfo);
return; } else {
return testService.whenCalled('queryHistory').then(query => {
return verifyFunction([query]);
});
} }
registerMessageCallback('queryHistory', this, verifyFunction);
}); });
}); });
} }
......
...@@ -6,15 +6,18 @@ suite('history-list supervised-user', function() { ...@@ -6,15 +6,18 @@ suite('history-list supervised-user', function() {
let app; let app;
let historyList; let historyList;
let toolbar; let toolbar;
let TEST_HISTORY_RESULTS; let testService;
const TEST_HISTORY_RESULTS =
suiteSetup(function() {
TEST_HISTORY_RESULTS =
[createHistoryEntry('2016-03-15', 'https://www.google.com')]; [createHistoryEntry('2016-03-15', 'https://www.google.com')];
});
setup(function() { setup(function() {
app = replaceApp(); PolymerTest.clearBody();
testService = new TestBrowserService();
history.BrowserService.instance_ = testService;
app = document.createElement('history-app');
document.body.appendChild(app);
historyList = app.$.history; historyList = app.$.history;
toolbar = app.$.toolbar; toolbar = app.$.toolbar;
app.historyResult(createHistoryInfo(), TEST_HISTORY_RESULTS); app.historyResult(createHistoryInfo(), TEST_HISTORY_RESULTS);
...@@ -32,12 +35,9 @@ suite('history-list supervised-user', function() { ...@@ -32,12 +35,9 @@ suite('history-list supervised-user', function() {
test('deletion disabled for supervised user', function() { test('deletion disabled for supervised user', function() {
// Make sure that removeVisits is not being called. // Make sure that removeVisits is not being called.
registerMessageCallback('removeVisits', this, function(toBeRemoved) {
assertNotReached();
});
historyList.historyData_[0].selected = true; historyList.historyData_[0].selected = true;
toolbar.deleteSelectedItems(); toolbar.deleteSelectedItems();
assertEquals(0, testService.getCallCount('deleteItems'));
}); });
test('remove history menu button disabled', function() { test('remove history menu button disabled', function() {
......
...@@ -18,19 +18,25 @@ function assertNoSyncedTabsMessageShown(manager, stringID) { ...@@ -18,19 +18,25 @@ function assertNoSyncedTabsMessageShown(manager, stringID) {
suite('<history-synced-device-manager>', function() { suite('<history-synced-device-manager>', function() {
let element; let element;
let testService;
const setForeignSessions = function(sessions) { const setForeignSessions = function(sessions) {
element.sessionList = sessions; element.sessionList = sessions;
}; };
setup(function() { setup(function() {
PolymerTest.clearBody();
window.history.replaceState({}, '', '/');
testService = new TestBrowserService();
history.BrowserService.instance_ = testService;
element = document.createElement('history-synced-device-manager'); element = document.createElement('history-synced-device-manager');
// |signInState| is generally set after |searchTerm| in Polymer 2. Set in // |signInState| is generally set after |searchTerm| in Polymer 2. Set in
// the same order in tests, in order to catch regressions like // the same order in tests, in order to catch regressions like
// https://crbug.com/915641. // https://crbug.com/915641.
element.searchTerm = ''; element.searchTerm = '';
element.signInState = true; element.signInState = true;
replaceBody(element); document.body.appendChild(element);
}); });
test('single card, single window', function() { test('single card, single window', function() {
...@@ -169,7 +175,7 @@ suite('<history-synced-device-manager>', function() { ...@@ -169,7 +175,7 @@ suite('<history-synced-device-manager>', function() {
}); });
}); });
test('delete a session', function(done) { test('delete a session', function() {
const sessionList = [ const sessionList = [
createSession('Nexus 5', [createWindow(['http://www.example.com'])]), createSession('Nexus 5', [createWindow(['http://www.example.com'])]),
createSession('Pixel C', [createWindow(['http://www.badssl.com'])]), createSession('Pixel C', [createWindow(['http://www.badssl.com'])]),
...@@ -177,7 +183,7 @@ suite('<history-synced-device-manager>', function() { ...@@ -177,7 +183,7 @@ suite('<history-synced-device-manager>', function() {
setForeignSessions(sessionList); setForeignSessions(sessionList);
test_util.flushTasks() return test_util.flushTasks()
.then(function() { .then(function() {
const cards = getCards(element); const cards = getCards(element);
assertEquals(2, cards.length); assertEquals(2, cards.length);
...@@ -186,21 +192,21 @@ suite('<history-synced-device-manager>', function() { ...@@ -186,21 +192,21 @@ suite('<history-synced-device-manager>', function() {
return test_util.flushTasks(); return test_util.flushTasks();
}) })
.then(function() { .then(function() {
registerMessageCallback('deleteForeignSession', this, function(args) { MockInteractions.tap(element.$$('#menuDeleteButton'));
assertEquals('Nexus 5', args[0]); return testService.whenCalled('deleteForeignSession');
})
.then(args => {
assertEquals('Nexus 5', args);
// Simulate deleting the first device. // Simulate deleting the first device.
setForeignSessions([sessionList[1]]); setForeignSessions([sessionList[1]]);
test_util.flushTasks().then(function() { return test_util.flushTasks();
})
.then(function() {
cards = getCards(element); cards = getCards(element);
assertEquals(1, cards.length); assertEquals(1, cards.length);
assertEquals('http://www.badssl.com', cards[0].tabs[0].title); assertEquals('http://www.badssl.com', cards[0].tabs[0].title);
done();
});
});
MockInteractions.tap(element.$$('#menuDeleteButton'));
}); });
}); });
...@@ -227,25 +233,24 @@ suite('<history-synced-device-manager>', function() { ...@@ -227,25 +233,24 @@ suite('<history-synced-device-manager>', function() {
}); });
}); });
test('click synced tab', function(done) { test('click synced tab', function() {
setForeignSessions( setForeignSessions(
[createSession('Chromebook', [createWindow(['https://example.com'])])]); [createSession('Chromebook', [createWindow(['https://example.com'])])]);
return test_util.flushTasks()
registerMessageCallback('openForeignSession', this, function(args) { .then(function() {
assertEquals('Chromebook', args[0], 'sessionTag is correct');
assertEquals('123', args[1], 'windowId is correct');
assertEquals('456', args[2], 'tabId is correct');
assertFalse(args[4], 'altKey is defined');
assertFalse(args[5], 'ctrlKey is defined');
assertFalse(args[6], 'metaKey is defined');
assertFalse(args[7], 'shiftKey is defined');
done();
});
test_util.flushTasks().then(function() {
const cards = getCards(element); const cards = getCards(element);
const anchor = cards[0].root.querySelector('a'); const anchor = cards[0].root.querySelector('a');
MockInteractions.tap(anchor); MockInteractions.tap(anchor);
return testService.whenCalled('openForeignSessionTab');
})
.then(args => {
assertEquals('Chromebook', args.sessionTag, 'sessionTag is correct');
assertEquals('123', args.windowId, 'windowId is correct');
assertEquals(456, args.tabId, 'tabId is correct');
assertFalse(args.e.altKey, 'altKey is defined');
assertFalse(args.e.ctrlKey, 'ctrlKey is defined');
assertFalse(args.e.metaKey, 'metaKey is defined');
assertFalse(args.e.shiftKey, 'shiftKey is defined');
}); });
}); });
...@@ -343,9 +348,4 @@ suite('<history-synced-device-manager>', function() { ...@@ -343,9 +348,4 @@ suite('<history-synced-device-manager>', function() {
assertEquals(0, cards.length); assertEquals(0, cards.length);
}); });
}); });
teardown(function() {
registerMessageCallback('openForeignSession', this, undefined);
registerMessageCallback('deleteForeignSession', this, undefined);
});
}); });
...@@ -6,15 +6,17 @@ suite('history-toolbar', function() { ...@@ -6,15 +6,17 @@ suite('history-toolbar', function() {
let app; let app;
let element; let element;
let toolbar; let toolbar;
let TEST_HISTORY_RESULTS; let testService;
const TEST_HISTORY_RESULTS =
suiteSetup(function() {
TEST_HISTORY_RESULTS =
[createHistoryEntry('2016-03-15', 'https://google.com')]; [createHistoryEntry('2016-03-15', 'https://google.com')];
});
setup(function() { setup(function() {
app = replaceApp(); PolymerTest.clearBody();
testService = new TestBrowserService();
history.BrowserService.instance_ = testService;
app = document.createElement('history-app');
document.body.appendChild(app);
element = app.$.history; element = app.$.history;
toolbar = app.$.toolbar; toolbar = app.$.toolbar;
return test_util.flushTasks(); return test_util.flushTasks();
...@@ -44,29 +46,25 @@ suite('history-toolbar', function() { ...@@ -44,29 +46,25 @@ suite('history-toolbar', function() {
}); });
}); });
test('search term gathered correctly from toolbar', function(done) { test('search term gathered correctly from toolbar', function() {
app.queryState_.queryingDisabled = false; app.queryState_.queryingDisabled = false;
registerMessageCallback('queryHistory', this, function(info) { toolbar.$$('cr-toolbar').fire('search-changed', 'Test');
assertEquals('Test', info[0]); return testService.whenCalled('queryHistory').then(query => {
assertEquals('Test', query);
app.historyResult(createHistoryInfo(), TEST_HISTORY_RESULTS); app.historyResult(createHistoryInfo(), TEST_HISTORY_RESULTS);
done();
}); });
toolbar.$$('cr-toolbar').fire('search-changed', 'Test');
}); });
test('spinner is active on search', function(done) { test('spinner is active on search', function() {
app.queryState_.queryingDisabled = false; app.queryState_.queryingDisabled = false;
registerMessageCallback('queryHistory', this, function(info) { toolbar.$$('cr-toolbar').fire('search-changed', 'Test2');
test_util.flushTasks().then(function() { return testService.whenCalled('queryHistory')
.then(test_util.flushTasks)
.then(() => {
assertTrue(toolbar.spinnerActive); assertTrue(toolbar.spinnerActive);
app.historyResult(createHistoryInfo(), TEST_HISTORY_RESULTS); app.historyResult(createHistoryInfo(), TEST_HISTORY_RESULTS);
assertFalse(toolbar.spinnerActive); assertFalse(toolbar.spinnerActive);
done();
});
}); });
toolbar.$$('cr-toolbar').fire('search-changed', 'Test2');
}); });
test('menu promo hides when drawer is opened', function() { test('menu promo hides when drawer is opened', function() {
...@@ -76,8 +74,4 @@ suite('history-toolbar', function() { ...@@ -76,8 +74,4 @@ suite('history-toolbar', function() {
MockInteractions.tap(toolbar.$['main-toolbar'].$$('#menuButton')); MockInteractions.tap(toolbar.$['main-toolbar'].$$('#menuButton'));
assertFalse(app.showMenuPromo_); assertFalse(app.showMenuPromo_);
}); });
teardown(function() {
registerMessageCallback('queryHistory', this, function() {});
});
}); });
// Copyright 2019 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.
class TestBrowserService extends TestBrowserProxy {
constructor() {
super([
'deleteForeignSession',
'deleteItems',
'navigateToUrl',
'openForeignSessionTab',
'recordHistogram',
'queryHistory',
]);
this.histogramMap = {};
this.actionMap = {};
this.pendingDeletePromise_ = null;
this.deleted_ = null;
}
/** @override */
deleteForeignSession(sessionTag) {
this.methodCalled('deleteForeignSession', sessionTag);
}
/** @override */
deleteItems(items) {
this.deleted_ = items;
this.pendingDeletePromise_ = new PromiseResolver();
this.methodCalled('deleteItems', items.map(item => {
return {
url: item.url,
timestamps: item.allTimestamps,
};
}));
return this.pendingDeletePromise_.promise;
}
/** @override */
historyLoaded() {}
/** @override */
menuPromoShown() {}
/** @override */
navigateToUrl(url, target, e) {
this.methodCalled('navigateToUrl', url);
}
/** @override */
openClearBrowsingData() {}
/** @override */
openForeignSessionAllTabs() {}
/** @override */
openForeignSessionTab(sessionTag, windowId, tabId, e) {
this.methodCalled('openForeignSessionTab', {
sessionTag: sessionTag,
windowId: windowId,
tabId: tabId,
e: e,
});
}
/** @override */
otherDevicesInitialized() {}
/** @override */
queryHistory(searchTerm) {
this.methodCalled('queryHistory', searchTerm);
}
/** @override */
queryHistoryContinuation() {}
/** @override */
recordAction(action) {
if (!(action in this.actionMap)) {
this.actionMap[action] = 0;
}
this.actionMap[action]++;
}
/** @override */
recordHistogram(histogram, value, max) {
assertTrue(value <= max);
if (!(histogram in this.histogramMap)) {
this.histogramMap[histogram] = {};
}
if (!(value in this.histogramMap[histogram])) {
this.histogramMap[histogram][value] = 0;
}
this.histogramMap[histogram][value]++;
this.methodCalled('recordHistogram');
}
/** @override */
recordTime() {}
/** @override */
removeBookmark() {}
/** @override */
resolveDelete(successful) {
if (successful) {
this.pendingDeletePromise_.resolve(this.deleted_);
} else {
this.pendingDeletePromise_.reject(this.deleted_);
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment