Skip to content

Commit

Permalink
Add FilterOptions to performance.getEntries() behind a flag
Browse files Browse the repository at this point in the history
This CL adds a new GetEntries(FilterOptions options) API. The
FilterOptions consists of name, entryType and includeChildFrames on which performance entries can be filtered.

The CL also removes the optional argument includeFrames from GetEntries,
GetEntriesByName and GetEntriesByType.

Change-Id: Ib4dcdba95268d873b86ce1dbd3a30ef29d09f5e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4188992
Reviewed-by: Yoav Weiss <[email protected]>
Commit-Queue: Hao Liu <[email protected]>
Reviewed-by: Ian Clelland <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1099995}
  • Loading branch information
haoliuk authored and chromium-wpt-export-bot committed Feb 1, 2023
1 parent 6e081c8 commit 531d5a4
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
const childFrame = document.createElement('iframe');

childFrame.addEventListener('load', async () => {
const entries = performance.getEntries(true);
const entries = performance.getEntries({ includeChildFrames: true });

// Report number of performance entries to the parent.
window.parent.postMessage(entries.length, "*");
Expand Down
5 changes: 2 additions & 3 deletions performance-timeline/tentative/detached-frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
// Detach the child frame
document.body.removeChild(childFrame);

const entries = childWindow.performance.getEntries(true);
const parent_entries = performance.getEntries(true);
const entries = childWindow.performance.getEntries({ includeChildFrames: true });
const parent_entries = performance.getEntries({ includeChildFrames: true });
}, "GetEntries of a detached parent frame does not crash");
</script>

33 changes: 29 additions & 4 deletions performance-timeline/tentative/include-frames-originA-A-A.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
// Verify the number of performance entries in the child frame.
assert_equals(childFrameEntrySize, 6, 'Child Frame should have 6 entries.');

const entries = performance.getEntries(true);
const entries = performance.getEntries({ includeChildFrames: true });

const navigationEntries = performance.getEntriesByType('navigation', true);

const markedEntries = performance.getEntriesByName('entry-name', undefined, true);
const navigationEntries = performance.getEntries({ entryType: "navigation", includeChildFrames: true });

const markedEntries = performance.getEntries(
{ name: 'entry-name', includeChildFrames: true });

// 3 entries for parent, 4 for child, 2 for grandchild.
assert_equals(entries.length, 9, 'Total entries should be 9.');
Expand All @@ -48,6 +48,31 @@
// 1 entry for child, 1 for grandchild.
assert_equals(markedEntries.length, 2, 'Mark entries should be 2.');

// Test cases where includeChildFrames is false.
const entriesWithNoFitlerOptions = performance.getEntries();

const entriesWithoutIncludingChildFrames = performance.getEntries({ includeChildFrames: false });

const navigationEntriesWithoutIncludingChildFrames = performance.getEntries({ entryType: "navigation", includeChildFrames: false });

const markedEntriesWithoutIncludingChildFrames = performance.getEntries(
{ name: 'entry-name', includeChildFrames: false });

// 3 entries for parent.
assert_equals(entriesWithNoFitlerOptions.length, 3,
'Total entries without filter options should be 3 without filter options.');

assert_equals(entriesWithoutIncludingChildFrames.length, 3,
'Total entries with includeChildFrame being false should be 3.');

// 1 entry for parent.
assert_equals(navigationEntriesWithoutIncludingChildFrames.length, 1,
'Navigation entries with includeChildFrame being false should be 1.');

// 0 entry for child.
assert_equals(markedEntriesWithoutIncludingChildFrames.length, 0,
'Mark entries with includeChildFrame being false should be 0.');

}, 'GetEntries of a document of origin A, its child frame of origin B and \
its grandchild frame of origin A.');
</script>
Expand Down
33 changes: 30 additions & 3 deletions performance-timeline/tentative/include-frames-originA-A.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
// Load a child frame.
await loadSameOriginChildFrame();

const entries = performance.getEntries(true);
const entries = performance.getEntries({ includeChildFrames: true });

const navigationEntries = performance.getEntriesByType('navigation', true);
const navigationEntries = performance.getEntries({ entryType: "navigation", includeChildFrames: true });

const markedEntries = performance.getEntriesByName('entry-name', undefined, true);
const markedEntries = performance.getEntries(
{ name: 'entry-name', includeChildFrames: true });

// 3 entries for parent, 2 for child.
assert_equals(entries.length, 5, 'Total entries should be 5.');
Expand All @@ -42,6 +43,32 @@

// 1 entry for child.
assert_equals(markedEntries.length, 1, 'Mark entries should be 1.');

// Test cases where includeChildFrames is false.
const entriesWithNoFitlerOptions = performance.getEntries();

const entriesWithoutIncludingChildFrames = performance.getEntries({ includeChildFrames: false });

const navigationEntriesWithoutIncludingChildFrames = performance.getEntries({ entryType: "navigation", includeChildFrames: false });

const markedEntriesWithoutIncludingChildFrames = performance.getEntries(
{ name: 'entry-name', includeChildFrames: false });

// 3 entries for parent.
assert_equals(entriesWithNoFitlerOptions.length, 3,
'Total entries without filter options should be 3 without filter options.');

assert_equals(entriesWithoutIncludingChildFrames.length, 3,
'Total entries with includeChildFrame being false should be 3.');

// 1 entry for parent.
assert_equals(navigationEntriesWithoutIncludingChildFrames.length, 1,
'Navigation entries with includeChildFrame being false should be 1.');

