Chromium Code Reviews| Index: chrome/test/data/webui/history_browsertest.js |
| =================================================================== |
| --- chrome/test/data/webui/history_browsertest.js (revision 193987) |
| +++ chrome/test/data/webui/history_browsertest.js (working copy) |
| @@ -2,10 +2,19 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +GEN('#include "chrome/test/data/webui/history_ui_browsertest.h"'); |
| + |
| /** @const */ var TOTAL_RESULT_COUNT = 160; |
| /** @const */ var WAIT_TIMEOUT = 200; |
| /** |
| + * Test fixture for history WebUI testing. |
| + * @constructor |
| + * @extends {testing.Test} |
| + */ |
| +function HistoryUIBrowserTest() {} |
| + |
| +/** |
| * Create a fake history result with the given timestamp. |
| * @param {Number} timestamp Timestamp of the entry, in ms since the epoch. |
| * @param {String} url The URL to set on this entry. |
| @@ -127,6 +136,9 @@ |
| */ |
| browsePreload: 'chrome://history-frame', |
| + /** @override */ |
| + typedefCppFixture: 'HistoryUIBrowserTest', |
|
Patrick Dubroy
2013/04/18 14:15:19
Sweeeet! Thanks for figuring out how to do this. T
|
| + |
| isAsync: true, |
| /** |
| @@ -244,8 +256,7 @@ |
| preLoad: function() { |
| BaseHistoryWebUITest.prototype.preLoad.call(this); |
| - this.registerMockHandler_( |
| - 'removeVisits', this.removeVisitsStub_.bind(this)); |
| + this.registerRemoveVisitsStub_(); |
| // Prepare a list of fake history results. The entries will begin at |
| // 1:00 AM on Sept 2, 2008, and will be spaced two minutes apart. |
| @@ -260,6 +271,15 @@ |
| }, |
| /** |
| + * Register a mock handler for the 'removeVisits' message. This is pulled out |
| + * into a separate method so subclasses can override it. |
| + */ |
| + registerRemoveVisitsStub_: function() { |
| + this.registerMockHandler_( |
| + 'removeVisits', this.removeVisitsStub_.bind(this)); |
| + }, |
| + |
| + /** |
| * Stub for the 'queryHistory' message to the history backend. |
| * Simulates a history database using the fake history data that is |
| * initialized in preLoad(). |
| @@ -420,7 +440,7 @@ |
| // Confirm all the things!!! |
| window.confirm = function() { return true; }; |
| - // The "remote" button should be initially selected. |
| + // The "remove" button should be initially disabled. |
|
Patrick Dubroy
2013/04/18 14:15:19
Haha, I don't know what happened here. Thanks for
|
| var removeButton = $('remove-selected'); |
| expectTrue(removeButton.disabled); |
| @@ -710,3 +730,50 @@ |
| testDone(); |
| }); |
| }); |
| + |
| +/** |
| + * Fixture for History WebUI testing when deletions are prohibited. |
| + * @extends {BaseHistoryWebUITest} |
| + * @constructor |
| + */ |
| +function HistoryWebUIDeleteProhibitedTest() {} |
| + |
| +HistoryWebUIDeleteProhibitedTest.prototype = { |
| + __proto__: HistoryWebUITest.prototype, |
| + |
| + /** |
| + * Don't stub out the 'removeVisits' call in this class. |
| + * @override |
| + */ |
| + registerRemoveVisitsStub_: function() {}, |
| + |
| + /** @override */ |
| + testGenPreamble: function() { |
| + GEN(' SetDeleteAllowed(false);'); |
| + }, |
| +}; |
| + |
| +// Test UI when removing entries is prohibited. |
| +TEST_F('HistoryWebUIDeleteProhibitedTest', 'deleteProhibited', function() { |
| + // No checkboxes should be created. |
| + var checkboxes = document.querySelectorAll( |
| + '#results-display input[type=checkbox]'); |
| + expectEquals(0, checkboxes.length); |
| + |
| + // The "remove" button should be disabled. |
| + var removeButton = $('remove-selected'); |
| + expectTrue(removeButton.disabled); |
| + |
| + // The "Remove from history" drop-down item should be disabled. |
| + var removeVisit = $('remove-visit'); |
| + expectTrue(removeVisit.disabled); |
| + |
| + // Attempting to remove items anyway should fail. |
| + waitForCallback('deleteFailed', testDone); |
| + var model = new HistoryModel(); |
|
Patrick Dubroy
2013/04/18 14:15:19
Why are you creating a new HistoryModel here? Why
|
| + model.removeVisitsFromHistory(this.fakeHistory_.slice(0, 2), function () { |
| + // The callback is only called on success. |
| + throw new Error('Delete succeeded even though it was prohibited.'); |
| + testDone(); |
|
Patrick Dubroy
2013/04/18 14:15:19
Hmmm, won't the test hang on failure then?
Pam (message me for reviews)
2013/04/18 14:41:44
In principle (I thought), if it "succeeds" (which
Patrick Dubroy
2013/04/18 14:55:53
All of these tests are required to call testDone()
|
| + }); |
| +}); |