mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-10 05:35:05 +08:00
Move and rename files. NOAUTOREVERT=true NOPRESUBMIT=true NOTREECHECKS=true Bug: 768828 TBR=darin@chromium.org NOTRY=true Change-Id: I66d3b155808bc5bdbf237b80208e1e552bcf7f28 Reviewed-on: https://chromium-review.googlesource.com/1001153 Reviewed-by: Blink Reformat <blink-reformat@chromium.org> Commit-Queue: Blink Reformat <blink-reformat@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#549061} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 0aee4434a4dba42a42abaea9bfbc0cd196a63bc1
147 lines
4.7 KiB
JavaScript
147 lines
4.7 KiB
JavaScript
// Copyright 2017 The Chromium Authors. All
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
/**
|
|
* @fileoverview using private properties isn't a Closure violation in tests.
|
|
* @suppress {accessControls}
|
|
*/
|
|
|
|
SourcesTestRunner.dumpSearchResults = function(searchResults) {
|
|
function comparator(a, b) {
|
|
a.url.localeCompare(b.url);
|
|
}
|
|
|
|
searchResults.sort(comparator);
|
|
TestRunner.addResult('Search results: ');
|
|
|
|
for (let i = 0; i < searchResults.length; i++) {
|
|
TestRunner.addResult(
|
|
'url: ' + searchResults[i].url.replace(/VM\d+/, 'VMXX') + ', matchesCount: ' + searchResults[i].matchesCount);
|
|
}
|
|
|
|
TestRunner.addResult('');
|
|
};
|
|
|
|
SourcesTestRunner.dumpSearchMatches = function(searchMatches) {
|
|
TestRunner.addResult('Search matches: ');
|
|
|
|
for (let i = 0; i < searchMatches.length; i++) {
|
|
TestRunner.addResult(
|
|
'lineNumber: ' + searchMatches[i].lineNumber + ', line: \'' + searchMatches[i].lineContent + '\'');
|
|
}
|
|
|
|
TestRunner.addResult('');
|
|
};
|
|
|
|
SourcesTestRunner.runSearchAndDumpResults = function(scope, searchConfig, callback) {
|
|
const searchResults = [];
|
|
const progress = new Common.Progress();
|
|
scope.performSearch(searchConfig, progress, searchResultCallback, searchFinishedCallback);
|
|
|
|
function searchResultCallback(searchResult) {
|
|
searchResults.push(searchResult);
|
|
}
|
|
|
|
function searchFinishedCallback() {
|
|
function comparator(searchResultA, searchResultB) {
|
|
return searchResultA._uiSourceCode.url().compareTo(searchResultB._uiSourceCode.url());
|
|
}
|
|
|
|
searchResults.sort(comparator);
|
|
|
|
for (let i = 0; i < searchResults.length; ++i) {
|
|
const searchResult = searchResults[i];
|
|
const uiSourceCode = searchResult._uiSourceCode;
|
|
const searchMatches = searchResult._searchMatches;
|
|
|
|
if (!searchMatches.length)
|
|
continue;
|
|
|
|
TestRunner.addResult(
|
|
'Search result #' + (i + 1) + ': uiSourceCode.url = ' + uiSourceCode.url().replace(/VM\d+/, 'VMXX'));
|
|
|
|
for (let j = 0; j < searchMatches.length; ++j) {
|
|
const lineNumber = searchMatches[j].lineNumber;
|
|
const lineContent = searchMatches[j].lineContent;
|
|
TestRunner.addResult(
|
|
' search match #' + (j + 1) + ': lineNumber = ' + lineNumber + ', lineContent = \'' + lineContent + '\'');
|
|
}
|
|
}
|
|
|
|
callback();
|
|
}
|
|
};
|
|
|
|
SourcesTestRunner.replaceAndDumpChange = function(sourceFrame, searchConfig, replacement, replaceAll) {
|
|
const modifiers = [];
|
|
|
|
if (searchConfig.isRegex)
|
|
modifiers.push('regex');
|
|
|
|
if (searchConfig.caseSensitive)
|
|
modifiers.push('caseSensitive');
|
|
|
|
if (replaceAll)
|
|
modifiers.push('replaceAll');
|
|
|
|
const modifiersString = (modifiers.length ? ' (' + modifiers.join(', ') + ')' : '');
|
|
TestRunner.addResult(
|
|
'Running replace test for /' + searchConfig.query + '/' + replacement + '/ ' + modifiersString + ':');
|
|
editor = sourceFrame._textEditor;
|
|
const oldLines = [];
|
|
|
|
for (let i = 0; i < editor.linesCount; ++i)
|
|
oldLines.push(editor.line(i));
|
|
|
|
const searchableView = UI.panels.sources.sourcesView().searchableView();
|
|
searchableView.showSearchField();
|
|
searchableView._caseSensitiveButton.setToggled(searchConfig.caseSensitive);
|
|
searchableView._regexButton.setToggled(searchConfig.isRegex);
|
|
searchableView._searchInputElement.value = searchConfig.query;
|
|
searchableView._replaceToggleButton.setToggled(true);
|
|
searchableView._updateSecondRowVisibility();
|
|
searchableView._replaceInputElement.value = replacement;
|
|
searchableView._performSearch(true, true);
|
|
|
|
if (replaceAll)
|
|
searchableView._replaceAll();
|
|
else
|
|
searchableView._replace();
|
|
|
|
const newLines = [];
|
|
|
|
for (let i = 0; i < editor.linesCount; ++i)
|
|
newLines.push(editor.line(i));
|
|
|
|
for (let i = 0; i < newLines.length; ++i) {
|
|
if (oldLines[i] === newLines[i])
|
|
continue;
|
|
|
|
const oldLine = oldLines[i];
|
|
const newLine = newLines[i];
|
|
let prefixLength = 0;
|
|
|
|
for (let j = 0; j < oldLine.length && j < newLine.length && newLine[j] === oldLine[j]; ++j)
|
|
++prefixLength;
|
|
|
|
let postfixLength = 0;
|
|
|
|
for (let j = 0; j < oldLine.length && j < newLine.length &&
|
|
newLine[newLine.length - j - 1] === oldLine[oldLine.length - j - 1];
|
|
++j)
|
|
++postfixLength;
|
|
|
|
const prefix = oldLine.substring(0, prefixLength);
|
|
const removed = oldLine.substring(prefixLength, oldLine.length - postfixLength);
|
|
const added = newLine.substring(prefixLength, newLine.length - postfixLength);
|
|
const postfix = oldLine.substring(oldLine.length - postfixLength);
|
|
TestRunner.addResult(' - ' + prefix + '#' + removed + '#' + added + '#' + postfix);
|
|
}
|
|
};
|
|
|
|
TestRunner.deprecatedInitAsync(`
|
|
if (window.GCController)
|
|
GCController.collect();
|
|
`);
|