// 0 entry for child.
assert_equals(markedEntriesWithoutIncludingChildFrames.length, 0,
'Mark entries with includeChildFrame being false should be 0.');

}, 'GetEntries of a document of origin A and its child frame of origin A.');
</script>
</body>
7 changes: 4 additions & 3 deletions performance-timeline/tentative/include-frames-originA-AA.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
<body>
<script>
const verifyPerformanceEntries = () => {
const entries = performance.getEntries(true);
const entries = performance.getEntries({ includeChildFrames: true });

const navigationEntries = performance.getEntriesByType( 'navigation', true);
const navigationEntries = performance.getEntries({ entryType: "navigation", includeChildFrames: true });

const markedEntries = performance.getEntriesByName('entry-name', undefined, true );
const markedEntries = performance.getEntries(
{ name: 'entry-name', includeChildFrames: true });

// 4 entries for parent, 2 for each child
assert_equals(entries.length, 8,'Total entries should be 8.');
Expand Down
7 changes: 4 additions & 3 deletions performance-timeline/tentative/include-frames-originA-AB.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
}

const verifyPerformanceEntries = () => {
const entries = performance.getEntries(true);
const entries = performance.getEntries({ includeChildFrames: true });

const navigationEntries = performance.getEntriesByType('navigation', true);
const navigationEntries = performance.getEntries({ entryType: "navigation", includeChildFrames: true });

const markedEntries = performance.getEntriesByName('entry-name', undefined, true);
const markedEntries = performance.getEntries(
{ name: 'entry-name', includeChildFrames: true });

// 4 entries for parent, 2 for local child, 0 for remote child.
assert_equals(entries.length, 6, 'Total entries should 6.');
Expand Down
34 changes: 30 additions & 4 deletions performance-timeline/tentative/include-frames-originA-B-A.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
// Verify the number of performance entries in the child frame.
assert_equals(childFrameEntrySize, 4, 'Child frame entries should be 4.');

const entries = performance.getEntries(true);
const entries = performance.getEntries({ includeChildFrames: true });

const navigationEntries = performance.getEntriesByType(
'navigation', true);
const navigationEntries = performance.getEntries({ entryType: "navigation", includeChildFrames: true });

const markedEntries = performance.getEntriesByName('entry-name', undefined, true);
const markedEntries = performance.getEntries(
{ name: 'entry-name', includeChildFrames: true });

// 3 entries for parent, 0 for child, 2 for grandchild.
assert_equals(entries.length, 5, 'Total entries should be 5.');
Expand All @@ -51,6 +51,32 @@

// 1 entry for grandchild.
assert_equals(markedEntries.length, 1, 'Mark entries should be 1.');

// Test cases where includeChildFrames is false.
const entriesWithNoFitlerOptions = performance.getEntries();

const entriesWithoutIncludingChildFrames = performance.getEntries({ includeChildFrames: false });

const navigationEntriesWithoutIncludingChildFrames = performance.getEntries({ entryType: "navigation", includeChildFrames: false });

const markedEntriesWithoutIncludingChildFrames = performance.getEntries(
{ name: 'entry-name', includeChildFrames: false });

// 3 entries for parent.
assert_equals(entriesWithNoFitlerOptions.length, 3,
'Total entries without filter options should be 3 without filter options.');

assert_equals(entriesWithoutIncludingChildFrames.length, 3,
'Total entries with includeChildFrame being false should be 3.');

// 1 entry for parent.
assert_equals(navigationEntriesWithoutIncludingChildFrames.length, 1,
'Navigation entries with includeChildFrame being false should be 1.');

// 1 entry for child.
assert_equals(markedEntriesWithoutIncludingChildFrames.length, 0,
'Mark entries with includeChildFrame being false should be 0.');

}, 'GetEntries of a document of origin A, its child frame of origin B and \
its grandchild frame of origin A.');
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// 4 for child, 2 for grandchild.
assert_equals(childFrameEntrySize, 6, 'Child frame entries should be 6.');

const entries = performance.getEntries(true);
const entries = performance.getEntries({ includeChildFrames: true });

// 3 entries for parent, 0 for child, 0 for grandchild.
assert_equals(entries.length, 3, 'Total entries should be 3.');
Expand Down
7 changes: 4 additions & 3 deletions performance-timeline/tentative/include-frames-originA-B.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@

await loadCrossOriginChildFrame();

const entries = performance.getEntries(true);
const entries = performance.getEntries({ includeChildFrames: true });

const navigationEntries = performance.getEntriesByType("navigation", true);
const navigationEntries = performance.getEntries({ entryType: "navigation", includeChildFrames: true });

const markedEntries = performance.getEntriesByName('entry-name', undefined, true);
const markedEntries = performance.getEntries(
{ name: 'entry-name', includeChildFrames: true });

// 3 entries for parent, 0 for child.
assert_equals(entries.length, 3, 'Total entries should be 3.');
Expand Down
8 changes: 5 additions & 3 deletions performance-timeline/tentative/performance-entry-source.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script>
promise_test(() => {
return new Promise(resolve => {
const navigationEntries = performance.getEntriesByType("navigation")
const navigationEntries = performance.getEntries({ type: 'navigation' })
const parentEntry = navigationEntries[0]

// Parent NavigationTiming source is current window.
Expand All @@ -20,7 +20,9 @@
document.body.appendChild(childFrame)

childFrame.addEventListener('load', () => {
const markedEntries = performance.getEntriesByName("entry-name", undefined, true)
const markedEntries = performance.getEntries(
{ name: 'entry-name', includeChildFrames: true });

const childEntry = markedEntries[0]

// Child PerformanceMark source is the child's Window.
Expand All @@ -30,4 +32,4 @@
})
})
}, "PerformanceEntry source is equal to its respective Window")
</script>
</script>

0 comments on commit 531d5a4

Please sign in to comment.