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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/inspector/persistence/automapping-test.js

Issue 2418813005: DevTools: [Persistence] implement automapping (Closed)
Patch Set: address comments Created 4 years, 1 month 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
(Empty)
1 var initialize_AutomappingTest = function() {
2
3 InspectorTest.addFiles = function(testFileSystem, files)
4 {
5 for (var filePath in files) {
6 var file = files[filePath];
7 testFileSystem.addFile(filePath, file.content, file.time ? file.time.get Time() : 0);
8 }
9 }
10
11 var timeOverrides;
12 var originalRequestMetadata;
13 InspectorTest.overrideNetworkModificationTime = function(urlToTime)
14 {
15 if (!timeOverrides) {
16 timeOverrides = new Map();
17 originalRequestMetadata = InspectorTest.override(WebInspector.ContentPro viderBasedProject.prototype, "requestMetadata", overrideTime, true);
18 }
19 for (var url in urlToTime)
20 timeOverrides.set(url, urlToTime[url]);
21
22 function overrideTime(uiSourceCode)
23 {
24 if (!timeOverrides.has(uiSourceCode.url()))
25 return originalRequestMetadata.call(this, uiSourceCode);
26 var override = timeOverrides.get(uiSourceCode.url());
27 return originalRequestMetadata.call(this, uiSourceCode).then(onOriginalM etadata.bind(null, override));
28 }
29
30 function onOriginalMetadata(timeOverride, metadata)
31 {
32 if (!timeOverride && !metadata)
33 return null;
34 return new WebInspector.UISourceCodeMetadata(timeOverride, metadata ? me tadata.contentSize : null);
35 }
36 }
37
38 InspectorTest.AutomappingTest = function(workspace)
39 {
40 this._workspace = workspace;
41 this._networkProject = new WebInspector.ContentProviderBasedProject(this._wo rkspace, "AUTOMAPPING", WebInspector.projectTypes.Network, "simple website");
42 if (workspace !== WebInspector.workspace)
43 new WebInspector.FileSystemWorkspaceBinding(WebInspector.isolatedFileSys temManager, this._workspace);
44 this._failedBindingsCount = 0;
45 this._automapping = new WebInspector.Automapping(this._workspace, this._onBi ndingAdded.bind(this), this._onBindingRemoved.bind(this));
46 InspectorTest.addSniffer(this._automapping, "_onBindingFailedForTest", this. _onBindingFailed.bind(this), true);
47 InspectorTest.addSniffer(this._automapping, "_onSweepHappenedForTest", this. _onSweepHappened.bind(this), true);
48 }
49
50 InspectorTest.AutomappingTest.prototype = {
51 removeResources: function(urls)
52 {
53 for (var url of urls)
54 this._networkProject.removeFile(url);
55 },
56
57 addNetworkResources: function(assets)
58 {
59 for (var url in assets) {
60 var asset = assets[url];
61 var contentType = asset.contentType || WebInspector.resourceTypes.Sc ript;
62 var contentProvider = new WebInspector.StaticContentProvider(url, co ntentType, Promise.resolve(asset.content));
63 var metadata = typeof asset.content === "string" || asset.time ? new WebInspector.UISourceCodeMetadata(asset.time, asset.content.length) : null;
64 var uiSourceCode = this._networkProject.createUISourceCode(url, cont entType);
65 this._networkProject.addUISourceCodeWithProvider(uiSourceCode, conte ntProvider, metadata);
66 }
67 },
68
69 waitUntilMappingIsStabilized: function(callback)
70 {
71 this._stabilizedCallback = callback;
72 this._checkStabilized();
73 },
74
75 _onSweepHappened: function()
76 {
77 this._failedBindingsCount = 0;
78 this._checkStabilized();
79 },
80
81 _onBindingAdded: function(binding)
82 {
83 InspectorTest.addResult("Binding created: " + binding);
84 this._checkStabilized();
85 },
86
87 _onBindingFailed: function()
88 {
89 ++this._failedBindingsCount;
90 this._checkStabilized();
91 },
92
93 _onBindingRemoved: function(binding)
94 {
95 InspectorTest.addResult("Binding removed: " + binding);
96 this._checkStabilized();
97 },
98
99 _checkStabilized: function()
100 {
101 if (!this._stabilizedCallback || this._automapping._sweepThrottler._proc ess)
102 return;
103 var networkUISourceCodes = this._workspace.uiSourceCodesForProjectType(W ebInspector.projectTypes.Network);
104 var stabilized = this._failedBindingsCount + this._automapping._bindings .size === networkUISourceCodes.length;
105 if (stabilized) {
106 InspectorTest.addResult("Mapping has stabilized.");
107 var callback = this._stabilizedCallback;
108 delete this._stabilizedCallback;
109 callback.call(null);
110 }
111 }
112 }
113
114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698