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.initializeTestMapping = function() { | |
51 var testMapping; | |
52 Persistence.persistence._setMappingForTest((bindingCreated, bindingRemoved) => { | |
53 testMapping = new TestMapping(bindingCreated, bindingRemoved); | |
54 return testMapping; | |
55 }); | |
56 return testMapping; | |
50 } | 57 } |
58 | |
59 class TestMapping{ | |
60 constructor(onBindingAdded, onBindingRemoved) { | |
61 this._onBindingAdded = onBindingAdded; | |
62 this._onBindingRemoved = onBindingRemoved; | |
63 this._bindings = new Set(); | |
64 } | |
65 | |
66 async addBinding(urlSuffix) { | |
67 if (this._findBinding(urlSuffix)) | |
68 throw new Error(`FAILED TO ADD BINDING: binding already exists for $ {urlSuffix}`); | |
dgozman
2017/03/28 22:51:20
InspectorTest.addResult + completeTest instead to
lushnikov
2017/03/28 23:11:27
Done.
| |
69 var networkUISourceCode = await InspectorTest.waitForUISourceCode(urlSuf fix, Workspace.projectTypes.Network); | |
70 var fileSystemUISourceCode = await InspectorTest.waitForUISourceCode(url Suffix, Workspace.projectTypes.FileSystem); | |
71 | |
72 var binding = new Persistence.PersistenceBinding(networkUISourceCode, fi leSystemUISourceCode, false); | |
73 this._bindings.add(binding); | |
74 this._onBindingAdded.call(null, binding); | |
75 } | |
76 | |
77 _findBinding(urlSuffix) { | |
78 for (var binding of this._bindings) { | |
79 if (binding.network.url().endsWith(urlSuffix)) | |
80 return binding; | |
81 } | |
82 return null; | |
83 } | |
84 | |
85 async removeBinding(urlSuffix) { | |
86 var binding = this._findBinding(urlSuffix); | |
87 if (!binding) | |
88 throw new Error(`FAILED TO REMOVE BINDING: binding does not exist fo r ${urlSuffix}`); | |
dgozman
2017/03/28 22:51:20
ditto
lushnikov
2017/03/28 23:11:27
Done.
| |
89 this._bindings.delete(binding); | |
90 this._onBindingRemoved.call(null, binding); | |
91 } | |
92 | |
93 dispose() { | |
94 for (var binding of this._bindings) | |
95 this._onBindingRemoved.call(null, binding); | |
96 this._bindings.clear(); | |
97 } | |
98 } | |
99 | |
100 } | |
OLD | NEW |