OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 GEN('#include "chrome/test/data/webui/history_ui_browsertest.h"'); |
| 6 |
5 /** @const */ var TOTAL_RESULT_COUNT = 160; | 7 /** @const */ var TOTAL_RESULT_COUNT = 160; |
6 /** @const */ var WAIT_TIMEOUT = 200; | 8 /** @const */ var WAIT_TIMEOUT = 200; |
7 | 9 |
8 /** | 10 /** |
| 11 * Test fixture for history WebUI testing. |
| 12 * @constructor |
| 13 * @extends {testing.Test} |
| 14 */ |
| 15 function HistoryUIBrowserTest() {} |
| 16 |
| 17 /** |
9 * Create a fake history result with the given timestamp. | 18 * Create a fake history result with the given timestamp. |
10 * @param {Number} timestamp Timestamp of the entry, in ms since the epoch. | 19 * @param {Number} timestamp Timestamp of the entry, in ms since the epoch. |
11 * @param {String} url The URL to set on this entry. | 20 * @param {String} url The URL to set on this entry. |
12 * @return {Object} An object representing a history entry. | 21 * @return {Object} An object representing a history entry. |
13 */ | 22 */ |
14 function createHistoryEntry(timestamp, url) { | 23 function createHistoryEntry(timestamp, url) { |
15 var d = new Date(timestamp); | 24 var d = new Date(timestamp); |
16 return { | 25 return { |
17 dateTimeOfDay: d.getHours() + ':' + d.getMinutes(), | 26 dateTimeOfDay: d.getHours() + ':' + d.getMinutes(), |
18 dateRelativeDay: d.toDateString(), | 27 dateRelativeDay: d.toDateString(), |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 function BaseHistoryWebUITest() {} | 129 function BaseHistoryWebUITest() {} |
121 | 130 |
122 BaseHistoryWebUITest.prototype = { | 131 BaseHistoryWebUITest.prototype = { |
123 __proto__: testing.Test.prototype, | 132 __proto__: testing.Test.prototype, |
124 | 133 |
125 /** | 134 /** |
126 * Browse to the history page & call our preLoad(). | 135 * Browse to the history page & call our preLoad(). |
127 */ | 136 */ |
128 browsePreload: 'chrome://history-frame', | 137 browsePreload: 'chrome://history-frame', |
129 | 138 |
| 139 /** @override */ |
| 140 typedefCppFixture: 'HistoryUIBrowserTest', |
| 141 |
130 isAsync: true, | 142 isAsync: true, |
131 | 143 |
132 /** | 144 /** |
133 * Register handlers to stub out calls to the history backend. | 145 * Register handlers to stub out calls to the history backend. |
134 * @override | 146 * @override |
135 */ | 147 */ |
136 preLoad: function() { | 148 preLoad: function() { |
137 this.registerMockHandler_( | 149 this.registerMockHandler_( |
138 'queryHistory', this.queryHistoryStub_.bind(this)); | 150 'queryHistory', this.queryHistoryStub_.bind(this)); |
139 }, | 151 }, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 * @constructor | 249 * @constructor |
238 */ | 250 */ |
239 function HistoryWebUITest() {} | 251 function HistoryWebUITest() {} |
240 | 252 |
241 HistoryWebUITest.prototype = { | 253 HistoryWebUITest.prototype = { |
242 __proto__: BaseHistoryWebUITest.prototype, | 254 __proto__: BaseHistoryWebUITest.prototype, |
243 | 255 |
244 preLoad: function() { | 256 preLoad: function() { |
245 BaseHistoryWebUITest.prototype.preLoad.call(this); | 257 BaseHistoryWebUITest.prototype.preLoad.call(this); |
246 | 258 |
247 this.registerMockHandler_( | 259 this.registerRemoveVisitsStub_(); |
248 'removeVisits', this.removeVisitsStub_.bind(this)); | |
249 | 260 |
250 // Prepare a list of fake history results. The entries will begin at | 261 // Prepare a list of fake history results. The entries will begin at |
251 // 1:00 AM on Sept 2, 2008, and will be spaced two minutes apart. | 262 // 1:00 AM on Sept 2, 2008, and will be spaced two minutes apart. |
252 var timestamp = new Date(2008, 9, 2, 1, 0).getTime(); | 263 var timestamp = new Date(2008, 9, 2, 1, 0).getTime(); |
253 this.fakeHistory_ = []; | 264 this.fakeHistory_ = []; |
254 | 265 |
255 for (var i = 0; i < TOTAL_RESULT_COUNT; i++) { | 266 for (var i = 0; i < TOTAL_RESULT_COUNT; i++) { |
256 this.fakeHistory_.push( | 267 this.fakeHistory_.push( |
257 createHistoryEntry(timestamp, 'http://google.com/' + timestamp)); | 268 createHistoryEntry(timestamp, 'http://google.com/' + timestamp)); |
258 timestamp -= 2 * 60 * 1000; // Next visit is two minutes earlier. | 269 timestamp -= 2 * 60 * 1000; // Next visit is two minutes earlier. |
259 } | 270 } |
260 }, | 271 }, |
261 | 272 |
262 /** | 273 /** |
| 274 * Register a mock handler for the 'removeVisits' message. This is pulled out |
| 275 * into a separate method so subclasses can override it. |
| 276 */ |
| 277 registerRemoveVisitsStub_: function() { |
| 278 this.registerMockHandler_( |
| 279 'removeVisits', this.removeVisitsStub_.bind(this)); |
| 280 }, |
| 281 |
| 282 /** |
263 * Stub for the 'queryHistory' message to the history backend. | 283 * Stub for the 'queryHistory' message to the history backend. |
264 * Simulates a history database using the fake history data that is | 284 * Simulates a history database using the fake history data that is |
265 * initialized in preLoad(). | 285 * initialized in preLoad(). |
266 * @param {Array} arguments The original arguments to queryHistory. | 286 * @param {Array} arguments The original arguments to queryHistory. |
267 */ | 287 */ |
268 queryHistoryStub_: function(args) { | 288 queryHistoryStub_: function(args) { |
269 var searchText = args[0]; | 289 var searchText = args[0]; |
270 var offset = args[1]; | 290 var offset = args[1]; |
271 var range = args[2]; | 291 var range = args[2]; |
272 var endTime = args[3] || Number.MAX_VALUE; | 292 var endTime = args[3] || Number.MAX_VALUE; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 /** | 433 /** |
414 * Test deletion of history entries. | 434 * Test deletion of history entries. |
415 */ | 435 */ |
416 TEST_F('HistoryWebUITest', 'deletion', function() { | 436 TEST_F('HistoryWebUITest', 'deletion', function() { |
417 var checkboxes = document.querySelectorAll( | 437 var checkboxes = document.querySelectorAll( |
418 '#results-display input[type=checkbox]'); | 438 '#results-display input[type=checkbox]'); |
419 | 439 |
420 // Confirm all the things!!! | 440 // Confirm all the things!!! |
421 window.confirm = function() { return true; }; | 441 window.confirm = function() { return true; }; |
422 | 442 |
423 // The "remote" button should be initially selected. | 443 // The "remove" button should be initially disabled. |
424 var removeButton = $('remove-selected'); | 444 var removeButton = $('remove-selected'); |
425 expectTrue(removeButton.disabled); | 445 expectTrue(removeButton.disabled); |
426 | 446 |
427 checkboxes[0].click(); | 447 checkboxes[0].click(); |
428 expectFalse(removeButton.disabled); | 448 expectFalse(removeButton.disabled); |
429 | 449 |
430 var firstEntry = document.querySelector('.title a').textContent; | 450 var firstEntry = document.querySelector('.title a').textContent; |
431 removeButton.click(); | 451 removeButton.click(); |
432 | 452 |
433 // After deletion, expect the results to be reloaded. | 453 // After deletion, expect the results to be reloaded. |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 | 723 |
704 waitForCallback('historyResult', function() { | 724 waitForCallback('historyResult', function() { |
705 // See if the correct number of days is shown. | 725 // See if the correct number of days is shown. |
706 var resultsDisplay = $('results-display'); | 726 var resultsDisplay = $('results-display'); |
707 assertEquals(0, resultsDisplay.querySelectorAll('.months-results').length); | 727 assertEquals(0, resultsDisplay.querySelectorAll('.months-results').length); |
708 assertEquals(1, resultsDisplay.querySelectorAll('div').length); | 728 assertEquals(1, resultsDisplay.querySelectorAll('div').length); |
709 | 729 |
710 testDone(); | 730 testDone(); |
711 }); | 731 }); |
712 }); | 732 }); |
| 733 |
| 734 /** |
| 735 * Fixture for History WebUI testing when deletions are prohibited. |
| 736 * @extends {BaseHistoryWebUITest} |
| 737 * @constructor |
| 738 */ |
| 739 function HistoryWebUIDeleteProhibitedTest() {} |
| 740 |
| 741 HistoryWebUIDeleteProhibitedTest.prototype = { |
| 742 __proto__: HistoryWebUITest.prototype, |
| 743 |
| 744 /** |
| 745 * Don't stub out the 'removeVisits' call in this class. |
| 746 * @override |
| 747 */ |
| 748 registerRemoveVisitsStub_: function() {}, |
| 749 |
| 750 /** @override */ |
| 751 testGenPreamble: function() { |
| 752 GEN(' SetDeleteAllowed(false);'); |
| 753 }, |
| 754 }; |
| 755 |
| 756 // Test UI when removing entries is prohibited. |
| 757 TEST_F('HistoryWebUIDeleteProhibitedTest', 'deleteProhibited', function() { |
| 758 // No checkboxes should be created. |
| 759 var checkboxes = document.querySelectorAll( |
| 760 '#results-display input[type=checkbox]'); |
| 761 expectEquals(0, checkboxes.length); |
| 762 |
| 763 // The "remove" button should be disabled. |
| 764 var removeButton = $('remove-selected'); |
| 765 expectTrue(removeButton.disabled); |
| 766 |
| 767 // The "Remove from history" drop-down item should be disabled. |
| 768 var removeVisit = $('remove-visit'); |
| 769 expectTrue(removeVisit.disabled); |
| 770 |
| 771 // Attempting to remove items anyway should fail. |
| 772 historyModel.removeVisitsFromHistory(this.fakeHistory_.slice(0, 2), |
| 773 function () { |
| 774 // The callback is only called on success. |
| 775 testDone([false, 'Delete succeeded even though it was prohibited.']); |
| 776 }); |
| 777 waitForCallback('deleteFailed', testDone); |
| 778 }); |
OLD | NEW |