1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.performance;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.junit.annotation.Alerts;
19 import org.junit.jupiter.api.Test;
20 import org.openqa.selenium.WebDriver;
21
22
23
24
25
26
27 public class PerformanceNavigationTest extends WebDriverTestCase {
28
29
30
31
32 @Test
33 public void toJSON() throws Exception {
34 final String html = DOCTYPE_HTML
35 + "<html>\n"
36 + "<head>\n"
37 + "<script>\n"
38 + " function test() {\n"
39 + " alert(JSON.stringify(performance.navigation.toJSON()));\n"
40 + " }\n"
41 + " test();\n"
42 + "</script>\n"
43 + "</head>\n"
44 + "<body></body>\n"
45 + "</html>";
46
47 final WebDriver driver = loadPage2(html);
48 final String json = getCollectedAlerts(driver, 1).get(0);
49 assertTrue(json, json.contains("\"type\":0"));
50 assertTrue(json, json.contains("\"redirectCount\":0"));
51 }
52
53
54
55
56 @Test
57 @Alerts("0")
58 public void redirectCount() throws Exception {
59 final String html = DOCTYPE_HTML
60 + "<html>\n"
61 + "<head>\n"
62 + "<script>\n"
63 + LOG_TITLE_FUNCTION
64 + " function test() {\n"
65 + " log(performance.navigation.redirectCount);\n"
66 + " }\n"
67 + " test();\n"
68 + "</script>\n"
69 + "</head>\n"
70 + "<body></body>\n"
71 + "</html>";
72
73 loadPageVerifyTitle2(html);
74 }
75
76
77
78
79 @Test
80 @Alerts("0")
81 public void type() throws Exception {
82 final String html = DOCTYPE_HTML
83 + "<html>\n"
84 + "<head>\n"
85 + "<script>\n"
86 + LOG_TITLE_FUNCTION
87 + " function test() {\n"
88 + " log(performance.navigation.type);\n"
89 + " }\n"
90 + " test();\n"
91 + "</script>\n"
92 + "</head>\n"
93 + "<body></body>\n"
94 + "</html>";
95
96 loadPageVerifyTitle2(html);
97 }
98
99
100
101
102 @Test
103 @Alerts({"number", "function"})
104 public void methods() throws Exception {
105 final String html = DOCTYPE_HTML
106 + "<html>\n"
107 + "<body>\n"
108 + "<script>\n"
109 + LOG_TITLE_FUNCTION
110 + " log(typeof performance.navigation.redirectCount);\n"
111 + " log(typeof performance.navigation.toJSON);\n"
112 + "</script>\n"
113 + "</body></html>";
114
115 loadPageVerifyTitle2(html);
116 }
117 }