OLD | NEW |
1 var initialize_PersistenceTest = function() { | 1 var initialize_PersistenceTest = function() { |
2 | 2 |
3 InspectorTest.preloadModule("persistence"); | 3 InspectorTest.preloadModule("persistence"); |
4 InspectorTest.preloadModule("sources"); | 4 InspectorTest.preloadModule("sources"); |
5 | 5 |
6 Runtime.experiments.enableForTest("persistenceValidation"); | 6 Runtime.experiments.enableForTest("persistenceValidation"); |
7 | 7 |
8 Persistence.PersistenceBinding.prototype.toString = function() | 8 Persistence.PersistenceBinding.prototype.toString = function() |
9 { | 9 { |
10 var lines = [ | 10 var lines = [ |
(...skipping 29 matching lines...) Expand all Loading... |
40 Persistence.persistence.removeEventListener(Persistence.Persistence.Even
ts.BindingCreated, onBindingCreated); | 40 Persistence.persistence.removeEventListener(Persistence.Persistence.Even
ts.BindingCreated, onBindingCreated); |
41 fulfill(binding); | 41 fulfill(binding); |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 InspectorTest.addFooJSFile = function(fs) | 45 InspectorTest.addFooJSFile = function(fs) |
46 { | 46 { |
47 return fs.root.mkdir("inspector").mkdir("persistence").mkdir("resources").ad
dFile("foo.js", "\n\nwindow.foo = ()=>'foo';"); | 47 return fs.root.mkdir("inspector").mkdir("persistence").mkdir("resources").ad
dFile("foo.js", "\n\nwindow.foo = ()=>'foo';"); |
48 } | 48 } |
49 | 49 |
| 50 InspectorTest.forceUseDefaultMapping = function() { |
| 51 Persistence.persistence._setMappingForTest((bindingCreated, bindingRemoved)
=> { |
| 52 return new Persistence.DefaultMapping(Workspace.workspace, Workspace.fil
eSystemMapping, bindingCreated, bindingRemoved); |
| 53 }); |
50 } | 54 } |
| 55 |
| 56 InspectorTest.initializeTestMapping = function() { |
| 57 var testMapping; |
| 58 Persistence.persistence._setMappingForTest((bindingCreated, bindingRemoved)
=> { |
| 59 testMapping = new TestMapping(bindingCreated, bindingRemoved); |
| 60 return testMapping; |
| 61 }); |
| 62 return testMapping; |
| 63 } |
| 64 |
| 65 class TestMapping{ |
| 66 constructor(onBindingAdded, onBindingRemoved) { |
| 67 this._onBindingAdded = onBindingAdded; |
| 68 this._onBindingRemoved = onBindingRemoved; |
| 69 this._bindings = new Set(); |
| 70 } |
| 71 |
| 72 async addBinding(urlSuffix) { |
| 73 if (this._findBinding(urlSuffix)) { |
| 74 InspectorTest.addResult(`FAILED TO ADD BINDING: binding already exis
ts for ${urlSuffix}`); |
| 75 InspectorTest.completeTest(); |
| 76 return; |
| 77 } |
| 78 var networkUISourceCode = await InspectorTest.waitForUISourceCode(urlSuf
fix, Workspace.projectTypes.Network); |
| 79 var fileSystemUISourceCode = await InspectorTest.waitForUISourceCode(url
Suffix, Workspace.projectTypes.FileSystem); |
| 80 |
| 81 var binding = new Persistence.PersistenceBinding(networkUISourceCode, fi
leSystemUISourceCode, false); |
| 82 this._bindings.add(binding); |
| 83 this._onBindingAdded.call(null, binding); |
| 84 } |
| 85 |
| 86 _findBinding(urlSuffix) { |
| 87 for (var binding of this._bindings) { |
| 88 if (binding.network.url().endsWith(urlSuffix)) |
| 89 return binding; |
| 90 } |
| 91 return null; |
| 92 } |
| 93 |
| 94 async removeBinding(urlSuffix) { |
| 95 var binding = this._findBinding(urlSuffix); |
| 96 if (!binding) { |
| 97 InspectorTest.addResult(`FAILED TO REMOVE BINDING: binding does not
exist for ${urlSuffix}`); |
| 98 InspectorTest.completeTest(); |
| 99 return; |
| 100 } |
| 101 this._bindings.delete(binding); |
| 102 this._onBindingRemoved.call(null, binding); |
| 103 } |
| 104 |
| 105 dispose() { |
| 106 for (var binding of this._bindings) |
| 107 this._onBindingRemoved.call(null, binding); |
| 108 this._bindings.clear(); |
| 109 } |
| 110 } |
| 111 |
| 112 } |
OLD | NEW |