Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following disclaimer |
| 12 | * in the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * * Neither the name of Google Inc. nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived from |
| 16 | * this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | /* eslint-disable indent */ |
| 31 | |
| 32 | /** |
| 33 | * @fileoverview This file contains small testing framework along with the |
| 34 | * test suite for the frontend. These tests are a part of the continues build |
| 35 | * and are executed by the devtools_sanity_unittest.cc as a part of the |
| 36 | * Interactive UI Test suite. |
| 37 | * FIXME: change field naming style to use trailing underscore. |
| 38 | */ |
| 39 | |
| 40 | (function createTestSuite(window) { |
| 41 | |
| 42 | /** |
| 43 | * @unrestricted |
| 44 | */ |
| 45 | const TestSuite = class { |
| 46 | /** |
| 47 | * Test suite for interactive UI tests. |
| 48 | * @param {Object} domAutomationController DomAutomationController instance. |
| 49 | */ |
| 50 | constructor(domAutomationController) { |
| 51 | this.domAutomationController_ = domAutomationController; |
| 52 | this.controlTaken_ = false; |
| 53 | this.timerId_ = -1; |
| 54 | this._asyncInvocationId = 0; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Key event with given key identifier. |
| 59 | */ |
| 60 | static createKeyEvent(key) { |
| 61 | return new KeyboardEvent('keydown', {bubbles: true, cancelable: true, key: key}); |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | /** |
| 66 | * Reports test failure. |
| 67 | * @param {string} message Failure description. |
| 68 | */ |
| 69 | TestSuite.prototype.fail = function(message) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 70 | if (this.controlTaken_) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 71 | this.reportFailure_(message); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 72 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 73 | throw message; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 74 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | /** |
| 78 | * Equals assertion tests that expected === actual. |
| 79 | * @param {!Object|boolean} expected Expected object. |
| 80 | * @param {!Object|boolean} actual Actual object. |
| 81 | * @param {string} opt_message User message to print if the test fails. |
| 82 | */ |
| 83 | TestSuite.prototype.assertEquals = function(expected, actual, opt_message) { |
| 84 | if (expected !== actual) { |
| 85 | let message = 'Expected: \'' + expected + '\', but was \'' + actual + '\''; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 86 | if (opt_message) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 87 | message = opt_message + '(' + message + ')'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 88 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 89 | this.fail(message); |
| 90 | } |
| 91 | }; |
| 92 | |
| 93 | /** |
| 94 | * True assertion tests that value == true. |
| 95 | * @param {!Object} value Actual object. |
| 96 | * @param {string} opt_message User message to print if the test fails. |
| 97 | */ |
| 98 | TestSuite.prototype.assertTrue = function(value, opt_message) { |
| 99 | this.assertEquals(true, !!value, opt_message); |
| 100 | }; |
| 101 | |
| 102 | /** |
| 103 | * Takes control over execution. |
| 104 | */ |
| 105 | TestSuite.prototype.takeControl = function() { |
| 106 | this.controlTaken_ = true; |
| 107 | // Set up guard timer. |
| 108 | const self = this; |
| 109 | this.timerId_ = setTimeout(function() { |
| 110 | self.reportFailure_('Timeout exceeded: 20 sec'); |
| 111 | }, 20000); |
| 112 | }; |
| 113 | |
| 114 | /** |
| 115 | * Releases control over execution. |
| 116 | */ |
| 117 | TestSuite.prototype.releaseControl = function() { |
| 118 | if (this.timerId_ !== -1) { |
| 119 | clearTimeout(this.timerId_); |
| 120 | this.timerId_ = -1; |
| 121 | } |
| 122 | this.controlTaken_ = false; |
| 123 | this.reportOk_(); |
| 124 | }; |
| 125 | |
| 126 | /** |
| 127 | * Async tests use this one to report that they are completed. |
| 128 | */ |
| 129 | TestSuite.prototype.reportOk_ = function() { |
| 130 | this.domAutomationController_.send('[OK]'); |
| 131 | }; |
| 132 | |
| 133 | /** |
| 134 | * Async tests use this one to report failures. |
| 135 | */ |
| 136 | TestSuite.prototype.reportFailure_ = function(error) { |
| 137 | if (this.timerId_ !== -1) { |
| 138 | clearTimeout(this.timerId_); |
| 139 | this.timerId_ = -1; |
| 140 | } |
| 141 | this.domAutomationController_.send('[FAILED] ' + error); |
| 142 | }; |
| 143 | |
| 144 | /** |
| 145 | * Run specified test on a fresh instance of the test suite. |
| 146 | * @param {Array<string>} args method name followed by its parameters. |
| 147 | */ |
| 148 | TestSuite.prototype.dispatchOnTestSuite = function(args) { |
| 149 | const methodName = args.shift(); |
| 150 | try { |
| 151 | this[methodName].apply(this, args); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 152 | if (!this.controlTaken_) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 153 | this.reportOk_(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 154 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 155 | } catch (e) { |
| 156 | this.reportFailure_(e); |
| 157 | } |
| 158 | }; |
| 159 | |
| 160 | /** |
| 161 | * Wrap an async method with TestSuite.{takeControl(), releaseControl()} |
| 162 | * and invoke TestSuite.reportOk_ upon completion. |
| 163 | * @param {Array<string>} args method name followed by its parameters. |
| 164 | */ |
| 165 | TestSuite.prototype.waitForAsync = function(var_args) { |
| 166 | const args = Array.prototype.slice.call(arguments); |
| 167 | this.takeControl(); |
| 168 | args.push(this.releaseControl.bind(this)); |
| 169 | this.dispatchOnTestSuite(args); |
| 170 | }; |
| 171 | |
| 172 | /** |
| 173 | * Overrides the method with specified name until it's called first time. |
| 174 | * @param {!Object} receiver An object whose method to override. |
| 175 | * @param {string} methodName Name of the method to override. |
| 176 | * @param {!Function} override A function that should be called right after the |
| 177 | * overridden method returns. |
| 178 | * @param {?boolean} opt_sticky Whether restore original method after first run |
| 179 | * or not. |
| 180 | */ |
| 181 | TestSuite.prototype.addSniffer = function(receiver, methodName, override, opt_sticky) { |
| 182 | const orig = receiver[methodName]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 183 | if (typeof orig !== 'function') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 184 | this.fail('Cannot find method to override: ' + methodName); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 185 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 186 | const test = this; |
| 187 | receiver[methodName] = function(var_args) { |
| 188 | let result; |
| 189 | try { |
| 190 | result = orig.apply(this, arguments); |
| 191 | } finally { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 192 | if (!opt_sticky) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 193 | receiver[methodName] = orig; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 194 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 195 | } |
| 196 | // In case of exception the override won't be called. |
| 197 | try { |
| 198 | override.apply(this, arguments); |
| 199 | } catch (e) { |
| 200 | test.fail('Exception in overriden method \'' + methodName + '\': ' + e); |
| 201 | } |
| 202 | return result; |
| 203 | }; |
| 204 | }; |
| 205 | |
| 206 | /** |
| 207 | * Waits for current throttler invocations, if any. |
| 208 | * @param {!Common.Throttler} throttler |
| 209 | * @param {function()} callback |
| 210 | */ |
| 211 | TestSuite.prototype.waitForThrottler = function(throttler, callback) { |
| 212 | const test = this; |
| 213 | let scheduleShouldFail = true; |
| 214 | test.addSniffer(throttler, 'schedule', onSchedule); |
| 215 | |
| 216 | function hasSomethingScheduled() { |
| 217 | return throttler._isRunningProcess || throttler._process; |
| 218 | } |
| 219 | |
| 220 | function checkState() { |
| 221 | if (!hasSomethingScheduled()) { |
| 222 | scheduleShouldFail = false; |
| 223 | callback(); |
| 224 | return; |
| 225 | } |
| 226 | |
| 227 | test.addSniffer(throttler, '_processCompletedForTests', checkState); |
| 228 | } |
| 229 | |
| 230 | function onSchedule() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 231 | if (scheduleShouldFail) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 232 | test.fail('Unexpected Throttler.schedule'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 233 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | checkState(); |
| 237 | }; |
| 238 | |
| 239 | /** |
| 240 | * @param {string} panelName Name of the panel to show. |
| 241 | */ |
| 242 | TestSuite.prototype.showPanel = function(panelName) { |
Paul Lewis | 0a7c6b6 | 2020-01-23 16:16:22 | [diff] [blame] | 243 | return self.UI.inspectorView.showPanel(panelName); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 244 | }; |
| 245 | |
| 246 | // UI Tests |
| 247 | |
| 248 | /** |
| 249 | * Tests that scripts tab can be open and populated with inspected scripts. |
| 250 | */ |
| 251 | TestSuite.prototype.testShowScriptsTab = function() { |
| 252 | const test = this; |
| 253 | this.showPanel('sources').then(function() { |
| 254 | // There should be at least main page script. |
| 255 | this._waitUntilScriptsAreParsed(['debugger_test_page.html'], function() { |
| 256 | test.releaseControl(); |
| 257 | }); |
| 258 | }.bind(this)); |
| 259 | // Wait until all scripts are added to the debugger. |
| 260 | this.takeControl(); |
| 261 | }; |
| 262 | |
| 263 | /** |
| 264 | * Tests that scripts tab is populated with inspected scripts even if it |
| 265 | * hadn't been shown by the moment inspected paged refreshed. |
| 266 | * @see http://crbug.com/26312 |
| 267 | */ |
| 268 | TestSuite.prototype.testScriptsTabIsPopulatedOnInspectedPageRefresh = function() { |
| 269 | const test = this; |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 270 | const debuggerModel = self.SDK.targetManager.mainTarget().model(SDK.DebuggerModel); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 271 | debuggerModel.addEventListener(SDK.DebuggerModel.Events.GlobalObjectCleared, waitUntilScriptIsParsed); |
| 272 | |
| 273 | this.showPanel('elements').then(function() { |
| 274 | // Reload inspected page. It will reset the debugger agent. |
| 275 | test.evaluateInConsole_('window.location.reload(true);', function(resultText) {}); |
| 276 | }); |
| 277 | |
| 278 | function waitUntilScriptIsParsed() { |
| 279 | debuggerModel.removeEventListener(SDK.DebuggerModel.Events.GlobalObjectCleared, waitUntilScriptIsParsed); |
| 280 | test.showPanel('sources').then(function() { |
| 281 | test._waitUntilScriptsAreParsed(['debugger_test_page.html'], function() { |
| 282 | test.releaseControl(); |
| 283 | }); |
| 284 | }); |
| 285 | } |
| 286 | |
| 287 | // Wait until all scripts are added to the debugger. |
| 288 | this.takeControl(); |
| 289 | }; |
| 290 | |
| 291 | /** |
| 292 | * Tests that scripts list contains content scripts. |
| 293 | */ |
| 294 | TestSuite.prototype.testContentScriptIsPresent = function() { |
| 295 | const test = this; |
| 296 | this.showPanel('sources').then(function() { |
| 297 | test._waitUntilScriptsAreParsed(['page_with_content_script.html', 'simple_content_script.js'], function() { |
| 298 | test.releaseControl(); |
| 299 | }); |
| 300 | }); |
| 301 | |
| 302 | // Wait until all scripts are added to the debugger. |
| 303 | this.takeControl(); |
| 304 | }; |
| 305 | |
| 306 | /** |
| 307 | * Tests that scripts are not duplicaed on Scripts tab switch. |
| 308 | */ |
| 309 | TestSuite.prototype.testNoScriptDuplicatesOnPanelSwitch = function() { |
| 310 | const test = this; |
| 311 | |
| 312 | function switchToElementsTab() { |
| 313 | test.showPanel('elements').then(function() { |
| 314 | setTimeout(switchToScriptsTab, 0); |
| 315 | }); |
| 316 | } |
| 317 | |
| 318 | function switchToScriptsTab() { |
| 319 | test.showPanel('sources').then(function() { |
| 320 | setTimeout(checkScriptsPanel, 0); |
| 321 | }); |
| 322 | } |
| 323 | |
| 324 | function checkScriptsPanel() { |
| 325 | test.assertTrue(test._scriptsAreParsed(['debugger_test_page.html']), 'Some scripts are missing.'); |
| 326 | checkNoDuplicates(); |
| 327 | test.releaseControl(); |
| 328 | } |
| 329 | |
| 330 | function checkNoDuplicates() { |
| 331 | const uiSourceCodes = test.nonAnonymousUISourceCodes_(); |
| 332 | for (let i = 0; i < uiSourceCodes.length; i++) { |
| 333 | for (let j = i + 1; j < uiSourceCodes.length; j++) { |
| 334 | test.assertTrue( |
| 335 | uiSourceCodes[i].url() !== uiSourceCodes[j].url(), |
| 336 | 'Found script duplicates: ' + test.uiSourceCodesToString_(uiSourceCodes)); |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | this.showPanel('sources').then(function() { |
| 342 | test._waitUntilScriptsAreParsed(['debugger_test_page.html'], function() { |
| 343 | checkNoDuplicates(); |
| 344 | setTimeout(switchToElementsTab, 0); |
| 345 | }); |
| 346 | }); |
| 347 | |
| 348 | // Wait until all scripts are added to the debugger. |
| 349 | this.takeControl(); |
| 350 | }; |
| 351 | |
| 352 | // Tests that debugger works correctly if pause event occurs when DevTools |
| 353 | // frontend is being loaded. |
| 354 | TestSuite.prototype.testPauseWhenLoadingDevTools = function() { |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 355 | const debuggerModel = self.SDK.targetManager.mainTarget().model(SDK.DebuggerModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 356 | if (debuggerModel.debuggerPausedDetails) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 357 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 358 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 359 | |
| 360 | this.showPanel('sources').then(function() { |
| 361 | // Script execution can already be paused. |
| 362 | |
| 363 | this._waitForScriptPause(this.releaseControl.bind(this)); |
| 364 | }.bind(this)); |
| 365 | |
| 366 | this.takeControl(); |
| 367 | }; |
| 368 | |
| 369 | // Tests that pressing "Pause" will pause script execution if the script |
| 370 | // is already running. |
| 371 | TestSuite.prototype.testPauseWhenScriptIsRunning = function() { |
| 372 | this.showPanel('sources').then(function() { |
| 373 | this.evaluateInConsole_('setTimeout("handleClick()", 0)', didEvaluateInConsole.bind(this)); |
| 374 | }.bind(this)); |
| 375 | |
| 376 | function didEvaluateInConsole(resultText) { |
| 377 | this.assertTrue(!isNaN(resultText), 'Failed to get timer id: ' + resultText); |
| 378 | // Wait for some time to make sure that inspected page is running the |
| 379 | // infinite loop. |
| 380 | setTimeout(testScriptPause.bind(this), 300); |
| 381 | } |
| 382 | |
| 383 | function testScriptPause() { |
| 384 | // The script should be in infinite loop. Click "Pause" button to |
| 385 | // pause it and wait for the result. |
| 386 | UI.panels.sources._togglePause(); |
| 387 | |
| 388 | this._waitForScriptPause(this.releaseControl.bind(this)); |
| 389 | } |
| 390 | |
| 391 | this.takeControl(); |
| 392 | }; |
| 393 | |
| 394 | /** |
| 395 | * Tests network size. |
| 396 | */ |
| 397 | TestSuite.prototype.testNetworkSize = function() { |
| 398 | const test = this; |
| 399 | |
| 400 | function finishRequest(request, finishTime) { |
| 401 | test.assertEquals(25, request.resourceSize, 'Incorrect total data length'); |
| 402 | test.releaseControl(); |
| 403 | } |
| 404 | |
| 405 | this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', finishRequest); |
| 406 | |
| 407 | // Reload inspected page to sniff network events |
| 408 | test.evaluateInConsole_('window.location.reload(true);', function(resultText) {}); |
| 409 | |
| 410 | this.takeControl(); |
| 411 | }; |
| 412 | |
| 413 | /** |
| 414 | * Tests network sync size. |
| 415 | */ |
| 416 | TestSuite.prototype.testNetworkSyncSize = function() { |
| 417 | const test = this; |
| 418 | |
| 419 | function finishRequest(request, finishTime) { |
| 420 | test.assertEquals(25, request.resourceSize, 'Incorrect total data length'); |
| 421 | test.releaseControl(); |
| 422 | } |
| 423 | |
| 424 | this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', finishRequest); |
| 425 | |
| 426 | // Send synchronous XHR to sniff network events |
| 427 | test.evaluateInConsole_( |
| 428 | 'let xhr = new XMLHttpRequest(); xhr.open("GET", "chunked", false); xhr.send(null);', function() {}); |
| 429 | |
| 430 | this.takeControl(); |
| 431 | }; |
| 432 | |
| 433 | /** |
| 434 | * Tests network raw headers text. |
| 435 | */ |
| 436 | TestSuite.prototype.testNetworkRawHeadersText = function() { |
| 437 | const test = this; |
| 438 | |
| 439 | function finishRequest(request, finishTime) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 440 | if (!request.responseHeadersText) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 441 | test.fail('Failure: resource does not have response headers text'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 442 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 443 | const index = request.responseHeadersText.indexOf('Date:'); |
| 444 | test.assertEquals( |
| 445 | 112, request.responseHeadersText.substring(index).length, 'Incorrect response headers text length'); |
| 446 | test.releaseControl(); |
| 447 | } |
| 448 | |
| 449 | this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', finishRequest); |
| 450 | |
| 451 | // Reload inspected page to sniff network events |
| 452 | test.evaluateInConsole_('window.location.reload(true);', function(resultText) {}); |
| 453 | |
| 454 | this.takeControl(); |
| 455 | }; |
| 456 | |
| 457 | /** |
| 458 | * Tests network timing. |
| 459 | */ |
| 460 | TestSuite.prototype.testNetworkTiming = function() { |
| 461 | const test = this; |
| 462 | |
| 463 | function finishRequest(request, finishTime) { |
| 464 | // Setting relaxed expectations to reduce flakiness. |
| 465 | // Server sends headers after 100ms, then sends data during another 100ms. |
| 466 | // We expect these times to be measured at least as 70ms. |
| 467 | test.assertTrue( |
| 468 | request.timing.receiveHeadersEnd - request.timing.connectStart >= 70, |
| 469 | 'Time between receiveHeadersEnd and connectStart should be >=70ms, but was ' + |
| 470 | 'receiveHeadersEnd=' + request.timing.receiveHeadersEnd + ', connectStart=' + |
| 471 | request.timing.connectStart + '.'); |
| 472 | test.assertTrue( |
| 473 | request.responseReceivedTime - request.startTime >= 0.07, |
| 474 | 'Time between responseReceivedTime and startTime should be >=0.07s, but was ' + |
| 475 | 'responseReceivedTime=' + request.responseReceivedTime + ', startTime=' + request.startTime + '.'); |
| 476 | test.assertTrue( |
| 477 | request.endTime - request.startTime >= 0.14, |
| 478 | 'Time between endTime and startTime should be >=0.14s, but was ' + |
| 479 | 'endtime=' + request.endTime + ', startTime=' + request.startTime + '.'); |
| 480 | |
| 481 | test.releaseControl(); |
| 482 | } |
| 483 | |
| 484 | this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', finishRequest); |
| 485 | |
| 486 | // Reload inspected page to sniff network events |
| 487 | test.evaluateInConsole_('window.location.reload(true);', function(resultText) {}); |
| 488 | |
| 489 | this.takeControl(); |
| 490 | }; |
| 491 | |
| 492 | TestSuite.prototype.testPushTimes = function(url) { |
| 493 | const test = this; |
| 494 | let pendingRequestCount = 2; |
| 495 | |
| 496 | function finishRequest(request, finishTime) { |
| 497 | test.assertTrue( |
| 498 | typeof request.timing.pushStart === 'number' && request.timing.pushStart > 0, |
| 499 | `pushStart is invalid: ${request.timing.pushStart}`); |
| 500 | test.assertTrue(typeof request.timing.pushEnd === 'number', `pushEnd is invalid: ${request.timing.pushEnd}`); |
| 501 | test.assertTrue(request.timing.pushStart < request.startTime, 'pushStart should be before startTime'); |
| 502 | if (request.url().endsWith('?pushUseNullEndTime')) { |
| 503 | test.assertTrue(request.timing.pushEnd === 0, `pushEnd should be 0 but is ${request.timing.pushEnd}`); |
| 504 | } else { |
| 505 | test.assertTrue( |
| 506 | request.timing.pushStart < request.timing.pushEnd, |
| 507 | `pushStart should be before pushEnd (${request.timing.pushStart} >= ${request.timing.pushEnd})`); |
| 508 | // The below assertion is just due to the way we generate times in the moch URLRequestJob and is not generally an invariant. |
| 509 | test.assertTrue(request.timing.pushEnd < request.endTime, 'pushEnd should be before endTime'); |
| 510 | test.assertTrue(request.startTime < request.timing.pushEnd, 'pushEnd should be after startTime'); |
| 511 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 512 | if (!--pendingRequestCount) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 513 | test.releaseControl(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 514 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', finishRequest, true); |
| 518 | |
| 519 | test.evaluateInConsole_('addImage(\'' + url + '\')', function(resultText) {}); |
| 520 | test.evaluateInConsole_('addImage(\'' + url + '?pushUseNullEndTime\')', function(resultText) {}); |
| 521 | this.takeControl(); |
| 522 | }; |
| 523 | |
| 524 | TestSuite.prototype.testConsoleOnNavigateBack = function() { |
| 525 | |
| 526 | function filteredMessages() { |
Paul Lewis | e504fd6 | 2020-01-23 16:52:33 | [diff] [blame] | 527 | return self.SDK.consoleModel.messages().filter(a => a.source !== SDK.ConsoleMessage.MessageSource.Violation); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 528 | } |
| 529 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 530 | if (filteredMessages().length === 1) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 531 | firstConsoleMessageReceived.call(this, null); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 532 | } else { |
Paul Lewis | e504fd6 | 2020-01-23 16:52:33 | [diff] [blame] | 533 | self.SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.MessageAdded, firstConsoleMessageReceived, this); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 534 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 535 | |
| 536 | |
| 537 | function firstConsoleMessageReceived(event) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 538 | if (event && event.data.source === SDK.ConsoleMessage.MessageSource.Violation) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 539 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 540 | } |
Paul Lewis | e504fd6 | 2020-01-23 16:52:33 | [diff] [blame] | 541 | self.SDK.consoleModel.removeEventListener( |
| 542 | SDK.ConsoleModel.Events.MessageAdded, firstConsoleMessageReceived, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 543 | this.evaluateInConsole_('clickLink();', didClickLink.bind(this)); |
| 544 | } |
| 545 | |
| 546 | function didClickLink() { |
| 547 | // Check that there are no new messages(command is not a message). |
| 548 | this.assertEquals(3, filteredMessages().length); |
| 549 | this.evaluateInConsole_('history.back();', didNavigateBack.bind(this)); |
| 550 | } |
| 551 | |
| 552 | function didNavigateBack() { |
| 553 | // Make sure navigation completed and possible console messages were pushed. |
| 554 | this.evaluateInConsole_('void 0;', didCompleteNavigation.bind(this)); |
| 555 | } |
| 556 | |
| 557 | function didCompleteNavigation() { |
| 558 | this.assertEquals(7, filteredMessages().length); |
| 559 | this.releaseControl(); |
| 560 | } |
| 561 | |
| 562 | this.takeControl(); |
| 563 | }; |
| 564 | |
| 565 | TestSuite.prototype.testSharedWorker = function() { |
| 566 | function didEvaluateInConsole(resultText) { |
| 567 | this.assertEquals('2011', resultText); |
| 568 | this.releaseControl(); |
| 569 | } |
| 570 | this.evaluateInConsole_('globalVar', didEvaluateInConsole.bind(this)); |
| 571 | this.takeControl(); |
| 572 | }; |
| 573 | |
| 574 | TestSuite.prototype.testPauseInSharedWorkerInitialization1 = function() { |
| 575 | // Make sure the worker is loaded. |
| 576 | this.takeControl(); |
Joey Arhar | a6abfa2 | 2019-08-08 12:23:00 | [diff] [blame] | 577 | this._waitForTargets(1, callback.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 578 | |
| 579 | function callback() { |
Simon Zünd | b6414c9 | 2020-03-19 07:16:40 | [diff] [blame] | 580 | ProtocolClient.test.deprecatedRunAfterPendingDispatches(this.releaseControl.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 581 | } |
| 582 | }; |
| 583 | |
| 584 | TestSuite.prototype.testPauseInSharedWorkerInitialization2 = function() { |
| 585 | this.takeControl(); |
Joey Arhar | a6abfa2 | 2019-08-08 12:23:00 | [diff] [blame] | 586 | this._waitForTargets(1, callback.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 587 | |
| 588 | function callback() { |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 589 | const debuggerModel = self.SDK.targetManager.models(SDK.DebuggerModel)[0]; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 590 | if (debuggerModel.isPaused()) { |
Paul Lewis | e504fd6 | 2020-01-23 16:52:33 | [diff] [blame] | 591 | self.SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.MessageAdded, onConsoleMessage, this); |
Alexey Kozyatinskiy | 88f257f | 2018-09-21 01:12:31 | [diff] [blame] | 592 | debuggerModel.resume(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 593 | return; |
| 594 | } |
Alexey Kozyatinskiy | 88f257f | 2018-09-21 01:12:31 | [diff] [blame] | 595 | this._waitForScriptPause(callback.bind(this)); |
| 596 | } |
| 597 | |
| 598 | function onConsoleMessage(event) { |
| 599 | const message = event.data.messageText; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 600 | if (message !== 'connected') { |
Alexey Kozyatinskiy | 88f257f | 2018-09-21 01:12:31 | [diff] [blame] | 601 | this.fail('Unexpected message: ' + message); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 602 | } |
Alexey Kozyatinskiy | 88f257f | 2018-09-21 01:12:31 | [diff] [blame] | 603 | this.releaseControl(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 604 | } |
| 605 | }; |
| 606 | |
Joey Arhar | 0585e6f | 2018-10-30 23:11:18 | [diff] [blame] | 607 | TestSuite.prototype.testSharedWorkerNetworkPanel = function() { |
| 608 | this.takeControl(); |
| 609 | this.showPanel('network').then(() => { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 610 | if (!document.querySelector('#network-container')) { |
Joey Arhar | 0585e6f | 2018-10-30 23:11:18 | [diff] [blame] | 611 | this.fail('unable to find #network-container'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 612 | } |
Joey Arhar | 0585e6f | 2018-10-30 23:11:18 | [diff] [blame] | 613 | this.releaseControl(); |
| 614 | }); |
| 615 | }; |
| 616 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 617 | TestSuite.prototype.enableTouchEmulation = function() { |
| 618 | const deviceModeModel = new Emulation.DeviceModeModel(function() {}); |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 619 | deviceModeModel._target = self.SDK.targetManager.mainTarget(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 620 | deviceModeModel._applyTouch(true, true); |
| 621 | }; |
| 622 | |
| 623 | TestSuite.prototype.waitForDebuggerPaused = function() { |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 624 | const debuggerModel = self.SDK.targetManager.mainTarget().model(SDK.DebuggerModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 625 | if (debuggerModel.debuggerPausedDetails) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 626 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 627 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 628 | |
| 629 | this.takeControl(); |
| 630 | this._waitForScriptPause(this.releaseControl.bind(this)); |
| 631 | }; |
| 632 | |
| 633 | TestSuite.prototype.switchToPanel = function(panelName) { |
| 634 | this.showPanel(panelName).then(this.releaseControl.bind(this)); |
| 635 | this.takeControl(); |
| 636 | }; |
| 637 | |
| 638 | // Regression test for crbug.com/370035. |
| 639 | TestSuite.prototype.testDeviceMetricsOverrides = function() { |
| 640 | function dumpPageMetrics() { |
| 641 | return JSON.stringify( |
| 642 | {width: window.innerWidth, height: window.innerHeight, deviceScaleFactor: window.devicePixelRatio}); |
| 643 | } |
| 644 | |
| 645 | const test = this; |
| 646 | |
| 647 | async function testOverrides(params, metrics, callback) { |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 648 | await self.SDK.targetManager.mainTarget().emulationAgent().invoke_setDeviceMetricsOverride(params); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 649 | test.evaluateInConsole_('(' + dumpPageMetrics.toString() + ')()', checkMetrics); |
| 650 | |
| 651 | function checkMetrics(consoleResult) { |
| 652 | test.assertEquals( |
| 653 | '"' + JSON.stringify(metrics) + '"', consoleResult, 'Wrong metrics for params: ' + JSON.stringify(params)); |
| 654 | callback(); |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | function step1() { |
| 659 | testOverrides( |
| 660 | {width: 1200, height: 1000, deviceScaleFactor: 1, mobile: false, fitWindow: true}, |
| 661 | {width: 1200, height: 1000, deviceScaleFactor: 1}, step2); |
| 662 | } |
| 663 | |
| 664 | function step2() { |
| 665 | testOverrides( |
| 666 | {width: 1200, height: 1000, deviceScaleFactor: 1, mobile: false, fitWindow: false}, |
| 667 | {width: 1200, height: 1000, deviceScaleFactor: 1}, step3); |
| 668 | } |
| 669 | |
| 670 | function step3() { |
| 671 | testOverrides( |
| 672 | {width: 1200, height: 1000, deviceScaleFactor: 3, mobile: false, fitWindow: true}, |
| 673 | {width: 1200, height: 1000, deviceScaleFactor: 3}, step4); |
| 674 | } |
| 675 | |
| 676 | function step4() { |
| 677 | testOverrides( |
| 678 | {width: 1200, height: 1000, deviceScaleFactor: 3, mobile: false, fitWindow: false}, |
| 679 | {width: 1200, height: 1000, deviceScaleFactor: 3}, finish); |
| 680 | } |
| 681 | |
| 682 | function finish() { |
| 683 | test.releaseControl(); |
| 684 | } |
| 685 | |
| 686 | test.takeControl(); |
| 687 | step1(); |
| 688 | }; |
| 689 | |
| 690 | TestSuite.prototype.testDispatchKeyEventShowsAutoFill = function() { |
| 691 | const test = this; |
| 692 | let receivedReady = false; |
| 693 | |
| 694 | function signalToShowAutofill() { |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 695 | self.SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 696 | {type: 'rawKeyDown', key: 'Down', windowsVirtualKeyCode: 40, nativeVirtualKeyCode: 40}); |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 697 | self.SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 698 | {type: 'keyUp', key: 'Down', windowsVirtualKeyCode: 40, nativeVirtualKeyCode: 40}); |
| 699 | } |
| 700 | |
| 701 | function selectTopAutoFill() { |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 702 | self.SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 703 | {type: 'rawKeyDown', key: 'Down', windowsVirtualKeyCode: 40, nativeVirtualKeyCode: 40}); |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 704 | self.SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 705 | {type: 'keyUp', key: 'Down', windowsVirtualKeyCode: 40, nativeVirtualKeyCode: 40}); |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 706 | self.SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 707 | {type: 'rawKeyDown', key: 'Enter', windowsVirtualKeyCode: 13, nativeVirtualKeyCode: 13}); |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 708 | self.SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 709 | {type: 'keyUp', key: 'Enter', windowsVirtualKeyCode: 13, nativeVirtualKeyCode: 13}); |
| 710 | |
| 711 | test.evaluateInConsole_('document.getElementById("name").value', onResultOfInput); |
| 712 | } |
| 713 | |
| 714 | function onResultOfInput(value) { |
| 715 | // Console adds "" around the response. |
| 716 | test.assertEquals('"Abbf"', value); |
| 717 | test.releaseControl(); |
| 718 | } |
| 719 | |
| 720 | function onConsoleMessage(event) { |
| 721 | const message = event.data.messageText; |
| 722 | if (message === 'ready' && !receivedReady) { |
| 723 | receivedReady = true; |
| 724 | signalToShowAutofill(); |
| 725 | } |
| 726 | // This log comes from the browser unittest code. |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 727 | if (message === 'didShowSuggestions') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 728 | selectTopAutoFill(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 729 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | this.takeControl(); |
| 733 | |
| 734 | // It is possible for the ready console messagage to be already received but not handled |
| 735 | // or received later. This ensures we can catch both cases. |
Paul Lewis | e504fd6 | 2020-01-23 16:52:33 | [diff] [blame] | 736 | self.SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.MessageAdded, onConsoleMessage, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 737 | |
Paul Lewis | e504fd6 | 2020-01-23 16:52:33 | [diff] [blame] | 738 | const messages = self.SDK.consoleModel.messages(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 739 | if (messages.length) { |
| 740 | const text = messages[0].messageText; |
| 741 | this.assertEquals('ready', text); |
| 742 | signalToShowAutofill(); |
| 743 | } |
| 744 | }; |
| 745 | |
Pâris MEULEMAN | d4709cb | 2019-04-17 08:32:48 | [diff] [blame] | 746 | TestSuite.prototype.testKeyEventUnhandled = function() { |
| 747 | function onKeyEventUnhandledKeyDown(event) { |
| 748 | this.assertEquals('keydown', event.data.type); |
| 749 | this.assertEquals('F8', event.data.key); |
| 750 | this.assertEquals(119, event.data.keyCode); |
| 751 | this.assertEquals(0, event.data.modifiers); |
| 752 | this.assertEquals('', event.data.code); |
Tim van der Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 753 | Host.InspectorFrontendHost.events.removeEventListener( |
Tim van der Lippe | 7b19016 | 2019-09-27 15:10:44 | [diff] [blame] | 754 | Host.InspectorFrontendHostAPI.Events.KeyEventUnhandled, onKeyEventUnhandledKeyDown, this); |
Tim van der Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 755 | Host.InspectorFrontendHost.events.addEventListener( |
Tim van der Lippe | 7b19016 | 2019-09-27 15:10:44 | [diff] [blame] | 756 | Host.InspectorFrontendHostAPI.Events.KeyEventUnhandled, onKeyEventUnhandledKeyUp, this); |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 757 | self.SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent( |
Pâris MEULEMAN | d4709cb | 2019-04-17 08:32:48 | [diff] [blame] | 758 | {type: 'keyUp', key: 'F8', code: 'F8', windowsVirtualKeyCode: 119, nativeVirtualKeyCode: 119}); |
| 759 | } |
| 760 | function onKeyEventUnhandledKeyUp(event) { |
| 761 | this.assertEquals('keyup', event.data.type); |
| 762 | this.assertEquals('F8', event.data.key); |
| 763 | this.assertEquals(119, event.data.keyCode); |
| 764 | this.assertEquals(0, event.data.modifiers); |
| 765 | this.assertEquals('F8', event.data.code); |
| 766 | this.releaseControl(); |
| 767 | } |
| 768 | this.takeControl(); |
Tim van der Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 769 | Host.InspectorFrontendHost.events.addEventListener( |
Tim van der Lippe | 7b19016 | 2019-09-27 15:10:44 | [diff] [blame] | 770 | Host.InspectorFrontendHostAPI.Events.KeyEventUnhandled, onKeyEventUnhandledKeyDown, this); |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 771 | self.SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent( |
Pâris MEULEMAN | d4709cb | 2019-04-17 08:32:48 | [diff] [blame] | 772 | {type: 'rawKeyDown', key: 'F8', windowsVirtualKeyCode: 119, nativeVirtualKeyCode: 119}); |
| 773 | }; |
| 774 | |
Jack Lynch | 080a0fd | 2020-06-15 19:55:19 | [diff] [blame^] | 775 | // Tests that the key whitelist in the browser is updated when shortcuts |
| 776 | // are changed |
| 777 | TestSuite.prototype.testKeyWhitelistChanged = function() { |
| 778 | this.takeControl(); |
| 779 | |
| 780 | this.addSniffer(self.UI.shortcutRegistry, '_registerBindings', () => { |
| 781 | self.SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent( |
| 782 | {type: 'rawKeyDown', key: 'F1', windowsVirtualKeyCode: 112, nativeVirtualKeyCode: 112}); |
| 783 | }); |
| 784 | this.addSniffer(self.UI.shortcutRegistry, 'handleKey', key => { |
| 785 | this.assertEquals(112, key); |
| 786 | this.releaseControl(); |
| 787 | }); |
| 788 | |
| 789 | self.Common.settings.moduleSetting('activeKeybindSet').set('vsCode'); |
| 790 | }; |
| 791 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 792 | TestSuite.prototype.testDispatchKeyEventDoesNotCrash = function() { |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 793 | self.SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 794 | {type: 'rawKeyDown', windowsVirtualKeyCode: 0x23, key: 'End'}); |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 795 | self.SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 796 | {type: 'keyUp', windowsVirtualKeyCode: 0x23, key: 'End'}); |
| 797 | }; |
| 798 | |
Pâris MEULEMAN | d81f35f | 2019-05-07 09:04:34 | [diff] [blame] | 799 | // Check that showing the certificate viewer does not crash, crbug.com/954874 |
| 800 | TestSuite.prototype.testShowCertificate = function() { |
Tim van der Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 801 | Host.InspectorFrontendHost.showCertificateViewer([ |
Pâris MEULEMAN | d81f35f | 2019-05-07 09:04:34 | [diff] [blame] | 802 | 'MIIFIDCCBAigAwIBAgIQE0TsEu6R8FUHQv+9fE7j8TANBgkqhkiG9w0BAQsF' + |
| 803 | 'ADBUMQswCQYDVQQGEwJVUzEeMBwGA1UEChMVR29vZ2xlIFRydXN0IFNlcnZp' + |
| 804 | 'Y2VzMSUwIwYDVQQDExxHb29nbGUgSW50ZXJuZXQgQXV0aG9yaXR5IEczMB4X' + |
| 805 | 'DTE5MDMyNjEzNDEwMVoXDTE5MDYxODEzMjQwMFowZzELMAkGA1UEBhMCVVMx' + |
| 806 | 'EzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDU1vdW50YWluIFZpZXcx' + |
| 807 | 'EzARBgNVBAoMCkdvb2dsZSBMTEMxFjAUBgNVBAMMDSouYXBwc3BvdC5jb20w' + |
| 808 | 'ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCwca7hj0kyoJVxcvyA' + |
| 809 | 'a8zNKMIXcoPM3aU1KVe7mxZITtwC6/D/D/q4Oe8fBQLeZ3c6qR5Sr3M+611k' + |
| 810 | 'Ab15AcGUgh1Xi0jZqERvd/5+P0aVCFJYeoLrPBzwSMZBStkoiO2CwtV8x06e' + |
| 811 | 'X7qUz7Hvr3oeG+Ma9OUMmIebl//zHtC82mE0mCRBQAW0MWEgT5nOWey74tJR' + |
| 812 | 'GRqUEI8ftV9grAshD5gY8kxxUoMfqrreaXVqcRF58ZPiwUJ0+SbtC5q9cJ+K' + |
| 813 | 'MuYM4TCetEuk/WQsa+1EnSa40dhGRtZjxbwEwQAJ1vLOcIA7AVR/Ck22Uj8X' + |
| 814 | 'UOECercjUrKdDyaAPcLp2TThAgMBAAGjggHZMIIB1TATBgNVHSUEDDAKBggr' + |
| 815 | 'BgEFBQcDATCBrwYDVR0RBIGnMIGkgg0qLmFwcHNwb3QuY29tggsqLmEucnVu' + |
| 816 | 'LmFwcIIVKi50aGlua3dpdGhnb29nbGUuY29tghAqLndpdGhnb29nbGUuY29t' + |
| 817 | 'ghEqLndpdGh5b3V0dWJlLmNvbYILYXBwc3BvdC5jb22CB3J1bi5hcHCCE3Ro' + |
| 818 | 'aW5rd2l0aGdvb2dsZS5jb22CDndpdGhnb29nbGUuY29tgg93aXRoeW91dHVi' + |
| 819 | 'ZS5jb20waAYIKwYBBQUHAQEEXDBaMC0GCCsGAQUFBzAChiFodHRwOi8vcGtp' + |
| 820 | 'Lmdvb2cvZ3NyMi9HVFNHSUFHMy5jcnQwKQYIKwYBBQUHMAGGHWh0dHA6Ly9v' + |
| 821 | 'Y3NwLnBraS5nb29nL0dUU0dJQUczMB0GA1UdDgQWBBTGkpE5o0H9+Wjc05rF' + |
| 822 | 'hNQiYDjBFjAMBgNVHRMBAf8EAjAAMB8GA1UdIwQYMBaAFHfCuFCaZ3Z2sS3C' + |
| 823 | 'htCDoH6mfrpLMCEGA1UdIAQaMBgwDAYKKwYBBAHWeQIFAzAIBgZngQwBAgIw' + |
| 824 | 'MQYDVR0fBCowKDAmoCSgIoYgaHR0cDovL2NybC5wa2kuZ29vZy9HVFNHSUFH' + |
| 825 | 'My5jcmwwDQYJKoZIhvcNAQELBQADggEBALqoYGqWtJW/6obEzY+ehsgfyXb+' + |
| 826 | 'qNIuV09wt95cRF93HlLbBlSZ/Iz8HXX44ZT1/tGAkwKnW0gDKSSab3I8U+e9' + |
| 827 | 'LHbC9VXrgAFENzu89MNKNmK5prwv+MPA2HUQPu4Pad3qXmd4+nKc/EUjtg1d' + |
| 828 | '/xKGK1Vn6JX3i5ly/rduowez3LxpSAJuIwseum331aQaKC2z2ri++96B8MPU' + |
| 829 | 'KFXzvV2gVGOe3ZYqmwPaG8y38Tba+OzEh59ygl8ydJJhoI6+R3itPSy0aXUU' + |
| 830 | 'lMvvAbfCobXD5kBRQ28ysgbDSDOPs3fraXpAKL92QUjsABs58XBz5vka4swu' + |
| 831 | 'gg/u+ZxaKOqfIm8=', |
| 832 | 'MIIEXDCCA0SgAwIBAgINAeOpMBz8cgY4P5pTHTANBgkqhkiG9w0BAQsFADBM' + |
| 833 | 'MSAwHgYDVQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMjETMBEGA1UEChMK' + |
| 834 | 'R2xvYmFsU2lnbjETMBEGA1UEAxMKR2xvYmFsU2lnbjAeFw0xNzA2MTUwMDAw' + |
| 835 | 'NDJaFw0yMTEyMTUwMDAwNDJaMFQxCzAJBgNVBAYTAlVTMR4wHAYDVQQKExVH' + |
| 836 | 'b29nbGUgVHJ1c3QgU2VydmljZXMxJTAjBgNVBAMTHEdvb2dsZSBJbnRlcm5l' + |
| 837 | 'dCBBdXRob3JpdHkgRzMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB' + |
| 838 | 'AQDKUkvqHv/OJGuo2nIYaNVWXQ5IWi01CXZaz6TIHLGp/lOJ+600/4hbn7vn' + |
| 839 | '6AAB3DVzdQOts7G5pH0rJnnOFUAK71G4nzKMfHCGUksW/mona+Y2emJQ2N+a' + |
| 840 | 'icwJKetPKRSIgAuPOB6Aahh8Hb2XO3h9RUk2T0HNouB2VzxoMXlkyW7XUR5m' + |
| 841 | 'w6JkLHnA52XDVoRTWkNty5oCINLvGmnRsJ1zouAqYGVQMc/7sy+/EYhALrVJ' + |
| 842 | 'EA8KbtyX+r8snwU5C1hUrwaW6MWOARa8qBpNQcWTkaIeoYvy/sGIJEmjR0vF' + |
| 843 | 'EwHdp1cSaWIr6/4g72n7OqXwfinu7ZYW97EfoOSQJeAzAgMBAAGjggEzMIIB' + |
| 844 | 'LzAOBgNVHQ8BAf8EBAMCAYYwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUF' + |
| 845 | 'BwMCMBIGA1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFHfCuFCaZ3Z2sS3C' + |
| 846 | 'htCDoH6mfrpLMB8GA1UdIwQYMBaAFJviB1dnHB7AagbeWbSaLd/cGYYuMDUG' + |
| 847 | 'CCsGAQUFBwEBBCkwJzAlBggrBgEFBQcwAYYZaHR0cDovL29jc3AucGtpLmdv' + |
| 848 | 'b2cvZ3NyMjAyBgNVHR8EKzApMCegJaAjhiFodHRwOi8vY3JsLnBraS5nb29n' + |
| 849 | 'L2dzcjIvZ3NyMi5jcmwwPwYDVR0gBDgwNjA0BgZngQwBAgIwKjAoBggrBgEF' + |
| 850 | 'BQcCARYcaHR0cHM6Ly9wa2kuZ29vZy9yZXBvc2l0b3J5LzANBgkqhkiG9w0B' + |
| 851 | 'AQsFAAOCAQEAHLeJluRT7bvs26gyAZ8so81trUISd7O45skDUmAge1cnxhG1' + |
| 852 | 'P2cNmSxbWsoiCt2eux9LSD+PAj2LIYRFHW31/6xoic1k4tbWXkDCjir37xTT' + |
| 853 | 'NqRAMPUyFRWSdvt+nlPqwnb8Oa2I/maSJukcxDjNSfpDh/Bd1lZNgdd/8cLd' + |
| 854 | 'sE3+wypufJ9uXO1iQpnh9zbuFIwsIONGl1p3A8CgxkqI/UAih3JaGOqcpcda' + |
| 855 | 'CIzkBaR9uYQ1X4k2Vg5APRLouzVy7a8IVk6wuy6pm+T7HT4LY8ibS5FEZlfA' + |
| 856 | 'FLSW8NwsVz9SBK2Vqn1N0PIMn5xA6NZVc7o835DLAFshEWfC7TIe3g==', |
| 857 | 'MIIDujCCAqKgAwIBAgILBAAAAAABD4Ym5g0wDQYJKoZIhvcNAQEFBQAwTDEg' + |
| 858 | 'MB4GA1UECxMXR2xvYmFsU2lnbiBSb290IENBIC0gUjIxEzARBgNVBAoTCkds' + |
| 859 | 'b2JhbFNpZ24xEzARBgNVBAMTCkdsb2JhbFNpZ24wHhcNMDYxMjE1MDgwMDAw' + |
| 860 | 'WhcNMjExMjE1MDgwMDAwWjBMMSAwHgYDVQQLExdHbG9iYWxTaWduIFJvb3Qg' + |
| 861 | 'Q0EgLSBSMjETMBEGA1UEChMKR2xvYmFsU2lnbjETMBEGA1UEAxMKR2xvYmFs' + |
| 862 | 'U2lnbjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKbPJA6+Lm8o' + |
| 863 | 'mUVCxKs+IVSbC9N/hHD6ErPLv4dfxn+G07IwXNb9rfF73OX4YJYJkhD10FPe' + |
| 864 | '+3t+c4isUoh7SqbKSaZeqKeMWhG8eoLrvozps6yWJQeXSpkqBy+0Hne/ig+1' + |
| 865 | 'AnwblrjFuTosvNYSuetZfeLQBoZfXklqtTleiDTsvHgMCJiEbKjNS7SgfQx5' + |
| 866 | 'TfC4LcshytVsW33hoCmEofnTlEnLJGKRILzdC9XZzPnqJworc5HGnRusyMvo' + |
| 867 | '4KD0L5CLTfuwNhv2GXqF4G3yYROIXJ/gkwpRl4pazq+r1feqCapgvdzZX99y' + |
| 868 | 'qWATXgAByUr6P6TqBwMhAo6CygPCm48CAwEAAaOBnDCBmTAOBgNVHQ8BAf8E' + |
| 869 | 'BAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUm+IHV2ccHsBqBt5Z' + |
| 870 | 'tJot39wZhi4wNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovL2NybC5nbG9iYWxz' + |
| 871 | 'aWduLm5ldC9yb290LXIyLmNybDAfBgNVHSMEGDAWgBSb4gdXZxwewGoG3lm0' + |
| 872 | 'mi3f3BmGLjANBgkqhkiG9w0BAQUFAAOCAQEAmYFThxxol4aR7OBKuEQLq4Gs' + |
| 873 | 'J0/WwbgcQ3izDJr86iw8bmEbTUsp9Z8FHSbBuOmDAGJFtqkIk7mpM0sYmsL4' + |
| 874 | 'h4hO291xNBrBVNpGP+DTKqttVCL1OmLNIG+6KYnX3ZHu01yiPqFbQfXf5WRD' + |
| 875 | 'LenVOavSot+3i9DAgBkcRcAtjOj4LaR0VknFBbVPFd5uRHg5h6h+u/N5GJG7' + |
| 876 | '9G+dwfCMNYxdAfvDbbnvRG15RjF+Cv6pgsH/76tuIMRQyV+dTZsXjAzlAcmg' + |
| 877 | 'QWpzU/qlULRuJQ/7TBj0/VLZjmmx6BEP3ojY+x1J96relc8geMJgEtslQIxq' + |
| 878 | '/H5COEBkEveegeGTLg==' |
| 879 | ]); |
| 880 | }; |
| 881 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 882 | // Simple sanity check to make sure network throttling is wired up |
| 883 | // See crbug.com/747724 |
| 884 | TestSuite.prototype.testOfflineNetworkConditions = async function() { |
| 885 | const test = this; |
Paul Lewis | 5a922e7 | 2020-01-24 11:58:08 | [diff] [blame] | 886 | self.SDK.multitargetNetworkManager.setNetworkConditions(SDK.NetworkManager.OfflineConditions); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 887 | |
| 888 | function finishRequest(request) { |
| 889 | test.assertEquals( |
| 890 | 'net::ERR_INTERNET_DISCONNECTED', request.localizedFailDescription, 'Request should have failed'); |
| 891 | test.releaseControl(); |
| 892 | } |
| 893 | |
| 894 | this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', finishRequest); |
| 895 | |
| 896 | test.takeControl(); |
| 897 | test.evaluateInConsole_('window.location.reload(true);', function(resultText) {}); |
| 898 | }; |
| 899 | |
| 900 | TestSuite.prototype.testEmulateNetworkConditions = function() { |
| 901 | const test = this; |
| 902 | |
| 903 | function testPreset(preset, messages, next) { |
| 904 | function onConsoleMessage(event) { |
| 905 | const index = messages.indexOf(event.data.messageText); |
| 906 | if (index === -1) { |
| 907 | test.fail('Unexpected message: ' + event.data.messageText); |
| 908 | return; |
| 909 | } |
| 910 | |
| 911 | messages.splice(index, 1); |
| 912 | if (!messages.length) { |
Paul Lewis | e504fd6 | 2020-01-23 16:52:33 | [diff] [blame] | 913 | self.SDK.consoleModel.removeEventListener(SDK.ConsoleModel.Events.MessageAdded, onConsoleMessage, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 914 | next(); |
| 915 | } |
| 916 | } |
| 917 | |
Paul Lewis | e504fd6 | 2020-01-23 16:52:33 | [diff] [blame] | 918 | self.SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.MessageAdded, onConsoleMessage, this); |
Paul Lewis | 5a922e7 | 2020-01-24 11:58:08 | [diff] [blame] | 919 | self.SDK.multitargetNetworkManager.setNetworkConditions(preset); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | test.takeControl(); |
| 923 | step1(); |
| 924 | |
| 925 | function step1() { |
| 926 | testPreset( |
| 927 | MobileThrottling.networkPresets[2], |
| 928 | [ |
| 929 | 'offline event: online = false', 'connection change event: type = none; downlinkMax = 0; effectiveType = 4g' |
| 930 | ], |
| 931 | step2); |
| 932 | } |
| 933 | |
| 934 | function step2() { |
| 935 | testPreset( |
| 936 | MobileThrottling.networkPresets[1], |
| 937 | [ |
| 938 | 'online event: online = true', |
Wolfgang Beyer | 585ded4 | 2020-02-25 08:42:41 | [diff] [blame] | 939 | 'connection change event: type = cellular; downlinkMax = 0.390625; effectiveType = 2g' |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 940 | ], |
| 941 | step3); |
| 942 | } |
| 943 | |
| 944 | function step3() { |
| 945 | testPreset( |
| 946 | MobileThrottling.networkPresets[0], |
Wolfgang Beyer | 585ded4 | 2020-02-25 08:42:41 | [diff] [blame] | 947 | ['connection change event: type = cellular; downlinkMax = 1.4400000000000002; effectiveType = 3g'], |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 948 | test.releaseControl.bind(test)); |
| 949 | } |
| 950 | }; |
| 951 | |
| 952 | TestSuite.prototype.testScreenshotRecording = function() { |
| 953 | const test = this; |
| 954 | |
| 955 | function performActionsInPage(callback) { |
| 956 | let count = 0; |
| 957 | const div = document.createElement('div'); |
| 958 | div.setAttribute('style', 'left: 0px; top: 0px; width: 100px; height: 100px; position: absolute;'); |
| 959 | document.body.appendChild(div); |
| 960 | requestAnimationFrame(frame); |
| 961 | function frame() { |
| 962 | const color = [0, 0, 0]; |
| 963 | color[count % 3] = 255; |
| 964 | div.style.backgroundColor = 'rgb(' + color.join(',') + ')'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 965 | if (++count > 10) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 966 | requestAnimationFrame(callback); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 967 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 968 | requestAnimationFrame(frame); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 969 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 973 | const captureFilmStripSetting = self.Common.settings.createSetting('timelineCaptureFilmStrip', false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 974 | captureFilmStripSetting.set(true); |
| 975 | test.evaluateInConsole_(performActionsInPage.toString(), function() {}); |
| 976 | test.invokeAsyncWithTimeline_('performActionsInPage', onTimelineDone); |
| 977 | |
| 978 | function onTimelineDone() { |
| 979 | captureFilmStripSetting.set(false); |
| 980 | const filmStripModel = UI.panels.timeline._performanceModel.filmStripModel(); |
| 981 | const frames = filmStripModel.frames(); |
| 982 | test.assertTrue(frames.length > 4 && typeof frames.length === 'number'); |
| 983 | loadFrameImages(frames); |
| 984 | } |
| 985 | |
| 986 | function loadFrameImages(frames) { |
| 987 | const readyImages = []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 988 | for (const frame of frames) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 989 | frame.imageDataPromise().then(onGotImageData); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 990 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 991 | |
| 992 | function onGotImageData(data) { |
| 993 | const image = new Image(); |
| 994 | test.assertTrue(!!data, 'No image data for frame'); |
| 995 | image.addEventListener('load', onLoad); |
| 996 | image.src = 'data:image/jpg;base64,' + data; |
| 997 | } |
| 998 | |
| 999 | function onLoad(event) { |
| 1000 | readyImages.push(event.target); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1001 | if (readyImages.length === frames.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1002 | validateImagesAndCompleteTest(readyImages); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1003 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | function validateImagesAndCompleteTest(images) { |
| 1008 | let redCount = 0; |
| 1009 | let greenCount = 0; |
| 1010 | let blueCount = 0; |
| 1011 | |
| 1012 | const canvas = document.createElement('canvas'); |
| 1013 | const ctx = canvas.getContext('2d'); |
| 1014 | for (const image of images) { |
| 1015 | test.assertTrue(image.naturalWidth > 10); |
| 1016 | test.assertTrue(image.naturalHeight > 10); |
| 1017 | canvas.width = image.naturalWidth; |
| 1018 | canvas.height = image.naturalHeight; |
| 1019 | ctx.drawImage(image, 0, 0); |
| 1020 | const data = ctx.getImageData(0, 0, 1, 1); |
| 1021 | const color = Array.prototype.join.call(data.data, ','); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1022 | if (data.data[0] > 200) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1023 | redCount++; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1024 | } else if (data.data[1] > 200) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1025 | greenCount++; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1026 | } else if (data.data[2] > 200) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1027 | blueCount++; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1028 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1029 | test.fail('Unexpected color: ' + color); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1030 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1031 | } |
| 1032 | test.assertTrue(redCount && greenCount && blueCount, 'Color sanity check failed'); |
| 1033 | test.releaseControl(); |
| 1034 | } |
| 1035 | |
| 1036 | test.takeControl(); |
| 1037 | }; |
| 1038 | |
| 1039 | TestSuite.prototype.testSettings = function() { |
| 1040 | const test = this; |
| 1041 | |
| 1042 | createSettings(); |
| 1043 | test.takeControl(); |
| 1044 | setTimeout(reset, 0); |
| 1045 | |
| 1046 | function createSettings() { |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 1047 | const localSetting = self.Common.settings.createLocalSetting('local', undefined); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1048 | localSetting.set({s: 'local', n: 1}); |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 1049 | const globalSetting = self.Common.settings.createSetting('global', undefined); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1050 | globalSetting.set({s: 'global', n: 2}); |
| 1051 | } |
| 1052 | |
| 1053 | function reset() { |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 1054 | Root.Runtime.experiments.clearForTest(); |
Tim van der Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 1055 | Host.InspectorFrontendHost.getPreferences(gotPreferences); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | function gotPreferences(prefs) { |
| 1059 | Main.Main._instanceForTest._createSettings(prefs); |
| 1060 | |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 1061 | const localSetting = self.Common.settings.createLocalSetting('local', undefined); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1062 | test.assertEquals('object', typeof localSetting.get()); |
| 1063 | test.assertEquals('local', localSetting.get().s); |
| 1064 | test.assertEquals(1, localSetting.get().n); |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 1065 | const globalSetting = self.Common.settings.createSetting('global', undefined); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1066 | test.assertEquals('object', typeof globalSetting.get()); |
| 1067 | test.assertEquals('global', globalSetting.get().s); |
| 1068 | test.assertEquals(2, globalSetting.get().n); |
| 1069 | test.releaseControl(); |
| 1070 | } |
| 1071 | }; |
| 1072 | |
| 1073 | TestSuite.prototype.testWindowInitializedOnNavigateBack = function() { |
| 1074 | const test = this; |
| 1075 | test.takeControl(); |
Paul Lewis | e504fd6 | 2020-01-23 16:52:33 | [diff] [blame] | 1076 | const messages = self.SDK.consoleModel.messages(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1077 | if (messages.length === 1) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1078 | checkMessages(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1079 | } else { |
Paul Lewis | e504fd6 | 2020-01-23 16:52:33 | [diff] [blame] | 1080 | self.SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.MessageAdded, checkMessages.bind(this), this); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1081 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1082 | |
| 1083 | function checkMessages() { |
Paul Lewis | e504fd6 | 2020-01-23 16:52:33 | [diff] [blame] | 1084 | const messages = self.SDK.consoleModel.messages(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1085 | test.assertEquals(1, messages.length); |
| 1086 | test.assertTrue(messages[0].messageText.indexOf('Uncaught') === -1); |
| 1087 | test.releaseControl(); |
| 1088 | } |
| 1089 | }; |
| 1090 | |
| 1091 | TestSuite.prototype.testConsoleContextNames = function() { |
| 1092 | const test = this; |
| 1093 | test.takeControl(); |
| 1094 | this.showPanel('console').then(() => this._waitForExecutionContexts(2, onExecutionContexts.bind(this))); |
| 1095 | |
| 1096 | function onExecutionContexts() { |
| 1097 | const consoleView = Console.ConsoleView.instance(); |
| 1098 | const selector = consoleView._consoleContextSelector; |
| 1099 | const values = []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1100 | for (const item of selector._items) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1101 | values.push(selector.titleFor(item)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1102 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1103 | test.assertEquals('top', values[0]); |
| 1104 | test.assertEquals('Simple content script', values[1]); |
| 1105 | test.releaseControl(); |
| 1106 | } |
| 1107 | }; |
| 1108 | |
| 1109 | TestSuite.prototype.testRawHeadersWithHSTS = function(url) { |
| 1110 | const test = this; |
| 1111 | test.takeControl(); |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1112 | self.SDK.targetManager.addModelListener( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1113 | SDK.NetworkManager, SDK.NetworkManager.Events.ResponseReceived, onResponseReceived); |
| 1114 | |
| 1115 | this.evaluateInConsole_(` |
| 1116 | let img = document.createElement('img'); |
| 1117 | img.src = "${url}"; |
| 1118 | document.body.appendChild(img); |
| 1119 | `, () => {}); |
| 1120 | |
| 1121 | let count = 0; |
| 1122 | function onResponseReceived(event) { |
| 1123 | const networkRequest = event.data; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1124 | if (!networkRequest.url().startsWith('http')) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1125 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1126 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1127 | switch (++count) { |
| 1128 | case 1: // Original redirect |
| 1129 | test.assertEquals(301, networkRequest.statusCode); |
| 1130 | test.assertEquals('Moved Permanently', networkRequest.statusText); |
| 1131 | test.assertTrue(url.endsWith(networkRequest.responseHeaderValue('Location'))); |
| 1132 | break; |
| 1133 | |
| 1134 | case 2: // HSTS internal redirect |
| 1135 | test.assertTrue(networkRequest.url().startsWith('http://')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1136 | test.assertEquals(307, networkRequest.statusCode); |
| 1137 | test.assertEquals('Internal Redirect', networkRequest.statusText); |
| 1138 | test.assertEquals('HSTS', networkRequest.responseHeaderValue('Non-Authoritative-Reason')); |
| 1139 | test.assertTrue(networkRequest.responseHeaderValue('Location').startsWith('https://')); |
| 1140 | break; |
| 1141 | |
| 1142 | case 3: // Final response |
| 1143 | test.assertTrue(networkRequest.url().startsWith('https://')); |
| 1144 | test.assertTrue(networkRequest.requestHeaderValue('Referer').startsWith('http://127.0.0.1')); |
| 1145 | test.assertEquals(200, networkRequest.statusCode); |
| 1146 | test.assertEquals('OK', networkRequest.statusText); |
| 1147 | test.assertEquals('132', networkRequest.responseHeaderValue('Content-Length')); |
| 1148 | test.releaseControl(); |
| 1149 | } |
| 1150 | } |
| 1151 | }; |
| 1152 | |
| 1153 | TestSuite.prototype.testDOMWarnings = function() { |
Paul Lewis | e504fd6 | 2020-01-23 16:52:33 | [diff] [blame] | 1154 | const messages = self.SDK.consoleModel.messages(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1155 | this.assertEquals(1, messages.length); |
| 1156 | const expectedPrefix = '[DOM] Found 2 elements with non-unique id #dup:'; |
| 1157 | this.assertTrue(messages[0].messageText.startsWith(expectedPrefix)); |
| 1158 | }; |
| 1159 | |
| 1160 | TestSuite.prototype.waitForTestResultsInConsole = function() { |
Paul Lewis | e504fd6 | 2020-01-23 16:52:33 | [diff] [blame] | 1161 | const messages = self.SDK.consoleModel.messages(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1162 | for (let i = 0; i < messages.length; ++i) { |
| 1163 | const text = messages[i].messageText; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1164 | if (text === 'PASS') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1165 | return; |
Mathias Bynens | f06e8c0 | 2020-02-28 13:58:28 | [diff] [blame] | 1166 | } |
| 1167 | if (/^FAIL/.test(text)) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1168 | this.fail(text); |
| 1169 | } // This will throw. |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1170 | } |
| 1171 | // Neither PASS nor FAIL, so wait for more messages. |
| 1172 | function onConsoleMessage(event) { |
| 1173 | const text = event.data.messageText; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1174 | if (text === 'PASS') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1175 | this.releaseControl(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1176 | } else if (/^FAIL/.test(text)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1177 | this.fail(text); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1178 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1179 | } |
| 1180 | |
Paul Lewis | e504fd6 | 2020-01-23 16:52:33 | [diff] [blame] | 1181 | self.SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.MessageAdded, onConsoleMessage, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1182 | this.takeControl(); |
| 1183 | }; |
| 1184 | |
Andrey Kosyakov | a08cb9b | 2020-04-01 21:49:52 | [diff] [blame] | 1185 | TestSuite.prototype.waitForTestResultsAsMessage = function() { |
| 1186 | const onMessage = event => { |
| 1187 | if (!event.data.testOutput) { |
| 1188 | return; |
| 1189 | } |
| 1190 | top.removeEventListener('message', onMessage); |
| 1191 | const text = event.data.testOutput; |
| 1192 | if (text === 'PASS') { |
| 1193 | this.releaseControl(); |
| 1194 | } else { |
| 1195 | this.fail(text); |
| 1196 | } |
| 1197 | }; |
| 1198 | top.addEventListener('message', onMessage); |
| 1199 | this.takeControl(); |
| 1200 | }; |
| 1201 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1202 | TestSuite.prototype._overrideMethod = function(receiver, methodName, override) { |
| 1203 | const original = receiver[methodName]; |
| 1204 | if (typeof original !== 'function') { |
Mathias Bynens | 23ee1aa | 2020-03-02 12:06:38 | [diff] [blame] | 1205 | this.fail(`TestSuite._overrideMethod: ${methodName} is not a function`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1206 | return; |
| 1207 | } |
| 1208 | receiver[methodName] = function() { |
| 1209 | let value; |
| 1210 | try { |
| 1211 | value = original.apply(receiver, arguments); |
| 1212 | } finally { |
| 1213 | receiver[methodName] = original; |
| 1214 | } |
| 1215 | override.apply(original, arguments); |
| 1216 | return value; |
| 1217 | }; |
| 1218 | }; |
| 1219 | |
| 1220 | TestSuite.prototype.startTimeline = function(callback) { |
| 1221 | const test = this; |
| 1222 | this.showPanel('timeline').then(function() { |
| 1223 | const timeline = UI.panels.timeline; |
| 1224 | test._overrideMethod(timeline, '_recordingStarted', callback); |
| 1225 | timeline._toggleRecording(); |
| 1226 | }); |
| 1227 | }; |
| 1228 | |
| 1229 | TestSuite.prototype.stopTimeline = function(callback) { |
| 1230 | const timeline = UI.panels.timeline; |
| 1231 | this._overrideMethod(timeline, 'loadingComplete', callback); |
| 1232 | timeline._toggleRecording(); |
| 1233 | }; |
| 1234 | |
| 1235 | TestSuite.prototype.invokePageFunctionAsync = function(functionName, opt_args, callback_is_always_last) { |
| 1236 | const callback = arguments[arguments.length - 1]; |
| 1237 | const doneMessage = `DONE: ${functionName}.${++this._asyncInvocationId}`; |
| 1238 | const argsString = arguments.length < 3 ? |
| 1239 | '' : |
| 1240 | Array.prototype.slice.call(arguments, 1, -1).map(arg => JSON.stringify(arg)).join(',') + ','; |
| 1241 | this.evaluateInConsole_( |
| 1242 | `${functionName}(${argsString} function() { console.log('${doneMessage}'); });`, function() {}); |
Paul Lewis | e504fd6 | 2020-01-23 16:52:33 | [diff] [blame] | 1243 | self.SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.MessageAdded, onConsoleMessage); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1244 | |
| 1245 | function onConsoleMessage(event) { |
| 1246 | const text = event.data.messageText; |
| 1247 | if (text === doneMessage) { |
Paul Lewis | e504fd6 | 2020-01-23 16:52:33 | [diff] [blame] | 1248 | self.SDK.consoleModel.removeEventListener(SDK.ConsoleModel.Events.MessageAdded, onConsoleMessage); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1249 | callback(); |
| 1250 | } |
| 1251 | } |
| 1252 | }; |
| 1253 | |
| 1254 | TestSuite.prototype.invokeAsyncWithTimeline_ = function(functionName, callback) { |
| 1255 | const test = this; |
| 1256 | |
| 1257 | this.startTimeline(onRecordingStarted); |
| 1258 | |
| 1259 | function onRecordingStarted() { |
| 1260 | test.invokePageFunctionAsync(functionName, pageActionsDone); |
| 1261 | } |
| 1262 | |
| 1263 | function pageActionsDone() { |
| 1264 | test.stopTimeline(callback); |
| 1265 | } |
| 1266 | }; |
| 1267 | |
| 1268 | TestSuite.prototype.enableExperiment = function(name) { |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 1269 | Root.Runtime.experiments.enableForTest(name); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1270 | }; |
| 1271 | |
| 1272 | TestSuite.prototype.checkInputEventsPresent = function() { |
| 1273 | const expectedEvents = new Set(arguments); |
| 1274 | const model = UI.panels.timeline._performanceModel.timelineModel(); |
| 1275 | const asyncEvents = model.virtualThreads().find(thread => thread.isMainFrame).asyncEventsByGroup; |
| 1276 | const input = asyncEvents.get(TimelineModel.TimelineModel.AsyncEventGroup.input) || []; |
| 1277 | const prefix = 'InputLatency::'; |
| 1278 | for (const e of input) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1279 | if (!e.name.startsWith(prefix)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1280 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1281 | } |
| 1282 | if (e.steps.length < 2) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1283 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1284 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1285 | if (e.name.startsWith(prefix + 'Mouse') && |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1286 | typeof TimelineModel.TimelineData.forEvent(e.steps[0]).timeWaitingForMainThread !== 'number') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1287 | throw `Missing timeWaitingForMainThread on ${e.name}`; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1288 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1289 | expectedEvents.delete(e.name.substr(prefix.length)); |
| 1290 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1291 | if (expectedEvents.size) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1292 | throw 'Some expected events are not found: ' + Array.from(expectedEvents.keys()).join(','); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1293 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1294 | }; |
| 1295 | |
| 1296 | TestSuite.prototype.testInspectedElementIs = async function(nodeName) { |
| 1297 | this.takeControl(); |
| 1298 | await self.runtime.loadModulePromise('elements'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1299 | if (!Elements.ElementsPanel._firstInspectElementNodeNameForTest) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1300 | await new Promise(f => this.addSniffer(Elements.ElementsPanel, '_firstInspectElementCompletedForTest', f)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1301 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1302 | this.assertEquals(nodeName, Elements.ElementsPanel._firstInspectElementNodeNameForTest); |
| 1303 | this.releaseControl(); |
| 1304 | }; |
| 1305 | |
Andrey Lushnikov | d92662b | 2018-05-09 03:57:00 | [diff] [blame] | 1306 | TestSuite.prototype.testDisposeEmptyBrowserContext = async function(url) { |
| 1307 | this.takeControl(); |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1308 | const targetAgent = self.SDK.targetManager.mainTarget().targetAgent(); |
Andrey Lushnikov | d92662b | 2018-05-09 03:57:00 | [diff] [blame] | 1309 | const {browserContextId} = await targetAgent.invoke_createBrowserContext(); |
| 1310 | const response1 = await targetAgent.invoke_getBrowserContexts(); |
| 1311 | this.assertEquals(response1.browserContextIds.length, 1); |
| 1312 | await targetAgent.invoke_disposeBrowserContext({browserContextId}); |
| 1313 | const response2 = await targetAgent.invoke_getBrowserContexts(); |
| 1314 | this.assertEquals(response2.browserContextIds.length, 0); |
| 1315 | this.releaseControl(); |
| 1316 | }; |
| 1317 | |
Peter Marshall | d2f58c3 | 2020-04-21 13:23:13 | [diff] [blame] | 1318 | TestSuite.prototype.testNewWindowFromBrowserContext = async function(url) { |
| 1319 | this.takeControl(); |
| 1320 | // Create a BrowserContext. |
| 1321 | const targetAgent = self.SDK.targetManager.mainTarget().targetAgent(); |
| 1322 | const {browserContextId} = await targetAgent.invoke_createBrowserContext(); |
| 1323 | |
| 1324 | // Cause a Browser to be created with the temp profile. |
| 1325 | const {targetId} = |
| 1326 | await targetAgent.invoke_createTarget({url: 'data:text/html,', browserContextId, newWindow: true}); |
| 1327 | await targetAgent.invoke_attachToTarget({targetId, flatten: true}); |
| 1328 | |
| 1329 | // Destroy the temp profile. |
| 1330 | await targetAgent.invoke_disposeBrowserContext({browserContextId}); |
| 1331 | |
| 1332 | this.releaseControl(); |
| 1333 | }; |
| 1334 | |
Andrey Lushnikov | 0eea25e | 2018-04-24 22:29:51 | [diff] [blame] | 1335 | TestSuite.prototype.testCreateBrowserContext = async function(url) { |
| 1336 | this.takeControl(); |
| 1337 | const browserContextIds = []; |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1338 | const targetAgent = self.SDK.targetManager.mainTarget().targetAgent(); |
Andrey Lushnikov | 0eea25e | 2018-04-24 22:29:51 | [diff] [blame] | 1339 | |
| 1340 | const target1 = await createIsolatedTarget(url); |
| 1341 | const target2 = await createIsolatedTarget(url); |
| 1342 | |
Andrey Lushnikov | 07477b4 | 2018-05-08 22:00:52 | [diff] [blame] | 1343 | const response = await targetAgent.invoke_getBrowserContexts(); |
| 1344 | this.assertEquals(response.browserContextIds.length, 2); |
| 1345 | this.assertTrue(response.browserContextIds.includes(browserContextIds[0])); |
| 1346 | this.assertTrue(response.browserContextIds.includes(browserContextIds[1])); |
| 1347 | |
Andrey Lushnikov | 0eea25e | 2018-04-24 22:29:51 | [diff] [blame] | 1348 | await evalCode(target1, 'localStorage.setItem("page1", "page1")'); |
| 1349 | await evalCode(target2, 'localStorage.setItem("page2", "page2")'); |
| 1350 | |
| 1351 | this.assertEquals(await evalCode(target1, 'localStorage.getItem("page1")'), 'page1'); |
| 1352 | this.assertEquals(await evalCode(target1, 'localStorage.getItem("page2")'), null); |
| 1353 | this.assertEquals(await evalCode(target2, 'localStorage.getItem("page1")'), null); |
| 1354 | this.assertEquals(await evalCode(target2, 'localStorage.getItem("page2")'), 'page2'); |
| 1355 | |
Andrey Lushnikov | 6949970 | 2018-05-08 18:20:47 | [diff] [blame] | 1356 | const removedTargets = []; |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1357 | self.SDK.targetManager.observeTargets( |
| 1358 | {targetAdded: () => {}, targetRemoved: target => removedTargets.push(target)}); |
Andrey Lushnikov | 6949970 | 2018-05-08 18:20:47 | [diff] [blame] | 1359 | await Promise.all([disposeBrowserContext(browserContextIds[0]), disposeBrowserContext(browserContextIds[1])]); |
| 1360 | this.assertEquals(removedTargets.length, 2); |
| 1361 | this.assertEquals(removedTargets.indexOf(target1) !== -1, true); |
| 1362 | this.assertEquals(removedTargets.indexOf(target2) !== -1, true); |
Andrey Lushnikov | 0eea25e | 2018-04-24 22:29:51 | [diff] [blame] | 1363 | |
| 1364 | this.releaseControl(); |
| 1365 | |
| 1366 | /** |
| 1367 | * @param {string} url |
| 1368 | * @return {!Promise<!SDK.Target>} |
| 1369 | */ |
| 1370 | async function createIsolatedTarget(url) { |
Andrey Lushnikov | 0eea25e | 2018-04-24 22:29:51 | [diff] [blame] | 1371 | const {browserContextId} = await targetAgent.invoke_createBrowserContext(); |
| 1372 | browserContextIds.push(browserContextId); |
| 1373 | |
| 1374 | const {targetId} = await targetAgent.invoke_createTarget({url: 'about:blank', browserContextId}); |
Dmitry Gozman | 99d7a6c | 2018-11-12 17:55:11 | [diff] [blame] | 1375 | await targetAgent.invoke_attachToTarget({targetId, flatten: true}); |
Andrey Lushnikov | 0eea25e | 2018-04-24 22:29:51 | [diff] [blame] | 1376 | |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1377 | const target = self.SDK.targetManager.targets().find(target => target.id() === targetId); |
Andrey Lushnikov | 0eea25e | 2018-04-24 22:29:51 | [diff] [blame] | 1378 | const pageAgent = target.pageAgent(); |
| 1379 | await pageAgent.invoke_enable(); |
| 1380 | await pageAgent.invoke_navigate({url}); |
| 1381 | return target; |
| 1382 | } |
| 1383 | |
Andrey Lushnikov | 0eea25e | 2018-04-24 22:29:51 | [diff] [blame] | 1384 | async function disposeBrowserContext(browserContextId) { |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1385 | const targetAgent = self.SDK.targetManager.mainTarget().targetAgent(); |
Andrey Lushnikov | 6949970 | 2018-05-08 18:20:47 | [diff] [blame] | 1386 | await targetAgent.invoke_disposeBrowserContext({browserContextId}); |
Andrey Lushnikov | 0eea25e | 2018-04-24 22:29:51 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | async function evalCode(target, code) { |
| 1390 | return (await target.runtimeAgent().invoke_evaluate({expression: code})).result.value; |
| 1391 | } |
| 1392 | }; |
| 1393 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1394 | TestSuite.prototype.testInputDispatchEventsToOOPIF = async function() { |
| 1395 | this.takeControl(); |
| 1396 | |
| 1397 | await new Promise(callback => this._waitForTargets(2, callback)); |
| 1398 | |
| 1399 | async function takeLogs(target) { |
| 1400 | const code = ` |
| 1401 | (function() { |
| 1402 | var result = window.logs.join(' '); |
| 1403 | window.logs = []; |
| 1404 | return result; |
| 1405 | })() |
| 1406 | `; |
| 1407 | return (await target.runtimeAgent().invoke_evaluate({expression: code})).result.value; |
| 1408 | } |
| 1409 | |
| 1410 | let parentFrameOutput; |
| 1411 | let childFrameOutput; |
| 1412 | |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1413 | const inputAgent = self.SDK.targetManager.mainTarget().inputAgent(); |
| 1414 | const runtimeAgent = self.SDK.targetManager.mainTarget().runtimeAgent(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1415 | await inputAgent.invoke_dispatchMouseEvent({type: 'mousePressed', button: 'left', clickCount: 1, x: 10, y: 10}); |
| 1416 | await inputAgent.invoke_dispatchMouseEvent({type: 'mouseMoved', button: 'left', clickCount: 1, x: 10, y: 20}); |
| 1417 | await inputAgent.invoke_dispatchMouseEvent({type: 'mouseReleased', button: 'left', clickCount: 1, x: 10, y: 20}); |
| 1418 | await inputAgent.invoke_dispatchMouseEvent({type: 'mousePressed', button: 'left', clickCount: 1, x: 230, y: 140}); |
| 1419 | await inputAgent.invoke_dispatchMouseEvent({type: 'mouseMoved', button: 'left', clickCount: 1, x: 230, y: 150}); |
| 1420 | await inputAgent.invoke_dispatchMouseEvent({type: 'mouseReleased', button: 'left', clickCount: 1, x: 230, y: 150}); |
| 1421 | parentFrameOutput = 'Event type: mousedown button: 0 x: 10 y: 10 Event type: mouseup button: 0 x: 10 y: 20'; |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1422 | this.assertEquals(parentFrameOutput, await takeLogs(self.SDK.targetManager.targets()[0])); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1423 | childFrameOutput = 'Event type: mousedown button: 0 x: 30 y: 40 Event type: mouseup button: 0 x: 30 y: 50'; |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1424 | this.assertEquals(childFrameOutput, await takeLogs(self.SDK.targetManager.targets()[1])); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1425 | |
| 1426 | |
| 1427 | await inputAgent.invoke_dispatchKeyEvent({type: 'keyDown', key: 'a'}); |
Mathias Bynens | 23ee1aa | 2020-03-02 12:06:38 | [diff] [blame] | 1428 | await runtimeAgent.invoke_evaluate({expression: "document.querySelector('iframe').focus()"}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1429 | await inputAgent.invoke_dispatchKeyEvent({type: 'keyDown', key: 'a'}); |
| 1430 | parentFrameOutput = 'Event type: keydown'; |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1431 | this.assertEquals(parentFrameOutput, await takeLogs(self.SDK.targetManager.targets()[0])); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1432 | childFrameOutput = 'Event type: keydown'; |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1433 | this.assertEquals(childFrameOutput, await takeLogs(self.SDK.targetManager.targets()[1])); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1434 | |
| 1435 | await inputAgent.invoke_dispatchTouchEvent({type: 'touchStart', touchPoints: [{x: 10, y: 10}]}); |
| 1436 | await inputAgent.invoke_dispatchTouchEvent({type: 'touchEnd', touchPoints: []}); |
| 1437 | await inputAgent.invoke_dispatchTouchEvent({type: 'touchStart', touchPoints: [{x: 230, y: 140}]}); |
| 1438 | await inputAgent.invoke_dispatchTouchEvent({type: 'touchEnd', touchPoints: []}); |
| 1439 | parentFrameOutput = 'Event type: touchstart touch x: 10 touch y: 10'; |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1440 | this.assertEquals(parentFrameOutput, await takeLogs(self.SDK.targetManager.targets()[0])); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1441 | childFrameOutput = 'Event type: touchstart touch x: 30 touch y: 40'; |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1442 | this.assertEquals(childFrameOutput, await takeLogs(self.SDK.targetManager.targets()[1])); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1443 | |
| 1444 | this.releaseControl(); |
| 1445 | }; |
| 1446 | |
Andrey Kosyakov | 4f7fb05 | 2019-03-19 15:53:43 | [diff] [blame] | 1447 | TestSuite.prototype.testLoadResourceForFrontend = async function(baseURL, fileURL) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1448 | const test = this; |
| 1449 | const loggedHeaders = new Set(['cache-control', 'pragma']); |
| 1450 | function testCase(url, headers, expectedStatus, expectedHeaders, expectedContent) { |
| 1451 | return new Promise(fulfill => { |
| 1452 | Host.ResourceLoader.load(url, headers, callback); |
| 1453 | |
Sigurd Schneider | a327cde | 2020-01-21 15:48:12 | [diff] [blame] | 1454 | function callback(success, headers, content, errorDescription) { |
| 1455 | test.assertEquals(expectedStatus, errorDescription.statusCode); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1456 | |
| 1457 | const headersArray = []; |
| 1458 | for (const name in headers) { |
| 1459 | const nameLower = name.toLowerCase(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1460 | if (loggedHeaders.has(nameLower)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1461 | headersArray.push(nameLower); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1462 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1463 | } |
| 1464 | headersArray.sort(); |
| 1465 | test.assertEquals(expectedHeaders.join(', '), headersArray.join(', ')); |
| 1466 | test.assertEquals(expectedContent, content); |
| 1467 | fulfill(); |
| 1468 | } |
| 1469 | }); |
| 1470 | } |
| 1471 | |
| 1472 | this.takeControl(); |
| 1473 | await testCase(baseURL + 'non-existent.html', undefined, 404, [], ''); |
| 1474 | await testCase(baseURL + 'hello.html', undefined, 200, [], '<!doctype html>\n<p>hello</p>\n'); |
| 1475 | await testCase(baseURL + 'echoheader?x-devtools-test', {'x-devtools-test': 'Foo'}, 200, ['cache-control'], 'Foo'); |
| 1476 | await testCase(baseURL + 'set-header?pragma:%20no-cache', undefined, 200, ['pragma'], 'pragma: no-cache'); |
| 1477 | |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1478 | await self.SDK.targetManager.mainTarget().runtimeAgent().invoke_evaluate({ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1479 | expression: `fetch("/set-cookie?devtools-test-cookie=Bar", |
| 1480 | {credentials: 'include'})`, |
| 1481 | awaitPromise: true |
| 1482 | }); |
| 1483 | await testCase(baseURL + 'echoheader?Cookie', undefined, 200, ['cache-control'], 'devtools-test-cookie=Bar'); |
| 1484 | |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1485 | await self.SDK.targetManager.mainTarget().runtimeAgent().invoke_evaluate({ |
Andrey Kosyakov | 73081cc | 2019-01-08 03:50:59 | [diff] [blame] | 1486 | expression: `fetch("/set-cookie?devtools-test-cookie=same-site-cookie;SameSite=Lax", |
| 1487 | {credentials: 'include'})`, |
| 1488 | awaitPromise: true |
| 1489 | }); |
| 1490 | await testCase( |
| 1491 | baseURL + 'echoheader?Cookie', undefined, 200, ['cache-control'], 'devtools-test-cookie=same-site-cookie'); |
Andrey Kosyakov | 4f7fb05 | 2019-03-19 15:53:43 | [diff] [blame] | 1492 | await testCase('data:text/html,<body>hello</body>', undefined, 200, [], '<body>hello</body>'); |
| 1493 | await testCase(fileURL, undefined, 200, [], '<html>\n<body>\nDummy page.\n</body>\n</html>\n'); |
Rob Paveza | 30df048 | 2019-10-09 23:15:49 | [diff] [blame] | 1494 | await testCase(fileURL + 'thisfileshouldnotbefound', undefined, 404, [], ''); |
Andrey Kosyakov | 73081cc | 2019-01-08 03:50:59 | [diff] [blame] | 1495 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1496 | this.releaseControl(); |
| 1497 | }; |
| 1498 | |
Joey Arhar | 723d5b5 | 2019-04-19 01:31:39 | [diff] [blame] | 1499 | TestSuite.prototype.testExtensionWebSocketUserAgentOverride = async function(websocketPort) { |
| 1500 | this.takeControl(); |
| 1501 | |
| 1502 | const testUserAgent = 'test user agent'; |
Paul Lewis | 5a922e7 | 2020-01-24 11:58:08 | [diff] [blame] | 1503 | self.SDK.multitargetNetworkManager.setUserAgentOverride(testUserAgent); |
Joey Arhar | 723d5b5 | 2019-04-19 01:31:39 | [diff] [blame] | 1504 | |
| 1505 | function onRequestUpdated(event) { |
| 1506 | const request = event.data; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1507 | if (request.resourceType() !== Common.resourceTypes.WebSocket) { |
Joey Arhar | 723d5b5 | 2019-04-19 01:31:39 | [diff] [blame] | 1508 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1509 | } |
| 1510 | if (!request.requestHeadersText()) { |
Joey Arhar | 723d5b5 | 2019-04-19 01:31:39 | [diff] [blame] | 1511 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1512 | } |
Joey Arhar | 723d5b5 | 2019-04-19 01:31:39 | [diff] [blame] | 1513 | |
| 1514 | let actualUserAgent = 'no user-agent header'; |
| 1515 | for (const {name, value} of request.requestHeaders()) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1516 | if (name.toLowerCase() === 'user-agent') { |
Joey Arhar | 723d5b5 | 2019-04-19 01:31:39 | [diff] [blame] | 1517 | actualUserAgent = value; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1518 | } |
Joey Arhar | 723d5b5 | 2019-04-19 01:31:39 | [diff] [blame] | 1519 | } |
| 1520 | this.assertEquals(testUserAgent, actualUserAgent); |
| 1521 | this.releaseControl(); |
| 1522 | } |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1523 | self.SDK.targetManager.addModelListener( |
Joey Arhar | 723d5b5 | 2019-04-19 01:31:39 | [diff] [blame] | 1524 | SDK.NetworkManager, SDK.NetworkManager.Events.RequestUpdated, onRequestUpdated.bind(this)); |
| 1525 | |
| 1526 | this.evaluateInConsole_(`new WebSocket('ws://127.0.0.1:${websocketPort}')`, () => {}); |
| 1527 | }; |
| 1528 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1529 | /** |
| 1530 | * Serializes array of uiSourceCodes to string. |
| 1531 | * @param {!Array.<!Workspace.UISourceCode>} uiSourceCodes |
| 1532 | * @return {string} |
| 1533 | */ |
| 1534 | TestSuite.prototype.uiSourceCodesToString_ = function(uiSourceCodes) { |
| 1535 | const names = []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1536 | for (let i = 0; i < uiSourceCodes.length; i++) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1537 | names.push('"' + uiSourceCodes[i].url() + '"'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1538 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1539 | return names.join(','); |
| 1540 | }; |
| 1541 | |
| 1542 | /** |
| 1543 | * Returns all loaded non anonymous uiSourceCodes. |
| 1544 | * @return {!Array.<!Workspace.UISourceCode>} |
| 1545 | */ |
| 1546 | TestSuite.prototype.nonAnonymousUISourceCodes_ = function() { |
| 1547 | /** |
| 1548 | * @param {!Workspace.UISourceCode} uiSourceCode |
| 1549 | */ |
| 1550 | function filterOutService(uiSourceCode) { |
| 1551 | return !uiSourceCode.project().isServiceProject(); |
| 1552 | } |
| 1553 | |
Paul Lewis | 10e83a9 | 2020-01-23 14:07:58 | [diff] [blame] | 1554 | const uiSourceCodes = self.Workspace.workspace.uiSourceCodes(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1555 | return uiSourceCodes.filter(filterOutService); |
| 1556 | }; |
| 1557 | |
| 1558 | /* |
| 1559 | * Evaluates the code in the console as if user typed it manually and invokes |
| 1560 | * the callback when the result message is received and added to the console. |
| 1561 | * @param {string} code |
| 1562 | * @param {function(string)} callback |
| 1563 | */ |
| 1564 | TestSuite.prototype.evaluateInConsole_ = function(code, callback) { |
| 1565 | function innerEvaluate() { |
Paul Lewis | d990734 | 2020-01-24 13:49:47 | [diff] [blame] | 1566 | self.UI.context.removeFlavorChangeListener(SDK.ExecutionContext, showConsoleAndEvaluate, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1567 | const consoleView = Console.ConsoleView.instance(); |
| 1568 | consoleView._prompt._appendCommand(code); |
| 1569 | |
| 1570 | this.addSniffer(Console.ConsoleView.prototype, '_consoleMessageAddedForTest', function(viewMessage) { |
| 1571 | callback(viewMessage.toMessageElement().deepTextContent()); |
| 1572 | }.bind(this)); |
| 1573 | } |
| 1574 | |
| 1575 | function showConsoleAndEvaluate() { |
Paul Lewis | 04ccecc | 2020-01-22 17:15:14 | [diff] [blame] | 1576 | self.Common.console.showPromise().then(innerEvaluate.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1577 | } |
| 1578 | |
Paul Lewis | d990734 | 2020-01-24 13:49:47 | [diff] [blame] | 1579 | if (!self.UI.context.flavor(SDK.ExecutionContext)) { |
| 1580 | self.UI.context.addFlavorChangeListener(SDK.ExecutionContext, showConsoleAndEvaluate, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1581 | return; |
| 1582 | } |
| 1583 | showConsoleAndEvaluate.call(this); |
| 1584 | }; |
| 1585 | |
| 1586 | /** |
| 1587 | * Checks that all expected scripts are present in the scripts list |
| 1588 | * in the Scripts panel. |
| 1589 | * @param {!Array.<string>} expected Regular expressions describing |
| 1590 | * expected script names. |
| 1591 | * @return {boolean} Whether all the scripts are in "scripts-files" select |
| 1592 | * box |
| 1593 | */ |
| 1594 | TestSuite.prototype._scriptsAreParsed = function(expected) { |
| 1595 | const uiSourceCodes = this.nonAnonymousUISourceCodes_(); |
| 1596 | // Check that at least all the expected scripts are present. |
| 1597 | const missing = expected.slice(0); |
| 1598 | for (let i = 0; i < uiSourceCodes.length; ++i) { |
| 1599 | for (let j = 0; j < missing.length; ++j) { |
| 1600 | if (uiSourceCodes[i].name().search(missing[j]) !== -1) { |
| 1601 | missing.splice(j, 1); |
| 1602 | break; |
| 1603 | } |
| 1604 | } |
| 1605 | } |
| 1606 | return missing.length === 0; |
| 1607 | }; |
| 1608 | |
| 1609 | /** |
| 1610 | * Waits for script pause, checks expectations, and invokes the callback. |
| 1611 | * @param {function():void} callback |
| 1612 | */ |
| 1613 | TestSuite.prototype._waitForScriptPause = function(callback) { |
| 1614 | this.addSniffer(SDK.DebuggerModel.prototype, '_pausedScript', callback); |
| 1615 | }; |
| 1616 | |
| 1617 | /** |
| 1618 | * Waits until all the scripts are parsed and invokes the callback. |
| 1619 | */ |
| 1620 | TestSuite.prototype._waitUntilScriptsAreParsed = function(expectedScripts, callback) { |
| 1621 | const test = this; |
| 1622 | |
| 1623 | function waitForAllScripts() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1624 | if (test._scriptsAreParsed(expectedScripts)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1625 | callback(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1626 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1627 | test.addSniffer(UI.panels.sources.sourcesView(), '_addUISourceCode', waitForAllScripts); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1628 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1629 | } |
| 1630 | |
| 1631 | waitForAllScripts(); |
| 1632 | }; |
| 1633 | |
| 1634 | TestSuite.prototype._waitForTargets = function(n, callback) { |
| 1635 | checkTargets.call(this); |
| 1636 | |
| 1637 | function checkTargets() { |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1638 | if (self.SDK.targetManager.targets().length >= n) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1639 | callback.call(null); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1640 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1641 | this.addSniffer(SDK.TargetManager.prototype, 'createTarget', checkTargets.bind(this)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1642 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1643 | } |
| 1644 | }; |
| 1645 | |
| 1646 | TestSuite.prototype._waitForExecutionContexts = function(n, callback) { |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1647 | const runtimeModel = self.SDK.targetManager.mainTarget().model(SDK.RuntimeModel); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1648 | checkForExecutionContexts.call(this); |
| 1649 | |
| 1650 | function checkForExecutionContexts() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1651 | if (runtimeModel.executionContexts().length >= n) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1652 | callback.call(null); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1653 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1654 | this.addSniffer(SDK.RuntimeModel.prototype, '_executionContextCreated', checkForExecutionContexts.bind(this)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1655 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1656 | } |
| 1657 | }; |
| 1658 | |
| 1659 | |
| 1660 | window.uiTests = new TestSuite(window.domAutomationController); |
| 1661 | })(window); |