File size: 1,729 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/* eslint-env jest */

import { assertNoRedbox, waitFor } from 'next-test-utils'
import path from 'path'
import { nextTestSetup } from 'e2e-utils'

describe('Client navigation with foreign history manipulation', () => {
  const { next } = nextTestSetup({
    files: path.join(__dirname, 'fixture'),
    env: {
      TEST_STRICT_NEXT_HEAD: String(true),
    },
  })

  it('should ignore history state without options', async () => {
    const browser = await next.browser('/nav')
    // push history object without options
    await browser.eval(
      'window.history.pushState({ url: "/whatever" }, "", "/whatever")'
    )
    await browser.elementByCss('#about-link').click()
    await browser.waitForElementByCss('.nav-about')
    await browser.back()
    await waitFor(1000)
    await assertNoRedbox(browser)
  })

  it('should ignore history state with an invalid url', async () => {
    const browser = await next.browser('/nav')
    // push history object wit invalid url (not relative)
    await browser.eval(
      'window.history.pushState({ url: "http://google.com" }, "", "/whatever")'
    )
    await browser.elementByCss('#about-link').click()
    await browser.waitForElementByCss('.nav-about')
    await browser.back()
    await waitFor(1000)
    await assertNoRedbox(browser)
  })

  it('should ignore foreign history state with missing properties', async () => {
    const browser = await next.browser('/nav')
    // push empty history state
    await browser.eval('window.history.pushState({}, "", "/whatever")')
    await browser.elementByCss('#about-link').click()
    await browser.waitForElementByCss('.nav-about')
    await browser.back()
    await waitFor(1000)
    await assertNoRedbox(browser)
  })
})