1 /*
2 * Copyright (c) 2002-2026 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.javascript.host.performance;
16
17 import org.htmlunit.javascript.HtmlUnitScriptable;
18 import org.htmlunit.javascript.configuration.JsxClass;
19 import org.htmlunit.javascript.configuration.JsxConstructor;
20 import org.htmlunit.javascript.configuration.JsxGetter;
21
22 /**
23 * JavaScript host object for {@code PerformanceTiming}.
24 * This implementation is a simple mock for the moment.
25 *
26 * @author Ahmed Ashour
27 * @author Ronald Brill
28 *
29 * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming">MDN Documentation</a>
30 */
31 @JsxClass
32 public class PerformanceTiming extends HtmlUnitScriptable {
33
34 private final long domainLookupStart_;
35 private final long domainLookupEnd_;
36 private final long connectStart_;
37 private final long connectEnd_;
38 private final long responseStart_;
39 private final long responseEnd_;
40
41 private final long domContentLoadedEventStart_;
42 private final long domContentLoadedEventEnd_;
43 private final long domLoading_;
44 private final long domInteractive_;
45 private final long domComplete_;
46
47 private final long loadEventStart_;
48 private final long loadEventEnd_;
49 private final long navigationStart_;
50 private final long fetchStart_;
51
52 /**
53 * Creates an instance.
54 */
55 public PerformanceTiming() {
56 super();
57 final long now = System.currentTimeMillis();
58
59 // simulate the fastest browser on earth
60 domainLookupStart_ = now;
61 domainLookupEnd_ = domainLookupStart_ + 1L;
62
63 connectStart_ = domainLookupEnd_;
64 connectEnd_ = connectStart_ + 1L;
65
66 responseStart_ = connectEnd_;
67 responseEnd_ = responseStart_ + 1L;
68
69 loadEventStart_ = responseEnd_;
70 loadEventEnd_ = loadEventStart_ + 1L;
71 domLoading_ = responseEnd_;
72 domInteractive_ = responseEnd_;
73 domContentLoadedEventStart_ = responseEnd_;
74 domContentLoadedEventEnd_ = domContentLoadedEventStart_ + 1L;
75 domComplete_ = domContentLoadedEventEnd_;
76
77 navigationStart_ = now;
78 fetchStart_ = now;
79 }
80
81 /**
82 * Creates an instance of this object.
83 */
84 @JsxConstructor
85 public void jsConstructor() {
86 // nothing to do
87 }
88
89 /**
90 * Returns the value of the {@code domainLookupStart} property.
91 *
92 * @return the timestamp immediately before the browser starts the domain name lookup
93 */
94 @JsxGetter
95 public long getDomainLookupStart() {
96 return domainLookupStart_;
97 }
98
99 /**
100 * Returns the value of the {@code domainLookupEnd} property.
101 *
102 * @return the timestamp immediately after the browser finishes the domain name lookup
103 */
104 @JsxGetter
105 public long getDomainLookupEnd() {
106 return domainLookupEnd_;
107 }
108
109 /**
110 * Returns the value of the {@code connectStart} property.
111 *
112 * @return the timestamp immediately before the browser starts to establish the connection to the server
113 */
114 @JsxGetter
115 public long getConnectStart() {
116 return connectStart_;
117 }
118
119 /**
120 * Returns the value of the {@code connectEnd} property.
121 *
122 * @return the timestamp immediately after the browser finishes establishing the connection to the server
123 */
124 @JsxGetter
125 public long getConnectEnd() {
126 return connectEnd_;
127 }
128
129 /**
130 * Returns the value of the {@code responseStart} property.
131 *
132 * @return the timestamp immediately after the browser receives the first byte of the response
133 */
134 @JsxGetter
135 public long getResponseStart() {
136 return responseStart_;
137 }
138
139 /**
140 * Returns the value of the {@code responseEnd} property.
141 *
142 * @return the timestamp immediately after the browser receives the last byte of the response
143 */
144 @JsxGetter
145 public long getResponseEnd() {
146 return responseEnd_;
147 }
148
149 /**
150 * Returns the value of the {@code secureConnectionStart} property.
151 *
152 * @return the timestamp immediately before the browser starts the handshake process to secure the current connection
153 */
154 @JsxGetter
155 public long getSecureConnectionStart() {
156 return 0;
157 }
158
159 /**
160 * Returns the value of the {@code unloadEventStart} property.
161 *
162 * @return the timestamp immediately before the unload event is fired
163 */
164 @JsxGetter
165 public long getUnloadEventStart() {
166 return 0;
167 }
168
169 /**
170 * Returns the value of the {@code unloadEventEnd} property.
171 *
172 * @return the timestamp immediately after the unload event completes
173 */
174 @JsxGetter
175 public long getUnloadEventEnd() {
176 return 0;
177 }
178
179 /**
180 * Returns the value of the {@code redirectStart} property.
181 *
182 * @return the timestamp of the start of the first HTTP redirect
183 */
184 @JsxGetter
185 public long getRedirectStart() {
186 return 0;
187 }
188
189 /**
190 * Returns the value of the {@code redirectEnd} property.
191 *
192 * @return the timestamp immediately after the last redirect response is received
193 */
194 @JsxGetter
195 public long getRedirectEnd() {
196 return 0;
197 }
198
199 /**
200 * Returns the value of the {@code domContentLoadedEventStart} property.
201 *
202 * @return the timestamp immediately before the {@code DOMContentLoaded} event is fired
203 */
204 @JsxGetter
205 public long getDomContentLoadedEventStart() {
206 return domContentLoadedEventStart_;
207 }
208
209 /**
210 * Returns the value of the {@code domLoading} property.
211 *
212 * @return the timestamp immediately before the browser sets the document readyState to {@code loading}
213 */
214 @JsxGetter
215 public long getDomLoading() {
216 return domLoading_;
217 }
218
219 /**
220 * Returns the value of the {@code domInteractive} property.
221 *
222 * @return the timestamp immediately before the browser sets the document readyState to {@code interactive}
223 */
224 @JsxGetter
225 public long getDomInteractive() {
226 return domInteractive_;
227 }
228
229 /**
230 * Returns the value of the {@code domContentLoadedEventEnd} property.
231 *
232 * @return the timestamp immediately after the {@code DOMContentLoaded} event completes
233 */
234 @JsxGetter
235 public long getDomContentLoadedEventEnd() {
236 return domContentLoadedEventEnd_;
237 }
238
239 /**
240 * Returns the value of the {@code domComplete} property.
241 *
242 * @return the timestamp immediately before the browser sets the document readyState to {@code complete}
243 */
244 @JsxGetter
245 public long getDomComplete() {
246 return domComplete_;
247 }
248
249 /**
250 * Returns the value of the {@code loadEventStart} property.
251 *
252 * @return the timestamp immediately before the load event is fired
253 */
254 @JsxGetter
255 public long getLoadEventStart() {
256 return loadEventStart_;
257 }
258
259 /**
260 * Returns the value of the {@code loadEventEnd} property.
261 *
262 * @return the timestamp immediately after the load event completes
263 */
264 @JsxGetter
265 public long getLoadEventEnd() {
266 return loadEventEnd_;
267 }
268
269 /**
270 * Returns the value of the {@code navigationStart} property.
271 *
272 * @return the timestamp immediately after the previous document's unload event completes
273 */
274 @JsxGetter
275 public long getNavigationStart() {
276 return navigationStart_;
277 }
278
279 /**
280 * Returns the value of the {@code fetchStart} property.
281 *
282 * @return the timestamp immediately before the browser starts to fetch the resource
283 */
284 @JsxGetter
285 public long getFetchStart() {
286 return fetchStart_;
287 }
288 }