diff options
author | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-27 17:44:58 +0000 |
---|---|---|
committer | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-27 17:44:58 +0000 |
commit | 99771aa83a596fa2c6dd8780ee5c83aa1282602f (patch) | |
tree | 0e828d28419353ecd33b21c80c6760858e416f1a /chrome/test | |
parent | c0c884d90bb929d6719d650836d27b6e244b0f92 (diff) | |
download | chromium_src-99771aa83a596fa2c6dd8780ee5c83aa1282602f.zip chromium_src-99771aa83a596fa2c6dd8780ee5c83aa1282602f.tar.gz chromium_src-99771aa83a596fa2c6dd8780ee5c83aa1282602f.tar.bz2 |
Fixes for the net-internals StopCapturing button.
It now dumps a log to memory and loads it. The
results in updating all tabs, hiding tabs and buttons
that don't work when the BrowserBridge is disabled.
Also allows export of logs in stop capturing mode or
when viewing a loaded log (Which are now equivalent
states).
R=eroman@chromium.org
BUG=111195
Review URL: http://codereview.chromium.org/9291001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119462 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
4 files changed, 174 insertions, 52 deletions
diff --git a/chrome/test/data/webui/net_internals/log_util.js b/chrome/test/data/webui/net_internals/log_util.js index f601e8c..da833ab 100644 --- a/chrome/test/data/webui/net_internals/log_util.js +++ b/chrome/test/data/webui/net_internals/log_util.js @@ -2,6 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +/** + * @fileoverview This file contains tests for creating and loading log files. + * It also tests the stop capturing button, since it both creates and then loads + * a log dump. + */ + // Include test fixture. GEN_INCLUDE(['net_internals_test.js']); @@ -9,6 +15,113 @@ GEN_INCLUDE(['net_internals_test.js']); (function() { /** + * A Task that create a log dump and then loads it. + * @param {string} userComments User comments to copy to the ExportsView before + * creating the log dump. + * @extends {NetInternalsTest.Task} + */ +function CreateAndLoadLogTask(userComments) { + this.userComments_ = userComments; + NetInternalsTest.Task.call(this); + // Not strictly necessary, but since we complete from a call to the observer, + // seems reasonable to complete asynchronously. + this.setCompleteAsync(true); +} + +CreateAndLoadLogTask.prototype = { + __proto__: NetInternalsTest.Task.prototype, + + /** + * Start creating the log dump. Use ExportView's function as it supports + * both creating completely new logs and using existing logs to create new + * ones, depending on whether or not we're currently viewing a log. + */ + start: function() { + $(ExportView.USER_COMMENTS_TEXT_AREA_ID).value = this.userComments_; + ExportView.getInstance().createLogDump_(this.onLogDumpCreated.bind(this), + true); + }, + + /** + * Callback passed to |createLogDumpAsync|. Tries to load the dumped log + * text. Checks the status bar and user comments after loading the log. + * @param {string} logDumpText Log dump, as a string. + */ + onLogDumpCreated: function(logDumpText) { + expectEquals('Log loaded.', log_util.loadLogFile(logDumpText, 'log.txt')); + + NetInternalsTest.expectStatusViewNodeVisible(StatusView.FOR_FILE_ID); + + expectEquals(this.userComments_, + $(ExportView.USER_COMMENTS_TEXT_AREA_ID).value); + // Make sure the DIV on the import tab containing the comments is visible + // before checking the displayed text. + expectTrue(NetInternalsTest.nodeIsVisible($(ImportView.LOADED_DIV_ID))); + expectEquals(this.userComments_, + $(ImportView.LOADED_INFO_USER_COMMENTS_ID).innerText); + + this.onTaskDone(); + } +}; + +/** + * A Task that waits we receive, then asynchronously completes. + * @extends {NetInternalsTest.Task} + */ +function WaitForConstantsTask() { + NetInternalsTest.Task.call(this); + this.setCompleteAsync(true); +} + +WaitForConstantsTask.prototype = { + __proto__: NetInternalsTest.Task.prototype, + + /** + * Starts watching for constants. + */ + start: function() { + g_browser.addConstantsObserver(this); + }, + + /** + * Resumes the test once we receive constants. + */ + onReceivedConstants: function() { + if (!this.isDone()) + this.onTaskDone(); + } +}; + +/** + * Checks the visibility of each view after loading a freshly created log dump. + * Also checks that the BrowserBridge is disabled. + */ +function checkViewsAfterLogLoaded() { + expectTrue(g_browser.isDisabled()); + var tabVisibilityState = { + capture: false, + export: true, + import: true, + proxy: true, + events: true, + timeline: true, + dns: true, + sockets: true, + spdy: true, + httpPipeline: false, + httpCache: true, + httpThrottling: false, + serviceProviders: cr.isWindows, + tests: false, + hsts: false, + logs: false, + prerender: true, + chromeos: false + }; + NetInternalsTest.checkTabHandleVisibility(tabVisibilityState, false); +} + +/** * Exports a log dump to a string and loads it. Makes sure no errors occur, * and checks visibility of tabs aftwards. Does not actually save the log to a * file. @@ -17,42 +130,65 @@ GEN_INCLUDE(['net_internals_test.js']); */ TEST_F('NetInternalsTest', 'netInternalsExportImportDump', function() { expectFalse(g_browser.isDisabled()); + NetInternalsTest.expectStatusViewNodeVisible(StatusView.FOR_CAPTURE_ID); - // Callback passed to |createLogDumpAsync|. Tries to load the dumped log - // file, and then checks tab visibility afterwards. - // @param {string} logDumpText Log dump, as a string. - function onLogDumpCreated(logDumpText) { - expectEquals('Log loaded.', logutil.loadLogFile(logDumpText)); + var taskQueue = new NetInternalsTest.TaskQueue(true); + taskQueue.addTask(new CreateAndLoadLogTask('Detailed explanation.')); + taskQueue.addFunctionTask(checkViewsAfterLogLoaded); + taskQueue.run(true); +}); - expectTrue(g_browser.isDisabled()); - NetInternalsTest.expectStatusViewNodeVisible(StatusView.FOR_FILE_ID); +/** + * Exports a log dump to a string and loads it, and then repeats, making sure + * we can export loaded logs. + */ +TEST_F('NetInternalsTest', 'netInternalsExportImportExportImport', function() { + var taskQueue = new NetInternalsTest.TaskQueue(true); + taskQueue.addTask(new CreateAndLoadLogTask('Random comment on the weather.')); + taskQueue.addFunctionTask(checkViewsAfterLogLoaded); + taskQueue.addTask(new CreateAndLoadLogTask('Detailed explanation.')); + taskQueue.addFunctionTask(checkViewsAfterLogLoaded); + taskQueue.run(true); +}); - var tabVisibilityState = { - capture: false, - export: false, - import: true, - proxy: true, - events: true, - timeline: true, - dns: true, - sockets: true, - spdy: true, - httpPipeline: false, - httpCache: true, - httpThrottling: false, - serviceProviders: cr.isWindows, - tests: false, - hsts: false, - logs: false, - prerender: true, - chromeos: false - }; - - NetInternalsTest.checkTabHandleVisibility(tabVisibilityState, false); - testDone(); - } +/** + * Checks pressing the stop capturing button. + */ +TEST_F('NetInternalsTest', 'netInternalsStopCapturing', function() { + var taskQueue = new NetInternalsTest.TaskQueue(true); + // Switching to stop capturing mode will load a log dump, which will update + // the constants. + taskQueue.addTask(new WaitForConstantsTask()); + + taskQueue.addFunctionTask( + NetInternalsTest.expectStatusViewNodeVisible.bind( + null, StatusView.FOR_VIEW_ID)); + taskQueue.addFunctionTask(checkViewsAfterLogLoaded); + taskQueue.run(); + + // Simulate a click on the stop capturing button. + $(StatusView.STOP_CAPTURING_BUTTON_ID).click(); +}); + +/** + * Switches to stop capturing mode, then exports and imports a log dump. + */ +TEST_F('NetInternalsTest', 'netInternalsStopCapturingExportImport', function() { + var taskQueue = new NetInternalsTest.TaskQueue(true); + // Switching to stop capturing mode will load a log dump, which will update + // the constants. + taskQueue.addTask(new WaitForConstantsTask()); + + taskQueue.addFunctionTask( + NetInternalsTest.expectStatusViewNodeVisible.bind( + null, StatusView.FOR_VIEW_ID)); + taskQueue.addFunctionTask(checkViewsAfterLogLoaded); + taskQueue.addTask(new CreateAndLoadLogTask('Detailed explanation.')); + taskQueue.addFunctionTask(checkViewsAfterLogLoaded); + taskQueue.run(); - logutil.createLogDumpAsync('Log dump test', onLogDumpCreated); + // Simulate a click on the stop capturing button. + $(StatusView.STOP_CAPTURING_BUTTON_ID).click(); }); })(); // Anonymous namespace diff --git a/chrome/test/data/webui/net_internals/main.js b/chrome/test/data/webui/net_internals/main.js index 0f56110..00611b9 100644 --- a/chrome/test/data/webui/net_internals/main.js +++ b/chrome/test/data/webui/net_internals/main.js @@ -15,7 +15,7 @@ GEN_INCLUDE(['net_internals_test.js']); */ TEST_F('NetInternalsTest', 'netInternalsTourTabs', function() { // Prevent sending any events to the browser as we flip through tabs, since - // this tests is just intended to make sure everything's created and hooked + // this test is just intended to make sure everything's created and hooked // up properly Javascript side. g_browser.disable(); @@ -46,20 +46,4 @@ TEST_F('NetInternalsTest', 'netInternalsTourTabs', function() { testDone(); }); -/** - * Checks pressing the stop capturing button. - */ -TEST_F('NetInternalsTest', 'netInternalsStopCapturing', function() { - expectFalse(g_browser.isDisabled()); - NetInternalsTest.expectStatusViewNodeVisible( - StatusView.FOR_CAPTURE_ID); - - $(StatusView.STOP_CAPTURING_BUTTON_ID).onclick(); - - expectTrue(g_browser.isDisabled()); - NetInternalsTest.expectStatusViewNodeVisible(StatusView.FOR_VIEW_ID); - - testDone(); -}); - })(); // Anonymous namespace diff --git a/chrome/test/data/webui/net_internals/net_internals_test.js b/chrome/test/data/webui/net_internals/net_internals_test.js index 49c4151..accadbd 100644 --- a/chrome/test/data/webui/net_internals/net_internals_test.js +++ b/chrome/test/data/webui/net_internals/net_internals_test.js @@ -86,7 +86,9 @@ var NetInternalsTest = (function() { ConstantsObserver.prototype.onReceivedConstants = function() { if (!this.testStarted_) { this.testStarted_ = true; - // Stat test asynchronously, to avoid running a nested test function. + // Stat test asynchronously, to avoid running a nested test function, + // and so we don't call any constants observers used by individual + // tests. window.setTimeout(runTest, 0); } }; diff --git a/chrome/test/data/webui/net_internals/timeline_view.js b/chrome/test/data/webui/net_internals/timeline_view.js index 6442cef..8c714f9 100644 --- a/chrome/test/data/webui/net_internals/timeline_view.js +++ b/chrome/test/data/webui/net_internals/timeline_view.js @@ -54,7 +54,7 @@ LoadLogWithNewEventsTask.prototype = { * Starts creating a log dump. */ start: function() { - logutil.createLogDumpAsync('test', this.onLogDumpCreated.bind(this)); + log_util.createLogDumpAsync('test', this.onLogDumpCreated.bind(this), true); }, /** @@ -75,7 +75,7 @@ LoadLogWithNewEventsTask.prototype = { this.endTime_, null)); logDumpText = JSON.stringify(logDump); - assertEquals('Log loaded.', logutil.loadLogFile(logDumpText)); + assertEquals('Log loaded.', log_util.loadLogFile(logDumpText)); endTime = this.endTime_; startTime = this.startTime_; |