diff --git a/blink/renderer/core/frame/local_frame.cc b/blink/renderer/core/frame/local_frame.cc index 88d0d5a62da..5a0c482e866 100644 --- a/blink/renderer/core/frame/local_frame.cc +++ b/blink/renderer/core/frame/local_frame.cc @@ -594,6 +594,8 @@ bool LocalFrame::DetachImpl(FrameDetachType type) { if (text_fragment_handler_) text_fragment_handler_->DidDetachDocumentOrFrame(); + not_restored_reasons_.reset(); + DCHECK(!view_->IsAttached()); Client()->WillBeDetached(); @@ -3314,4 +3316,40 @@ void LocalFrame::MaybeUpdateWindowControlsOverlayWithNewZoomLevel() { } #endif // !BUILDFLAG(IS_ANDROID) +void LocalFrame::SetNotRestoredReasons( + mojom::blink::BackForwardCacheNotRestoredReasonsPtr not_restored_reasons) { + // Back/forward cache is only enabled for outermost main frame. + DCHECK(IsOutermostMainFrame()); + not_restored_reasons_ = mojo::Clone(not_restored_reasons); +} + +const mojom::blink::BackForwardCacheNotRestoredReasonsPtr& +LocalFrame::GetNotRestoredReasons() { + // Back/forward cache is only enabled for the outermost main frames, and the + // web exposed API returns non-null values only for the outermost main frames. + DCHECK(IsOutermostMainFrame()); + return not_restored_reasons_; +} + +bool LocalFrame::HasBlockingReasons() { + DCHECK(IsOutermostMainFrame()); + if (!not_restored_reasons_) + return false; + return HasBlockingReasonsHelper(not_restored_reasons_); +} + +bool LocalFrame::HasBlockingReasonsHelper( + const mojom::blink::BackForwardCacheNotRestoredReasonsPtr& not_restored) { + if (not_restored->blocked) + return true; + if (not_restored->same_origin_details) { + for (const auto& child : not_restored->same_origin_details->children) { + if (HasBlockingReasonsHelper(child)) + return true; + } + return false; + } + return false; +} + } // namespace blink diff --git a/blink/renderer/core/frame/local_frame.h b/blink/renderer/core/frame/local_frame.h index 078f42051b5..baac5c90c88 100644 --- a/blink/renderer/core/frame/local_frame.h +++ b/blink/renderer/core/frame/local_frame.h @@ -43,6 +43,7 @@ #include "third_party/blink/public/common/frame/frame_ad_evidence.h" #include "third_party/blink/public/common/frame/transient_allow_fullscreen.h" #include "third_party/blink/public/common/tokens/tokens.h" +#include "third_party/blink/public/mojom/back_forward_cache_not_restored_reasons.mojom-blink.h" #include "third_party/blink/public/mojom/blob/blob_url_store.mojom-blink-forward.h" #include "third_party/blink/public/mojom/devtools/devtools_agent.mojom-blink-forward.h" #include "third_party/blink/public/mojom/devtools/inspector_issue.mojom-blink-forward.h" @@ -604,6 +605,15 @@ class CORE_EXPORT LocalFrame final mojom::blink::BackForwardCacheControllerHost& GetBackForwardCacheControllerHostRemote(); + // Sets back/forward cache NotRestoredReasons for this frame. Only set for + // outermost main frame. + void SetNotRestoredReasons( + mojom::blink::BackForwardCacheNotRestoredReasonsPtr); + const mojom::blink::BackForwardCacheNotRestoredReasonsPtr& + GetNotRestoredReasons(); + // Returns if the saved NotRestoredReasons has any blocking reasons. + bool HasBlockingReasons(); + const AtomicString& GetReducedAcceptLanguage() const { return reduced_accept_language_; } @@ -871,6 +881,10 @@ class CORE_EXPORT LocalFrame final String& clip_html, gfx::Rect& clip_rect); + // Helper function for |HasBlockingReasons()|. + bool HasBlockingReasonsHelper( + const mojom::blink::BackForwardCacheNotRestoredReasonsPtr&); + #if !BUILDFLAG(IS_ANDROID) void SetTitlebarAreaDocumentStyleEnvironmentVariables() const; void MaybeUpdateWindowControlsOverlayWithNewZoomLevel(); @@ -943,6 +957,9 @@ class CORE_EXPORT LocalFrame final mojom::blink::ViewportIntersectionState intersection_state_; + // Only set for outermost main frame. + mojom::blink::BackForwardCacheNotRestoredReasonsPtr not_restored_reasons_; + // Per-frame URLLoader factory. std::unique_ptr url_loader_factory_; diff --git a/blink/renderer/core/frame/web_local_frame_impl.cc b/blink/renderer/core/frame/web_local_frame_impl.cc index 8a7eb9945f0..682a6bb23e3 100644 --- a/blink/renderer/core/frame/web_local_frame_impl.cc +++ b/blink/renderer/core/frame/web_local_frame_impl.cc @@ -3041,30 +3041,43 @@ void WebLocalFrameImpl::SetSessionStorageArea( void WebLocalFrameImpl::SetNotRestoredReasons( const mojom::BackForwardCacheNotRestoredReasonsPtr& not_restored_reasons) { - not_restored_reasons_ = - not_restored_reasons.is_null() - ? mojom::BackForwardCacheNotRestoredReasonsPtr(nullptr) - : not_restored_reasons->Clone(); + GetFrame()->SetNotRestoredReasons( + ConvertNotRestoredReasons(not_restored_reasons)); } bool WebLocalFrameImpl::HasBlockingReasons() { - if (!not_restored_reasons_) - return false; - return HasBlockingReasonsHelper(not_restored_reasons_); -} - -bool WebLocalFrameImpl::HasBlockingReasonsHelper( - const mojom::BackForwardCacheNotRestoredReasonsPtr& not_restored) { - if (not_restored->blocked) - return true; - if (not_restored->same_origin_details) { - for (const auto& child : not_restored->same_origin_details->children) { - if (HasBlockingReasonsHelper(child)) - return true; + return GetFrame()->HasBlockingReasons(); +} + +const mojom::blink::BackForwardCacheNotRestoredReasonsPtr& +WebLocalFrameImpl::GetNotRestoredReasons() { + return GetFrame()->GetNotRestoredReasons(); +} + +mojom::blink::BackForwardCacheNotRestoredReasonsPtr +WebLocalFrameImpl::ConvertNotRestoredReasons( + const mojom::BackForwardCacheNotRestoredReasonsPtr& reasons_to_copy) { + mojom::blink::BackForwardCacheNotRestoredReasonsPtr not_restored_reasons; + if (!reasons_to_copy.is_null()) { + not_restored_reasons = + mojom::blink::BackForwardCacheNotRestoredReasons::New(); + not_restored_reasons->blocked = reasons_to_copy->blocked; + auto details = mojom::blink::SameOriginBfcacheNotRestoredDetails::New(); + if (reasons_to_copy->same_origin_details) { + details->id = reasons_to_copy->same_origin_details->id.c_str(); + details->name = reasons_to_copy->same_origin_details->name.c_str(); + details->src = reasons_to_copy->same_origin_details->src.c_str(); + details->url = reasons_to_copy->same_origin_details->url.c_str(); + for (const auto& reason : reasons_to_copy->same_origin_details->reasons) { + details->reasons.push_back(reason.c_str()); + } + for (const auto& child : reasons_to_copy->same_origin_details->children) { + details->children.push_back(ConvertNotRestoredReasons(child)); + } } - return false; + not_restored_reasons->same_origin_details = std::move(details); } - return not_restored->blocked; + return not_restored_reasons; } void WebLocalFrameImpl::AddHitTestOnTouchStartCallback( diff --git a/blink/renderer/core/frame/web_local_frame_impl.h b/blink/renderer/core/frame/web_local_frame_impl.h index 8480cf8bfde..ecdea72246e 100644 --- a/blink/renderer/core/frame/web_local_frame_impl.h +++ b/blink/renderer/core/frame/web_local_frame_impl.h @@ -386,6 +386,9 @@ class CORE_EXPORT WebLocalFrameImpl final // Returns if the current frame's NotRestoredReasons has any blocking reasons. bool HasBlockingReasons() override; + const mojom::blink::BackForwardCacheNotRestoredReasonsPtr& + GetNotRestoredReasons(); + void InitializeCoreFrame( Page&, FrameOwner*, @@ -555,10 +558,6 @@ class CORE_EXPORT WebLocalFrameImpl final // Sets the local core frame and registers destruction observers. void SetCoreFrame(LocalFrame*); - // Helper function for |HasBlockingReasons()|. - bool HasBlockingReasonsHelper( - const mojom::BackForwardCacheNotRestoredReasonsPtr&); - // Inherited from WebFrame, but intentionally hidden: it never makes sense // to call these on a WebLocalFrameImpl. bool IsWebLocalFrame() const override; @@ -611,6 +610,11 @@ class CORE_EXPORT WebLocalFrameImpl final network::mojom::blink::WebSandboxFlags sandbox_flags = network::mojom::blink::WebSandboxFlags::kNone); + // This function converts mojom::BackForwardCacheNotRestoredReasonsPtr to + // mojom::blink::BackForwardCacheNotRestoredReasonsPtr. + mojom::blink::BackForwardCacheNotRestoredReasonsPtr ConvertNotRestoredReasons( + const mojom::BackForwardCacheNotRestoredReasonsPtr& reasons_struct); + WebLocalFrameClient* client_; // TODO(dcheng): Inline this field directly rather than going through Member. diff --git a/blink/renderer/core/timing/performance_navigation_timing.cc b/blink/renderer/core/timing/performance_navigation_timing.cc index e1b2567d46a..3aa591a2349 100644 --- a/blink/renderer/core/timing/performance_navigation_timing.cc +++ b/blink/renderer/core/timing/performance_navigation_timing.cc @@ -9,6 +9,7 @@ #include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document_timing.h" #include "third_party/blink/renderer/core/frame/local_dom_window.h" +#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/loader/document_load_timing.h" #include "third_party/blink/renderer/core/loader/document_loader.h" #include "third_party/blink/renderer/core/performance_entry_names.h" @@ -310,6 +311,54 @@ DOMHighResTimeStamp PerformanceNavigationTiming::duration() const { return loadEventEnd(); } +ScriptValue PerformanceNavigationTiming::notRestoredReasons( + ScriptState* script_state) const { + DocumentLoader* loader = GetDocumentLoader(); + if (!loader || !loader->GetFrame()->IsOutermostMainFrame()) + return ScriptValue::CreateNull(script_state->GetIsolate()); + + // TODO(crbug.com/1370954): Save NotRestoredReasons in Document instead of + // Frame. + return NotRestoredReasonsBuilder(script_state, + loader->GetFrame()->GetNotRestoredReasons()); +} + +ScriptValue PerformanceNavigationTiming::NotRestoredReasonsBuilder( + ScriptState* script_state, + const mojom::blink::BackForwardCacheNotRestoredReasonsPtr& reasons) const { + if (!reasons) + return ScriptValue::CreateNull(script_state->GetIsolate()); + V8ObjectBuilder builder(script_state); + builder.AddBoolean("blocked", reasons->blocked); + builder.AddString("url", AtomicString(reasons->same_origin_details + ? reasons->same_origin_details->url + : "")); + builder.AddString("src", AtomicString(reasons->same_origin_details + ? reasons->same_origin_details->src + : "")); + builder.AddString("id", AtomicString(reasons->same_origin_details + ? reasons->same_origin_details->id + : "")); + builder.AddString("name", + AtomicString(reasons->same_origin_details + ? reasons->same_origin_details->name + : "")); + Vector reason_strings; + Vector> children_result; + if (reasons->same_origin_details) { + for (const auto& reason : reasons->same_origin_details->reasons) { + reason_strings.push_back(reason); + } + for (const auto& child : reasons->same_origin_details->children) { + children_result.push_back( + NotRestoredReasonsBuilder(script_state, child).V8Value()); + } + } + builder.Add("reasons", reason_strings); + builder.Add("children", children_result); + return builder.GetScriptValue(); +} + void PerformanceNavigationTiming::BuildJSONValue( V8ObjectBuilder& builder) const { PerformanceResourceTiming::BuildJSONValue(builder); @@ -330,5 +379,11 @@ void PerformanceNavigationTiming::BuildJSONValue( "activationStart", PerformanceNavigationTimingActivationStart::activationStart(*this)); } + + if (RuntimeEnabledFeatures::BackForwardCacheNotRestoredReasonsEnabled( + ExecutionContext::From(builder.GetScriptState()))) { + builder.Add("notRestoredReasons", + notRestoredReasons(builder.GetScriptState())); + } } } // namespace blink diff --git a/blink/renderer/core/timing/performance_navigation_timing.h b/blink/renderer/core/timing/performance_navigation_timing.h index 8d6418bade7..47d2fa18570 100644 --- a/blink/renderer/core/timing/performance_navigation_timing.h +++ b/blink/renderer/core/timing/performance_navigation_timing.h @@ -5,6 +5,7 @@ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_TIMING_PERFORMANCE_NAVIGATION_TIMING_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_TIMING_PERFORMANCE_NAVIGATION_TIMING_H_ +#include "third_party/blink/public/mojom/back_forward_cache_not_restored_reasons.mojom-blink.h" #include "third_party/blink/public/web/web_navigation_type.h" #include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/dom/dom_high_res_time_stamp.h" @@ -55,6 +56,7 @@ class CORE_EXPORT PerformanceNavigationTiming final DOMHighResTimeStamp loadEventEnd() const; AtomicString type() const; uint16_t redirectCount() const; + ScriptValue notRestoredReasons(ScriptState* script_state) const; // PerformanceResourceTiming overrides: DOMHighResTimeStamp fetchStart() const override; @@ -88,6 +90,10 @@ class CORE_EXPORT PerformanceNavigationTiming final AtomicString AlpnNegotiatedProtocol() const override; AtomicString ConnectionInfo() const override; + ScriptValue NotRestoredReasonsBuilder( + ScriptState* script_state, + const mojom::blink::BackForwardCacheNotRestoredReasonsPtr& reasons) const; + scoped_refptr resource_timing_info_; }; } // namespace blink diff --git a/blink/renderer/core/timing/performance_navigation_timing.idl b/blink/renderer/core/timing/performance_navigation_timing.idl index e5360f4d6eb..52f7146c787 100644 --- a/blink/renderer/core/timing/performance_navigation_timing.idl +++ b/blink/renderer/core/timing/performance_navigation_timing.idl @@ -23,5 +23,6 @@ enum NavigationType { readonly attribute DOMHighResTimeStamp loadEventEnd; readonly attribute NavigationType type; readonly attribute unsigned short redirectCount; + [RuntimeEnabled=BackForwardCacheNotRestoredReasons, CallWith=ScriptState] readonly attribute object notRestoredReasons; [CallWith=ScriptState, ImplementedAs=toJSONForBinding] object toJSON(); }; diff --git a/blink/web_tests/NeverFixTests b/blink/web_tests/NeverFixTests index d1506b10b08..55cd7766036 100644 --- a/blink/web_tests/NeverFixTests +++ b/blink/web_tests/NeverFixTests @@ -1954,3 +1954,7 @@ crbug.com/1293679 virtual/pending-beacon/external/wpt/pending_beacon/* [ Pass ] # Experimental JS shared memory features crbug.com/1351118 wpt_internal/js/shared_memory/* [ Skip ] crbug.com/1351118 virtual/js-shared-memory/wpt_internal/js/shared_memory/* [ Pass ] + +# Feature is not yet launched, so skip the base. +crbug.com/1326344 external/wpt/performance-timeline/not-restored-reasons/* [ Skip ] +crbug.com/1326344 virtual/not-restored-reasons/external/wpt/performance-timeline/not-restored-reasons/* [ Pass ] diff --git a/blink/web_tests/VirtualTestSuites b/blink/web_tests/VirtualTestSuites index 0cc2f4f18ee..e7f56c42c72 100644 --- a/blink/web_tests/VirtualTestSuites +++ b/blink/web_tests/VirtualTestSuites @@ -1312,5 +1312,11 @@ "platforms": ["Linux", "Mac", "Win"], "bases": ["external/wpt/custom-elements/scoped-registry"], "args": ["--disable-blink-features=ScopedCustomElementRegistry"] + }, + { + "prefix": "not-restored-reasons", + "platforms": ["Linux", "Mac", "Win"], + "bases": ["external/wpt/performance-timeline/not-restored-reasons/"], + "args": ["--enable-features=BackForwardCacheSendNotRestoredReasons"] } ] diff --git a/blink/web_tests/external/wpt/html/browsers/browsing-the-web/remote-context-helper-tests/resources/test-helper.js b/blink/web_tests/external/wpt/html/browsers/browsing-the-web/remote-context-helper-tests/resources/test-helper.js index 95d516e2752..5f8e07711cb 100644 --- a/blink/web_tests/external/wpt/html/browsers/browsing-the-web/remote-context-helper-tests/resources/test-helper.js +++ b/blink/web_tests/external/wpt/html/browsers/browsing-the-web/remote-context-helper-tests/resources/test-helper.js @@ -46,3 +46,40 @@ async function assertHeaderIsAsExpected( return res.headers.get(headerName); }, [headerName]), 'header is set'); } + +async function assertNotRestoredReasonsEquals( + remoteContextHelper, blocked, url, src, id, name, reasons, children) { + let result = await remoteContextHelper.executeScript(() => { + return performance.getEntriesByType('navigation')[0].notRestoredReasons; + }); + assertReasonsStructEquals(result, blocked, url, src, id, name, reasons, children); +} + +function assertReasonsStructEquals(result, blocked, url, src, id, name, reasons, children) { + assert_equals(result.blocked, blocked); + assert_equals(result.url, url); + assert_equals(result.src, src); + assert_equals(result.id, id); + assert_equals(result.name, name); + // Reasons should match. + assert_equals(result.reasons.length, reasons.length); + reasons.sort(); + result.reasons.sort(); + for (let i=0; i { + const rcHelper = new RemoteContextHelper(); + + // Open a window with noopener so that BFCache will work. + const rc1 = await rcHelper.addWindow( + /*config=*/ null, /*options=*/ {features: 'noopener'}); + + // Navigate away. + const rc2 = await rc1.navigateToNew(); + + // Navigate back. + await rc2.historyBack(); + + // Verify that no reasons are recorded for successful restore. + assert_true(await rc1.executeScript(() => { + let reasons = performance.getEntriesByType('navigation')[0].notRestoredReasons; + return reasons == null; + })); +}); \ No newline at end of file diff --git a/blink/web_tests/external/wpt/performance-timeline/not-restored-reasons/performance-navigation-timing-cross-origin-bfcache.window.js b/blink/web_tests/external/wpt/performance-timeline/not-restored-reasons/performance-navigation-timing-cross-origin-bfcache.window.js new file mode 100644 index 00000000000..f906b4b0735 --- /dev/null +++ b/blink/web_tests/external/wpt/performance-timeline/not-restored-reasons/performance-navigation-timing-cross-origin-bfcache.window.js @@ -0,0 +1,70 @@ +// META: title=RemoteContextHelper navigation using BFCache +// META: script=/common/dispatcher/dispatcher.js +// META: script=/common/get-host-info.sub.js +// META: script=/common/utils.js +// META: script=/resources/testharness.js +// META: script=/resources/testharnessreport.js +// META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js +// META: script=/html/browsers/browsing-the-web/remote-context-helper-tests/resources/test-helper.js +// META: script=/websockets/constants.sub.js + +'use strict'; + +// Ensure that cross-origin subtree's reasons are not exposed to notRestoredReasons. +promise_test(async t => { + const rcHelper = new RemoteContextHelper(); + // Open a window with noopener so that BFCache will work. + const rc1 = await rcHelper.addWindow( + /*config=*/ null, /*options=*/ {features: 'noopener'}); + const rc1_url = await rc1.executeScript(() => { + return location.href; + }); + // Add a cross-origin iframe and use BroadcastChannel. + const rc1_child = await rc1.addIframe( + /*extraConfig=*/ { + origin: 'HTTP_REMOTE_ORIGIN', + scripts: [], + headers: [], + }, + /*attributes=*/ {id: 'test-id'}, + ); + + const domainPort = SCHEME_DOMAIN_PORT; + await rc1_child.executeScript((domain) => { + var ws = new WebSocket(domain + '/echo'); + }, [domainPort]); + + const rc1_child_url = await rc1_child.executeScript(() => { + return location.href; + }); + // Add a child to the iframe. + const rc1_grand_child = await rc1_child.addIframe(); + const rc1_grand_child_url = await rc1_grand_child.executeScript(() => { + return location.href; + }); + + // Navigate away. + const rc2 = await rc1.navigateToNew(); + + // Navigate back. + await rc2.historyBack(); + + // Check the reported reasons. + await assertNotRestoredReasonsEquals( + rc1, + /*blocked=*/false, + /*url=*/rc1_url, + /*src=*/ "", + /*id=*/"", + /*name=*/"", + /*reasons=*/[], + /*children=*/[{ + "blocked": true, + "url": "", + "src": "", + "id": "", + "name": "", + "reasons": [], + "children": [] + }]); +}); \ No newline at end of file diff --git a/blink/web_tests/external/wpt/performance-timeline/not-restored-reasons/performance-navigation-timing-not-bfcached.window.js b/blink/web_tests/external/wpt/performance-timeline/not-restored-reasons/performance-navigation-timing-not-bfcached.window.js new file mode 100644 index 00000000000..ac8af0e88c8 --- /dev/null +++ b/blink/web_tests/external/wpt/performance-timeline/not-restored-reasons/performance-navigation-timing-not-bfcached.window.js @@ -0,0 +1,44 @@ +// META: title=RemoteContextHelper navigation using BFCache +// META: script=/common/dispatcher/dispatcher.js +// META: script=/common/get-host-info.sub.js +// META: script=/common/utils.js +// META: script=/resources/testharness.js +// META: script=/resources/testharnessreport.js +// META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js +// META: script=/html/browsers/browsing-the-web/remote-context-helper-tests/resources/test-helper.js +// META: script=/websockets/constants.sub.js + +'use strict'; + +// Ensure that notRestoredReasons is populated when not restored. +promise_test(async t => { + const rcHelper = new RemoteContextHelper(); + // Open a window with noopener so that BFCache will work. + const rc1 = await rcHelper.addWindow( + /*config=*/ null, /*options=*/ {features: 'noopener'}); + + const domainPort = SCHEME_DOMAIN_PORT; + await rc1.executeScript((domain) => { + var ws = new WebSocket(domain + '/echo'); + }, [domainPort]); + + const rc1_url = await rc1.executeScript(() => { + return location.href; + }); + + // Navigate away. + const rc2 = await rc1.navigateToNew(); + + // Navigate back. + await rc2.historyBack(); + // Check the reported reasons. + await assertNotRestoredReasonsEquals( + rc1, + /*blocked=*/true, + /*url=*/rc1_url, + /*src=*/ "", + /*id=*/"", + /*name=*/"", + /*reasons=*/["WebSocket"], + /*children=*/[]); +}); \ No newline at end of file diff --git a/blink/web_tests/external/wpt/performance-timeline/not-restored-reasons/performance-navigation-timing-same-origin-bfcache.window.js b/blink/web_tests/external/wpt/performance-timeline/not-restored-reasons/performance-navigation-timing-same-origin-bfcache.window.js new file mode 100644 index 00000000000..fb5ec50400e --- /dev/null +++ b/blink/web_tests/external/wpt/performance-timeline/not-restored-reasons/performance-navigation-timing-same-origin-bfcache.window.js @@ -0,0 +1,73 @@ +// META: title=RemoteContextHelper navigation using BFCache +// META: script=/common/dispatcher/dispatcher.js +// META: script=/common/get-host-info.sub.js +// META: script=/common/utils.js +// META: script=/resources/testharness.js +// META: script=/resources/testharnessreport.js +// META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js +// META: script=/html/browsers/browsing-the-web/remote-context-helper-tests/resources/test-helper.js +// META: script=/websockets/constants.sub.js + +'use strict'; + +// Ensure that same-origin subtree's reasons are exposed to notRestoredReasons. +promise_test(async t => { + const rcHelper = new RemoteContextHelper(); + // Open a window with noopener so that BFCache will work. + const rc1 = await rcHelper.addWindow( + /*config=*/ null, /*options=*/ {features: 'noopener'}); + const rc1_url = await rc1.executeScript(() => { + return location.href; + }); + // Add a same-origin iframe and use WebSocket. + const rc1_child = await rc1.addIframe(/*extra_config=*/{}, /*attributes=*/ {id: 'test-id'}); + + const domainPort = SCHEME_DOMAIN_PORT; + await rc1_child.executeScript((domain) => { + var ws = new WebSocket(domain + '/echo'); + }, [domainPort]); + + const rc1_child_url = await rc1_child.executeScript(() => { + return location.href; + }); + // Add a child to the iframe. + const rc1_grand_child = await rc1_child.addIframe(); + const rc1_grand_child_url = await rc1_grand_child.executeScript(() => { + return location.href; + }); + + // Navigate away. + const rc2 = await rc1.navigateToNew(); + + // Navigate back. + await rc2.historyBack(); + + // Check the reported reasons. + await assertNotRestoredReasonsEquals( + rc1, + /*blocked=*/false, + /*url=*/rc1_url, + /*src=*/ "", + /*id=*/"", + /*name=*/"", + /*reasons=*/[], + /*children=*/[{ + "blocked": true, + "url": rc1_child_url, + "src": rc1_child_url, + "id": "test-id", + "name": "", + "reasons": ["WebSocket"], + "children": [ + { + "blocked": false, + "url": rc1_grand_child_url, + "src": rc1_grand_child_url, + "id": "", + "name": "", + "reasons": [], + "children": [] + } + ] + }]); +}); \ No newline at end of file diff --git a/blink/web_tests/http/tests/misc/performance-entry-serializer-expected.txt b/blink/web_tests/http/tests/misc/performance-entry-serializer-expected.txt index 788c31ad6bc..5cf088d9cfb 100644 --- a/blink/web_tests/http/tests/misc/performance-entry-serializer-expected.txt +++ b/blink/web_tests/http/tests/misc/performance-entry-serializer-expected.txt @@ -1,4 +1,4 @@ This is a testharness.js-based test. -FAIL PerformanceEntry subclasses should serialize all attributes assert_equals: PerformanceMark.detail expected (object) null but got (undefined) undefined +FAIL PerformanceEntry subclasses should serialize all attributes assert_equals: PerformanceNavigationTiming.notRestoredReasons expected (undefined) undefined but got (object) null Harness: the test ran to completion. diff --git a/blink/web_tests/virtual/not-restored-reasons/README.md b/blink/web_tests/virtual/not-restored-reasons/README.md new file mode 100644 index 00000000000..2437ad1acad --- /dev/null +++ b/blink/web_tests/virtual/not-restored-reasons/README.md @@ -0,0 +1,11 @@ +# Virtual Tests for BackForwardCache NotRestoredReasons + +This folder contains virtual test suites to cover NotRestoredReasons feature. + +The suite runs `external/wpt/performance-timeline/not-restored-reasons/` with `--enable-features=BackForwardCacheSendNotRestoredReasons`. + +To manually run the suites, use the following command: + +```bash +third_party/blink/tools/run_web_tests.py -t Default virtual/not-restored-reasons/external/wpt/performance-timeline/not-restored-reasons/ +``` \ No newline at end of file diff --git a/blink/web_tests/virtual/not-restored-reasons/external/wpt/performance-timeline/not-restored-reasons/README.txt b/blink/web_tests/virtual/not-restored-reasons/external/wpt/performance-timeline/not-restored-reasons/README.txt new file mode 100644 index 00000000000..2437ad1acad --- /dev/null +++ b/blink/web_tests/virtual/not-restored-reasons/external/wpt/performance-timeline/not-restored-reasons/README.txt @@ -0,0 +1,11 @@ +# Virtual Tests for BackForwardCache NotRestoredReasons + +This folder contains virtual test suites to cover NotRestoredReasons feature. + +The suite runs `external/wpt/performance-timeline/not-restored-reasons/` with `--enable-features=BackForwardCacheSendNotRestoredReasons`. + +To manually run the suites, use the following command: + +```bash +third_party/blink/tools/run_web_tests.py -t Default virtual/not-restored-reasons/external/wpt/performance-timeline/not-restored-reasons/ +``` \ No newline at end of file diff --git a/blink/web_tests/webexposed/global-interface-listing-expected.txt b/blink/web_tests/webexposed/global-interface-listing-expected.txt index 961723b6d98..0b2a77af309 100644 --- a/blink/web_tests/webexposed/global-interface-listing-expected.txt +++ b/blink/web_tests/webexposed/global-interface-listing-expected.txt @@ -6552,6 +6552,7 @@ interface PerformanceNavigationTiming : PerformanceResourceTiming getter domInteractive getter loadEventEnd getter loadEventStart + getter notRestoredReasons getter redirectCount getter type getter unloadEventEnd