From 2869b4b48d276165d65259c3cc91379ea03cc35c Mon Sep 17 00:00:00 2001 From: "haoliuk@google.com" Date: Fri, 10 Jun 2022 09:50:09 +0000 Subject: [PATCH] Bug 1769564 [wpt PR 34073] - Add navigation_id to all types of performance entries., a=testonly Automatic update from web-platform-tests Add navigation_id to all types of performance entries. Add navigation_id field to all performance entries. The navigation_id starts from 1 and increments whenever there is a back/forward cache navigation. This way, its value represents different sessions in the navigation history. Bug: I15d9396303e868aa5850b86aa4cc624f15d55f7e Change-Id: I99652c42a166916294c1c9994ac2161534cdcf52 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3599609 Reviewed-by: Yoav Weiss Reviewed-by: Ian Clelland Commit-Queue: Yoav Weiss Cr-Commit-Position: refs/heads/main@{#1011846} -- wpt-commits: f399d7b775fade572b2e99cff3ef181b805893aa wpt-pr: 34073 --- testing/web-platform/tests/lint.ignore | 1 + .../navigation-id-detached-frame.tentative.html | 30 +++ ...=> navigation-id-element-timing.tentative.html} | 7 +- ...n-id-long-task-task-attribution.tentative.html} | 7 +- ...l => navigation-id-mark-measure.tentative.html} | 7 +- ...> navigation-id-resource-timing.tentative.html} | 7 +- .../performance-timeline/navigation-id.helper.js | 212 +++++++++++++-------- .../resources/json_resource.json | 4 + .../resources/make_long_task.js | 4 + .../navigation-id-detached-frame-page.html | 21 ++ 10 files changed, 206 insertions(+), 94 deletions(-) create mode 100644 testing/web-platform/tests/performance-timeline/navigation-id-detached-frame.tentative.html copy testing/web-platform/tests/performance-timeline/{navigation-id.tentative.html => navigation-id-element-timing.tentative.html} (80%) copy testing/web-platform/tests/performance-timeline/{navigation-id.tentative.html => navigation-id-long-task-task-attribution.tentative.html} (76%) copy testing/web-platform/tests/performance-timeline/{navigation-id.tentative.html => navigation-id-mark-measure.tentative.html} (80%) rename testing/web-platform/tests/performance-timeline/{navigation-id.tentative.html => navigation-id-resource-timing.tentative.html} (79%) rewrite testing/web-platform/tests/performance-timeline/navigation-id.helper.js (61%) create mode 100644 testing/web-platform/tests/performance-timeline/resources/json_resource.json create mode 100644 testing/web-platform/tests/performance-timeline/resources/make_long_task.js create mode 100644 testing/web-platform/tests/performance-timeline/resources/navigation-id-detached-frame-page.html diff --git a/testing/web-platform/tests/lint.ignore b/testing/web-platform/tests/lint.ignore index fdba97deda7a..07ad220e4f7d 100644 --- a/testing/web-platform/tests/lint.ignore +++ b/testing/web-platform/tests/lint.ignore @@ -199,6 +199,7 @@ SET TIMEOUT: navigation-api/navigation-history-entry/entries-after-bfcache-in-if SET TIMEOUT: navigation-timing/* SET TIMEOUT: old-tests/submission/Microsoft/history/history_000.htm SET TIMEOUT: paint-timing/resources/subframe-painting.html +SET TIMEOUT: performance-timeline/resources/navigation-id-detached-frame-page.html SET TIMEOUT: portals/resources/portals-adopt-predecessor-portal.html SET TIMEOUT: preload/single-download-preload.html SET TIMEOUT: preload/resources/slow-exec.js diff --git a/testing/web-platform/tests/performance-timeline/navigation-id-detached-frame.tentative.html b/testing/web-platform/tests/performance-timeline/navigation-id-detached-frame.tentative.html new file mode 100644 index 000000000000..add11255af45 --- /dev/null +++ b/testing/web-platform/tests/performance-timeline/navigation-id-detached-frame.tentative.html @@ -0,0 +1,30 @@ + + + + + + The navigation_id Detached iframe Parent Page. + + + + + + + + + \ No newline at end of file diff --git a/testing/web-platform/tests/performance-timeline/navigation-id.tentative.html b/testing/web-platform/tests/performance-timeline/navigation-id-element-timing.tentative.html similarity index 80% copy from testing/web-platform/tests/performance-timeline/navigation-id.tentative.html copy to testing/web-platform/tests/performance-timeline/navigation-id-element-timing.tentative.html index 08dbd4b01b13..bc52f208b072 100644 --- a/testing/web-platform/tests/performance-timeline/navigation-id.tentative.html +++ b/testing/web-platform/tests/performance-timeline/navigation-id-element-timing.tentative.html @@ -7,7 +7,8 @@ + testName: 'element_timing', + }, "Element Timing navigation id test"); + \ No newline at end of file diff --git a/testing/web-platform/tests/performance-timeline/navigation-id.tentative.html b/testing/web-platform/tests/performance-timeline/navigation-id-long-task-task-attribution.tentative.html similarity index 76% copy from testing/web-platform/tests/performance-timeline/navigation-id.tentative.html copy to testing/web-platform/tests/performance-timeline/navigation-id-long-task-task-attribution.tentative.html index 08dbd4b01b13..662e17508b26 100644 --- a/testing/web-platform/tests/performance-timeline/navigation-id.tentative.html +++ b/testing/web-platform/tests/performance-timeline/navigation-id-long-task-task-attribution.tentative.html @@ -7,7 +7,8 @@ + testName: 'long_task_task_attribution', + }, "Long Task/Task Attribution navigation id test"); + \ No newline at end of file diff --git a/testing/web-platform/tests/performance-timeline/navigation-id.tentative.html b/testing/web-platform/tests/performance-timeline/navigation-id-mark-measure.tentative.html similarity index 80% copy from testing/web-platform/tests/performance-timeline/navigation-id.tentative.html copy to testing/web-platform/tests/performance-timeline/navigation-id-mark-measure.tentative.html index 08dbd4b01b13..42795f94a98c 100644 --- a/testing/web-platform/tests/performance-timeline/navigation-id.tentative.html +++ b/testing/web-platform/tests/performance-timeline/navigation-id-mark-measure.tentative.html @@ -7,7 +7,8 @@ + testName: 'mark_measure', + }, "Mark/Measure navigation id test"); + \ No newline at end of file diff --git a/testing/web-platform/tests/performance-timeline/navigation-id.tentative.html b/testing/web-platform/tests/performance-timeline/navigation-id-resource-timing.tentative.html similarity index 79% rename from testing/web-platform/tests/performance-timeline/navigation-id.tentative.html rename to testing/web-platform/tests/performance-timeline/navigation-id-resource-timing.tentative.html index 08dbd4b01b13..1ec906ebbbba 100644 --- a/testing/web-platform/tests/performance-timeline/navigation-id.tentative.html +++ b/testing/web-platform/tests/performance-timeline/navigation-id-resource-timing.tentative.html @@ -7,7 +7,8 @@ + testName: 'resource_timing', + }, "Resource Timing navigation id test"); + \ No newline at end of file diff --git a/testing/web-platform/tests/performance-timeline/navigation-id.helper.js b/testing/web-platform/tests/performance-timeline/navigation-id.helper.js dissimilarity index 61% index fd6e24d5c584..53099cadb254 100644 --- a/testing/web-platform/tests/performance-timeline/navigation-id.helper.js +++ b/testing/web-platform/tests/performance-timeline/navigation-id.helper.js @@ -1,82 +1,130 @@ -// The test functions called in the navigation-counter test. They rely on -// artifacts defined in -// '/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js' -// which should be included before this file to use these functions. - -function runNavigationIdTest(params, description) { - const defaultParams = { - constants: { - performanceMarkName: 'mark_navigation_id', - performanceMeasureName: 'measure_navigation_id', - }, - // This function is to make and obtain the navigation counter value for a - // performance entries of mark and measure type. It is to be extended for - // other types of performance entry in future. - funcBeforeNavigation: (constants) => { - window.performance.mark(constants.performanceMarkName); - return window.performance - .getEntriesByName(constants.performanceMarkName)[0] - .navigationId; - }, - funcAfterBFCacheLoad: (expectedNavigationId, constants) => { - window.performance.mark( - constants.performanceMarkName + expectedNavigationId); - window.performance.measure( - constants.performanceMeasureName + expectedNavigationId, - constants.performanceMarkName, - constants.performanceMarkName + expectedNavigationId); - return [ - window.performance - .getEntriesByName( - constants.performanceMarkName + expectedNavigationId)[0] - .navigationId, - window.performance - .getEntriesByName( - constants.performanceMeasureName + expectedNavigationId)[0] - .navigationId - ]; - }, - }; - params = { ...defaultParams, ...params }; - runBfcacheWithMultipleNavigationTest(params, description); -} - -function runBfcacheWithMultipleNavigationTest(params, description) { - const defaultParams = { - openFunc: url => window.open(url, '_blank', 'noopener'), - scripts: [], - funcBeforeNavigation: () => { }, - targetOrigin: originCrossSite, - navigationTimes: 1, - funcAfterAssertion: () => { }, - } // Apply defaults. - params = { ...defaultParams, ...params }; - - promise_test(async t => { - const pageA = new RemoteContext(token()); - const pageB = new RemoteContext(token()); - - const urlA = executorPath + pageA.context_id; - const urlB = params.targetOrigin + executorPath + pageB.context_id; - - params.openFunc(urlA); - - await pageA.execute_script(waitForPageShow); - - // Assert navigation id is 1 when the document is loaded first time. - let navigationId = await pageA.execute_script( - params.funcBeforeNavigation, [params.constants]) - assert_implements_optional( - navigationId === 1, 'Navigation Id should be 0.'); - - for (i = 1; i <= params.navigationTimes; i++) { - await navigateAndThenBack(pageA, pageB, urlB); - - let navigationIds = await pageA.execute_script( - params.funcAfterBFCacheLoad, [i + 1, params.constants]); - assert_implements_optional( - navigationIds.every(t => t === (i + 1)), - 'Navigation Id should all be ' + (i + 1) + '.'); - } - }, description); -} +// The test functions called in the navigation-counter test. They rely on +// artifacts defined in +// '/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js' +// which should be included before this file to use these functions. + +// This function is to obtain navigation ids of all performance entries to +// verify. +let testInitial = () => { + return window.performance.getEntries().map(e => e.navigationId); +} + +let testMarkMeasure = (expectedNavigationId, markName, MeasureName) => { + const markName1 = 'test-mark'; + const markName2 = 'test-mark' + expectedNavigationId; + const measureName = 'test-measure' + expectedNavigationId; + + window.performance.mark(markName1); + window.performance.mark(markName2); + window.performance.measure(measureName, markName1, markName2); + return window.performance.getEntriesByName(markName2).concat( + window.performance.getEntriesByName(measureName)).map(e => e.navigationId); +} + +let testResourceTiming = async (expectedNavigationId) => { + let navigationId = -1; + + let p = new Promise(resolve => { + new PerformanceObserver((list) => { + const entry = list.getEntries().find(e => e.name.includes('json_resource') && e.navigationId == expectedNavigationId); + if (entry) { + navigationId = entry.navigationId; + resolve(); + } + }).observe({ type: 'resource' }); + }); + + const resp = await fetch('/performance-timeline/resources/json_resource.json'); + await p; + return [navigationId]; +} + +let testElementTiming = async (expectedNavigationId) => { + let navigationId = -1; + let p = new Promise(resolve => { + new PerformanceObserver((list) => { + const entry = list.getEntries().find(e => e.entryType === 'element' && e.identifier === 'test-element-timing' + expectedNavigationId); + if (entry) { + navigationId = entry.navigationId; + resolve(); + } + }).observe({ type: 'element' }); + }); + + let el = document.createElement('p'); + el.setAttribute('elementtiming', 'test-element-timing' + expectedNavigationId); + el.textContent = 'test element timing text'; + document.body.appendChild(el); + await p; + return [navigationId]; +} + +let testLongTask = async () => { + let navigationIds = []; + + let p = new Promise(resolve => { + new PerformanceObserver((list) => { + const entry = list.getEntries().find(e => e.entryType === 'longtask') + if (entry) { + navigationIds.push(entry.navigationId); + navigationIds = navigationIds.concat( + entry.attribution.map(a => a.navigationId)); + resolve(); + } + }).observe({ type: 'longtask' }); + }); + + const script = document.createElement('script'); + script.src = '/performance-timeline/resources/make_long_task.js'; + document.body.appendChild(script); + await p; + document.body.removeChild(script); + return navigationIds; +} + +const testFunctionMap = { + 'mark_measure': testMarkMeasure, + 'resource_timing': testResourceTiming, + 'element_timing': testElementTiming, + 'long_task_task_attribution': testLongTask, +}; + +function runNavigationIdTest(params, description) { + const defaultParams = { + openFunc: url => window.open(url, '_blank', 'noopener'), + scripts: [], + funcBeforeNavigation: () => { }, + targetOrigin: originCrossSite, + navigationTimes: 4, + funcAfterAssertion: () => { }, + } // Apply defaults. + params = { ...defaultParams, ...params }; + + promise_test(async t => { + const pageA = new RemoteContext(token()); + const pageB = new RemoteContext(token()); + + const urlA = executorPath + pageA.context_id; + const urlB = params.targetOrigin + executorPath + pageB.context_id; + // Open url A. + params.openFunc(urlA); + await pageA.execute_script(waitForPageShow); + + // Assert navigation id is 1 when the document is loaded first time. + let navigationIds = await pageA.execute_script(testInitial); + assert_true( + navigationIds.every(t => t === 1), 'All Navigation Ids should be 1.'); + + for (i = 1; i <= params.navigationTimes; i++) { + // Navigate away to url B and back. + await navigateAndThenBack(pageA, pageB, urlB); + + // Assert navigation id increments when the document is load from bfcache. + navigationIds = await pageA.execute_script( + testFunctionMap[params.testName], [i + 1]); + assert_true( + navigationIds.every(t => t === (i + 1)), + params.testName + ' Navigation Id should all be ' + (i + 1) + '.'); + } + }, description); +} diff --git a/testing/web-platform/tests/performance-timeline/resources/json_resource.json b/testing/web-platform/tests/performance-timeline/resources/json_resource.json new file mode 100644 index 000000000000..68b6ac1d56f7 --- /dev/null +++ b/testing/web-platform/tests/performance-timeline/resources/json_resource.json @@ -0,0 +1,4 @@ +{ + "name": "nav_id_test", + "target": "resource_timing" +} \ No newline at end of file diff --git a/testing/web-platform/tests/performance-timeline/resources/make_long_task.js b/testing/web-platform/tests/performance-timeline/resources/make_long_task.js new file mode 100644 index 000000000000..a52d6d839298 --- /dev/null +++ b/testing/web-platform/tests/performance-timeline/resources/make_long_task.js @@ -0,0 +1,4 @@ +(function () { + let now = window.performance.now(); + while (window.performance.now() < now + 60); +}()); \ No newline at end of file diff --git a/testing/web-platform/tests/performance-timeline/resources/navigation-id-detached-frame-page.html b/testing/web-platform/tests/performance-timeline/resources/navigation-id-detached-frame-page.html new file mode 100644 index 000000000000..02aafbb5c783 --- /dev/null +++ b/testing/web-platform/tests/performance-timeline/resources/navigation-id-detached-frame-page.html @@ -0,0 +1,21 @@ + + + + + + The navigation_id Detached iframe Page. + + + + + + + \ No newline at end of file -- 2.11.4.GIT