View Javadoc
1   /*
2    * Copyright (c) 2002-2025 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   * A JavaScript 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  @JsxClass
30  public class PerformanceTiming extends HtmlUnitScriptable {
31  
32      private final long domainLookupStart_;
33      private final long domainLookupEnd_;
34      private final long connectStart_;
35      private final long connectEnd_;
36      private final long responseStart_;
37      private final long responseEnd_;
38  
39      private final long domContentLoadedEventStart_;
40      private final long domContentLoadedEventEnd_;
41      private final long domLoading_;
42      private final long domInteractive_;
43      private final long domComplete_;
44  
45      private final long loadEventStart_;
46      private final long loadEventEnd_;
47      private final long navigationStart_;
48      private final long fetchStart_;
49  
50      /**
51       * Creates an instance.
52       */
53      public PerformanceTiming() {
54          super();
55          final long now = System.currentTimeMillis();
56  
57          // simulate the fastest browser on earth
58          domainLookupStart_ = now;
59          domainLookupEnd_ = domainLookupStart_ + 1L;
60  
61          connectStart_ = domainLookupEnd_;
62          connectEnd_ = connectStart_ + 1L;
63  
64          responseStart_ = connectEnd_;
65          responseEnd_ = responseStart_ + 1L;
66  
67          loadEventStart_ = responseEnd_;
68          loadEventEnd_ = loadEventStart_ + 1L;
69          domLoading_ = responseEnd_;
70          domInteractive_ = responseEnd_;
71          domContentLoadedEventStart_ = responseEnd_;
72          domContentLoadedEventEnd_ = domContentLoadedEventStart_ + 1L;
73          domComplete_ = domContentLoadedEventEnd_;
74  
75          navigationStart_ = now;
76          fetchStart_ = now;
77      }
78  
79      /**
80       * JavaScript constructor.
81       */
82      @JsxConstructor
83      public void jsConstructor() {
84          // nothing to do
85      }
86  
87      /**
88       * @return a domainLookupStart
89       */
90      @JsxGetter
91      public long getDomainLookupStart() {
92          return domainLookupStart_;
93      }
94  
95      /**
96       * @return a domainLookupEnd
97       */
98      @JsxGetter
99      public long getDomainLookupEnd() {
100         return domainLookupEnd_;
101     }
102 
103     /**
104      * @return a connectStart
105      */
106     @JsxGetter
107     public long getConnectStart() {
108         return connectStart_;
109     }
110 
111     /**
112      * @return a connectEnd
113      */
114     @JsxGetter
115     public long getConnectEnd() {
116         return connectEnd_;
117     }
118 
119     /**
120      * @return a responseStart
121      */
122     @JsxGetter
123     public long getResponseStart() {
124         return responseStart_;
125     }
126 
127     /**
128      * @return a responseEnd
129      */
130     @JsxGetter
131     public long getResponseEnd() {
132         return responseEnd_;
133     }
134 
135     /**
136      * @return a secureConnectionStart
137      */
138     @JsxGetter
139     public long getSecureConnectionStart() {
140         return 0;
141     }
142 
143     /**
144      * @return an unloadEventStart
145      */
146     @JsxGetter
147     public long getUnloadEventStart() {
148         return 0;
149     }
150 
151     /**
152      * @return an unloadEventEnd
153      */
154     @JsxGetter
155     public long getUnloadEventEnd() {
156         return 0;
157     }
158 
159     /**
160      * @return a redirectStart
161      */
162     @JsxGetter
163     public long getRedirectStart() {
164         return 0;
165     }
166 
167     /**
168      * @return a redirectEnd
169      */
170     @JsxGetter
171     public long getRedirectEnd() {
172         return 0;
173     }
174 
175     /**
176      * @return a domContentLoadedEventStart
177      */
178     @JsxGetter
179     public long getDomContentLoadedEventStart() {
180         return domContentLoadedEventStart_;
181     }
182 
183     /**
184      * @return a domLoading
185      */
186     @JsxGetter
187     public long getDomLoading() {
188         return domLoading_;
189     }
190 
191     /**
192      * @return a domInteractive
193      */
194     @JsxGetter
195     public long getDomInteractive() {
196         return domInteractive_;
197     }
198 
199     /**
200      * @return a domContentLoadedEventEnd
201      */
202     @JsxGetter
203     public long getDomContentLoadedEventEnd() {
204         return domContentLoadedEventEnd_;
205     }
206 
207     /**
208      * @return a domComplete
209      */
210     @JsxGetter
211     public long getDomComplete() {
212         return domComplete_;
213     }
214 
215     /**
216      * @return a loadEventStart
217      */
218     @JsxGetter
219     public long getLoadEventStart() {
220         return loadEventStart_;
221     }
222 
223     /**
224      * @return a loadEventEnd
225      */
226     @JsxGetter
227     public long getLoadEventEnd() {
228         return loadEventEnd_;
229     }
230 
231     /**
232      * @return a navigationStart
233      */
234     @JsxGetter
235     public long getNavigationStart() {
236         return navigationStart_;
237     }
238 
239     /**
240      * @return a navigationStart
241      */
242     @JsxGetter
243     public long getFetchStart() {
244         return fetchStart_;
245     }
246 }