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

Side by Side 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, 8 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 unified diff | Download patch
OLDNEW
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698