Commit d7b32423 authored by Joel Einbinder's avatar Joel Einbinder Committed by Commit Bot

DevTools: Make snippets work wtih local overrides

Local network overrides was turning off automapping, but automapping is
needed for snippets to work.

Bug: 980083
Change-Id: I90b7043eb7a0ca7e1b8a280e3a5c569d527d2b3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1713464
Commit-Queue: Joel Einbinder <einbinder@chromium.org>
Reviewed-by: default avatarAndrey Lushnikov <lushnikov@chromium.org>
Reviewed-by: default avatarErik Luo <luoe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680538}
parent b8fb65d2
...@@ -55,7 +55,7 @@ BindingsTestRunner.initializeTestMapping = function() { ...@@ -55,7 +55,7 @@ BindingsTestRunner.initializeTestMapping = function() {
class TestMapping { class TestMapping {
constructor(persistence) { constructor(persistence) {
this._persistence = persistence; this._persistence = persistence;
persistence.setAutomappingEnabled(false); persistence.addNetworkInterceptor(() => true);
this._bindings = new Set(); this._bindings = new Set();
} }
......
...@@ -37,6 +37,8 @@ Persistence.NetworkPersistenceManager = class extends Common.Object { ...@@ -37,6 +37,8 @@ Persistence.NetworkPersistenceManager = class extends Common.Object {
Workspace.Workspace.Events.ProjectRemoved, Workspace.Workspace.Events.ProjectRemoved,
event => this._onProjectRemoved(/** @type {!Workspace.Project} */ (event.data))); event => this._onProjectRemoved(/** @type {!Workspace.Project} */ (event.data)));
Persistence.persistence.addNetworkInterceptor(this._canHandleNetworkUISourceCode.bind(this));
/** @type {!Array<!Common.EventTarget.EventDescriptor>} */ /** @type {!Array<!Common.EventTarget.EventDescriptor>} */
this._eventDescriptors = []; this._eventDescriptors = [];
this._enabledChanged(); this._enabledChanged();
...@@ -114,7 +116,7 @@ Persistence.NetworkPersistenceManager = class extends Common.Object { ...@@ -114,7 +116,7 @@ Persistence.NetworkPersistenceManager = class extends Common.Object {
this._project.uiSourceCodes().forEach(this._filesystemUISourceCodeRemoved.bind(this)); this._project.uiSourceCodes().forEach(this._filesystemUISourceCodeRemoved.bind(this));
this._networkUISourceCodeForEncodedPath.clear(); this._networkUISourceCodeForEncodedPath.clear();
} }
Persistence.persistence.setAutomappingEnabled(!this._active); Persistence.persistence.refreshAutomapping();
} }
/** /**
...@@ -287,11 +289,19 @@ Persistence.NetworkPersistenceManager = class extends Common.Object { ...@@ -287,11 +289,19 @@ Persistence.NetworkPersistenceManager = class extends Common.Object {
this._filesystemUISourceCodeAdded(uiSourceCode); this._filesystemUISourceCodeAdded(uiSourceCode);
} }
/**
* @param {!Workspace.UISourceCode} uiSourceCode
*/
_canHandleNetworkUISourceCode(uiSourceCode) {
return this._active && !uiSourceCode.url().startsWith('snippet://');
}
/** /**
* @param {!Workspace.UISourceCode} uiSourceCode * @param {!Workspace.UISourceCode} uiSourceCode
*/ */
_networkUISourceCodeAdded(uiSourceCode) { _networkUISourceCodeAdded(uiSourceCode) {
if (!this._active || uiSourceCode.project().type() !== Workspace.projectTypes.Network) if (uiSourceCode.project().type() !== Workspace.projectTypes.Network ||
!this._canHandleNetworkUISourceCode(uiSourceCode))
return; return;
const url = Common.ParsedURL.urlWithoutHash(uiSourceCode.url()); const url = Common.ParsedURL.urlWithoutHash(uiSourceCode.url());
this._networkUISourceCodeForEncodedPath.set(this._encodedPathFromUrl(url), uiSourceCode); this._networkUISourceCodeForEncodedPath.set(this._encodedPathFromUrl(url), uiSourceCode);
......
...@@ -22,23 +22,20 @@ Persistence.Persistence = class extends Common.Object { ...@@ -22,23 +22,20 @@ Persistence.Persistence = class extends Common.Object {
const linkDecorator = new Persistence.PersistenceUtils.LinkDecorator(this); const linkDecorator = new Persistence.PersistenceUtils.LinkDecorator(this);
Components.Linkifier.setLinkDecorator(linkDecorator); Components.Linkifier.setLinkDecorator(linkDecorator);
this._mapping = null;
this.setAutomappingEnabled(true); this._mapping =
new Persistence.Automapping(this._workspace, this._onStatusAdded.bind(this), this._onStatusRemoved.bind(this));
} }
/** /**
* @param {boolean} enabled * @param {function(!Workspace.UISourceCode):boolean} interceptor
*/ */
setAutomappingEnabled(enabled) { addNetworkInterceptor(interceptor) {
if (enabled === !!this._mapping) this._mapping.addNetworkInterceptor(interceptor);
return; }
if (!enabled) {
this._mapping.dispose(); refreshAutomapping() {
this._mapping = null; this._mapping.scheduleRemap();
} else {
this._mapping = new Persistence.Automapping(
this._workspace, this._onStatusAdded.bind(this), this._onStatusRemoved.bind(this));
}
} }
/** /**
...@@ -387,13 +384,6 @@ Persistence.Persistence = class extends Common.Object { ...@@ -387,13 +384,6 @@ Persistence.Persistence = class extends Common.Object {
filePath += '/'; filePath += '/';
return this._filePathPrefixesToBindingCount.has(filePath); return this._filePathPrefixesToBindingCount.has(filePath);
} }
dispose() {
if (this._mapping) {
this._mapping.dispose();
this._mapping = null;
}
}
}; };
Persistence.Persistence._binding = Symbol('Persistence.Binding'); Persistence.Persistence._binding = Symbol('Persistence.Binding');
...@@ -449,14 +439,5 @@ Persistence.PersistenceBinding = class { ...@@ -449,14 +439,5 @@ Persistence.PersistenceBinding = class {
} }
}; };
/**
* @interface
*/
Persistence.MappingSystem = function() {};
Persistence.MappingSystem.prototype = {
dispose: function() {}
};
/** @type {!Persistence.Persistence} */ /** @type {!Persistence.Persistence} */
Persistence.persistence; Persistence.persistence;
Verifies that snippets still map when local overrides is on.
snippet:///my_snippet_name <=> snippet:///my_snippet_name
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(async function() {
TestRunner.addResult(
'Verifies that snippets still map when local overrides is on.\n');
await TestRunner.loadModule('sources_test_runner');
await TestRunner.loadModule('bindings_test_runner');
await TestRunner.showPanel('sources');
await BindingsTestRunner.createOverrideProject('file:///tmp');
BindingsTestRunner.setOverridesEnabled(true);
const sourceCode = `'hello';`;
const projects =
Workspace.workspace.projectsForType(Workspace.projectTypes.FileSystem);
const snippetsProject = projects.find(
project => Persistence.FileSystemWorkspaceBinding.fileSystemType(
project) === 'snippets');
const uiSourceCode = await snippetsProject.createFile('');
uiSourceCode.setContent(sourceCode);
await Common.Revealer.reveal(uiSourceCode);
await uiSourceCode.rename('my_snippet_name');
const bindingPromise = Persistence.persistence.once(Persistence.Persistence.Events.BindingCreated);
Sources.SourcesPanel.instance()._runSnippet();
const binding = await bindingPromise;
TestRunner.addResult(binding.network.url() + ' <=> ' + binding.fileSystem.url());
TestRunner.completeTest();
})();
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