| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Export all public members onto TestRunner namespace so test writers have a si
mpler API. | 6 * Export all public members onto TestRunner namespace so test writers have a si
mpler API. |
| 7 * @fileoverview using private properties isn't a Closure violation in tests. | 7 * @fileoverview using private properties isn't a Closure violation in tests. |
| 8 * @suppress {accessControls} | 8 * @suppress {accessControls} |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 TestRunner.domModel = target.model(SDK.DOMModel); | 34 TestRunner.domModel = target.model(SDK.DOMModel); |
| 35 TestRunner.domDebuggerModel = target.model(SDK.DOMDebuggerModel); | 35 TestRunner.domDebuggerModel = target.model(SDK.DOMDebuggerModel); |
| 36 TestRunner.cssModel = target.model(SDK.CSSModel); | 36 TestRunner.cssModel = target.model(SDK.CSSModel); |
| 37 TestRunner.cpuProfilerModel = target.model(SDK.CPUProfilerModel); | 37 TestRunner.cpuProfilerModel = target.model(SDK.CPUProfilerModel); |
| 38 TestRunner.serviceWorkerManager = target.model(SDK.ServiceWorkerManager); | 38 TestRunner.serviceWorkerManager = target.model(SDK.ServiceWorkerManager); |
| 39 TestRunner.tracingManager = target.model(SDK.TracingManager); | 39 TestRunner.tracingManager = target.model(SDK.TracingManager); |
| 40 TestRunner.mainTarget = target; | 40 TestRunner.mainTarget = target; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * @param {string} code | 44 * @param {string|!Function} code |
| 45 * @param {!Function} callback | 45 * @param {!Function} callback |
| 46 */ | 46 */ |
| 47 TestRunner.evaluateInPage = async function(code, callback) { | 47 TestRunner.evaluateInPage = async function(code, callback) { |
| 48 if (typeof code === 'function') |
| 49 code = `(${code.toString()})()`; |
| 48 var response = await TestRunner.RuntimeAgent.invoke_evaluate({expression: code
, objectGroup: 'console'}); | 50 var response = await TestRunner.RuntimeAgent.invoke_evaluate({expression: code
, objectGroup: 'console'}); |
| 49 if (!response[Protocol.Error]) { | 51 if (!response[Protocol.Error]) { |
| 50 TestRunner.safeWrap(callback)( | 52 TestRunner.safeWrap(callback)( |
| 51 TestRunner.runtimeModel.createRemoteObject(response.result), response.ex
ceptionDetails); | 53 TestRunner.runtimeModel.createRemoteObject(response.result), response.ex
ceptionDetails); |
| 52 } | 54 } |
| 53 }; | 55 }; |
| 54 | 56 |
| 55 /** | 57 /** |
| 56 * @param {string} code | 58 * @param {string|!Function} code |
| 57 * @return {!Promise<!SDK.RemoteObject>} | 59 * @return {!Promise<!SDK.RemoteObject>} |
| 58 */ | 60 */ |
| 59 TestRunner.evaluateInPagePromise = function(code) { | 61 TestRunner.evaluateInPagePromise = function(code) { |
| 60 return new Promise(success => TestRunner.evaluateInPage(code, success)); | 62 return new Promise(success => TestRunner.evaluateInPage(code, success)); |
| 61 }; | 63 }; |
| 62 | 64 |
| 63 /** | 65 /** |
| 64 * @param {!Function} callback | 66 * @param {!Function} callback |
| 65 */ | 67 */ |
| 66 TestRunner.deprecatedRunAfterPendingDispatches = function(callback) { | 68 TestRunner.deprecatedRunAfterPendingDispatches = function(callback) { |
| 67 var targets = SDK.targetManager.targets(); | 69 var targets = SDK.targetManager.targets(); |
| 68 var promises = targets.map(target => new Promise(resolve => target._deprecated
RunAfterPendingDispatches(resolve))); | 70 var promises = targets.map(target => new Promise(resolve => target._deprecated
RunAfterPendingDispatches(resolve))); |
| 69 Promise.all(promises).then(TestRunner.safeWrap(callback)); | 71 Promise.all(promises).then(TestRunner.safeWrap(callback)); |
| 70 }; | 72 }; |
| 71 | 73 |
| 74 /** |
| 75 * @param {string} html |
| 76 * @return {!Promise<!SDK.RemoteObject>} |
| 77 */ |
| 78 TestRunner.loadHTML = function(html) { |
| 79 html = html.replace(/'/g, '\\\'').replace(/\n/g, '\\n'); |
| 80 return TestRunner.evaluateInPagePromise(`document.write('${html}');document.cl
ose();`); |
| 81 }; |
| 82 |
| 72 /** @type {boolean} */ | 83 /** @type {boolean} */ |
| 73 IntegrationTestRunner._startedTest = false; | 84 IntegrationTestRunner._startedTest = false; |
| 74 | 85 |
| 75 /** | 86 /** |
| 76 * @implements {SDK.TargetManager.Observer} | 87 * @implements {SDK.TargetManager.Observer} |
| 77 */ | 88 */ |
| 78 IntegrationTestRunner.TestObserver = class { | 89 IntegrationTestRunner.TestObserver = class { |
| 79 /** | 90 /** |
| 80 * @param {!SDK.Target} target | 91 * @param {!SDK.Target} target |
| 81 * @override | 92 * @override |
| 82 */ | 93 */ |
| 83 targetAdded(target) { | 94 targetAdded(target) { |
| 84 if (IntegrationTestRunner._startedTest) | 95 if (IntegrationTestRunner._startedTest) |
| 85 return; | 96 return; |
| 86 IntegrationTestRunner._startedTest = true; | 97 IntegrationTestRunner._startedTest = true; |
| 87 IntegrationTestRunner._setupTestHelpers(target); | 98 IntegrationTestRunner._setupTestHelpers(target); |
| 88 TestRunner.executeTestScript(); | 99 TestRunner.executeTestScript(); |
| 89 } | 100 } |
| 90 | 101 |
| 91 /** | 102 /** |
| 92 * @param {!SDK.Target} target | 103 * @param {!SDK.Target} target |
| 93 * @override | 104 * @override |
| 94 */ | 105 */ |
| 95 targetRemoved(target) { | 106 targetRemoved(target) { |
| 96 } | 107 } |
| 97 }; | 108 }; |
| 98 | 109 |
| 99 SDK.targetManager.observeTargets(new IntegrationTestRunner.TestObserver()); | 110 SDK.targetManager.observeTargets(new IntegrationTestRunner.TestObserver()); |
| OLD | NEW |