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

Unified Diff: third_party/WebKit/LayoutTests/http/tests/inspector/page-mock.js

Issue 2879503002: [Devtools] Added product entry tests for network
Patch Set: [Devtools] Added product entry tests for network Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/http/tests/inspector/page-mock.js
diff --git a/third_party/WebKit/LayoutTests/http/tests/inspector/page-mock.js b/third_party/WebKit/LayoutTests/http/tests/inspector/page-mock.js
index f7f5e410d8199bbf848b5bf5a0dc32049e7a8f2f..f4cd9c767cfea94ab800bdc7326abd9a76e98cb8 100644
--- a/third_party/WebKit/LayoutTests/http/tests/inspector/page-mock.js
+++ b/third_party/WebKit/LayoutTests/http/tests/inspector/page-mock.js
@@ -18,7 +18,7 @@ InspectorTest.connectToPage = function(targetName, pageMock, makeMainTarget) {
InspectorTest.PageMock = class {
constructor(url) {
this._url = url;
- this._capabilities = SDK.Target.Capability.DOM | SDK.Target.Capability.JS | SDK.Target.Capability.Browser;
+ this._capabilities = SDK.Target.Capability.DOM | SDK.Target.Capability.JS | SDK.Target.Capability.Browser | SDK.Target.Capability.Network;
/** @type {!Set<string>} */
this._enabledDomains = new Set();
@@ -36,6 +36,9 @@ InspectorTest.PageMock = class {
this._scripts = [];
this._scriptContents = new Map();
+ this._childFrames = [];
+ this._pageGetResourceTreeHasRan = false;
+
this._dispatchMap = {
'Debugger.enable': this._debuggerEnable,
'Debugger.getScriptSource': this._debuggerGetScriptSource,
@@ -43,6 +46,7 @@ InspectorTest.PageMock = class {
'Runtime.enable': this._runtimeEnable,
'Page.enable': this._pageEnable,
'Page.getResourceTree': this._pageGetResourceTree,
+ 'Network.enable': this._networkEnable
};
}
@@ -117,6 +121,52 @@ InspectorTest.PageMock = class {
}
}
+ /**
+ * @param {string} url
+ * @return {!Promise<string>} frameId
+ */
+ addFrame(url) {
+ console.assert(!this._pageGetResourceTreeHasRan, "Cannot add frames after getResourceTreeTree has ran.");
dgozman 2017/05/10 22:57:14 InspectorTest.completeTest here so we see the test
+ var frameId = nextId('page-');
+ this._childFrames.push({
+ id: frameId,
+ loaderId: this._mainFrame.loaderId,
dgozman 2017/05/10 22:57:14 loaderId should be unique.
+ url: url,
+ securityOrigin: url,
+ mimeType: "text/html"
+ });
+ return frameId;
+ }
+
+
+ /**
+ * @param {string} url
+ * @param {!SDK.ResourceTreeFrame=} frame
+ * @return {!Promise<string>}
dgozman 2017/05/10 22:57:14 Why return Promise? I think we should waitForReque
+ */
+ requestWillBeSent(url, frame) {
dgozman 2017/05/10 22:57:14 Let's call this sendXHR and issue responseReceived
+ var requestId = nextId('network-');
+ return this._fireEvent('Network.requestWillBeSent', {
+ requestId: requestId,
+ frameId: (frame || this._mainFrame).id,
+ loaderId: this._mainFrame.loaderId,
+ documentURL: this._mainFrame.url,
+ request: {
+ url: url,
+ method: 'GET',
+ headers: {},
+ initialPriority: 'Medium',
+ referrerPolicy: 'origin'
+ },
+ timestamp: 0,
+ initiator: {
+ name: 'other'
+ },
+ type: "Other"
+ }).then(() => requestId);
+ }
+
+
_createExecutionContext(frame, isContentScript) {
return {
id: nextId(),
@@ -130,6 +180,11 @@ InspectorTest.PageMock = class {
// Command Handlers
// -------------------------------------------------------------------------
+ _networkEnable(id, params) {
+ this._enabledDomains.add('Network');
+ this._sendResponse(id, {});
+ }
+
_debuggerEnable(id, params) {
this._enabledDomains.add('Debugger');
this._sendResponse(id, {});
@@ -162,9 +217,12 @@ InspectorTest.PageMock = class {
}
_pageGetResourceTree(id, params) {
+ this._pageGetResourceTreeHasRan = true;
+ var childFrames = this._childFrames.map(frame => ({frame: frame, resources: []}));
var result = {
frameTree: {
frame: this._mainFrame,
+ childFrames: childFrames,
resources: []
dgozman 2017/05/10 22:57:14 Let's report html resource. Or add TODO for it.
}
}
@@ -194,7 +252,7 @@ InspectorTest.PageMock = class {
result: result,
error: error
};
- this._connection.sendMessageToDevTools(message);
+ return this._connection.sendMessageToDevTools(message);
}
_fireEvent(methodName, params) {
@@ -206,7 +264,7 @@ InspectorTest.PageMock = class {
method: methodName,
params: params
};
- this._connection.sendMessageToDevTools(message);
+ return this._connection.sendMessageToDevTools(message);
}
}
@@ -221,7 +279,7 @@ var MockPageConnection = class {
}
sendMessageToDevTools(message) {
- setTimeout(() => this._onMessage.call(null, JSON.stringify(message)), 0);
+ return Promise.resolve().then(() => this._onMessage.call(null, JSON.stringify(message)));
allada 2017/05/10 22:25:01 These were in non-deterministic order, so I went t
}
/**

Powered by Google App Engine
This is Rietveld 408576698