Commit 75ba7ff2 authored by Tim van der Lippe's avatar Tim van der Lippe Committed by Commit Bot

Fix DevTools strict mode issues

We will soon make the TestRunner run DevTools run in strict mode [1].
Some tests started failing as they were relying on sloppy mode behavior.

Fix these tests by running in strict mode. The tests are manually
verified passing with the updated TestRunner behavior.

[1]: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1953583

Bug: 1006759
Change-Id: Ib0fdc9c044987c797929999b056cde9800142f79
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1958116
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: default avatarMathias Bynens <mathias@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722996}
parent 7f5c4946
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(`Test that each agent could be enabled/disabled separately.\n`);
function printResult(agentName, action, errorString) {
......@@ -14,38 +15,37 @@
TestRunner.addResult(agentName + '.' + action + ' finished successfully');
}
var targets = SDK.targetManager.targets();
for (var target of targets) {
var agentNames = Object.keys(target._agents)
.filter(function(agentName) {
var agent = target._agents[agentName];
return agent['enable'] && agent['disable']
&& agentName !== 'ServiceWorker'
&& agentName !== 'Security'
&& agentName !== 'Inspector'
&& agentName !== 'HeadlessExperimental'
&& agentName !== 'Fetch'
&& agentName !== 'Cast'
&& agentName !== 'BackgroundService';
})
.sort();
const targets = SDK.targetManager.targets();
for (const target of targets) {
const agentNames =
Object.keys(target._agents)
.filter(function(agentName) {
const agent = target._agents[agentName];
return agent['enable'] && agent['disable'] &&
agentName !== 'ServiceWorker' && agentName !== 'Security' &&
agentName !== 'Inspector' &&
agentName !== 'HeadlessExperimental' &&
agentName !== 'Fetch' && agentName !== 'Cast' &&
agentName !== 'BackgroundService';
})
.sort();
async function disableAgent(agentName) {
var agent = target._agents[agentName];
var response = await agent.invoke_disable({});
const agent = target._agents[agentName];
const response = await agent.invoke_disable({});
printResult(agentName, 'disable', response[Protocol.Error]);
}
async function enableAgent(agentName) {
var agent = target._agents[agentName];
var response = await agent.invoke_enable({});
const agent = target._agents[agentName];
const response = await agent.invoke_enable({});
printResult(agentName, 'enable', response[Protocol.Error]);
}
for (agentName of agentNames)
for (const agentName of agentNames)
await disableAgent(agentName);
for (agentName of agentNames) {
for (const agentName of agentNames) {
await enableAgent(agentName);
await disableAgent(agentName);
}
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(`This test checks Web Inspector utilities.\n`);
......@@ -40,8 +41,9 @@
var allValues = a.concat(b).concat(actual);
for (var i = 0; i < allValues.length; ++i) {
var value = allValues[i];
expectedCount = checkOperation(count(a, value), count(b, value));
actualCount = count(actual, value);
const expectedCount =
checkOperation(count(a, value), count(b, value));
const actualCount = count(actual, value);
TestRunner.assertEquals(
expectedCount, actualCount,
'Incorrect result for value: ' + value + ' at [' + a + '] ' + opName + ' [' + b + '] -> [' + actual +
......@@ -155,7 +157,7 @@
compareArrays(
middle.slice(first - left, first - left + count), actual.slice(first, first + count),
'sorted ' + left + ' ' + right + ' ' + first + ' ' + count);
actualRest = actual.slice(first + count, right + 1);
const actualRest = actual.slice(first + count, right + 1);
actualRest.sort(comparator);
compareArrays(
middle.slice(first - left + count), actualRest,
......
......@@ -2,7 +2,7 @@ Tests that evaluating 'console.log()' in the console will have access to its out
Running: testSnippet1
console-eval-scoped.js:67 with: Object property value
console-eval-scoped.js:69 with: Object property value
VM:1 eval in with: Object property value
Running: testSnippet2
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(
`Tests that evaluating 'console.log()' in the console will have access to its outer scope variables. Bug 60547.\n`
);
......@@ -32,14 +33,14 @@
};
`);
function snippet1() {
(function(obj) {
with (obj) {
console.log('with: ' + a);
eval("console.log('eval in with: ' + a)");
}
})({ a: 'Object property value' });
// Use `new Function` as with-statements are not allowed in strict-mode
const snippet1 = new Function(`
(function(obj) {
with (obj) {
console.log('with: ' + a);
eval("console.log('eval in with: ' + a)");
}
})({ a: 'Object property value' });`);
function snippet2() {
(function(a) {
......
......@@ -45,7 +45,7 @@
},
function beforeFilter(next) {
TestRunner.addResult(arguments.callee.name);
TestRunner.addResult('beforeFilter');
dumpVisibleMessages();
next();
},
......
......@@ -76,7 +76,7 @@
TestRunner.runTestSuite([
function beforeFilter(next) {
TestRunner.addResult(arguments.callee.name);
TestRunner.addResult('beforeFilter');
dumpVisibleMessages();
next();
},
......@@ -109,50 +109,43 @@
dumpVisibleMessages();
next();
},
function checkMultiTextFilter(next)
{
function checkMultiTextFilter(next) {
Console.ConsoleView.instance()._filter._textFilterUI.setValue("Group /[2-3]top/");
Console.ConsoleView.instance()._filter._onFilterChanged();
dumpVisibleMessages();
next();
},
function checkTextUrlFilter(next)
{
function checkTextUrlFilter(next) {
Console.ConsoleView.instance()._filter._textFilterUI.setValue("url:log-source");
Console.ConsoleView.instance()._filter._onFilterChanged();
dumpVisibleMessages();
next();
},
function checkNegativeTextUrlFilter(next)
{
function checkNegativeTextUrlFilter(next) {
Console.ConsoleView.instance()._filter._textFilterUI.setValue("-url:log-source");
Console.ConsoleView.instance()._filter._onFilterChanged();
dumpVisibleMessages();
next();
},
function checkSourceFilter(next)
{
function checkSourceFilter(next) {
Console.ConsoleView.instance()._filter._textFilterUI.setValue("source:violation");
Console.ConsoleView.instance()._filter._onFilterChanged();
dumpVisibleMessages();
next();
},
function checkContextTextFilter(next)
{
function checkContextTextFilter(next) {
Console.ConsoleView.instance()._filter._textFilterUI.setValue("context:context");
Console.ConsoleView.instance()._filter._onFilterChanged();
dumpVisibleMessages();
next();
},
function checkStartEndLineRegex(next)
{
function checkStartEndLineRegex(next) {
Console.ConsoleView.instance()._filter._textFilterUI.setValue("/^Hello\\s\\d$/");
Console.ConsoleView.instance()._filter._onFilterChanged();
dumpVisibleMessages();
next();
},
function checkStartEndLineRegexForAnchor(next)
{
function checkStartEndLineRegexForAnchor(next) {
Console.ConsoleView.instance()._filter._textFilterUI.setValue("/^log-source\\.js:\\d+$/");
Console.ConsoleView.instance()._filter._onFilterChanged();
dumpVisibleMessages();
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(`Tests curl command generation\n`);
await TestRunner.loadModule('network_test_runner');
await TestRunner.showPanel('network');
......@@ -54,8 +55,11 @@
await dumpRequest({}, '123');
await dumpRequest({'Content-Type': 'application/x-www-form-urlencoded'}, '1&b');
await dumpRequest({'Content-Type': 'application/json'}, '{"a":1}');
await dumpRequest({'Content-Type': 'application/binary'}, '1234\r\n\x30\x30\2\3\4\5\'"!');
await dumpRequest({'Content-Type': 'application/binary'}, '1234\r\n\1\x30\x30\2\3\4\5\'"!');
await dumpRequest(
{'Content-Type': 'application/binary'}, '1234\r\n00\x02\x03\x04\x05\'"!');
await dumpRequest(
{'Content-Type': 'application/binary'},
'1234\r\n\x0100\x02\x03\x04\x05\'"!');
await dumpRequest(
{'Content-Type': 'application/binary'},
'%OS%\r\n%%OS%%\r\n"\\"\'$&!'); // Ensure %OS% for windows is not env evaled
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(`Tests the gutter decorations in target source code after ScriptFormatterEditorAction\n`);
await TestRunner.loadModule('coverage_test_runner');
await TestRunner.loadHTML(`
......@@ -18,7 +19,7 @@
var decoratorPromise = TestRunner.addSnifferPromise(Coverage.CoverageView.LineDecorator.prototype, '_innerDecorate');
var editorActions = await self.runtime.allInstances(Sources.SourcesView.EditorAction);
for (action of editorActions) {
for (const action of editorActions) {
if (action instanceof Sources.ScriptFormatterEditorAction) {
action._toggleFormatScriptSource();
break;
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(`Tests that Elements properly populate and select after immediate updates crbug.com/829884\n`);
await TestRunner.loadModule('elements_test_runner');
await TestRunner.showPanel('elements');
......@@ -31,7 +32,7 @@
function afterExpand() {
ElementsTestRunner.selectNodeWithId('body', node => {
treeElement = node[treeOutline.treeElementSymbol()];
const treeElement = node[treeOutline.treeElementSymbol()];
TestRunner.addResult(`AFTER EXPAND: TreeElement childCount: ${treeElement.childCount()}`);
var selectedElement = treeOutline.selectedTreeElement;
......
......@@ -26,7 +26,7 @@
function findStyleSheet() {
var styleSheetHeaders = TestRunner.cssModel.styleSheetHeaders();
for (var i = 0; i < styleSheetHeaders.length; ++i) {
styleSheetHeader = styleSheetHeaders[i];
const styleSheetHeader = styleSheetHeaders[i];
if (styleSheetHeader.sourceURL.indexOf('get-set-stylesheet-text.css') >= 0) {
foundStyleSheetHeader = styleSheetHeader;
foundStyleSheetHeader.requestContent().then(callback);
......
......@@ -10,7 +10,7 @@
await ElementsTestRunner.selectNodeAndWaitForStylesPromise('inspected');
var section = ElementsTestRunner.inlineStyleSection();
treeElement = section.addNewBlankProperty(0);
const treeElement = section.addNewBlankProperty(0);
treeElement.startEditing();
await TestRunner.addSnifferPromise(UI.TextPrompt.prototype, '_completionsReady');
......
......@@ -3,11 +3,13 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(
`Ensure transactions created within Promise callbacks are not deactivated due to console activity\n`);
await TestRunner.loadModule('console_test_runner');
await TestRunner.loadModule('application_test_runner');
// Note: every test that uses a storage API must manually clean-up state from previous tests.
// Note: every test that uses a storage API must manually clean-up state from
// previous tests.
await ApplicationTestRunner.resetState();
var dbname = location.href;
......@@ -20,7 +22,7 @@
openRequest.onsuccess = function(event) {
var db = event.target.result;
Promise.resolve().then(function() {
tx = db.transaction('store');
const tx = db.transaction('store');
ConsoleTestRunner.evaluateInConsole('1 + 2');
try {
tx.objectStore('store').get(0);
......
......@@ -21,7 +21,7 @@
TestRunner.showPanel('layers');
await LayersTestRunner.requestLayers();
var layer = LayersTestRunner.findLayerByNodeIdAttribute('layer');
initialQuads = layer.quad().toString();
const initialQuads = layer.quad().toString();
// Updating layers should not produce invalid layer to-screen transforms
// (see: https://crbug.com/977578). Backface visibility is changed, rather
......
......@@ -47,8 +47,8 @@
TestRunner.completeTest();
function initLayers() {
layerA = LayersTestRunner.findLayerByNodeIdAttribute('a');
layerB = LayersTestRunner.findLayerByNodeIdAttribute('b');
const layerA = LayersTestRunner.findLayerByNodeIdAttribute('a');
const layerB = LayersTestRunner.findLayerByNodeIdAttribute('b');
contentRoot = LayersTestRunner.layerTreeModel().layerTree().contentRoot();
layers = [
{layer: layerA, name: 'layer a'}, {layer: layerB, name: 'layer b'}, {layer: contentRoot, name: 'content root'}
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(
`Tests that modifying a rule in a stylesheet loaded from a different domain does not crash the renderer.\n`);
await TestRunner.loadModule('elements_test_runner');
......@@ -36,7 +37,7 @@
function selectCallback() {
var idToDOMNode = TestRunner.domModel._idToDOMNode;
for (var id in idToDOMNode) {
node = idToDOMNode[id];
const node = idToDOMNode[id];
if (node.getAttribute && node.getAttribute('id') === 'inspected') {
nodeId = parseInt(id, 10);
break;
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(`Tests to make sure the proper view is used for the data that is received in network panel.\n`);
await TestRunner.loadModule('network_test_runner');
await TestRunner.showPanel('network');
......@@ -78,7 +79,7 @@
await testPreviewer('text/foobar', 'Foo Bar', 500);
TestRunner.addResult('Binary Image File');
await testPreviewer('image/png', 'Bin\0ary\1 File\0\0', 200);
await testPreviewer('image/png', 'Bin\0ary\x01 File\0\0', 200);
TestRunner.addResult('Binary Blank Image File');
await testPreviewer('image/png', '', 200);
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(`Tests content is available for failed image request.\n`);
await TestRunner.loadModule('network_test_runner');
await TestRunner.loadModule('console_test_runner');
......@@ -10,7 +11,7 @@
await TestRunner.evaluateInPagePromise(`
function loadData()
{
var image = new Image();
const image = new Image();
image.src = "resources/404.php";
image.onerror = resourceLoaded;
}
......@@ -26,7 +27,7 @@
TestRunner.evaluateInPage('loadData()');
function step2() {
var request1 = NetworkTestRunner.networkRequests().pop();
const request1 = NetworkTestRunner.networkRequests().pop();
TestRunner.addResult(request1.url());
TestRunner.addResult('resource.type: ' + request1.resourceType());
TestRunner.assertTrue(!request1.failed, 'Resource loading failed.');
......@@ -34,14 +35,14 @@
}
async function step3() {
var requests = NetworkTestRunner.networkRequests();
const requests = NetworkTestRunner.networkRequests();
requests.sort(function(a, b) {
return a.url().localeCompare(b.url());
});
TestRunner.addResult('resources count = ' + requests.length);
for (i = 0; i < requests.length; i++) {
for (let i = 0; i < requests.length; i++) {
TestRunner.addResult(requests[i].url());
var { content, error, isEncoded } = await requests[i].requestContent();
const {content} = await requests[i].requestContent();
TestRunner.addResult('resource.content after requesting content: ' + content);
}
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(
`Tests how revision requests content if original content was not loaded yet. https://bugs.webkit.org/show_bug.cgi?id=63631\n`);
await TestRunner.loadModule('network_test_runner');
......@@ -22,7 +23,8 @@
Workspace.workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeAdded, step2);
TestRunner.evaluateInPage('loadStylesheet()');
var resource;
let uiSourceCode;
function step2(event) {
var eventUISourceCode = event.data;
if (eventUISourceCode.url().indexOf('style.css') == -1)
......@@ -35,7 +37,7 @@
uiSourceCode.requestContent().then(step3);
}
function step3({ content, error, isEncoded }) {
function step3({content}) {
TestRunner.addResult(uiSourceCode.url());
TestRunner.addResult(content);
TestRunner.completeTest();
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(`Verify that tabs get merged when binding is added and removed.\n`);
await TestRunner.loadModule('sources_test_runner');
await TestRunner.loadModule('bindings_test_runner');
......@@ -80,7 +81,7 @@
var openedUISourceCodes = editorContainer._tabIds.keysArray();
openedUISourceCodes.sort((a, b) => a.url().compareTo(b.url()));
TestRunner.addResult('Opened tabs: ');
for (code of openedUISourceCodes)
for (const code of openedUISourceCodes)
TestRunner.addResult(' ' + code.url());
}
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(
`Verify that a network file tab gets substituted with filesystem tab when persistence binding comes.\n`);
await TestRunner.loadModule('sources_test_runner');
......@@ -42,7 +43,7 @@
var openedUISourceCodes = editorContainer._tabIds.keysArray();
openedUISourceCodes.sort((a, b) => a.url().compareTo(b.url()));
TestRunner.addResult('Opened tabs: ');
for (code of openedUISourceCodes)
for (const code of openedUISourceCodes)
TestRunner.addResult(' ' + code.url());
}
})();
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(
`Verify that for a fileSystem UISourceCode with persistence binding TabbedEditorContainer opens filesystem UISourceCode.\n`);
await TestRunner.loadModule('sources_test_runner');
......@@ -31,7 +32,7 @@
var openedUISourceCodes = editorContainer._tabIds.keysArray();
openedUISourceCodes.sort((a, b) => a.url().compareTo(b.url()));
TestRunner.addResult(title);
for (code of openedUISourceCodes)
for (const code of openedUISourceCodes)
TestRunner.addResult(' ' + code.url());
}
})();
......@@ -13,23 +13,24 @@
}
`);
MockedFile = function() {
this._buffer = '';
};
MockedFile.prototype = {
_appendData: function(data) {
class MockedFile {
constructor() {
this._buffer = '';
}
_appendData(data) {
this._buffer += data;
},
}
_data: function() {
_data() {
return this._buffer;
},
}
get size() {
return this._buffer.length;
},
}
slice: function(chunkStart, chunkEnd) {
slice(chunkStart, chunkEnd) {
var blob = new Blob([this._buffer], {type: 'text\/text'});
return blob;
}
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(`Tests Statistics view of detailed heap snapshots.\n`);
await TestRunner.loadModule('heap_profiler_test_runner');
await TestRunner.showPanel('heap_profiler');
......@@ -10,7 +11,7 @@
function createHeapSnapshot() {
var builder = new HeapProfilerTestRunner.HeapSnapshotBuilder();
var index = 0;
for (type in HeapProfilerTestRunner.HeapNode.Type) {
for (let type in HeapProfilerTestRunner.HeapNode.Type) {
if (!HeapProfilerTestRunner.HeapNode.Type.hasOwnProperty(type))
continue;
if (type === HeapProfilerTestRunner.HeapNode.Type.synthetic)
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(`Tests the nondeterministic bits of HAR conversion via the magic of hard-coded values.\n`);
await TestRunner.loadModule('application_test_runner');
await TestRunner.loadModule('network_test_runner');
......@@ -18,7 +19,6 @@
request.responseHeaders = [{name: 'Response', value: 'response-value'}];
request.responseHeadersText = 'HTTP/1.1 200 OK\r\nResponse: headers-text';
request.documentURL = 'http://example.com/inspector-test.js';
request.requestMethod = 'GET';
request.mimeType = 'text/html';
request.statusCode = 200;
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(`Tests scripts sorting in the scripts panel.\n`);
await TestRunner.loadModule('sources_test_runner');
await TestRunner.loadModule('sdk_test_runner');
......@@ -14,8 +15,10 @@
return navigatorView;
}
sourcesNavigatorView = createNavigatorView(Sources.NetworkNavigatorView);
contentScriptsNavigatorView = createNavigatorView(Sources.ContentScriptsNavigatorView);
const sourcesNavigatorView =
createNavigatorView(Sources.NetworkNavigatorView);
const contentScriptsNavigatorView =
createNavigatorView(Sources.ContentScriptsNavigatorView);
var pageMock = new SDKTestRunner.PageMock('http://example.com');
pageMock.turnIntoWorker();
......
......@@ -21,8 +21,6 @@
'x', 'y.foo'
]);
await SourcesTestRunner.startDebuggerTestPromise();
watchExpressionsPane =
self.runtime.sharedInstance(Sources.WatchExpressionsSidebarPane);
UI.panels.sources._sidebarPaneStack.showView(
UI.panels.sources._watchSidebarPane);
TestRunner.addResult('Watches before running testFunction:');
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
(async function() {
'use strict';
TestRunner.addResult(
`Tests breakpoints are correctly dimmed and restored in JavaScriptSourceFrame during live edit.\n`);
await TestRunner.loadModule('sources_test_runner');
......@@ -22,7 +23,7 @@
' ' + pathToFileName(breakpoints[i].url) + ':' + breakpoints[i].lineNumber +
', enabled:' + breakpoints[i].enabled);
locations = breakpointManager.allBreakpointLocations();
const locations = breakpointManager.allBreakpointLocations();
TestRunner.addResult(' Dumping breakpoint locations');
for (var i = 0; i < locations.length; ++i) {
var uiLocation = locations[i].uiLocation;
......
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