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) {
* @return {!Promise<!SDK.RemoteObject>}
*/
TestRunner.addScriptTag = function(path) {
var testScriptURL = /** @type {string} */ (Runtime.queryParam('test'));
var resolvedPath = testScriptURL + '/../' + path;
return TestRunner.evaluateInPagePromise(`
(function(){
var script = document.createElement('script');
script.src = '${resolvedPath}';
script.src = '${TestRunner.url(path)}';
document.head.append(script);
})();
`);
......@@ -180,15 +177,12 @@ TestRunner.addScriptTag = function(path) {
* @return {!Promise<!SDK.RemoteObject|undefined>}
*/
TestRunner.addStylesheetTag = function(path) {
var testScriptURL = /** @type {string} */ (Runtime.queryParam('test'));
var resolvedPath = testScriptURL + '/../' + path;
return TestRunner.evaluateInPageAsync(`
(function(){
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = '${resolvedPath}';
link.href = '${TestRunner.url(path)}';
link.onload = onload;
document.head.append(link);
var resolve;
......@@ -208,13 +202,10 @@ TestRunner.addStylesheetTag = function(path) {
* @return {!Promise<!SDK.RemoteObject|undefined>}
*/
TestRunner.addIframe = function(path) {
var testScriptURL = /** @type {string} */ (Runtime.queryParam('test'));
var resolvedPath = testScriptURL + '/../' + path;
return TestRunner.evaluateInPageAsync(`
(function(){
var iframe = document.createElement('iframe');
iframe.src = '${resolvedPath}';
iframe.src = '${TestRunner.url(path)}';
iframe.onload = onload;
document.body.appendChild(iframe);
......@@ -829,6 +820,15 @@ TestRunner.waitForUISourceCodeRemoved = function(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} */
IntegrationTestRunner._startedTest = false;
......@@ -857,8 +857,7 @@ IntegrationTestRunner.TestObserver = class {
};
IntegrationTestRunner.runTest = async function() {
var testScriptURL = /** @type {string} */ (Runtime.queryParam('test'));
var basePath = testScriptURL + '/../';
var basePath = TestRunner.url('');
await TestRunner.evaluateInPagePromise(`
function relativeToTest(relativePath) {
return '${basePath}' + relativePath;
......
......@@ -82,12 +82,9 @@ NetworkTestRunner.makeSimpleXHRWithPayload = function(method, url, async, payloa
NetworkTestRunner.makeXHR = function(
method, url, async, user, password, headers, withCredentials, payload, type, callback) {
var testScriptURL = /** @type {string} */ (Runtime.queryParam('test'));
var resolvedPath = testScriptURL + '/../' + url;
var args = {};
args.method = method;
args.url = resolvedPath;
args.url = TestRunner.url(url);
args.async = async;
args.user = user;
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