forked from microsoft/playwright-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_resource_timing.py
119 lines (105 loc) · 5.14 KB
/
test_resource_timing.py
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
# Copyright (c) Microsoft Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest
async def test_should_work(page, server, is_webkit, is_mac):
if is_webkit and is_mac:
pytest.skip()
async with page.expect_event("requestfinished") as request_info:
await page.goto(server.EMPTY_PAGE)
request = await request_info.value
timing = request.timing
assert timing["domainLookupStart"] >= 0
assert timing["domainLookupEnd"] >= timing["domainLookupStart"]
assert timing["connectStart"] >= timing["domainLookupEnd"]
assert timing["secureConnectionStart"] == -1
assert timing["connectEnd"] > timing["secureConnectionStart"]
assert timing["requestStart"] >= timing["connectEnd"]
assert timing["responseStart"] > timing["requestStart"]
assert timing["responseEnd"] >= timing["responseStart"]
assert timing["responseEnd"] < 10000
async def test_should_work_for_subresource(page, server, is_win, is_mac, is_webkit):
if is_webkit and is_win:
pytest.skip()
requests = []
page.on("requestfinished", lambda request: requests.append(request))
await page.goto(server.PREFIX + "/one-style.html")
assert len(requests) == 2
timing = requests[1].timing
if is_webkit and is_win:
# Curl does not reuse connections.
assert timing["domainLookupStart"] >= 0
assert timing["domainLookupEnd"] >= timing["domainLookupStart"]
assert timing["connectStart"] >= timing["domainLookupEnd"]
assert timing["secureConnectionStart"] == -1
assert timing["connectEnd"] > timing["secureConnectionStart"]
else:
assert timing["domainLookupStart"] == 0 or timing["domainLookupStart"] == -1
assert timing["domainLookupEnd"] == 0 or timing["domainLookupEnd"] == -1
assert timing["connectStart"] == 0 or timing["connectStart"] == -1
assert timing["connectEnd"] == 0 or timing["connectEnd"] == -1
assert timing["secureConnectionStart"] == -1
assert timing["requestStart"] >= 0
assert timing["responseStart"] > timing["requestStart"]
assert timing["responseEnd"] >= timing["responseStart"]
assert timing["responseEnd"] < 10000
async def test_should_work_for_ssl(browser, https_server, is_mac, is_webkit):
if is_webkit and is_mac:
pytest.skip()
page = await browser.newPage(ignoreHTTPSErrors=True)
async with page.expect_event("requestfinished") as request_info:
await page.goto(https_server.EMPTY_PAGE)
request = await request_info.value
timing = request.timing
if not (is_webkit and is_mac):
assert timing["domainLookupStart"] >= 0
assert timing["domainLookupEnd"] >= timing["domainLookupStart"]
assert timing["connectStart"] >= timing["domainLookupEnd"]
assert timing["secureConnectionStart"] > timing["connectStart"]
assert timing["connectEnd"] > timing["secureConnectionStart"]
assert timing["requestStart"] >= timing["connectEnd"]
assert timing["responseStart"] > timing["requestStart"]
assert timing["responseEnd"] >= timing["responseStart"]
assert timing["responseEnd"] < 10000
await page.close()
@pytest.mark.skip_browser("webkit") # In WebKit, redirects don"t carry the timing info
async def test_should_work_for_redirect(page, server):
server.set_redirect("/foo.html", "/empty.html")
responses = []
page.on("response", lambda response: responses.append(response))
await page.goto(server.PREFIX + "/foo.html")
for r in responses:
await r.finished()
assert len(responses) == 2
assert responses[0].url == server.PREFIX + "/foo.html"
assert responses[1].url == server.PREFIX + "/empty.html"
timing1 = responses[0].request.timing
assert timing1["domainLookupStart"] >= 0
assert timing1["domainLookupEnd"] >= timing1["domainLookupStart"]
assert timing1["connectStart"] >= timing1["domainLookupEnd"]
assert timing1["secureConnectionStart"] == -1
assert timing1["connectEnd"] > timing1["secureConnectionStart"]
assert timing1["requestStart"] >= timing1["connectEnd"]
assert timing1["responseStart"] > timing1["requestStart"]
assert timing1["responseEnd"] >= timing1["responseStart"]
assert timing1["responseEnd"] < 10000
timing2 = responses[1].request.timing
assert timing2["domainLookupStart"] == -1
assert timing2["domainLookupEnd"] == -1
assert timing2["connectStart"] == -1
assert timing2["secureConnectionStart"] == -1
assert timing2["connectEnd"] == -1
assert timing2["requestStart"] >= 0
assert timing2["responseStart"] > timing2["requestStart"]
assert timing2["responseEnd"] >= timing2["responseStart"]
assert timing2["responseEnd"] < 10000