| 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 /** | 5 /** |
| 6 * @fileoverview This file contains tests for creating and loading log files. | 6 * @fileoverview This file contains tests for creating and loading log files. |
| 7 * It also tests the stop capturing button, since it both creates and then loads | 7 * It also tests the stop capturing button, since it both creates and then loads |
| 8 * a log dump. | 8 * a log dump. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 // Include test fixture. | 11 // Include test fixture. |
| 12 GEN_INCLUDE(['net_internals_test.js']); | 12 GEN_INCLUDE(['net_internals_test.js']); |
| 13 | 13 |
| 14 // Anonymous namespace | 14 // Anonymous namespace |
| 15 (function() { | 15 (function() { |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * A Task that creates a log dump and then loads it. | 18 * A Task that creates a log dump and then loads it. |
| 19 * @param {string} userComments User comments to copy to the ExportsView before | 19 * @param {string} userComments User comments to use for the generated log. |
| 20 * creating the log dump. | |
| 21 * @extends {NetInternalsTest.Task} | 20 * @extends {NetInternalsTest.Task} |
| 22 */ | 21 */ |
| 23 function CreateAndLoadLogTask(userComments) { | 22 function CreateAndLoadLogTask(userComments) { |
| 24 this.userComments_ = userComments; | 23 this.userComments_ = userComments; |
| 25 NetInternalsTest.Task.call(this); | 24 NetInternalsTest.Task.call(this); |
| 26 // Not strictly necessary, but since we complete from a call to the observer, | 25 // Not strictly necessary, but since we complete from a call to the observer, |
| 27 // seems reasonable to complete asynchronously. | 26 // seems reasonable to complete asynchronously. |
| 28 this.setCompleteAsync(true); | 27 this.setCompleteAsync(true); |
| 29 } | 28 } |
| 30 | 29 |
| 31 CreateAndLoadLogTask.prototype = { | 30 CreateAndLoadLogTask.prototype = { |
| 32 __proto__: NetInternalsTest.Task.prototype, | 31 __proto__: NetInternalsTest.Task.prototype, |
| 33 | 32 |
| 34 /** | 33 /** |
| 35 * Start creating the log dump. Use ExportView's function as it supports | 34 * Starts creating the log dump. |
| 36 * both creating completely new logs and using existing logs to create new | |
| 37 * ones, depending on whether or not we're currently viewing a log. | |
| 38 */ | 35 */ |
| 39 start: function() { | 36 start: function() { |
| 40 this.initialPrivacyStripping_ = | 37 this.initialPrivacyStripping_ = |
| 41 SourceTracker.getInstance().getPrivacyStripping(); | 38 SourceTracker.getInstance().getPrivacyStripping(); |
| 42 $(ExportView.USER_COMMENTS_TEXT_AREA_ID).value = this.userComments_; | 39 log_util.createLogDumpAsync(this.userComments_, |
| 43 ExportView.getInstance().createLogDump_(this.onLogDumpCreated.bind(this), | 40 this.onLogDumpCreated.bind(this), true); |
| 44 true); | |
| 45 }, | 41 }, |
| 46 | 42 |
| 47 /** | 43 /** |
| 48 * Callback passed to |createLogDumpAsync|. Tries to load the dumped log | 44 * Callback passed to |createLogDumpAsync|. Tries to load the dumped log |
| 49 * text. Checks the status bar and user comments after loading the log. | 45 * text. Checks the status bar and user comments after loading the log. |
| 50 * @param {string} logDumpText Log dump, as a string. | 46 * @param {string} logDumpText Log dump, as a string. |
| 51 */ | 47 */ |
| 52 onLogDumpCreated: function(logDumpText) { | 48 onLogDumpCreated: function(logDumpText) { |
| 53 expectEquals(this.initialPrivacyStripping_, | 49 expectEquals(this.initialPrivacyStripping_, |
| 54 SourceTracker.getInstance().getPrivacyStripping()); | 50 SourceTracker.getInstance().getPrivacyStripping()); |
| 55 expectEquals('Log loaded.', log_util.loadLogFile(logDumpText, 'log.txt')); | 51 expectEquals('Log loaded.', log_util.loadLogFile(logDumpText, 'log.txt')); |
| 56 expectFalse(SourceTracker.getInstance().getPrivacyStripping()); | 52 expectFalse(SourceTracker.getInstance().getPrivacyStripping()); |
| 57 | 53 |
| 58 NetInternalsTest.expectStatusViewNodeVisible(LoadedStatusView.MAIN_BOX_ID); | 54 NetInternalsTest.expectStatusViewNodeVisible(LoadedStatusView.MAIN_BOX_ID); |
| 59 | 55 |
| 60 expectEquals(this.userComments_, | |
| 61 $(ExportView.USER_COMMENTS_TEXT_AREA_ID).value); | |
| 62 // Make sure the DIV on the import tab containing the comments is visible | 56 // Make sure the DIV on the import tab containing the comments is visible |
| 63 // before checking the displayed text. | 57 // before checking the displayed text. |
| 64 expectTrue(NetInternalsTest.nodeIsVisible($(ImportView.LOADED_DIV_ID))); | 58 expectTrue(NetInternalsTest.nodeIsVisible($(ImportView.LOADED_DIV_ID))); |
| 65 expectEquals(this.userComments_, | 59 expectEquals(this.userComments_, |
| 66 $(ImportView.LOADED_INFO_USER_COMMENTS_ID).innerText); | 60 $(ImportView.LOADED_INFO_USER_COMMENTS_ID).innerText); |
| 67 | 61 |
| 68 this.onTaskDone(); | 62 this.onTaskDone(); |
| 69 } | 63 } |
| 70 }; | 64 }; |
| 71 | 65 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 }; | 151 }; |
| 158 | 152 |
| 159 /** | 153 /** |
| 160 * Checks the visibility of each view after loading a freshly created log dump. | 154 * Checks the visibility of each view after loading a freshly created log dump. |
| 161 * Also checks that the BrowserBridge is disabled. | 155 * Also checks that the BrowserBridge is disabled. |
| 162 */ | 156 */ |
| 163 function checkViewsAfterLogLoaded() { | 157 function checkViewsAfterLogLoaded() { |
| 164 expectTrue(g_browser.isDisabled()); | 158 expectTrue(g_browser.isDisabled()); |
| 165 var tabVisibilityState = { | 159 var tabVisibilityState = { |
| 166 capture: false, | 160 capture: false, |
| 167 export: true, | |
| 168 import: true, | 161 import: true, |
| 169 proxy: true, | 162 proxy: true, |
| 170 events: true, | 163 events: true, |
| 171 timeline: true, | 164 timeline: true, |
| 172 dns: true, | 165 dns: true, |
| 173 sockets: true, | 166 sockets: true, |
| 174 http2: true, | 167 http2: true, |
| 175 quic: true, | 168 quic: true, |
| 176 'alt-svc': true, | 169 'alt-svc': true, |
| 177 sdch: false, | 170 sdch: false, |
| 178 httpCache: true, | 171 httpCache: true, |
| 179 modules: true, | 172 modules: true, |
| 180 hsts: false, | 173 hsts: false, |
| 181 prerender: true, | 174 prerender: true, |
| 182 bandwidth: true, | 175 bandwidth: true, |
| 183 chromeos: false | 176 chromeos: false |
| 184 }; | 177 }; |
| 185 NetInternalsTest.checkTabLinkVisibility(tabVisibilityState, false); | 178 NetInternalsTest.checkTabLinkVisibility(tabVisibilityState, false); |
| 186 } | 179 } |
| 187 | 180 |
| 188 /** | 181 /** |
| 189 * Checks the visibility of each view after loading a log dump created by the | 182 * Checks the visibility of each view after loading a log dump created by the |
| 190 * WriteToFileNetLogObserver. Also checks that the BrowserBridge is disabled. | 183 * WriteToFileNetLogObserver. Also checks that the BrowserBridge is disabled. |
| 191 */ | 184 */ |
| 192 function checkViewsAfterNetLogFileLoaded() { | 185 function checkViewsAfterNetLogFileLoaded() { |
| 193 expectTrue(g_browser.isDisabled()); | 186 expectTrue(g_browser.isDisabled()); |
| 194 var tabVisibilityState = { | 187 var tabVisibilityState = { |
| 195 capture: false, | 188 capture: false, |
| 196 export: true, | |
| 197 import: true, | 189 import: true, |
| 198 proxy: false, | 190 proxy: false, |
| 199 events: true, | 191 events: true, |
| 200 timeline: true, | 192 timeline: true, |
| 201 dns: false, | 193 dns: false, |
| 202 sockets: false, | 194 sockets: false, |
| 203 http2: false, | 195 http2: false, |
| 204 quic: false, | 196 quic: false, |
| 205 'alt-svc': false, | 197 'alt-svc': false, |
| 206 sdch: false, | 198 sdch: false, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 */ | 256 */ |
| 265 TEST_F('NetInternalsTest', 'netInternalsLogUtilImportNetLogFileTruncated', | 257 TEST_F('NetInternalsTest', 'netInternalsLogUtilImportNetLogFileTruncated', |
| 266 function() { | 258 function() { |
| 267 var taskQueue = new NetInternalsTest.TaskQueue(true); | 259 var taskQueue = new NetInternalsTest.TaskQueue(true); |
| 268 taskQueue.addTask(new GetNetLogFileContentsAndLoadLogTask(20)); | 260 taskQueue.addTask(new GetNetLogFileContentsAndLoadLogTask(20)); |
| 269 taskQueue.addFunctionTask(checkViewsAfterNetLogFileLoaded); | 261 taskQueue.addFunctionTask(checkViewsAfterNetLogFileLoaded); |
| 270 taskQueue.run(true); | 262 taskQueue.run(true); |
| 271 }); | 263 }); |
| 272 | 264 |
| 273 /** | 265 /** |
| 274 * Exports a log dump to a string and loads it, and then repeats, making sure | |
| 275 * we can export loaded logs. | |
| 276 */ | |
| 277 TEST_F('NetInternalsTest', | |
| 278 'netInternalsLogUtilExportImportExportImport', | |
| 279 function() { | |
| 280 var taskQueue = new NetInternalsTest.TaskQueue(true); | |
| 281 taskQueue.addTask(new CreateAndLoadLogTask('Random comment on the weather.')); | |
| 282 taskQueue.addFunctionTask(checkViewsAfterLogLoaded); | |
| 283 taskQueue.addTask(new CreateAndLoadLogTask('Detailed explanation.')); | |
| 284 taskQueue.addFunctionTask(checkViewsAfterLogLoaded); | |
| 285 taskQueue.run(true); | |
| 286 }); | |
| 287 | |
| 288 /** | |
| 289 * Checks pressing the stop capturing button. | 266 * Checks pressing the stop capturing button. |
| 290 */ | 267 */ |
| 291 TEST_F('NetInternalsTest', 'netInternalsLogUtilStopCapturing', function() { | 268 TEST_F('NetInternalsTest', 'netInternalsLogUtilStopCapturing', function() { |
| 292 var taskQueue = new NetInternalsTest.TaskQueue(true); | 269 var taskQueue = new NetInternalsTest.TaskQueue(true); |
| 293 // Switching to stop capturing mode will load a log dump, which will update | 270 // Switching to stop capturing mode will load a log dump, which will update |
| 294 // the constants. | 271 // the constants. |
| 295 taskQueue.addTask(new WaitForConstantsTask()); | 272 taskQueue.addTask(new WaitForConstantsTask()); |
| 296 | 273 |
| 297 taskQueue.addFunctionTask( | 274 taskQueue.addFunctionTask( |
| 298 NetInternalsTest.expectStatusViewNodeVisible.bind( | 275 NetInternalsTest.expectStatusViewNodeVisible.bind( |
| 299 null, HaltedStatusView.MAIN_BOX_ID)); | 276 null, HaltedStatusView.MAIN_BOX_ID)); |
| 300 taskQueue.addFunctionTask(checkViewsAfterLogLoaded); | 277 taskQueue.addFunctionTask(checkViewsAfterLogLoaded); |
| 301 taskQueue.addFunctionTask(checkPrivacyStripping.bind(null, true)); | 278 taskQueue.addFunctionTask(checkPrivacyStripping.bind(null, true)); |
| 302 taskQueue.addFunctionTask(checkActiveView.bind(null, ExportView.TAB_ID)); | 279 taskQueue.addFunctionTask(checkActiveView.bind(null, EventsView.TAB_ID)); |
| 303 taskQueue.run(); | 280 taskQueue.run(); |
| 304 | 281 |
| 305 // Simulate a click on the stop capturing button | 282 // Simulate a click on the stop capturing button |
| 306 $(CaptureView.STOP_BUTTON_ID).click(); | 283 $(CaptureView.STOP_BUTTON_ID).click(); |
| 307 }); | 284 }); |
| 308 | 285 |
| 309 /** | |
| 310 * Switches to stop capturing mode, then exports and imports a log dump. | |
| 311 */ | |
| 312 TEST_F('NetInternalsTest', | |
| 313 'netInternalsLogUtilStopCapturingExportImport', | |
| 314 function() { | |
| 315 var taskQueue = new NetInternalsTest.TaskQueue(true); | |
| 316 // Switching to stop capturing mode will load a log dump, which will update | |
| 317 // the constants. | |
| 318 taskQueue.addTask(new WaitForConstantsTask()); | |
| 319 | |
| 320 taskQueue.addFunctionTask( | |
| 321 NetInternalsTest.expectStatusViewNodeVisible.bind( | |
| 322 null, HaltedStatusView.MAIN_BOX_ID)); | |
| 323 taskQueue.addFunctionTask(checkViewsAfterLogLoaded); | |
| 324 taskQueue.addFunctionTask(checkPrivacyStripping.bind(null, true)); | |
| 325 taskQueue.addTask(new CreateAndLoadLogTask('Detailed explanation.')); | |
| 326 taskQueue.addFunctionTask(checkViewsAfterLogLoaded); | |
| 327 taskQueue.run(); | |
| 328 | |
| 329 // Simulate clicking the stop button. | |
| 330 $(CaptureView.STOP_BUTTON_ID).click(); | |
| 331 }); | |
| 332 | |
| 333 })(); // Anonymous namespace | 286 })(); // Anonymous namespace |
| OLD | NEW |