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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // Immediately confirm the history deletion. | 440 // Immediately confirm the history deletion. |
421 confirmDeletion = function(okCallback, cancelCallback) { | 441 confirmDeletion = function(okCallback, cancelCallback) { |
422 okCallback(); | 442 okCallback(); |
423 }; | 443 }; |
424 | 444 |
425 // The "remote" button should be initially selected. | 445 // The "remove" button should be initially disabled. |
426 var removeButton = $('remove-selected'); | 446 var removeButton = $('remove-selected'); |
427 expectTrue(removeButton.disabled); | 447 expectTrue(removeButton.disabled); |
428 | 448 |
429 checkboxes[0].click(); | 449 checkboxes[0].click(); |
430 expectFalse(removeButton.disabled); | 450 expectFalse(removeButton.disabled); |
431 | 451 |
432 var firstEntry = document.querySelector('.title a').textContent; | 452 var firstEntry = document.querySelector('.title a').textContent; |
433 removeButton.click(); | 453 removeButton.click(); |
434 | 454 |
435 // After deletion, expect the results to be reloaded. | 455 // After deletion, expect the results to be reloaded. |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 | 725 |
706 waitForCallback('historyResult', function() { | 726 waitForCallback('historyResult', function() { |
707 // See if the correct number of days is shown. | 727 // See if the correct number of days is shown. |
708 var resultsDisplay = $('results-display'); | 728 var resultsDisplay = $('results-display'); |
709 assertEquals(0, resultsDisplay.querySelectorAll('.months-results').length); | 729 assertEquals(0, resultsDisplay.querySelectorAll('.months-results').length); |
710 assertEquals(1, resultsDisplay.querySelectorAll('div').length); | 730 assertEquals(1, resultsDisplay.querySelectorAll('div').length); |
711 | 731 |
712 testDone(); | 732 testDone(); |
713 }); | 733 }); |
714 }); | 734 }); |
| 735 |
| 736 /** |
| 737 * Fixture for History WebUI testing when deletions are prohibited. |
| 738 * @extends {BaseHistoryWebUITest} |
| 739 * @constructor |
| 740 */ |
| 741 function HistoryWebUIDeleteProhibitedTest() {} |
| 742 |
| 743 HistoryWebUIDeleteProhibitedTest.prototype = { |
| 744 __proto__: HistoryWebUITest.prototype, |
| 745 |
| 746 /** |
| 747 * Don't stub out the 'removeVisits' call in this class. |
| 748 * @override |
| 749 */ |
| 750 registerRemoveVisitsStub_: function() {}, |
| 751 |
| 752 /** @override */ |
| 753 testGenPreamble: function() { |
| 754 GEN(' SetDeleteAllowed(false);'); |
| 755 }, |
| 756 }; |
| 757 |
| 758 // Test UI when removing entries is prohibited. |
| 759 TEST_F('HistoryWebUIDeleteProhibitedTest', 'deleteProhibited', function() { |
| 760 // No checkboxes should be created. |
| 761 var checkboxes = document.querySelectorAll( |
| 762 '#results-display input[type=checkbox]'); |
| 763 expectEquals(0, checkboxes.length); |
| 764 |
| 765 // The "remove" button should be disabled. |
| 766 var removeButton = $('remove-selected'); |
| 767 expectTrue(removeButton.disabled); |
| 768 |
| 769 // The "Remove from history" drop-down item should be disabled. |
| 770 var removeVisit = $('remove-visit'); |
| 771 expectTrue(removeVisit.disabled); |
| 772 |
| 773 // Attempting to remove items anyway should fail. |
| 774 historyModel.removeVisitsFromHistory(this.fakeHistory_.slice(0, 2), |
| 775 function () { |
| 776 // The callback is only called on success. |
| 777 testDone([false, 'Delete succeeded even though it was prohibited.']); |
| 778 }); |
| 779 waitForCallback('deleteFailed', testDone); |
| 780 }); |
OLD | NEW |