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(); |
+ } |
+} |
+ |
} |