Revert "view-transition: Ensure navigate event is dispatched before pageswap."
This reverts commit 3fb70711e2
.
Reason for revert: Test is failing on linux-bfcache-rel:
https://ci.chromium.org/ui/p/chromium/builders/ci/linux-bfcache-rel/57288/overview
Original change's description:
> view-transition: Ensure navigate event is dispatched before pageswap.
>
> When performing a browser traverse navigation with a ViewTransition,
> ensure that navigate fires before pageswap and capture steps on the
> old Document.
>
> Fixed: 41490961
> Change-Id: Iec422aad59709e2a8168a661e3541871e4871953
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5364073
> Auto-Submit: Khushal Sagar <khushalsagar@chromium.org>
> Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
> Commit-Queue: Khushal Sagar <khushalsagar@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1272324}
Change-Id: I760867d45e43fcfba5f242b645b19a33dfa51bd4
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5370648
Owners-Override: Nate Chapin <japhet@chromium.org>
Auto-Submit: Nate Chapin <japhet@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Nate Chapin <japhet@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1272426}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
c37f9a616e
commit
470985a103
content
browser
renderer_host
public
@ -6,12 +6,10 @@
|
||||
#include "components/viz/host/host_frame_sink_manager.h"
|
||||
#include "content/browser/compositor/surface_utils.h"
|
||||
#include "content/browser/renderer_host/frame_tree_node.h"
|
||||
#include "content/public/test/back_forward_cache_util.h"
|
||||
#include "content/public/test/browser_test.h"
|
||||
#include "content/public/test/browser_test_utils.h"
|
||||
#include "content/public/test/content_browser_test.h"
|
||||
#include "content/shell/browser/shell.h"
|
||||
#include "content/test/content_browser_test_utils_internal.h"
|
||||
#include "mojo/public/cpp/bindings/sync_call_restrictions.h"
|
||||
#include "net/dns/mock_host_resolver.h"
|
||||
#include "net/test/embedded_test_server/default_handlers.h"
|
||||
@ -118,90 +116,4 @@ IN_PROC_BROWSER_TEST_F(ViewTransitionBrowserTest,
|
||||
->HasViewTransitionResourcesForTesting());
|
||||
}
|
||||
|
||||
class ViewTransitionBrowserTestTraverse
|
||||
: public ViewTransitionBrowserTest,
|
||||
public testing::WithParamInterface<bool> {
|
||||
public:
|
||||
bool BFCacheEnabled() const { return GetParam(); }
|
||||
|
||||
bool NavigateBack(GURL back_url) {
|
||||
// We need to trigger the navigation *after* executing the script below so
|
||||
// the event handlers the script relies on are set before they're dispatched
|
||||
// by the navigation.
|
||||
//
|
||||
// We pass this as a callback to EvalJs so the navigation is initiated
|
||||
// before we wait for the script result since it relies on events dispatched
|
||||
// during the navigation.
|
||||
auto trigger_navigation = base::BindOnce(
|
||||
&ViewTransitionBrowserTestTraverse::TriggerBackNavigation,
|
||||
base::Unretained(this), back_url);
|
||||
|
||||
auto result =
|
||||
EvalJs(shell()->web_contents(),
|
||||
JsReplace(
|
||||
R"(
|
||||
(async () => {
|
||||
let navigateFired = false;
|
||||
navigation.onnavigate = (event) => {
|
||||
navigateFired = (event.navigationType === "traverse");
|
||||
};
|
||||
let pageswapfired = new Promise((resolve) => {
|
||||
onpageswap = (e) => {
|
||||
if (!navigateFired || e.viewTransition == null) {
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
activation = e.activation;
|
||||
resolve(activation);
|
||||
};
|
||||
});
|
||||
let result = await pageswapfired;
|
||||
return result != null;
|
||||
})();
|
||||
)"),
|
||||
EXECUTE_SCRIPT_DEFAULT_OPTIONS, ISOLATED_WORLD_ID_GLOBAL,
|
||||
std::move(trigger_navigation));
|
||||
return result.ExtractBool();
|
||||
}
|
||||
|
||||
void TriggerBackNavigation(GURL back_url) {
|
||||
if (BFCacheEnabled()) {
|
||||
TestActivationManager manager(shell()->web_contents(), back_url);
|
||||
shell()->web_contents()->GetController().GoBack();
|
||||
manager.WaitForNavigationFinished();
|
||||
} else {
|
||||
TestNavigationManager manager(shell()->web_contents(), back_url);
|
||||
shell()->web_contents()->GetController().GoBack();
|
||||
ASSERT_TRUE(manager.WaitForNavigationFinished());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
IN_PROC_BROWSER_TEST_P(ViewTransitionBrowserTestTraverse,
|
||||
NavigateEventFiresBeforeCapture) {
|
||||
if (!BFCacheEnabled()) {
|
||||
DisableBackForwardCacheForTesting(
|
||||
shell()->web_contents(),
|
||||
BackForwardCache::DisableForTestingReason::TEST_REQUIRES_NO_CACHING);
|
||||
}
|
||||
|
||||
GURL test_url(
|
||||
embedded_test_server()->GetURL("/view_transitions/basic-vt-opt-in.html"));
|
||||
ASSERT_TRUE(NavigateToURL(shell()->web_contents(), test_url));
|
||||
|
||||
GURL second_url(embedded_test_server()->GetURL(
|
||||
"/view_transitions/basic-vt-opt-in.html?new"));
|
||||
ASSERT_TRUE(NavigateToURL(shell()->web_contents(), second_url));
|
||||
WaitForCopyableViewInWebContents(shell()->web_contents());
|
||||
|
||||
auto& nav_controller = static_cast<NavigationControllerImpl&>(
|
||||
shell()->web_contents()->GetController());
|
||||
ASSERT_TRUE(nav_controller.CanGoBack());
|
||||
ASSERT_TRUE(NavigateBack(test_url));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(P,
|
||||
ViewTransitionBrowserTestTraverse,
|
||||
::testing::Bool());
|
||||
|
||||
} // namespace content
|
||||
|
@ -1667,13 +1667,11 @@ class ExecuteJavaScriptForTestsWaiter : public WebContentsObserver {
|
||||
base::WeakPtrFactory<ExecuteJavaScriptForTestsWaiter> weak_ptr_factory_{this};
|
||||
};
|
||||
|
||||
EvalJsResult EvalJsRunner(
|
||||
const ToRenderFrameHost& execution_target,
|
||||
base::StringPiece script,
|
||||
base::StringPiece source_url,
|
||||
int options,
|
||||
int32_t world_id,
|
||||
base::OnceClosure after_script_invoke = base::DoNothing()) {
|
||||
EvalJsResult EvalJsRunner(const ToRenderFrameHost& execution_target,
|
||||
base::StringPiece script,
|
||||
base::StringPiece source_url,
|
||||
int options,
|
||||
int32_t world_id) {
|
||||
RenderFrameHostImpl* rfh =
|
||||
static_cast<RenderFrameHostImpl*>(execution_target.render_frame_host());
|
||||
if (!rfh->IsRenderFrameLive()) {
|
||||
@ -1692,8 +1690,6 @@ EvalJsResult EvalJsRunner(
|
||||
resolve_promises, world_id,
|
||||
waiter.GetCallback());
|
||||
|
||||
std::move(after_script_invoke).Run();
|
||||
|
||||
bool has_value = waiter.Wait();
|
||||
if (!has_value) {
|
||||
return EvalJsResult(base::Value(),
|
||||
@ -1739,8 +1735,7 @@ EvalJsResult EvalJsRunner(
|
||||
EvalJsResult EvalJs(const ToRenderFrameHost& execution_target,
|
||||
base::StringPiece script,
|
||||
int options,
|
||||
int32_t world_id,
|
||||
base::OnceClosure after_script_invoke) {
|
||||
int32_t world_id) {
|
||||
TRACE_EVENT1("test", "EvalJs", "script", script);
|
||||
|
||||
// The sourceURL= parameter provides a string that replaces <anonymous> in
|
||||
@ -1755,7 +1750,7 @@ EvalJsResult EvalJs(const ToRenderFrameHost& execution_target,
|
||||
base::StrCat({"{", script, "\n}\n//# sourceURL=", kSourceURL});
|
||||
|
||||
return EvalJsRunner(execution_target, modified_script, kSourceURL, options,
|
||||
world_id, std::move(after_script_invoke));
|
||||
world_id);
|
||||
}
|
||||
|
||||
EvalJsResult EvalJsAfterLifecycleUpdate(
|
||||
|
@ -888,17 +888,12 @@ enum EvalJsOptions {
|
||||
// callers of domAutomationController.send() -- EvalJs does not rely on
|
||||
// domAutomationController.
|
||||
// - Lists, dicts, null values, etc. can be returned as base::Values.
|
||||
// - |after_script_invoke| is an optional callback which will be invoked after
|
||||
// script execution has started in the renderer but before the RunLoop is
|
||||
// blocked on the result.
|
||||
//
|
||||
// It is guaranteed that EvalJs works even when the target frame is frozen.
|
||||
[[nodiscard]] EvalJsResult EvalJs(
|
||||
const ToRenderFrameHost& execution_target,
|
||||
base::StringPiece script,
|
||||
int options = EXECUTE_SCRIPT_DEFAULT_OPTIONS,
|
||||
int32_t world_id = ISOLATED_WORLD_ID_GLOBAL,
|
||||
base::OnceClosure after_script_invoke = base::DoNothing());
|
||||
[[nodiscard]] EvalJsResult EvalJs(const ToRenderFrameHost& execution_target,
|
||||
base::StringPiece script,
|
||||
int options = EXECUTE_SCRIPT_DEFAULT_OPTIONS,
|
||||
int32_t world_id = ISOLATED_WORLD_ID_GLOBAL);
|
||||
|
||||
// Like EvalJs(), but runs |raf_script| inside a requestAnimationFrame handler,
|
||||
// and runs |script| after the rendering update has completed. By the time
|
||||
|
Reference in New Issue
Block a user