Skip to content

Commit

Permalink
Add toJSON tests for LongTasks, Performance, and PerformanceEntry
Browse files Browse the repository at this point in the history
This CL adds correctness tests for the toJSON methods for the idls that
are modified in this change:
https://chromium-review.googlesource.com/c/chromium/src/+/802019

Bug: 740094
Change-Id: I3fcdcf913c7f8a30b9f090a4538b159bf8b6200b
Reviewed-on: https://chromium-review.googlesource.com/818114
Reviewed-by: Timothy Dresser <tdresser@chromium.org>
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#526697}
  • Loading branch information
npm1 authored and chromium-wpt-export-bot committed Jan 3, 2018
1 parent bbfe349 commit 3b82bae
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 0 deletions.
76 changes: 76 additions & 0 deletions hr-time/performance-tojson.html
Original file line number Diff line number Diff line change
@@ -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>
71 changes: 71 additions & 0 deletions longtask-timing/longtask-tojson.html
Original file line number Diff line number Diff line change
@@ -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>
33 changes: 33 additions & 0 deletions performance-timeline/performanceentry-tojson.html
Original file line number Diff line number Diff line change
@@ -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>
51 changes: 51 additions & 0 deletions resource-timing/resource-timing-tojson.html
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 3b82bae

Please sign in to comment.