Skip to content

Commit

Permalink
chore: remove Request.fromCache/ServiceWorker APIs (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored and dgozman committed Nov 20, 2019
1 parent 76eb289 commit a216063
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 78 deletions.
12 changes: 0 additions & 12 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,6 @@
- [class: Response](#class-response)
* [response.buffer()](#responsebuffer)
* [response.frame()](#responseframe)
* [response.fromCache()](#responsefromcache)
* [response.fromServiceWorker()](#responsefromserviceworker)
* [response.headers()](#responseheaders)
* [response.json()](#responsejson)
* [response.ok()](#responseok)
Expand Down Expand Up @@ -3783,16 +3781,6 @@ page.on('request', request => {
#### response.frame()
- returns: <?[Frame]> A [Frame] that initiated this response, or `null` if navigating to error pages.

#### response.fromCache()
- returns: <[boolean]>

True if the response was served from either the browser's disk cache or memory cache.

#### response.fromServiceWorker()
- returns: <[boolean]>

True if the response was served by a service worker.

#### response.headers()
- returns: <[Object]> An object with HTTP headers associated with the response. All header names are lower-case.

Expand Down
20 changes: 0 additions & 20 deletions src/chromium/NetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export class NetworkManager extends EventEmitter {
this._client.on('Fetch.requestPaused', this._onRequestPaused.bind(this));
this._client.on('Fetch.authRequired', this._onAuthRequired.bind(this));
this._client.on('Network.requestWillBeSent', this._onRequestWillBeSent.bind(this));
this._client.on('Network.requestServedFromCache', this._onRequestServedFromCache.bind(this));
this._client.on('Network.responseReceived', this._onResponseReceived.bind(this));
this._client.on('Network.loadingFinished', this._onLoadingFinished.bind(this));
this._client.on('Network.loadingFailed', this._onLoadingFailed.bind(this));
Expand Down Expand Up @@ -204,12 +203,6 @@ export class NetworkManager extends EventEmitter {
}


_onRequestServedFromCache(event: Protocol.Network.requestServedFromCachePayload) {
const request = this._requestIdToRequest.get(event.requestId);
if (request)
request._fromMemoryCache = true;
}

_handleRequestRedirect(request: Request, responsePayload: Protocol.Network.Response) {
const response = new Response(this._client, request, responsePayload);
request._response = response;
Expand Down Expand Up @@ -279,7 +272,6 @@ export class Request {
private _postData: string;
private _headers: {[key: string]: string} = {};
private _frame: Frame;
_fromMemoryCache = false;

constructor(client: CDPSession, frame: Frame | null, interceptionId: string, allowInterception: boolean, event: Protocol.Network.requestWillBeSentPayload, redirectChain: Request[]) {
this._client = client;
Expand Down Expand Up @@ -448,8 +440,6 @@ export class Response {
private _status: number;
private _statusText: string;
private _url: string;
private _fromDiskCache: boolean;
private _fromServiceWorker: boolean;
private _headers: {[key: string]: string} = {};
private _securityDetails: SecurityDetails;

Expand All @@ -468,8 +458,6 @@ export class Response {
this._status = responsePayload.status;
this._statusText = responsePayload.statusText;
this._url = request.url();
this._fromDiskCache = !!responsePayload.fromDiskCache;
this._fromServiceWorker = !!responsePayload.fromServiceWorker;
for (const key of Object.keys(responsePayload.headers))
this._headers[key.toLowerCase()] = responsePayload.headers[key];
this._securityDetails = responsePayload.securityDetails ? new SecurityDetails(responsePayload.securityDetails) : null;
Expand Down Expand Up @@ -531,14 +519,6 @@ export class Response {
return this._request;
}

fromCache(): boolean {
return this._fromDiskCache || this._request._fromMemoryCache;
}

fromServiceWorker(): boolean {
return this._fromServiceWorker;
}

frame(): Frame | null {
return this._request.frame();
}
Expand Down
46 changes: 0 additions & 46 deletions test/network.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,52 +97,6 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {
});
});

describe.skip(FFOX)('Response.fromCache', function() {
it.skip(WEBKIT)('should return |false| for non-cached content', async({page, server}) => {
const response = await page.goto(server.EMPTY_PAGE);
expect(response.fromCache()).toBe(false);
});

it.skip(WEBKIT)('should work', async({page, server}) => {
const responses = new Map();
page.on('response', r => !utils.isFavicon(r.request()) && responses.set(r.url().split('/').pop(), r));

// Load and re-load to make sure it's cached.
await page.goto(server.PREFIX + '/cached/one-style.html');
await page.reload();

expect(responses.size).toBe(2);
expect(responses.get('one-style.css').status()).toBe(200);
expect(responses.get('one-style.css').fromCache()).toBe(true);
expect(responses.get('one-style.html').status()).toBe(304);
expect(responses.get('one-style.html').fromCache()).toBe(false);
});
});

describe.skip(FFOX)('Response.fromServiceWorker', function() {
it.skip(WEBKIT)('should return |false| for non-service-worker content', async({page, server}) => {
const response = await page.goto(server.EMPTY_PAGE);
expect(response.fromServiceWorker()).toBe(false);
});

// FIXME: WebKit responses contain sw.js
it.skip(WEBKIT)('Response.fromServiceWorker', async({page, server}) => {
const responses = new Map();
page.on('response', r => responses.set(r.url().split('/').pop(), r));

// Load and re-load to make sure serviceworker is installed and running.
await page.goto(server.PREFIX + '/serviceworkers/fetch/sw.html', {waitUntil: 'networkidle2'});
await page.evaluate(async() => await window.activationPromise);
await page.reload();

expect(responses.size).toBe(2);
expect(responses.get('sw.html').status()).toBe(200);
expect(responses.get('sw.html').fromServiceWorker()).toBe(true);
expect(responses.get('style.css').status()).toBe(200);
expect(responses.get('style.css').fromServiceWorker()).toBe(true);
});
});

describe('Request.postData', function() {
it('should work', async({page, server}) => {
await page.goto(server.EMPTY_PAGE);
Expand Down

0 comments on commit a216063

Please sign in to comment.