Commit d36c8d6d authored by Will Chen's avatar Will Chen Committed by Commit Bot

DevTools: refactor with new method TestRunner.url(...)

This cleans up several call-sites in the new test framework that's just
copy-and-paste code.

Bug: 667560
Change-Id: I7da98a1d25f4103f7e1789067f6f0ed3651830d1
Reviewed-on: https://chromium-review.googlesource.com/693144Reviewed-by: default avatarWill Chen <chenwilliam@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Will Chen <chenwilliam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505812}
parent 9f6b2091
...@@ -163,13 +163,10 @@ TestRunner.loadHTML = function(html) { ...@@ -163,13 +163,10 @@ TestRunner.loadHTML = function(html) {
* @return {!Promise<!SDK.RemoteObject>} * @return {!Promise<!SDK.RemoteObject>}
*/ */
TestRunner.addScriptTag = function(path) { TestRunner.addScriptTag = function(path) {
var testScriptURL = /** @type {string} */ (Runtime.queryParam('test'));
var resolvedPath = testScriptURL + '/../' + path;
return TestRunner.evaluateInPagePromise(` return TestRunner.evaluateInPagePromise(`
(function(){ (function(){
var script = document.createElement('script'); var script = document.createElement('script');
script.src = '${resolvedPath}'; script.src = '${TestRunner.url(path)}';
document.head.append(script); document.head.append(script);
})(); })();
`); `);
...@@ -180,15 +177,12 @@ TestRunner.addScriptTag = function(path) { ...@@ -180,15 +177,12 @@ TestRunner.addScriptTag = function(path) {
* @return {!Promise<!SDK.RemoteObject|undefined>} * @return {!Promise<!SDK.RemoteObject|undefined>}
*/ */
TestRunner.addStylesheetTag = function(path) { TestRunner.addStylesheetTag = function(path) {
var testScriptURL = /** @type {string} */ (Runtime.queryParam('test'));
var resolvedPath = testScriptURL + '/../' + path;
return TestRunner.evaluateInPageAsync(` return TestRunner.evaluateInPageAsync(`
(function(){ (function(){
var link = document.createElement('link'); var link = document.createElement('link');
link.rel = 'stylesheet'; link.rel = 'stylesheet';
link.type = 'text/css'; link.type = 'text/css';
link.href = '${resolvedPath}'; link.href = '${TestRunner.url(path)}';
link.onload = onload; link.onload = onload;
document.head.append(link); document.head.append(link);
var resolve; var resolve;
...@@ -208,13 +202,10 @@ TestRunner.addStylesheetTag = function(path) { ...@@ -208,13 +202,10 @@ TestRunner.addStylesheetTag = function(path) {
* @return {!Promise<!SDK.RemoteObject|undefined>} * @return {!Promise<!SDK.RemoteObject|undefined>}
*/ */
TestRunner.addIframe = function(path) { TestRunner.addIframe = function(path) {
var testScriptURL = /** @type {string} */ (Runtime.queryParam('test'));
var resolvedPath = testScriptURL + '/../' + path;
return TestRunner.evaluateInPageAsync(` return TestRunner.evaluateInPageAsync(`
(function(){ (function(){
var iframe = document.createElement('iframe'); var iframe = document.createElement('iframe');
iframe.src = '${resolvedPath}'; iframe.src = '${TestRunner.url(path)}';
iframe.onload = onload; iframe.onload = onload;
document.body.appendChild(iframe); document.body.appendChild(iframe);
...@@ -829,6 +820,15 @@ TestRunner.waitForUISourceCodeRemoved = function(callback) { ...@@ -829,6 +820,15 @@ TestRunner.waitForUISourceCodeRemoved = function(callback) {
Workspace.workspace.once(Workspace.Workspace.Events.UISourceCodeRemoved).then(callback); Workspace.workspace.once(Workspace.Workspace.Events.UISourceCodeRemoved).then(callback);
}; };
/**
* @param {string} relativeURL
* @return {string}
*/
TestRunner.url = function(relativeURL) {
var testScriptURL = /** @type {string} */ (Runtime.queryParam('test'));
return testScriptURL + '/../' + relativeURL;
};
/** @type {boolean} */ /** @type {boolean} */
IntegrationTestRunner._startedTest = false; IntegrationTestRunner._startedTest = false;
...@@ -857,8 +857,7 @@ IntegrationTestRunner.TestObserver = class { ...@@ -857,8 +857,7 @@ IntegrationTestRunner.TestObserver = class {
}; };
IntegrationTestRunner.runTest = async function() { IntegrationTestRunner.runTest = async function() {
var testScriptURL = /** @type {string} */ (Runtime.queryParam('test')); var basePath = TestRunner.url('');
var basePath = testScriptURL + '/../';
await TestRunner.evaluateInPagePromise(` await TestRunner.evaluateInPagePromise(`
function relativeToTest(relativePath) { function relativeToTest(relativePath) {
return '${basePath}' + relativePath; return '${basePath}' + relativePath;
......
...@@ -82,12 +82,9 @@ NetworkTestRunner.makeSimpleXHRWithPayload = function(method, url, async, payloa ...@@ -82,12 +82,9 @@ NetworkTestRunner.makeSimpleXHRWithPayload = function(method, url, async, payloa
NetworkTestRunner.makeXHR = function( NetworkTestRunner.makeXHR = function(
method, url, async, user, password, headers, withCredentials, payload, type, callback) { method, url, async, user, password, headers, withCredentials, payload, type, callback) {
var testScriptURL = /** @type {string} */ (Runtime.queryParam('test'));
var resolvedPath = testScriptURL + '/../' + url;
var args = {}; var args = {};
args.method = method; args.method = method;
args.url = resolvedPath; args.url = TestRunner.url(url);
args.async = async; args.async = async;
args.user = user; args.user = user;
args.password = password; args.password = password;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment