Merge pull request #8862 from w3c/sync_7ad06151140579b95e34c58150082f78a99bb44a

Wait for the URL to change in test before asserting
diff --git a/hr-time/performance-tojson.html b/hr-time/performance-tojson.html
new file mode 100644
index 0000000..fd8049c
--- /dev/null
+++ b/hr-time/performance-tojson.html
@@ -0,0 +1,76 @@
+<!doctype html>
+<html>
+<head>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+</head>
+<body>
+<script>
+
+test(() => {
+  // Check Performance attributes.
+  assert_equals(typeof(performance.toJSON), 'function');
+  const json = performance.toJSON();
+  assert_equals(typeof(json), 'object');
+  assert_equals(json.timeOrigin, performance.timeOrigin,
+    'performance.toJSON().timeOrigin should match performance.timeOrigin');
+
+  // Check PerformanceTiming toJSON.
+  const jsonTiming = json.timing;
+  const timing = performance.timing;
+  assert_equals(typeof(timing.toJSON), 'function');
+  const timingJSON = timing.toJSON();
+  assert_equals(typeof(timingJSON), 'object');
+  // Check PerformanceTiming attributes, from both:
+  // 1) |jsonTiming| from  Performance.
+  // 2) |timingJSON| from PerformanceTiming.
+  const performanceTimingKeys = [
+    'navigationStart',
+    'unloadEventStart',
+    'unloadEventEnd',
+    'redirectStart',
+    'redirectEnd',
+    'fetchStart',
+    'domainLookupStart',
+    'domainLookupEnd',
+    'connectStart',
+    'connectEnd',
+    'secureConnectionStart',
+    'requestStart',
+    'responseStart',
+    'responseEnd',
+    'domLoading',
+    'domInteractive',
+    'domContentLoadedEventStart',
+    'domContentLoadedEventEnd',
+    'domComplete',
+    'loadEventStart',
+    'loadEventEnd'
+  ];
+  for (const key of performanceTimingKeys) {
+    assert_equals(jsonTiming[key], timing[key],
+      `performance.toJSON().timing.${key} should match performance.timing.${key}`);
+    assert_equals(timingJSON[key], timing[key],
+      `performance.timing.toJSON().${key} should match performance.timing.${key}`);
+  }
+
+  // Check PerformanceNavigation toJSON.
+  const jsonNavigation = json.navigation;
+  const navigation = performance.navigation;
+  assert_equals(typeof(navigation.toJSON), 'function');
+  const navigationJSON = navigation.toJSON();
+  assert_equals(typeof(navigationJSON), 'object');
+  // Check PerformanceNavigation attributes, from both:
+  // 1) |jsonNavigation| from  Performance.
+  // 2) |navigationJSON| from PerformanceNavigation.
+  let performanceNavigationKeys = ['type', 'redirectCount'];
+  for (const key of performanceNavigationKeys) {
+    assert_equals(jsonNavigation[key], navigation[key],
+      `performance.toJSON().navigation.${key} should match performance.navigation.${key}`);
+    assert_equals(navigationJSON[key], navigation[key],
+      `performance.navigation.toJSON().${key} should match performance.navigation.${key}`);
+  }
+}, 'Test performance.toJSON()');
+</script>
+</body>
+</html>
\ No newline at end of file
diff --git a/longtask-timing/longtask-tojson.html b/longtask-timing/longtask-tojson.html
new file mode 100644
index 0000000..bbe0d66
--- /dev/null
+++ b/longtask-timing/longtask-tojson.html
@@ -0,0 +1,71 @@
+<!doctype html>
+<html>
+<head>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+</head>
+<body>
+<script>
+  async_test(function (t) {
+    const observer = new PerformanceObserver(
+      t.step_func(function (entryList) {
+        const entries = entryList.getEntries();
+        assert_greater_than_equal(entries.length, 1);
+        const entry = entries[0];
+        assert_equals(typeof(entry.toJSON), 'function');
+        const entryJSON = entry.toJSON();
+        assert_equals(typeof(entryJSON), 'object');
+        // Check attributes inheritted from PerformanceEntry.
+        const performanceEntryKeys = [
+            'name',
+            'entryType',
+            'startTime',
+            'duration'
+        ];
+        for (const key of performanceEntryKeys) {
+            assert_equals(entryJSON[key], entry[key],
+                `entry.toJSON().${key} should match entry.${key}`);
+        }
+
+        // Check PerformanceLongTaskTiming specific entries.
+        assert_equals(typeof(entryJSON.attribution), 'object');
+        const entryJsonAttribution = entryJSON.attribution[0];
+        assert_equals(typeof(entryJsonAttribution), 'object');
+        assert_equals(entryJSON.attribution.length, entry.attribution.length);
+
+        // Check TaskAttributionTiming toJSON.
+        const entryAttribution = entry.attribution[0];
+        assert_equals(typeof(entryAttribution.toJSON), 'function');
+        const entryAttributionJSON = entryAttribution.toJSON();
+        assert_equals(typeof(entryAttributionJSON), 'object');
+        // Check TaskAttributionTiming attributes, from both:
+        // 1) |entryJsonAttribution| from  PerformanceLongTaskTiming.
+        // 2) |entryAttributionJSON| from TaskAttributionTiming.
+        const taskAttributionTimingKeys = [
+            'name',
+            'entryType',
+            'startTime',
+            'duration',
+            'containerType',
+            'containerSrc',
+            'containerId',
+            'containerName'
+        ];
+        for (const key of taskAttributionTimingKeys) {
+            assert_equals(entryAttributionJSON[key], entryAttribution[key],
+                `attribution.toJSON().${key} should match attribution.${key}`);
+            assert_equals(entryJsonAttribution[key], entryAttribution[key],
+                `entry.toJSON().attribution[0].${key} should match attribution.${key}`);
+        }
+        t.done();
+      })
+    );
+    observer.observe({entryTypes: ['longtask']});
+
+    // Trigger a long task.
+    const begin = window.performance.now();
+    while (window.performance.now() < begin + 51);
+  }, 'Test toJSON() in PerformanceLongTaskTiming and TaskAttributionTiming');
+</script>
+</body>
+</html>
\ No newline at end of file
diff --git a/performance-timeline/performanceentry-tojson.html b/performance-timeline/performanceentry-tojson.html
new file mode 100644
index 0000000..8576872
--- /dev/null
+++ b/performance-timeline/performanceentry-tojson.html
@@ -0,0 +1,33 @@
+<!doctype html>
+<html>
+<head>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+</head>
+<body>
+<script>
+
+test(() => {
+  performance.mark('markName');
+  performance.measure('measureName');
+
+  const entries = performance.getEntries();
+  const performanceEntryKeys = [
+    'name',
+    'entryType',
+    'startTime',
+    'duration'
+  ];
+  for (let i = 0; i < entries.length; ++i) {
+    assert_equals(typeof(entries[i].toJSON), 'function');
+    const json = entries[i].toJSON();
+    assert_equals(typeof(json), 'object');
+    for (const key of performanceEntryKeys) {
+      assert_equals(json[key], entries[i][key],
+        `entries[${i}].toJSON().${key} should match entries[${i}].${key}`);
+    }
+  }
+}, 'Test toJSON() in PerformanceEntry');
+</script>
+</body>
+</html>
\ No newline at end of file
diff --git a/resource-timing/resource-timing-tojson.html b/resource-timing/resource-timing-tojson.html
new file mode 100644
index 0000000..77094f4
--- /dev/null
+++ b/resource-timing/resource-timing-tojson.html
@@ -0,0 +1,51 @@
+<!doctype html>
+<html>
+<head>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+</head>
+<body>
+<script>
+  const img_url = "resources/blue.png";
+  const img = document.createElement("img");
+  img.src = img_url;
+  window.onload = function() {
+    test(() => {
+      const entries = performance.getEntriesByType('resource');
+      assert_greater_than_equal(entries.length, 1);
+      const entry = entries[0];
+      assert_equals(typeof(entry.toJSON), 'function');
+      const json = entry.toJSON();
+      assert_equals(typeof(json), 'object');
+
+      const performanceResourceTimingKeys = [
+        'name',
+        'entryType',
+        'startTime',
+        'duration',
+        'initiatorType',
+        'nextHopProtocol',
+        'workerStart',
+        'redirectStart',
+        'fetchStart',
+        'domainLookupStart',
+        'domainLookupEnd',
+        'connectStart',
+        'connectEnd',
+        'secureConnectionStart',
+        'requestStart',
+        'responseStart',
+        'responseEnd',
+        'transferSize',
+        'encodedBodySize',
+        'decodedBodySize'
+      ];
+      for (const key of performanceResourceTimingKeys) {
+        assert_equals(json[key], entry[key],
+          `entry.toJSON().${key} should match entry.${key}`);
+      }
+    }, 'Test toJSON() in PerformanceResourceTiming');
+  };
+</script>
+</body>
+</html>
\ No newline at end of file