• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!doctype html>
2<html>
3<head>
4<script src="/resources/testharness.js"></script>
5<script src="/resources/testharnessreport.js"></script>
6</head>
7<body>
8<script>
9
10test(() => {
11  // Check Performance attributes.
12  assert_equals(typeof(performance.toJSON), 'function');
13  const json = performance.toJSON();
14  assert_equals(typeof(json), 'object');
15  assert_equals(json.timeOrigin, performance.timeOrigin,
16    'performance.toJSON().timeOrigin should match performance.timeOrigin');
17
18  // Check PerformanceTiming toJSON.
19  const jsonTiming = json.timing;
20  const timing = performance.timing;
21  assert_equals(typeof(timing.toJSON), 'function');
22  const timingJSON = timing.toJSON();
23  assert_equals(typeof(timingJSON), 'object');
24  // Check PerformanceTiming attributes, from both:
25  // 1) |jsonTiming| from  Performance.
26  // 2) |timingJSON| from PerformanceTiming.
27  const performanceTimingKeys = [
28    'navigationStart',
29    'unloadEventStart',
30    'unloadEventEnd',
31    'redirectStart',
32    'redirectEnd',
33    'fetchStart',
34    'domainLookupStart',
35    'domainLookupEnd',
36    'connectStart',
37    'connectEnd',
38    'secureConnectionStart',
39    'requestStart',
40    'responseStart',
41    'responseEnd',
42    'domLoading',
43    'domInteractive',
44    'domContentLoadedEventStart',
45    'domContentLoadedEventEnd',
46    'domComplete',
47    'loadEventStart',
48    'loadEventEnd'
49  ];
50  for (const key of performanceTimingKeys) {
51    assert_equals(jsonTiming[key], timing[key],
52      `performance.toJSON().timing.${key} should match performance.timing.${key}`);
53    assert_equals(timingJSON[key], timing[key],
54      `performance.timing.toJSON().${key} should match performance.timing.${key}`);
55  }
56
57  // Check PerformanceNavigation toJSON.
58  const jsonNavigation = json.navigation;
59  const navigation = performance.navigation;
60  assert_equals(typeof(navigation.toJSON), 'function');
61  const navigationJSON = navigation.toJSON();
62  assert_equals(typeof(navigationJSON), 'object');
63  // Check PerformanceNavigation attributes, from both:
64  // 1) |jsonNavigation| from  Performance.
65  // 2) |navigationJSON| from PerformanceNavigation.
66  let performanceNavigationKeys = ['type', 'redirectCount'];
67  for (const key of performanceNavigationKeys) {
68    assert_equals(jsonNavigation[key], navigation[key],
69      `performance.toJSON().navigation.${key} should match performance.navigation.${key}`);
70    assert_equals(navigationJSON[key], navigation[key],
71      `performance.navigation.toJSON().${key} should match performance.navigation.${key}`);
72  }
73}, 'Test performance.toJSON()');
74</script>
75</body>
76</html>