blob: 4d0dada8f0a706233a9c1dacbecc728ee5922552 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/**
* WordPress dependencies
*/
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
test.describe( 'Cache Control header directives', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.deleteAllPosts();
});
test(
'No private directive present in cache control when user not logged in.',
async ( { browser, admin, editor}
) => {
await admin.createNewPost( { title: 'Hello World' } );
await editor.publishPost();
await admin.visitAdminPage( '/' );
// Create a new incognito browser context to simulate logged-out state.
const context = await browser.newContext();
const loggedOutPage = await context.newPage();
const response = await loggedOutPage.goto( '/hello-world/' );
const responseHeaders = response.headers();
// Dispose context once it's no longer needed.
await context.close();
expect( responseHeaders ).toEqual( expect.not.objectContaining( { "cache-control": "no-cache" } ) );
expect( responseHeaders ).toEqual( expect.not.objectContaining( { "cache-control": "no-store" } ) );
expect( responseHeaders ).toEqual( expect.not.objectContaining( { "cache-control": "private" } ) );
} );
test(
'Private directive header present in cache control when logged in.',
async ( { page, admin }
) => {
await admin.visitAdminPage( '/' );
const response = await page.goto( '/wp-admin' );
const responseHeaders = response.headers();
expect( responseHeaders[ 'cache-control' ] ).toContain( 'no-cache' );
expect( responseHeaders[ 'cache-control' ] ).toContain( 'no-store' );
expect( responseHeaders[ 'cache-control' ] ).toContain( 'private' );
} );
test(
'Correct directives present in cache control header when not logged in on 404 page.',
async ( { browser }
) => {
const context = await browser.newContext();
const loggedOutPage = await context.newPage();
const response = await loggedOutPage.goto( '/this-does-not-exist/' );
const responseHeaders = response.headers();
const responseStatus = response.status();
// Dispose context once it's no longer needed.
await context.close();
expect( responseStatus ).toBe( 404 );
expect( responseHeaders[ 'cache-control' ] ).toContain( 'no-cache' );
expect( responseHeaders[ 'cache-control' ] ).toContain( 'no-store' );
expect( responseHeaders[ 'cache-control' ] ).toContain( 'private' );
} );
} );
|