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