Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Unified Diff: third_party/WebKit/LayoutTests/http/tests/inspector/persistence/persistence-test.js

Issue 2784733002: DevTools: prepare tests for Persistence2.0 release (Closed)
Patch Set: address comments + three special tests Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/http/tests/inspector/persistence/persistence-test.js
diff --git a/third_party/WebKit/LayoutTests/http/tests/inspector/persistence/persistence-test.js b/third_party/WebKit/LayoutTests/http/tests/inspector/persistence/persistence-test.js
index 7925b155380bad0debece7efeab9e1b39565adf1..37258a89ba05fba0ae45efb808e96278da10131c 100644
--- a/third_party/WebKit/LayoutTests/http/tests/inspector/persistence/persistence-test.js
+++ b/third_party/WebKit/LayoutTests/http/tests/inspector/persistence/persistence-test.js
@@ -47,4 +47,66 @@ InspectorTest.addFooJSFile = function(fs)
return fs.root.mkdir("inspector").mkdir("persistence").mkdir("resources").addFile("foo.js", "\n\nwindow.foo = ()=>'foo';");
}
+InspectorTest.forceUseDefaultMapping = function() {
+ Persistence.persistence._setMappingForTest((bindingCreated, bindingRemoved) => {
+ return new Persistence.DefaultMapping(Workspace.workspace, Workspace.fileSystemMapping, bindingCreated, bindingRemoved);
+ });
+}
+
+InspectorTest.initializeTestMapping = function() {
+ var testMapping;
+ Persistence.persistence._setMappingForTest((bindingCreated, bindingRemoved) => {
+ testMapping = new TestMapping(bindingCreated, bindingRemoved);
+ return testMapping;
+ });
+ return testMapping;
+}
+
+class TestMapping{
+ constructor(onBindingAdded, onBindingRemoved) {
+ this._onBindingAdded = onBindingAdded;
+ this._onBindingRemoved = onBindingRemoved;
+ this._bindings = new Set();
+ }
+
+ async addBinding(urlSuffix) {
+ if (this._findBinding(urlSuffix)) {
+ InspectorTest.addResult(`FAILED TO ADD BINDING: binding already exists for ${urlSuffix}`);
+ InspectorTest.completeTest();
+ return;
+ }
+ var networkUISourceCode = await InspectorTest.waitForUISourceCode(urlSuffix, Workspace.projectTypes.Network);
+ var fileSystemUISourceCode = await InspectorTest.waitForUISourceCode(urlSuffix, Workspace.projectTypes.FileSystem);
+
+ var binding = new Persistence.PersistenceBinding(networkUISourceCode, fileSystemUISourceCode, false);
+ this._bindings.add(binding);
+ this._onBindingAdded.call(null, binding);
+ }
+
+ _findBinding(urlSuffix) {
+ for (var binding of this._bindings) {
+ if (binding.network.url().endsWith(urlSuffix))
+ return binding;
+ }
+ return null;
+ }
+
+ async removeBinding(urlSuffix) {
+ var binding = this._findBinding(urlSuffix);
+ if (!binding) {
+ InspectorTest.addResult(`FAILED TO REMOVE BINDING: binding does not exist for ${urlSuffix}`);
+ InspectorTest.completeTest();
+ return;
+ }
+ this._bindings.delete(binding);
+ this._onBindingRemoved.call(null, binding);
+ }
+
+ dispose() {
+ for (var binding of this._bindings)
+ this._onBindingRemoved.call(null, binding);
+ this._bindings.clear();
+ }
+}
+
}

Powered by Google App Engine
This is Rietveld 408576698