| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 override.apply(this, arguments); | 192 override.apply(this, arguments); |
| 193 } catch (e) { | 193 } catch (e) { |
| 194 test.fail('Exception in overriden method \'' + methodName + '\': ' + e); | 194 test.fail('Exception in overriden method \'' + methodName + '\': ' + e); |
| 195 } | 195 } |
| 196 return result; | 196 return result; |
| 197 }; | 197 }; |
| 198 }; | 198 }; |
| 199 | 199 |
| 200 /** | 200 /** |
| 201 * Waits for current throttler invocations, if any. | 201 * Waits for current throttler invocations, if any. |
| 202 * @param {!WebInspector.Throttler} throttler | 202 * @param {!Common.Throttler} throttler |
| 203 * @param {function()} callback | 203 * @param {function()} callback |
| 204 */ | 204 */ |
| 205 TestSuite.prototype.waitForThrottler = function(throttler, callback) { | 205 TestSuite.prototype.waitForThrottler = function(throttler, callback) { |
| 206 var test = this; | 206 var test = this; |
| 207 var scheduleShouldFail = true; | 207 var scheduleShouldFail = true; |
| 208 test.addSniffer(throttler, 'schedule', onSchedule); | 208 test.addSniffer(throttler, 'schedule', onSchedule); |
| 209 | 209 |
| 210 function hasSomethingScheduled() { | 210 function hasSomethingScheduled() { |
| 211 return throttler._isRunningProcess || throttler._process; | 211 return throttler._isRunningProcess || throttler._process; |
| 212 } | 212 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 226 test.fail('Unexpected Throttler.schedule'); | 226 test.fail('Unexpected Throttler.schedule'); |
| 227 } | 227 } |
| 228 | 228 |
| 229 checkState(); | 229 checkState(); |
| 230 }; | 230 }; |
| 231 | 231 |
| 232 /** | 232 /** |
| 233 * @param {string} panelName Name of the panel to show. | 233 * @param {string} panelName Name of the panel to show. |
| 234 */ | 234 */ |
| 235 TestSuite.prototype.showPanel = function(panelName) { | 235 TestSuite.prototype.showPanel = function(panelName) { |
| 236 return WebInspector.inspectorView.showPanel(panelName); | 236 return UI.inspectorView.showPanel(panelName); |
| 237 }; | 237 }; |
| 238 | 238 |
| 239 // UI Tests | 239 // UI Tests |
| 240 | 240 |
| 241 /** | 241 /** |
| 242 * Tests that scripts tab can be open and populated with inspected scripts. | 242 * Tests that scripts tab can be open and populated with inspected scripts. |
| 243 */ | 243 */ |
| 244 TestSuite.prototype.testShowScriptsTab = function() { | 244 TestSuite.prototype.testShowScriptsTab = function() { |
| 245 var test = this; | 245 var test = this; |
| 246 this.showPanel('sources').then(function() { | 246 this.showPanel('sources').then(function() { |
| 247 // There should be at least main page script. | 247 // There should be at least main page script. |
| 248 this._waitUntilScriptsAreParsed(['debugger_test_page.html'], function() { | 248 this._waitUntilScriptsAreParsed(['debugger_test_page.html'], function() { |
| 249 test.releaseControl(); | 249 test.releaseControl(); |
| 250 }); | 250 }); |
| 251 }.bind(this)); | 251 }.bind(this)); |
| 252 // Wait until all scripts are added to the debugger. | 252 // Wait until all scripts are added to the debugger. |
| 253 this.takeControl(); | 253 this.takeControl(); |
| 254 }; | 254 }; |
| 255 | 255 |
| 256 /** | 256 /** |
| 257 * Tests that scripts tab is populated with inspected scripts even if it | 257 * Tests that scripts tab is populated with inspected scripts even if it |
| 258 * hadn't been shown by the moment inspected paged refreshed. | 258 * hadn't been shown by the moment inspected paged refreshed. |
| 259 * @see http://crbug.com/26312 | 259 * @see http://crbug.com/26312 |
| 260 */ | 260 */ |
| 261 TestSuite.prototype.testScriptsTabIsPopulatedOnInspectedPageRefresh = function
() { | 261 TestSuite.prototype.testScriptsTabIsPopulatedOnInspectedPageRefresh = function
() { |
| 262 var test = this; | 262 var test = this; |
| 263 var debuggerModel = WebInspector.DebuggerModel.fromTarget(WebInspector.targe
tManager.mainTarget()); | 263 var debuggerModel = SDK.DebuggerModel.fromTarget(SDK.targetManager.mainTarge
t()); |
| 264 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObjec
tCleared, waitUntilScriptIsParsed); | 264 debuggerModel.addEventListener(SDK.DebuggerModel.Events.GlobalObjectCleared,
waitUntilScriptIsParsed); |
| 265 | 265 |
| 266 this.showPanel('elements').then(function() { | 266 this.showPanel('elements').then(function() { |
| 267 // Reload inspected page. It will reset the debugger agent. | 267 // Reload inspected page. It will reset the debugger agent. |
| 268 test.evaluateInConsole_('window.location.reload(true);', function(resultTe
xt) {}); | 268 test.evaluateInConsole_('window.location.reload(true);', function(resultTe
xt) {}); |
| 269 }); | 269 }); |
| 270 | 270 |
| 271 function waitUntilScriptIsParsed() { | 271 function waitUntilScriptIsParsed() { |
| 272 debuggerModel.removeEventListener(WebInspector.DebuggerModel.Events.Global
ObjectCleared, waitUntilScriptIsParsed); | 272 debuggerModel.removeEventListener(SDK.DebuggerModel.Events.GlobalObjectCle
ared, waitUntilScriptIsParsed); |
| 273 test.showPanel('sources').then(function() { | 273 test.showPanel('sources').then(function() { |
| 274 test._waitUntilScriptsAreParsed(['debugger_test_page.html'], function()
{ | 274 test._waitUntilScriptsAreParsed(['debugger_test_page.html'], function()
{ |
| 275 test.releaseControl(); | 275 test.releaseControl(); |
| 276 }); | 276 }); |
| 277 }); | 277 }); |
| 278 } | 278 } |
| 279 | 279 |
| 280 // Wait until all scripts are added to the debugger. | 280 // Wait until all scripts are added to the debugger. |
| 281 this.takeControl(); | 281 this.takeControl(); |
| 282 }; | 282 }; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 }); | 343 }); |
| 344 }); | 344 }); |
| 345 | 345 |
| 346 // Wait until all scripts are added to the debugger. | 346 // Wait until all scripts are added to the debugger. |
| 347 this.takeControl(); | 347 this.takeControl(); |
| 348 }; | 348 }; |
| 349 | 349 |
| 350 // Tests that debugger works correctly if pause event occurs when DevTools | 350 // Tests that debugger works correctly if pause event occurs when DevTools |
| 351 // frontend is being loaded. | 351 // frontend is being loaded. |
| 352 TestSuite.prototype.testPauseWhenLoadingDevTools = function() { | 352 TestSuite.prototype.testPauseWhenLoadingDevTools = function() { |
| 353 var debuggerModel = WebInspector.DebuggerModel.fromTarget(WebInspector.targe
tManager.mainTarget()); | 353 var debuggerModel = SDK.DebuggerModel.fromTarget(SDK.targetManager.mainTarge
t()); |
| 354 if (debuggerModel.debuggerPausedDetails) | 354 if (debuggerModel.debuggerPausedDetails) |
| 355 return; | 355 return; |
| 356 | 356 |
| 357 this.showPanel('sources').then(function() { | 357 this.showPanel('sources').then(function() { |
| 358 // Script execution can already be paused. | 358 // Script execution can already be paused. |
| 359 | 359 |
| 360 this._waitForScriptPause(this.releaseControl.bind(this)); | 360 this._waitForScriptPause(this.releaseControl.bind(this)); |
| 361 }.bind(this)); | 361 }.bind(this)); |
| 362 | 362 |
| 363 this.takeControl(); | 363 this.takeControl(); |
| 364 }; | 364 }; |
| 365 | 365 |
| 366 // Tests that pressing "Pause" will pause script execution if the script | 366 // Tests that pressing "Pause" will pause script execution if the script |
| 367 // is already running. | 367 // is already running. |
| 368 TestSuite.prototype.testPauseWhenScriptIsRunning = function() { | 368 TestSuite.prototype.testPauseWhenScriptIsRunning = function() { |
| 369 this.showPanel('sources').then(function() { | 369 this.showPanel('sources').then(function() { |
| 370 this.evaluateInConsole_('setTimeout("handleClick()", 0)', didEvaluateInCon
sole.bind(this)); | 370 this.evaluateInConsole_('setTimeout("handleClick()", 0)', didEvaluateInCon
sole.bind(this)); |
| 371 }.bind(this)); | 371 }.bind(this)); |
| 372 | 372 |
| 373 function didEvaluateInConsole(resultText) { | 373 function didEvaluateInConsole(resultText) { |
| 374 this.assertTrue(!isNaN(resultText), 'Failed to get timer id: ' + resultTex
t); | 374 this.assertTrue(!isNaN(resultText), 'Failed to get timer id: ' + resultTex
t); |
| 375 // Wait for some time to make sure that inspected page is running the | 375 // Wait for some time to make sure that inspected page is running the |
| 376 // infinite loop. | 376 // infinite loop. |
| 377 setTimeout(testScriptPause.bind(this), 300); | 377 setTimeout(testScriptPause.bind(this), 300); |
| 378 } | 378 } |
| 379 | 379 |
| 380 function testScriptPause() { | 380 function testScriptPause() { |
| 381 // The script should be in infinite loop. Click "Pause" button to | 381 // The script should be in infinite loop. Click "Pause" button to |
| 382 // pause it and wait for the result. | 382 // pause it and wait for the result. |
| 383 WebInspector.panels.sources._togglePause(); | 383 UI.panels.sources._togglePause(); |
| 384 | 384 |
| 385 this._waitForScriptPause(this.releaseControl.bind(this)); | 385 this._waitForScriptPause(this.releaseControl.bind(this)); |
| 386 } | 386 } |
| 387 | 387 |
| 388 this.takeControl(); | 388 this.takeControl(); |
| 389 }; | 389 }; |
| 390 | 390 |
| 391 /** | 391 /** |
| 392 * Tests network size. | 392 * Tests network size. |
| 393 */ | 393 */ |
| 394 TestSuite.prototype.testNetworkSize = function() { | 394 TestSuite.prototype.testNetworkSize = function() { |
| 395 var test = this; | 395 var test = this; |
| 396 | 396 |
| 397 function finishResource(resource, finishTime) { | 397 function finishResource(resource, finishTime) { |
| 398 test.assertEquals(25, resource.resourceSize, 'Incorrect total data length'
); | 398 test.assertEquals(25, resource.resourceSize, 'Incorrect total data length'
); |
| 399 test.releaseControl(); | 399 test.releaseControl(); |
| 400 } | 400 } |
| 401 | 401 |
| 402 this.addSniffer(WebInspector.NetworkDispatcher.prototype, '_finishNetworkReq
uest', finishResource); | 402 this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', fi
nishResource); |
| 403 | 403 |
| 404 // Reload inspected page to sniff network events | 404 // Reload inspected page to sniff network events |
| 405 test.evaluateInConsole_('window.location.reload(true);', function(resultText
) {}); | 405 test.evaluateInConsole_('window.location.reload(true);', function(resultText
) {}); |
| 406 | 406 |
| 407 this.takeControl(); | 407 this.takeControl(); |
| 408 }; | 408 }; |
| 409 | 409 |
| 410 /** | 410 /** |
| 411 * Tests network sync size. | 411 * Tests network sync size. |
| 412 */ | 412 */ |
| 413 TestSuite.prototype.testNetworkSyncSize = function() { | 413 TestSuite.prototype.testNetworkSyncSize = function() { |
| 414 var test = this; | 414 var test = this; |
| 415 | 415 |
| 416 function finishResource(resource, finishTime) { | 416 function finishResource(resource, finishTime) { |
| 417 test.assertEquals(25, resource.resourceSize, 'Incorrect total data length'
); | 417 test.assertEquals(25, resource.resourceSize, 'Incorrect total data length'
); |
| 418 test.releaseControl(); | 418 test.releaseControl(); |
| 419 } | 419 } |
| 420 | 420 |
| 421 this.addSniffer(WebInspector.NetworkDispatcher.prototype, '_finishNetworkReq
uest', finishResource); | 421 this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', fi
nishResource); |
| 422 | 422 |
| 423 // Send synchronous XHR to sniff network events | 423 // Send synchronous XHR to sniff network events |
| 424 test.evaluateInConsole_( | 424 test.evaluateInConsole_( |
| 425 'var xhr = new XMLHttpRequest(); xhr.open("GET", "chunked", false); xhr.
send(null);', function() {}); | 425 'var xhr = new XMLHttpRequest(); xhr.open("GET", "chunked", false); xhr.
send(null);', function() {}); |
| 426 | 426 |
| 427 this.takeControl(); | 427 this.takeControl(); |
| 428 }; | 428 }; |
| 429 | 429 |
| 430 /** | 430 /** |
| 431 * Tests network raw headers text. | 431 * Tests network raw headers text. |
| 432 */ | 432 */ |
| 433 TestSuite.prototype.testNetworkRawHeadersText = function() { | 433 TestSuite.prototype.testNetworkRawHeadersText = function() { |
| 434 var test = this; | 434 var test = this; |
| 435 | 435 |
| 436 function finishResource(resource, finishTime) { | 436 function finishResource(resource, finishTime) { |
| 437 if (!resource.responseHeadersText) | 437 if (!resource.responseHeadersText) |
| 438 test.fail('Failure: resource does not have response headers text'); | 438 test.fail('Failure: resource does not have response headers text'); |
| 439 var index = resource.responseHeadersText.indexOf('Date:'); | 439 var index = resource.responseHeadersText.indexOf('Date:'); |
| 440 test.assertEquals( | 440 test.assertEquals( |
| 441 112, resource.responseHeadersText.substring(index).length, 'Incorrect
response headers text length'); | 441 112, resource.responseHeadersText.substring(index).length, 'Incorrect
response headers text length'); |
| 442 test.releaseControl(); | 442 test.releaseControl(); |
| 443 } | 443 } |
| 444 | 444 |
| 445 this.addSniffer(WebInspector.NetworkDispatcher.prototype, '_finishNetworkReq
uest', finishResource); | 445 this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', fi
nishResource); |
| 446 | 446 |
| 447 // Reload inspected page to sniff network events | 447 // Reload inspected page to sniff network events |
| 448 test.evaluateInConsole_('window.location.reload(true);', function(resultText
) {}); | 448 test.evaluateInConsole_('window.location.reload(true);', function(resultText
) {}); |
| 449 | 449 |
| 450 this.takeControl(); | 450 this.takeControl(); |
| 451 }; | 451 }; |
| 452 | 452 |
| 453 /** | 453 /** |
| 454 * Tests network timing. | 454 * Tests network timing. |
| 455 */ | 455 */ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 470 'Time between responseReceivedTime and startTime should be >=0.07s, bu
t was ' + | 470 'Time between responseReceivedTime and startTime should be >=0.07s, bu
t was ' + |
| 471 'responseReceivedTime=' + resource.responseReceivedTime + ', start
Time=' + resource.startTime + '.'); | 471 'responseReceivedTime=' + resource.responseReceivedTime + ', start
Time=' + resource.startTime + '.'); |
| 472 test.assertTrue( | 472 test.assertTrue( |
| 473 resource.endTime - resource.startTime >= 0.14, | 473 resource.endTime - resource.startTime >= 0.14, |
| 474 'Time between endTime and startTime should be >=0.14s, but was ' + | 474 'Time between endTime and startTime should be >=0.14s, but was ' + |
| 475 'endtime=' + resource.endTime + ', startTime=' + resource.startTim
e + '.'); | 475 'endtime=' + resource.endTime + ', startTime=' + resource.startTim
e + '.'); |
| 476 | 476 |
| 477 test.releaseControl(); | 477 test.releaseControl(); |
| 478 } | 478 } |
| 479 | 479 |
| 480 this.addSniffer(WebInspector.NetworkDispatcher.prototype, '_finishNetworkReq
uest', finishResource); | 480 this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', fi
nishResource); |
| 481 | 481 |
| 482 // Reload inspected page to sniff network events | 482 // Reload inspected page to sniff network events |
| 483 test.evaluateInConsole_('window.location.reload(true);', function(resultText
) {}); | 483 test.evaluateInConsole_('window.location.reload(true);', function(resultText
) {}); |
| 484 | 484 |
| 485 this.takeControl(); | 485 this.takeControl(); |
| 486 }; | 486 }; |
| 487 | 487 |
| 488 TestSuite.prototype.testPushTimes = function(url) { | 488 TestSuite.prototype.testPushTimes = function(url) { |
| 489 var test = this; | 489 var test = this; |
| 490 var pendingResourceCount = 2; | 490 var pendingResourceCount = 2; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 502 resource.timing.pushStart < resource.timing.pushEnd, | 502 resource.timing.pushStart < resource.timing.pushEnd, |
| 503 `pushStart should be before pushEnd (${resource.timing.pushStart} >=
${resource.timing.pushEnd})`); | 503 `pushStart should be before pushEnd (${resource.timing.pushStart} >=
${resource.timing.pushEnd})`); |
| 504 // The below assertion is just due to the way we generate times in the m
och URLRequestJob and is not generally an invariant. | 504 // The below assertion is just due to the way we generate times in the m
och URLRequestJob and is not generally an invariant. |
| 505 test.assertTrue(resource.timing.pushEnd < resource.endTime, 'pushEnd sho
uld be before endTime'); | 505 test.assertTrue(resource.timing.pushEnd < resource.endTime, 'pushEnd sho
uld be before endTime'); |
| 506 test.assertTrue(resource.startTime < resource.timing.pushEnd, 'pushEnd s
hould be after startTime'); | 506 test.assertTrue(resource.startTime < resource.timing.pushEnd, 'pushEnd s
hould be after startTime'); |
| 507 } | 507 } |
| 508 if (!--pendingResourceCount) | 508 if (!--pendingResourceCount) |
| 509 test.releaseControl(); | 509 test.releaseControl(); |
| 510 } | 510 } |
| 511 | 511 |
| 512 this.addSniffer(WebInspector.NetworkDispatcher.prototype, '_finishNetworkReq
uest', finishResource, true); | 512 this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', fi
nishResource, true); |
| 513 | 513 |
| 514 test.evaluateInConsole_('addImage(\'' + url + '\')', function(resultText) {}
); | 514 test.evaluateInConsole_('addImage(\'' + url + '\')', function(resultText) {}
); |
| 515 test.evaluateInConsole_('addImage(\'' + url + '?pushUseNullEndTime\')', func
tion(resultText) {}); | 515 test.evaluateInConsole_('addImage(\'' + url + '?pushUseNullEndTime\')', func
tion(resultText) {}); |
| 516 this.takeControl(); | 516 this.takeControl(); |
| 517 }; | 517 }; |
| 518 | 518 |
| 519 TestSuite.prototype.testConsoleOnNavigateBack = function() { | 519 TestSuite.prototype.testConsoleOnNavigateBack = function() { |
| 520 | 520 |
| 521 function filteredMessages() { | 521 function filteredMessages() { |
| 522 return WebInspector.multitargetConsoleModel.messages().filter( | 522 return SDK.multitargetConsoleModel.messages().filter( |
| 523 a => a.source !== WebInspector.ConsoleMessage.MessageSource.Violation
); | 523 a => a.source !== SDK.ConsoleMessage.MessageSource.Violation); |
| 524 } | 524 } |
| 525 | 525 |
| 526 if (filteredMessages().length === 1) | 526 if (filteredMessages().length === 1) |
| 527 firstConsoleMessageReceived.call(this, null); | 527 firstConsoleMessageReceived.call(this, null); |
| 528 else | 528 else |
| 529 WebInspector.multitargetConsoleModel.addEventListener( | 529 SDK.multitargetConsoleModel.addEventListener( |
| 530 WebInspector.ConsoleModel.Events.MessageAdded, firstConsoleMessageRece
ived, this); | 530 SDK.ConsoleModel.Events.MessageAdded, firstConsoleMessageReceived, thi
s); |
| 531 | 531 |
| 532 function firstConsoleMessageReceived(event) { | 532 function firstConsoleMessageReceived(event) { |
| 533 if (event && event.data.source === WebInspector.ConsoleMessage.MessageSour
ce.Violation) | 533 if (event && event.data.source === SDK.ConsoleMessage.MessageSource.Violat
ion) |
| 534 return; | 534 return; |
| 535 WebInspector.multitargetConsoleModel.removeEventListener( | 535 SDK.multitargetConsoleModel.removeEventListener( |
| 536 WebInspector.ConsoleModel.Events.MessageAdded, firstConsoleMessageRece
ived, this); | 536 SDK.ConsoleModel.Events.MessageAdded, firstConsoleMessageReceived, thi
s); |
| 537 this.evaluateInConsole_('clickLink();', didClickLink.bind(this)); | 537 this.evaluateInConsole_('clickLink();', didClickLink.bind(this)); |
| 538 } | 538 } |
| 539 | 539 |
| 540 function didClickLink() { | 540 function didClickLink() { |
| 541 // Check that there are no new messages(command is not a message). | 541 // Check that there are no new messages(command is not a message). |
| 542 this.assertEquals(3, filteredMessages().length); | 542 this.assertEquals(3, filteredMessages().length); |
| 543 this.evaluateInConsole_('history.back();', didNavigateBack.bind(this)); | 543 this.evaluateInConsole_('history.back();', didNavigateBack.bind(this)); |
| 544 } | 544 } |
| 545 | 545 |
| 546 function didNavigateBack() { | 546 function didNavigateBack() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 564 this.evaluateInConsole_('globalVar', didEvaluateInConsole.bind(this)); | 564 this.evaluateInConsole_('globalVar', didEvaluateInConsole.bind(this)); |
| 565 this.takeControl(); | 565 this.takeControl(); |
| 566 }; | 566 }; |
| 567 | 567 |
| 568 TestSuite.prototype.testPauseInSharedWorkerInitialization1 = function() { | 568 TestSuite.prototype.testPauseInSharedWorkerInitialization1 = function() { |
| 569 // Make sure the worker is loaded. | 569 // Make sure the worker is loaded. |
| 570 this.takeControl(); | 570 this.takeControl(); |
| 571 this._waitForTargets(2, callback.bind(this)); | 571 this._waitForTargets(2, callback.bind(this)); |
| 572 | 572 |
| 573 function callback() { | 573 function callback() { |
| 574 var target = WebInspector.targetManager.targets(WebInspector.Target.Capabi
lity.JS)[0]; | 574 var target = SDK.targetManager.targets(SDK.Target.Capability.JS)[0]; |
| 575 InspectorBackendClass.deprecatedRunAfterPendingDispatches(this.releaseCont
rol.bind(this)); | 575 InspectorBackendClass.deprecatedRunAfterPendingDispatches(this.releaseCont
rol.bind(this)); |
| 576 } | 576 } |
| 577 }; | 577 }; |
| 578 | 578 |
| 579 TestSuite.prototype.testPauseInSharedWorkerInitialization2 = function() { | 579 TestSuite.prototype.testPauseInSharedWorkerInitialization2 = function() { |
| 580 this.takeControl(); | 580 this.takeControl(); |
| 581 this._waitForTargets(2, callback.bind(this)); | 581 this._waitForTargets(2, callback.bind(this)); |
| 582 | 582 |
| 583 function callback() { | 583 function callback() { |
| 584 var target = WebInspector.targetManager.targets(WebInspector.Target.Capabi
lity.JS)[0]; | 584 var target = SDK.targetManager.targets(SDK.Target.Capability.JS)[0]; |
| 585 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); | 585 var debuggerModel = SDK.DebuggerModel.fromTarget(target); |
| 586 if (debuggerModel.isPaused()) { | 586 if (debuggerModel.isPaused()) { |
| 587 this.releaseControl(); | 587 this.releaseControl(); |
| 588 return; | 588 return; |
| 589 } | 589 } |
| 590 this._waitForScriptPause(this.releaseControl.bind(this)); | 590 this._waitForScriptPause(this.releaseControl.bind(this)); |
| 591 } | 591 } |
| 592 }; | 592 }; |
| 593 | 593 |
| 594 TestSuite.prototype.enableTouchEmulation = function() { | 594 TestSuite.prototype.enableTouchEmulation = function() { |
| 595 var deviceModeModel = new WebInspector.DeviceModeModel(function() {}); | 595 var deviceModeModel = new Emulation.DeviceModeModel(function() {}); |
| 596 deviceModeModel._target = WebInspector.targetManager.mainTarget(); | 596 deviceModeModel._target = SDK.targetManager.mainTarget(); |
| 597 deviceModeModel._applyTouch(true, true); | 597 deviceModeModel._applyTouch(true, true); |
| 598 }; | 598 }; |
| 599 | 599 |
| 600 TestSuite.prototype.enableAutoAttachToCreatedPages = function() { | 600 TestSuite.prototype.enableAutoAttachToCreatedPages = function() { |
| 601 WebInspector.settingForTest('autoAttachToCreatedPages').set(true); | 601 Common.settingForTest('autoAttachToCreatedPages').set(true); |
| 602 }; | 602 }; |
| 603 | 603 |
| 604 TestSuite.prototype.waitForDebuggerPaused = function() { | 604 TestSuite.prototype.waitForDebuggerPaused = function() { |
| 605 var debuggerModel = WebInspector.DebuggerModel.fromTarget(WebInspector.targe
tManager.mainTarget()); | 605 var debuggerModel = SDK.DebuggerModel.fromTarget(SDK.targetManager.mainTarge
t()); |
| 606 if (debuggerModel.debuggerPausedDetails) | 606 if (debuggerModel.debuggerPausedDetails) |
| 607 return; | 607 return; |
| 608 | 608 |
| 609 this.takeControl(); | 609 this.takeControl(); |
| 610 this._waitForScriptPause(this.releaseControl.bind(this)); | 610 this._waitForScriptPause(this.releaseControl.bind(this)); |
| 611 }; | 611 }; |
| 612 | 612 |
| 613 TestSuite.prototype.switchToPanel = function(panelName) { | 613 TestSuite.prototype.switchToPanel = function(panelName) { |
| 614 this.showPanel(panelName).then(this.releaseControl.bind(this)); | 614 this.showPanel(panelName).then(this.releaseControl.bind(this)); |
| 615 this.takeControl(); | 615 this.takeControl(); |
| 616 }; | 616 }; |
| 617 | 617 |
| 618 // Regression test for crbug.com/370035. | 618 // Regression test for crbug.com/370035. |
| 619 TestSuite.prototype.testDeviceMetricsOverrides = function() { | 619 TestSuite.prototype.testDeviceMetricsOverrides = function() { |
| 620 const dumpPageMetrics = function() { | 620 const dumpPageMetrics = function() { |
| 621 return JSON.stringify( | 621 return JSON.stringify( |
| 622 {width: window.innerWidth, height: window.innerHeight, deviceScaleFact
or: window.devicePixelRatio}); | 622 {width: window.innerWidth, height: window.innerHeight, deviceScaleFact
or: window.devicePixelRatio}); |
| 623 }; | 623 }; |
| 624 | 624 |
| 625 var test = this; | 625 var test = this; |
| 626 | 626 |
| 627 function testOverrides(params, metrics, callback) { | 627 function testOverrides(params, metrics, callback) { |
| 628 WebInspector.targetManager.mainTarget().emulationAgent().invoke_setDeviceM
etricsOverride(params, getMetrics); | 628 SDK.targetManager.mainTarget().emulationAgent().invoke_setDeviceMetricsOve
rride(params, getMetrics); |
| 629 | 629 |
| 630 function getMetrics() { | 630 function getMetrics() { |
| 631 test.evaluateInConsole_('(' + dumpPageMetrics.toString() + ')()', checkM
etrics); | 631 test.evaluateInConsole_('(' + dumpPageMetrics.toString() + ')()', checkM
etrics); |
| 632 } | 632 } |
| 633 | 633 |
| 634 function checkMetrics(consoleResult) { | 634 function checkMetrics(consoleResult) { |
| 635 test.assertEquals( | 635 test.assertEquals( |
| 636 '"' + JSON.stringify(metrics) + '"', consoleResult, 'Wrong metrics f
or params: ' + JSON.stringify(params)); | 636 '"' + JSON.stringify(metrics) + '"', consoleResult, 'Wrong metrics f
or params: ' + JSON.stringify(params)); |
| 637 callback(); | 637 callback(); |
| 638 } | 638 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 664 | 664 |
| 665 function finish() { | 665 function finish() { |
| 666 test.releaseControl(); | 666 test.releaseControl(); |
| 667 } | 667 } |
| 668 | 668 |
| 669 test.takeControl(); | 669 test.takeControl(); |
| 670 step1(); | 670 step1(); |
| 671 }; | 671 }; |
| 672 | 672 |
| 673 TestSuite.prototype.testDispatchKeyEventDoesNotCrash = function() { | 673 TestSuite.prototype.testDispatchKeyEventDoesNotCrash = function() { |
| 674 WebInspector.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent
( | 674 SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent( |
| 675 {type: 'rawKeyDown', windowsVirtualKeyCode: 0x23, key: 'End'}); | 675 {type: 'rawKeyDown', windowsVirtualKeyCode: 0x23, key: 'End'}); |
| 676 WebInspector.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent
( | 676 SDK.targetManager.mainTarget().inputAgent().invoke_dispatchKeyEvent( |
| 677 {type: 'keyUp', windowsVirtualKeyCode: 0x23, key: 'End'}); | 677 {type: 'keyUp', windowsVirtualKeyCode: 0x23, key: 'End'}); |
| 678 }; | 678 }; |
| 679 | 679 |
| 680 TestSuite.prototype.testEmulateNetworkConditions = function() { | 680 TestSuite.prototype.testEmulateNetworkConditions = function() { |
| 681 var test = this; | 681 var test = this; |
| 682 | 682 |
| 683 function testPreset(preset, messages, next) { | 683 function testPreset(preset, messages, next) { |
| 684 function onConsoleMessage(event) { | 684 function onConsoleMessage(event) { |
| 685 var index = messages.indexOf(event.data.messageText); | 685 var index = messages.indexOf(event.data.messageText); |
| 686 if (index === -1) { | 686 if (index === -1) { |
| 687 test.fail('Unexpected message: ' + event.data.messageText); | 687 test.fail('Unexpected message: ' + event.data.messageText); |
| 688 return; | 688 return; |
| 689 } | 689 } |
| 690 | 690 |
| 691 messages.splice(index, 1); | 691 messages.splice(index, 1); |
| 692 if (!messages.length) { | 692 if (!messages.length) { |
| 693 WebInspector.multitargetConsoleModel.removeEventListener( | 693 SDK.multitargetConsoleModel.removeEventListener( |
| 694 WebInspector.ConsoleModel.Events.MessageAdded, onConsoleMessage, t
his); | 694 SDK.ConsoleModel.Events.MessageAdded, onConsoleMessage, this); |
| 695 next(); | 695 next(); |
| 696 } | 696 } |
| 697 } | 697 } |
| 698 | 698 |
| 699 WebInspector.multitargetConsoleModel.addEventListener( | 699 SDK.multitargetConsoleModel.addEventListener( |
| 700 WebInspector.ConsoleModel.Events.MessageAdded, onConsoleMessage, this)
; | 700 SDK.ConsoleModel.Events.MessageAdded, onConsoleMessage, this); |
| 701 WebInspector.multitargetNetworkManager.setNetworkConditions(preset); | 701 SDK.multitargetNetworkManager.setNetworkConditions(preset); |
| 702 } | 702 } |
| 703 | 703 |
| 704 test.takeControl(); | 704 test.takeControl(); |
| 705 step1(); | 705 step1(); |
| 706 | 706 |
| 707 function step1() { | 707 function step1() { |
| 708 testPreset( | 708 testPreset( |
| 709 WebInspector.NetworkConditionsSelector._presets[0], | 709 Components.NetworkConditionsSelector._presets[0], |
| 710 ['offline event: online = false', 'connection change event: type = non
e; downlinkMax = 0'], step2); | 710 ['offline event: online = false', 'connection change event: type = non
e; downlinkMax = 0'], step2); |
| 711 } | 711 } |
| 712 | 712 |
| 713 function step2() { | 713 function step2() { |
| 714 testPreset( | 714 testPreset( |
| 715 WebInspector.NetworkConditionsSelector._presets[2], | 715 Components.NetworkConditionsSelector._presets[2], |
| 716 ['online event: online = true', 'connection change event: type = cellu
lar; downlinkMax = 0.244140625'], | 716 ['online event: online = true', 'connection change event: type = cellu
lar; downlinkMax = 0.244140625'], |
| 717 step3); | 717 step3); |
| 718 } | 718 } |
| 719 | 719 |
| 720 function step3() { | 720 function step3() { |
| 721 testPreset( | 721 testPreset( |
| 722 WebInspector.NetworkConditionsSelector._presets[8], | 722 Components.NetworkConditionsSelector._presets[8], |
| 723 ['connection change event: type = wifi; downlinkMax = 30'], test.relea
seControl.bind(test)); | 723 ['connection change event: type = wifi; downlinkMax = 30'], test.relea
seControl.bind(test)); |
| 724 } | 724 } |
| 725 }; | 725 }; |
| 726 | 726 |
| 727 TestSuite.prototype.testScreenshotRecording = function() { | 727 TestSuite.prototype.testScreenshotRecording = function() { |
| 728 var test = this; | 728 var test = this; |
| 729 | 729 |
| 730 function performActionsInPage(callback) { | 730 function performActionsInPage(callback) { |
| 731 var count = 0; | 731 var count = 0; |
| 732 var div = document.createElement('div'); | 732 var div = document.createElement('div'); |
| 733 div.setAttribute('style', 'left: 0px; top: 0px; width: 100px; height: 100p
x; position: absolute;'); | 733 div.setAttribute('style', 'left: 0px; top: 0px; width: 100px; height: 100p
x; position: absolute;'); |
| 734 document.body.appendChild(div); | 734 document.body.appendChild(div); |
| 735 requestAnimationFrame(frame); | 735 requestAnimationFrame(frame); |
| 736 function frame() { | 736 function frame() { |
| 737 var color = [0, 0, 0]; | 737 var color = [0, 0, 0]; |
| 738 color[count % 3] = 255; | 738 color[count % 3] = 255; |
| 739 div.style.backgroundColor = 'rgb(' + color.join(',') + ')'; | 739 div.style.backgroundColor = 'rgb(' + color.join(',') + ')'; |
| 740 if (++count > 10) | 740 if (++count > 10) |
| 741 requestAnimationFrame(callback); | 741 requestAnimationFrame(callback); |
| 742 else | 742 else |
| 743 requestAnimationFrame(frame); | 743 requestAnimationFrame(frame); |
| 744 } | 744 } |
| 745 } | 745 } |
| 746 | 746 |
| 747 var captureFilmStripSetting = WebInspector.settings.createSetting('timelineC
aptureFilmStrip', false); | 747 var captureFilmStripSetting = Common.settings.createSetting('timelineCapture
FilmStrip', false); |
| 748 captureFilmStripSetting.set(true); | 748 captureFilmStripSetting.set(true); |
| 749 test.evaluateInConsole_(performActionsInPage.toString(), function() {}); | 749 test.evaluateInConsole_(performActionsInPage.toString(), function() {}); |
| 750 test.invokeAsyncWithTimeline_('performActionsInPage', onTimelineDone); | 750 test.invokeAsyncWithTimeline_('performActionsInPage', onTimelineDone); |
| 751 | 751 |
| 752 function onTimelineDone() { | 752 function onTimelineDone() { |
| 753 captureFilmStripSetting.set(false); | 753 captureFilmStripSetting.set(false); |
| 754 var filmStripModel = new WebInspector.FilmStripModel(WebInspector.panels.t
imeline._tracingModel); | 754 var filmStripModel = new Components.FilmStripModel(UI.panels.timeline._tra
cingModel); |
| 755 var frames = filmStripModel.frames(); | 755 var frames = filmStripModel.frames(); |
| 756 test.assertTrue(frames.length > 4 && typeof frames.length === 'number'); | 756 test.assertTrue(frames.length > 4 && typeof frames.length === 'number'); |
| 757 loadFrameImages(frames); | 757 loadFrameImages(frames); |
| 758 } | 758 } |
| 759 | 759 |
| 760 function loadFrameImages(frames) { | 760 function loadFrameImages(frames) { |
| 761 var readyImages = []; | 761 var readyImages = []; |
| 762 for (var frame of frames) | 762 for (var frame of frames) |
| 763 frame.imageDataPromise().then(onGotImageData); | 763 frame.imageDataPromise().then(onGotImageData); |
| 764 | 764 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 }; | 808 }; |
| 809 | 809 |
| 810 TestSuite.prototype.testSettings = function() { | 810 TestSuite.prototype.testSettings = function() { |
| 811 var test = this; | 811 var test = this; |
| 812 | 812 |
| 813 createSettings(); | 813 createSettings(); |
| 814 test.takeControl(); | 814 test.takeControl(); |
| 815 setTimeout(reset, 0); | 815 setTimeout(reset, 0); |
| 816 | 816 |
| 817 function createSettings() { | 817 function createSettings() { |
| 818 var localSetting = WebInspector.settings.createSetting('local', undefined,
true); | 818 var localSetting = Common.settings.createSetting('local', undefined, true)
; |
| 819 localSetting.set({s: 'local', n: 1}); | 819 localSetting.set({s: 'local', n: 1}); |
| 820 var globalSetting = WebInspector.settings.createSetting('global', undefine
d, false); | 820 var globalSetting = Common.settings.createSetting('global', undefined, fal
se); |
| 821 globalSetting.set({s: 'global', n: 2}); | 821 globalSetting.set({s: 'global', n: 2}); |
| 822 } | 822 } |
| 823 | 823 |
| 824 function reset() { | 824 function reset() { |
| 825 Runtime.experiments.clearForTest(); | 825 Runtime.experiments.clearForTest(); |
| 826 InspectorFrontendHost.getPreferences(gotPreferences); | 826 InspectorFrontendHost.getPreferences(gotPreferences); |
| 827 } | 827 } |
| 828 | 828 |
| 829 function gotPreferences(prefs) { | 829 function gotPreferences(prefs) { |
| 830 WebInspector.Main._instanceForTest._createSettings(prefs); | 830 Main.Main._instanceForTest._createSettings(prefs); |
| 831 | 831 |
| 832 var localSetting = WebInspector.settings.createSetting('local', undefined,
true); | 832 var localSetting = Common.settings.createSetting('local', undefined, true)
; |
| 833 test.assertEquals('object', typeof localSetting.get()); | 833 test.assertEquals('object', typeof localSetting.get()); |
| 834 test.assertEquals('local', localSetting.get().s); | 834 test.assertEquals('local', localSetting.get().s); |
| 835 test.assertEquals(1, localSetting.get().n); | 835 test.assertEquals(1, localSetting.get().n); |
| 836 var globalSetting = WebInspector.settings.createSetting('global', undefine
d, false); | 836 var globalSetting = Common.settings.createSetting('global', undefined, fal
se); |
| 837 test.assertEquals('object', typeof globalSetting.get()); | 837 test.assertEquals('object', typeof globalSetting.get()); |
| 838 test.assertEquals('global', globalSetting.get().s); | 838 test.assertEquals('global', globalSetting.get().s); |
| 839 test.assertEquals(2, globalSetting.get().n); | 839 test.assertEquals(2, globalSetting.get().n); |
| 840 test.releaseControl(); | 840 test.releaseControl(); |
| 841 } | 841 } |
| 842 }; | 842 }; |
| 843 | 843 |
| 844 TestSuite.prototype.testWindowInitializedOnNavigateBack = function() { | 844 TestSuite.prototype.testWindowInitializedOnNavigateBack = function() { |
| 845 var messages = WebInspector.multitargetConsoleModel.messages(); | 845 var messages = SDK.multitargetConsoleModel.messages(); |
| 846 this.assertEquals(1, messages.length); | 846 this.assertEquals(1, messages.length); |
| 847 var text = messages[0].messageText; | 847 var text = messages[0].messageText; |
| 848 if (text.indexOf('Uncaught') !== -1) | 848 if (text.indexOf('Uncaught') !== -1) |
| 849 this.fail(text); | 849 this.fail(text); |
| 850 }; | 850 }; |
| 851 | 851 |
| 852 TestSuite.prototype.testConsoleContextNames = function() { | 852 TestSuite.prototype.testConsoleContextNames = function() { |
| 853 var test = this; | 853 var test = this; |
| 854 test.takeControl(); | 854 test.takeControl(); |
| 855 this.showPanel('console').then(() => this._waitForExecutionContexts(2, onExe
cutionContexts.bind(this))); | 855 this.showPanel('console').then(() => this._waitForExecutionContexts(2, onExe
cutionContexts.bind(this))); |
| 856 | 856 |
| 857 function onExecutionContexts() { | 857 function onExecutionContexts() { |
| 858 var consoleView = WebInspector.ConsoleView.instance(); | 858 var consoleView = Console.ConsoleView.instance(); |
| 859 var options = consoleView._consoleContextSelector._selectElement.options; | 859 var options = consoleView._consoleContextSelector._selectElement.options; |
| 860 var values = []; | 860 var values = []; |
| 861 for (var i = 0; i < options.length; ++i) | 861 for (var i = 0; i < options.length; ++i) |
| 862 values.push(options[i].value.trim()); | 862 values.push(options[i].value.trim()); |
| 863 test.assertEquals('top', values[0]); | 863 test.assertEquals('top', values[0]); |
| 864 test.assertEquals('Simple content script', values[1]); | 864 test.assertEquals('Simple content script', values[1]); |
| 865 test.releaseControl(); | 865 test.releaseControl(); |
| 866 } | 866 } |
| 867 }; | 867 }; |
| 868 | 868 |
| 869 TestSuite.prototype.testDevToolsSharedWorker = function() { | 869 TestSuite.prototype.testDevToolsSharedWorker = function() { |
| 870 this.takeControl(); | 870 this.takeControl(); |
| 871 WebInspector.TempFile.ensureTempStorageCleared().then(() => this.releaseCont
rol()); | 871 Bindings.TempFile.ensureTempStorageCleared().then(() => this.releaseControl(
)); |
| 872 }; | 872 }; |
| 873 | 873 |
| 874 TestSuite.prototype.waitForTestResultsInConsole = function() { | 874 TestSuite.prototype.waitForTestResultsInConsole = function() { |
| 875 var messages = WebInspector.multitargetConsoleModel.messages(); | 875 var messages = SDK.multitargetConsoleModel.messages(); |
| 876 for (var i = 0; i < messages.length; ++i) { | 876 for (var i = 0; i < messages.length; ++i) { |
| 877 var text = messages[i].messageText; | 877 var text = messages[i].messageText; |
| 878 if (text === 'PASS') | 878 if (text === 'PASS') |
| 879 return; | 879 return; |
| 880 else if (/^FAIL/.test(text)) | 880 else if (/^FAIL/.test(text)) |
| 881 this.fail(text); // This will throw. | 881 this.fail(text); // This will throw. |
| 882 } | 882 } |
| 883 // Neither PASS nor FAIL, so wait for more messages. | 883 // Neither PASS nor FAIL, so wait for more messages. |
| 884 function onConsoleMessage(event) { | 884 function onConsoleMessage(event) { |
| 885 var text = event.data.messageText; | 885 var text = event.data.messageText; |
| 886 if (text === 'PASS') | 886 if (text === 'PASS') |
| 887 this.releaseControl(); | 887 this.releaseControl(); |
| 888 else if (/^FAIL/.test(text)) | 888 else if (/^FAIL/.test(text)) |
| 889 this.fail(text); | 889 this.fail(text); |
| 890 } | 890 } |
| 891 | 891 |
| 892 WebInspector.multitargetConsoleModel.addEventListener( | 892 SDK.multitargetConsoleModel.addEventListener( |
| 893 WebInspector.ConsoleModel.Events.MessageAdded, onConsoleMessage, this); | 893 SDK.ConsoleModel.Events.MessageAdded, onConsoleMessage, this); |
| 894 this.takeControl(); | 894 this.takeControl(); |
| 895 }; | 895 }; |
| 896 | 896 |
| 897 TestSuite.prototype._overrideMethod = function(receiver, methodName, override)
{ | 897 TestSuite.prototype._overrideMethod = function(receiver, methodName, override)
{ |
| 898 var original = receiver[methodName]; | 898 var original = receiver[methodName]; |
| 899 if (typeof original !== 'function') { | 899 if (typeof original !== 'function') { |
| 900 this.fail(`TestSuite._overrideMethod: $[methodName] is not a function`); | 900 this.fail(`TestSuite._overrideMethod: $[methodName] is not a function`); |
| 901 return; | 901 return; |
| 902 } | 902 } |
| 903 receiver[methodName] = function() { | 903 receiver[methodName] = function() { |
| 904 try { | 904 try { |
| 905 var value = original.apply(receiver, arguments); | 905 var value = original.apply(receiver, arguments); |
| 906 } finally { | 906 } finally { |
| 907 receiver[methodName] = original; | 907 receiver[methodName] = original; |
| 908 } | 908 } |
| 909 override.apply(original, arguments); | 909 override.apply(original, arguments); |
| 910 return value; | 910 return value; |
| 911 }; | 911 }; |
| 912 }; | 912 }; |
| 913 | 913 |
| 914 TestSuite.prototype.startTimeline = function(callback) { | 914 TestSuite.prototype.startTimeline = function(callback) { |
| 915 var test = this; | 915 var test = this; |
| 916 this.showPanel('timeline').then(function() { | 916 this.showPanel('timeline').then(function() { |
| 917 var timeline = WebInspector.panels.timeline; | 917 var timeline = UI.panels.timeline; |
| 918 test._overrideMethod(timeline, 'recordingStarted', callback); | 918 test._overrideMethod(timeline, 'recordingStarted', callback); |
| 919 timeline._toggleRecording(); | 919 timeline._toggleRecording(); |
| 920 }); | 920 }); |
| 921 }; | 921 }; |
| 922 | 922 |
| 923 TestSuite.prototype.stopTimeline = function(callback) { | 923 TestSuite.prototype.stopTimeline = function(callback) { |
| 924 var timeline = WebInspector.panels.timeline; | 924 var timeline = UI.panels.timeline; |
| 925 this._overrideMethod(timeline, 'loadingComplete', callback); | 925 this._overrideMethod(timeline, 'loadingComplete', callback); |
| 926 timeline._toggleRecording(); | 926 timeline._toggleRecording(); |
| 927 }; | 927 }; |
| 928 | 928 |
| 929 TestSuite.prototype.invokePageFunctionAsync = function(functionName, opt_args,
callback_is_always_last) { | 929 TestSuite.prototype.invokePageFunctionAsync = function(functionName, opt_args,
callback_is_always_last) { |
| 930 var callback = arguments[arguments.length - 1]; | 930 var callback = arguments[arguments.length - 1]; |
| 931 var doneMessage = `DONE: ${functionName}.${++this._asyncInvocationId}`; | 931 var doneMessage = `DONE: ${functionName}.${++this._asyncInvocationId}`; |
| 932 var argsString = arguments.length < 3 ? | 932 var argsString = arguments.length < 3 ? |
| 933 '' : | 933 '' : |
| 934 Array.prototype.slice.call(arguments, 1, -1).map(arg => JSON.stringify(a
rg)).join(',') + ','; | 934 Array.prototype.slice.call(arguments, 1, -1).map(arg => JSON.stringify(a
rg)).join(',') + ','; |
| 935 this.evaluateInConsole_( | 935 this.evaluateInConsole_( |
| 936 `${functionName}(${argsString} function() { console.log('${doneMessage}'
); });`, function() {}); | 936 `${functionName}(${argsString} function() { console.log('${doneMessage}'
); });`, function() {}); |
| 937 WebInspector.multitargetConsoleModel.addEventListener( | 937 SDK.multitargetConsoleModel.addEventListener( |
| 938 WebInspector.ConsoleModel.Events.MessageAdded, onConsoleMessage); | 938 SDK.ConsoleModel.Events.MessageAdded, onConsoleMessage); |
| 939 | 939 |
| 940 function onConsoleMessage(event) { | 940 function onConsoleMessage(event) { |
| 941 var text = event.data.messageText; | 941 var text = event.data.messageText; |
| 942 if (text === doneMessage) { | 942 if (text === doneMessage) { |
| 943 WebInspector.multitargetConsoleModel.removeEventListener( | 943 SDK.multitargetConsoleModel.removeEventListener( |
| 944 WebInspector.ConsoleModel.Events.MessageAdded, onConsoleMessage); | 944 SDK.ConsoleModel.Events.MessageAdded, onConsoleMessage); |
| 945 callback(); | 945 callback(); |
| 946 } | 946 } |
| 947 } | 947 } |
| 948 }; | 948 }; |
| 949 | 949 |
| 950 TestSuite.prototype.invokeAsyncWithTimeline_ = function(functionName, callback
) { | 950 TestSuite.prototype.invokeAsyncWithTimeline_ = function(functionName, callback
) { |
| 951 var test = this; | 951 var test = this; |
| 952 | 952 |
| 953 this.startTimeline(onRecordingStarted); | 953 this.startTimeline(onRecordingStarted); |
| 954 | 954 |
| 955 function onRecordingStarted() { | 955 function onRecordingStarted() { |
| 956 test.invokePageFunctionAsync(functionName, pageActionsDone); | 956 test.invokePageFunctionAsync(functionName, pageActionsDone); |
| 957 } | 957 } |
| 958 | 958 |
| 959 function pageActionsDone() { | 959 function pageActionsDone() { |
| 960 test.stopTimeline(callback); | 960 test.stopTimeline(callback); |
| 961 } | 961 } |
| 962 }; | 962 }; |
| 963 | 963 |
| 964 TestSuite.prototype.enableExperiment = function(name) { | 964 TestSuite.prototype.enableExperiment = function(name) { |
| 965 Runtime.experiments.enableForTest(name); | 965 Runtime.experiments.enableForTest(name); |
| 966 }; | 966 }; |
| 967 | 967 |
| 968 TestSuite.prototype.checkInputEventsPresent = function() { | 968 TestSuite.prototype.checkInputEventsPresent = function() { |
| 969 var expectedEvents = new Set(arguments); | 969 var expectedEvents = new Set(arguments); |
| 970 var model = WebInspector.panels.timeline._model; | 970 var model = UI.panels.timeline._model; |
| 971 var asyncEvents = model.mainThreadAsyncEvents(); | 971 var asyncEvents = model.mainThreadAsyncEvents(); |
| 972 var input = asyncEvents.get(WebInspector.TimelineModel.AsyncEventGroup.input
) || []; | 972 var input = asyncEvents.get(TimelineModel.TimelineModel.AsyncEventGroup.inpu
t) || []; |
| 973 var prefix = 'InputLatency::'; | 973 var prefix = 'InputLatency::'; |
| 974 for (var e of input) { | 974 for (var e of input) { |
| 975 if (!e.name.startsWith(prefix)) | 975 if (!e.name.startsWith(prefix)) |
| 976 continue; | 976 continue; |
| 977 if (e.steps.length < 2) | 977 if (e.steps.length < 2) |
| 978 continue; | 978 continue; |
| 979 if (e.name.startsWith(prefix + 'Mouse') && typeof WebInspector.TimelineDat
a.forEvent(e.steps[0]).timeWaitingForMainThread !== 'number') | 979 if (e.name.startsWith(prefix + 'Mouse') && typeof TimelineModel.TimelineDa
ta.forEvent(e.steps[0]).timeWaitingForMainThread !== 'number') |
| 980 throw `Missing timeWaitingForMainThread on ${e.name}`; | 980 throw `Missing timeWaitingForMainThread on ${e.name}`; |
| 981 expectedEvents.delete(e.name.substr(prefix.length)); | 981 expectedEvents.delete(e.name.substr(prefix.length)); |
| 982 } | 982 } |
| 983 if (expectedEvents.size) | 983 if (expectedEvents.size) |
| 984 throw 'Some expected events are not found: ' + Array.from(expectedEvents.k
eys()).join(','); | 984 throw 'Some expected events are not found: ' + Array.from(expectedEvents.k
eys()).join(','); |
| 985 }; | 985 }; |
| 986 | 986 |
| 987 /** | 987 /** |
| 988 * Serializes array of uiSourceCodes to string. | 988 * Serializes array of uiSourceCodes to string. |
| 989 * @param {!Array.<!WebInspectorUISourceCode>} uiSourceCodes | 989 * @param {!Array.<!Workspace.UISourceCode>} uiSourceCodes |
| 990 * @return {string} | 990 * @return {string} |
| 991 */ | 991 */ |
| 992 TestSuite.prototype.uiSourceCodesToString_ = function(uiSourceCodes) { | 992 TestSuite.prototype.uiSourceCodesToString_ = function(uiSourceCodes) { |
| 993 var names = []; | 993 var names = []; |
| 994 for (var i = 0; i < uiSourceCodes.length; i++) | 994 for (var i = 0; i < uiSourceCodes.length; i++) |
| 995 names.push('"' + uiSourceCodes[i].url() + '"'); | 995 names.push('"' + uiSourceCodes[i].url() + '"'); |
| 996 return names.join(','); | 996 return names.join(','); |
| 997 }; | 997 }; |
| 998 | 998 |
| 999 /** | 999 /** |
| 1000 * Returns all loaded non anonymous uiSourceCodes. | 1000 * Returns all loaded non anonymous uiSourceCodes. |
| 1001 * @return {!Array.<!WebInspectorUISourceCode>} | 1001 * @return {!Array.<!Workspace.UISourceCode>} |
| 1002 */ | 1002 */ |
| 1003 TestSuite.prototype.nonAnonymousUISourceCodes_ = function() { | 1003 TestSuite.prototype.nonAnonymousUISourceCodes_ = function() { |
| 1004 /** | 1004 /** |
| 1005 * @param {!WebInspector.UISourceCode} uiSourceCode | 1005 * @param {!Workspace.UISourceCode} uiSourceCode |
| 1006 */ | 1006 */ |
| 1007 function filterOutService(uiSourceCode) { | 1007 function filterOutService(uiSourceCode) { |
| 1008 return !uiSourceCode.isFromServiceProject(); | 1008 return !uiSourceCode.isFromServiceProject(); |
| 1009 } | 1009 } |
| 1010 | 1010 |
| 1011 var uiSourceCodes = WebInspector.workspace.uiSourceCodes(); | 1011 var uiSourceCodes = Workspace.workspace.uiSourceCodes(); |
| 1012 return uiSourceCodes.filter(filterOutService); | 1012 return uiSourceCodes.filter(filterOutService); |
| 1013 }; | 1013 }; |
| 1014 | 1014 |
| 1015 /* | 1015 /* |
| 1016 * Evaluates the code in the console as if user typed it manually and invokes | 1016 * Evaluates the code in the console as if user typed it manually and invokes |
| 1017 * the callback when the result message is received and added to the console. | 1017 * the callback when the result message is received and added to the console. |
| 1018 * @param {string} code | 1018 * @param {string} code |
| 1019 * @param {function(string)} callback | 1019 * @param {function(string)} callback |
| 1020 */ | 1020 */ |
| 1021 TestSuite.prototype.evaluateInConsole_ = function(code, callback) { | 1021 TestSuite.prototype.evaluateInConsole_ = function(code, callback) { |
| 1022 function innerEvaluate() { | 1022 function innerEvaluate() { |
| 1023 WebInspector.context.removeFlavorChangeListener(WebInspector.ExecutionCont
ext, showConsoleAndEvaluate, this); | 1023 UI.context.removeFlavorChangeListener(SDK.ExecutionContext, showConsoleAnd
Evaluate, this); |
| 1024 var consoleView = WebInspector.ConsoleView.instance(); | 1024 var consoleView = Console.ConsoleView.instance(); |
| 1025 consoleView._prompt._appendCommand(code); | 1025 consoleView._prompt._appendCommand(code); |
| 1026 | 1026 |
| 1027 this.addSniffer(WebInspector.ConsoleView.prototype, '_consoleMessageAddedF
orTest', function(viewMessage) { | 1027 this.addSniffer(Console.ConsoleView.prototype, '_consoleMessageAddedForTes
t', function(viewMessage) { |
| 1028 callback(viewMessage.toMessageElement().deepTextContent()); | 1028 callback(viewMessage.toMessageElement().deepTextContent()); |
| 1029 }.bind(this)); | 1029 }.bind(this)); |
| 1030 } | 1030 } |
| 1031 | 1031 |
| 1032 function showConsoleAndEvaluate() { | 1032 function showConsoleAndEvaluate() { |
| 1033 WebInspector.console.showPromise().then(innerEvaluate.bind(this)); | 1033 Common.console.showPromise().then(innerEvaluate.bind(this)); |
| 1034 } | 1034 } |
| 1035 | 1035 |
| 1036 if (!WebInspector.context.flavor(WebInspector.ExecutionContext)) { | 1036 if (!UI.context.flavor(SDK.ExecutionContext)) { |
| 1037 WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext
, showConsoleAndEvaluate, this); | 1037 UI.context.addFlavorChangeListener(SDK.ExecutionContext, showConsoleAndEva
luate, this); |
| 1038 return; | 1038 return; |
| 1039 } | 1039 } |
| 1040 showConsoleAndEvaluate.call(this); | 1040 showConsoleAndEvaluate.call(this); |
| 1041 }; | 1041 }; |
| 1042 | 1042 |
| 1043 /** | 1043 /** |
| 1044 * Checks that all expected scripts are present in the scripts list | 1044 * Checks that all expected scripts are present in the scripts list |
| 1045 * in the Scripts panel. | 1045 * in the Scripts panel. |
| 1046 * @param {!Array.<string>} expected Regular expressions describing | 1046 * @param {!Array.<string>} expected Regular expressions describing |
| 1047 * expected script names. | 1047 * expected script names. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1061 } | 1061 } |
| 1062 } | 1062 } |
| 1063 return missing.length === 0; | 1063 return missing.length === 0; |
| 1064 }; | 1064 }; |
| 1065 | 1065 |
| 1066 /** | 1066 /** |
| 1067 * Waits for script pause, checks expectations, and invokes the callback. | 1067 * Waits for script pause, checks expectations, and invokes the callback. |
| 1068 * @param {function():void} callback | 1068 * @param {function():void} callback |
| 1069 */ | 1069 */ |
| 1070 TestSuite.prototype._waitForScriptPause = function(callback) { | 1070 TestSuite.prototype._waitForScriptPause = function(callback) { |
| 1071 this.addSniffer(WebInspector.DebuggerModel.prototype, '_pausedScript', callb
ack); | 1071 this.addSniffer(SDK.DebuggerModel.prototype, '_pausedScript', callback); |
| 1072 }; | 1072 }; |
| 1073 | 1073 |
| 1074 /** | 1074 /** |
| 1075 * Waits until all the scripts are parsed and invokes the callback. | 1075 * Waits until all the scripts are parsed and invokes the callback. |
| 1076 */ | 1076 */ |
| 1077 TestSuite.prototype._waitUntilScriptsAreParsed = function(expectedScripts, cal
lback) { | 1077 TestSuite.prototype._waitUntilScriptsAreParsed = function(expectedScripts, cal
lback) { |
| 1078 var test = this; | 1078 var test = this; |
| 1079 | 1079 |
| 1080 function waitForAllScripts() { | 1080 function waitForAllScripts() { |
| 1081 if (test._scriptsAreParsed(expectedScripts)) | 1081 if (test._scriptsAreParsed(expectedScripts)) |
| 1082 callback(); | 1082 callback(); |
| 1083 else | 1083 else |
| 1084 test.addSniffer(WebInspector.panels.sources.sourcesView(), '_addUISource
Code', waitForAllScripts); | 1084 test.addSniffer(UI.panels.sources.sourcesView(), '_addUISourceCode', wai
tForAllScripts); |
| 1085 } | 1085 } |
| 1086 | 1086 |
| 1087 waitForAllScripts(); | 1087 waitForAllScripts(); |
| 1088 }; | 1088 }; |
| 1089 | 1089 |
| 1090 TestSuite.prototype._waitForTargets = function(n, callback) { | 1090 TestSuite.prototype._waitForTargets = function(n, callback) { |
| 1091 checkTargets.call(this); | 1091 checkTargets.call(this); |
| 1092 | 1092 |
| 1093 function checkTargets() { | 1093 function checkTargets() { |
| 1094 if (WebInspector.targetManager.targets().length >= n) | 1094 if (SDK.targetManager.targets().length >= n) |
| 1095 callback.call(null); | 1095 callback.call(null); |
| 1096 else | 1096 else |
| 1097 this.addSniffer(WebInspector.TargetManager.prototype, 'addTarget', check
Targets.bind(this)); | 1097 this.addSniffer(SDK.TargetManager.prototype, 'addTarget', checkTargets.b
ind(this)); |
| 1098 } | 1098 } |
| 1099 }; | 1099 }; |
| 1100 | 1100 |
| 1101 TestSuite.prototype._waitForExecutionContexts = function(n, callback) { | 1101 TestSuite.prototype._waitForExecutionContexts = function(n, callback) { |
| 1102 var runtimeModel = WebInspector.targetManager.mainTarget().runtimeModel; | 1102 var runtimeModel = SDK.targetManager.mainTarget().runtimeModel; |
| 1103 checkForExecutionContexts.call(this); | 1103 checkForExecutionContexts.call(this); |
| 1104 | 1104 |
| 1105 function checkForExecutionContexts() { | 1105 function checkForExecutionContexts() { |
| 1106 if (runtimeModel.executionContexts().length >= n) | 1106 if (runtimeModel.executionContexts().length >= n) |
| 1107 callback.call(null); | 1107 callback.call(null); |
| 1108 else | 1108 else |
| 1109 this.addSniffer( | 1109 this.addSniffer( |
| 1110 WebInspector.RuntimeModel.prototype, '_executionContextCreated', che
ckForExecutionContexts.bind(this)); | 1110 SDK.RuntimeModel.prototype, '_executionContextCreated', checkForExec
utionContexts.bind(this)); |
| 1111 } | 1111 } |
| 1112 }; | 1112 }; |
| 1113 | 1113 |
| 1114 | 1114 |
| 1115 window.uiTests = new TestSuite(window.domAutomationController); | 1115 window.uiTests = new TestSuite(window.domAutomationController); |
| 1116 })(window); | 1116 })(window); |
| OLD | NEW |