forked from simov/markdown-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvanced-encoding.js
More file actions
121 lines (107 loc) · 3.77 KB
/
Copy pathadvanced-encoding.js
File metadata and controls
121 lines (107 loc) · 3.77 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var t = require('assert')
module.exports = ({advanced, content}) => {
before(async () => {
await advanced.bringToFront()
// remove origin
if (await advanced.evaluate(() => Object.keys(state.origins).length > 1)) {
// expand origin
if (!await advanced.evaluate(() =>
document.querySelector('.m-list li:nth-of-type(2)')
.classList.contains('m-expanded'))) {
await advanced.click('.m-list li:nth-of-type(2)')
}
await advanced.click('.m-list li:nth-of-type(2) .m-footer .m-button:nth-of-type(2)')
}
// add origin
await advanced.select('.m-select', 'http')
await advanced.type('[type=text]', 'localhost:3000')
await advanced.click('button')
await advanced.waitFor(200)
// expand origin
if (!await advanced.evaluate(() =>
document.querySelector('.m-list li:nth-of-type(2)')
.classList.contains('m-expanded'))) {
await advanced.click('.m-list li:nth-of-type(2)')
}
// enable path matching
await advanced.evaluate(() => {
document.querySelector('.m-list li:nth-of-type(2) input')
.value = 'windows-1251'
document.querySelector('.m-list li:nth-of-type(2) input')
.dispatchEvent(new Event('keyup'))
})
// there is debounce timeout of 750ms in the options UI
await advanced.waitFor(800)
})
describe('incorrect encoding', () => {
before(async () => {
// go to page serving windows-1251 encoded string
// with UTF-8 content-type charset
await content.goto('http://localhost:3000/windows-1251')
await content.bringToFront()
await content.waitFor(200)
})
it('use encoding set by the server', async () => {
t.equal(
await content.evaluate(() => document.charset),
'UTF-8',
'chrome should pick the encoding from the content-type charset'
)
t.equal(
await content.evaluate(() => document.querySelector('#_html p').innerText),
'�������',
'text should be decoded incorrectly'
)
})
})
describe('correct encoding', () => {
before(async () => {
await advanced.bringToFront()
// enable csp - required to enable the webRequest permission!
if (!await advanced.evaluate(() => state.origins['http://localhost:3000'].csp)) {
await advanced.click('.m-list li:nth-of-type(2) .m-switch')
}
// set encoding
await advanced.select('.m-list li:nth-of-type(2) .m-encoding select', 'Windows-1251')
// go to page serving windows-1251 encoded string
// with windows-1251 content-type charset
await content.goto('http://localhost:3000/windows-1251')
await content.bringToFront()
await content.waitFor(200)
})
it('use encoding set for the origin', async () => {
t.equal(
await content.evaluate(() => document.charset),
'windows-1251',
'the content-type charset should be overridden'
)
t.equal(
await content.evaluate(() => document.querySelector('#_html p').innerText),
'здрасти',
'text should be decoded correctly'
)
})
})
describe('persist state', () => {
before(async () => {
await advanced.bringToFront()
await advanced.reload()
await advanced.waitFor(200)
// expand origin
if (!await advanced.evaluate(() =>
document.querySelector('.m-list li:nth-of-type(2)')
.classList.contains('m-expanded'))) {
await advanced.click('.m-list li:nth-of-type(2)')
}
})
it('reload', async () => {
t.equal(
await advanced.evaluate(() =>
document.querySelector('.m-list li:nth-of-type(2) .m-encoding select').value
),
'Windows-1251',
'should persist the selected encoding'
)
})
})
}