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

DevTools: clean up TestRunner.js & isUnderTest() mechanism

This cleans up TestRunner's few spots where the code branched because it needed
to also support the legacy integration tests.

Also, this simplifies the "isUnderTest()" mechanism by relying on the queryParam
instead of a special Host API.

TBR=haraken@chromium.org

Bug: 667560
Change-Id: If161c6f485acaf96b38e437c64324635ebcbdcba
Reviewed-on: https://chromium-review.googlesource.com/833392Reviewed-by: default avatarWill Chen <chenwilliam@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Will Chen <chenwilliam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#525369}
parent dd5e4dd9
......@@ -38,7 +38,6 @@
#include "core/frame/WebLocalFrameImpl.h"
#include "core/inspector/DevToolsHost.h"
#include "core/page/Page.h"
#include "platform/LayoutTestSupport.h"
namespace blink {
......@@ -120,10 +119,6 @@ void DevToolsFrontendImpl::SendMessageToEmbedder(const String& message) {
host_->DispatchEmbedderMessage(message);
}
bool DevToolsFrontendImpl::IsUnderTest() {
return LayoutTestSupport::IsRunningLayoutTest();
}
void DevToolsFrontendImpl::ShowContextMenu(LocalFrame* target_frame,
float x,
float y,
......
......@@ -77,7 +77,6 @@ class DevToolsFrontendImpl final
// InspectorFrontendClient implementation.
void SendMessageToEmbedder(const String&) override;
bool IsUnderTest() override;
void ShowContextMenu(LocalFrame*,
float x,
float y,
......
......@@ -232,9 +232,6 @@ String DevToolsHost::getInactiveSelectionForegroundColor() {
.Serialized();
}
bool DevToolsHost::isUnderTest() {
return client_ && client_->IsUnderTest();
}
bool DevToolsHost::isHostedMode() {
return false;
......
......@@ -71,7 +71,6 @@ class CORE_EXPORT DevToolsHost final : public ScriptWrappable {
String getInactiveSelectionBackgroundColor();
String getInactiveSelectionForegroundColor();
bool isUnderTest();
bool isHostedMode();
LocalFrame* FrontendFrame() { return frontend_frame_; }
......
......@@ -46,6 +46,5 @@
DOMString getInactiveSelectionBackgroundColor();
DOMString getInactiveSelectionForegroundColor();
boolean isUnderTest();
boolean isHostedMode();
};
......@@ -45,8 +45,6 @@ class InspectorFrontendClient : public GarbageCollectedMixin {
virtual void SendMessageToEmbedder(const String&) = 0;
virtual bool IsUnderTest() = 0;
virtual void ShowContextMenu(LocalFrame* target_frame,
float x,
float y,
......
......@@ -657,14 +657,6 @@
DevToolsAPI.sendMessageToEmbedder('showCertificateViewer', [JSON.stringify(certChain)], null);
}
/**
* @override
* @return {boolean}
*/
isUnderTest() {
return DevToolsHost.isUnderTest();
}
/**
* @override
* @param {function()} callback
......
......@@ -267,11 +267,6 @@ DevToolsHost.getInactiveSelectionBackgroundColor = function() {};
*/
DevToolsHost.getInactiveSelectionForegroundColor = function() {};
/**
* @return {boolean}
*/
DevToolsHost.isUnderTest = function() {};
/**
* @return {boolean}
*/
......
......@@ -368,14 +368,6 @@ Host.InspectorFrontendHostStub = class {
showCertificateViewer(certChain) {
}
/**
* @override
* @return {boolean}
*/
isUnderTest() {
return false;
}
/**
* @override
* @param {function()} callback
......@@ -554,12 +546,13 @@ InspectorFrontendHost.events;
* @return {boolean}
*/
Host.isUnderTest = function(prefs) {
if (InspectorFrontendHost.isUnderTest())
// Integration tests rely on test queryParam.
if (Runtime.queryParam('test'))
return true;
// Browser tests rely on prefs.
if (prefs)
return prefs['isUnderTest'] === 'true';
return Common.settings.createSetting('isUnderTest', false).get();
return Common.settings && Common.settings.createSetting('isUnderTest', false).get();
};
/**
......
......@@ -316,11 +316,6 @@ InspectorFrontendHostAPI.prototype = {
*/
reattach(callback) {},
/**
* @return {boolean}
*/
isUnderTest() {},
readyForTest() {},
/**
......
......@@ -87,15 +87,15 @@ Main.Main = class {
* Note: this function is called from testSettings in Tests.js.
*/
_createSettings(prefs) {
this._initializeExperiments(prefs);
this._initializeExperiments();
var storagePrefix = '';
if (Host.isCustomDevtoolsFrontend())
storagePrefix = '__custom__';
else if (!Runtime.queryParam('can_dock') && !!Runtime.queryParam('debugFrontend') && !Host.isUnderTest(prefs))
else if (!Runtime.queryParam('can_dock') && !!Runtime.queryParam('debugFrontend') && !Host.isUnderTest())
storagePrefix = '__bundled__';
var localStorage;
if (!Host.isUnderTest(prefs) && window.localStorage) {
if (!Host.isUnderTest() && window.localStorage) {
localStorage = new Common.SettingsStorage(
window.localStorage, undefined, undefined, () => window.localStorage.clear(), storagePrefix);
} else {
......@@ -105,14 +105,11 @@ Main.Main = class {
prefs, InspectorFrontendHost.setPreference, InspectorFrontendHost.removePreference,
InspectorFrontendHost.clearPreferences, storagePrefix);
Common.settings = new Common.Settings(globalStorage, localStorage);
if (!Host.isUnderTest(prefs))
if (!Host.isUnderTest())
new Common.VersionController().updateVersion();
}
/**
* @param {!Object<string, string>} prefs
*/
_initializeExperiments(prefs) {
_initializeExperiments() {
// Keep this sorted alphabetically: both keys and values.
Runtime.experiments.register('accessibilityInspection', 'Accessibility Inspection');
Runtime.experiments.register('applyCustomStylesheet', 'Allow custom UI themes');
......@@ -143,8 +140,8 @@ Main.Main = class {
Runtime.experiments.cleanUpStaleExperiments();
if (Host.isUnderTest(prefs)) {
var testPath = Runtime.queryParam('test') || JSON.parse(prefs['testPath'] || '""');
if (Host.isUnderTest()) {
var testPath = Runtime.queryParam('test');
// Enable experiments for testing.
if (testPath.indexOf('accessibility/') !== -1)
Runtime.experiments.enableForTest('accessibilityInspection');
......
......@@ -1307,10 +1307,7 @@ TestRunner.waitForUISourceCodeRemoved = function(callback) {
* @return {string}
*/
TestRunner.url = function(url = '') {
// TODO(chenwilliam): only new-style tests will have a test queryParam;
// remove inspectedURL() after all tests have been migrated to new test framework.
var testScriptURL =
/** @type {string} */ (Runtime.queryParam('test')) || SDK.targetManager.mainTarget().inspectedURL();
var testScriptURL = /** @type {string} */ (Runtime.queryParam('test'));
// This handles relative (e.g. "../file"), root (e.g. "/resource"),
// absolute (e.g. "http://", "data:") and empty (e.g. "") paths
......@@ -1414,10 +1411,6 @@ TestRunner._isDebugTest = function() {
return !self.testRunner || !!Runtime.queryParam('debugFrontend');
};
// Old-style tests start test using inspector-test.js
if (Runtime.queryParam('test'))
SDK.targetManager.observeTargets(new TestRunner._TestObserver());
(function() {
/**
* @param {string|!Event} message
......@@ -1434,10 +1427,8 @@ function completeTestOnError(message, source, lineno, colno, error) {
self['onerror'] = completeTestOnError;
InspectorFrontendHost.events.addEventListener(
InspectorFrontendHostAPI.Events.EvaluateForTestInFrontend, TestRunner._evaluateForTestInFrontend, TestRunner);
// TODO(chenwilliam): remove check for legacy test when test migration is done.
if (!Runtime.queryParam('test'))
return;
TestRunner._printDevToolsConsole();
if (Host.isStartupTest())
TestRunner._executeTestScript();
SDK.targetManager.observeTargets(new TestRunner._TestObserver());
})();
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