Skip to content
Permalink
Browse files

[fuchsia] Only publish is_main_document_loaded bit for main frame.

A bug in the navigation listener code published main frame loading
change events for child frame loads.

(cherry picked from commit 3404c29)
TBR=ddorwin@chromium.org

Bug: 1034116, b/144869236
Change-Id: I00bfd20ab89de88d902ca342fe19e4ff6710e414
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1965599
Reviewed-by: David Dorwin <ddorwin@chromium.org>
Reviewed-by: Kevin Marshall <kmarshall@chromium.org>
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#725306}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1989144
Cr-Commit-Position: refs/branch-heads/3987@{#427}
Cr-Branched-From: c4e8da9-refs/heads/master@{#722274}
  • Loading branch information
Kevin Marshall Commit Bot
Kevin Marshall authored and Commit Bot committed Jan 7, 2020
1 parent 8cbb3bf commit 4a2ef92946cd9c587bb28222301f05742fb610b3
@@ -1495,6 +1495,48 @@ IN_PROC_BROWSER_TEST_F(FrameImplTest, RecreateView) {
navigation_listener_.RunUntilUrlAndTitleEquals(page1_url, kPage1Title);
}

IN_PROC_BROWSER_TEST_F(FrameImplTest, ChildFrameNavigationIgnored) {
net::test_server::EmbeddedTestServerHandle test_server_handle;
ASSERT_TRUE(test_server_handle =
embedded_test_server()->StartAndReturnHandle());
GURL page_url(embedded_test_server()->GetURL("/creates_child_frame.html"));

// Navigate to a page and wait for the navigation to complete.
fuchsia::web::FramePtr frame = CreateFrame();
fuchsia::web::NavigationControllerPtr controller;
frame->GetNavigationController(controller.NewRequest());
EXPECT_TRUE(cr_fuchsia::LoadUrlAndExpectResponse(
controller.get(), fuchsia::web::LoadUrlParams(), page_url.spec()));
fuchsia::web::NavigationState expected_state;
expected_state.set_url(page_url.spec());
expected_state.set_title("main frame");
expected_state.set_is_main_document_loaded(true);
navigation_listener_.RunUntilNavigationStateMatches(
std::move(expected_state));

// Notify the page so that it constructs a child iframe.
fuchsia::web::WebMessage message;
message.set_data(cr_fuchsia::MemBufferFromString("test", "test"));
cr_fuchsia::ResultReceiver<fuchsia::web::Frame_PostMessage_Result>
post_result;
frame->PostMessage(
page_url.GetOrigin().spec(), std::move(message),
cr_fuchsia::CallbackToFitFunction(post_result.GetReceiveCallback()));

navigation_listener_.SetBeforeAckHook(
base::BindRepeating([](const fuchsia::web::NavigationState& change,
OnNavigationStateChangedCallback callback) {
// The child iframe's loading status should not affect the
// is_main_document_loaded() bit.
if (change.has_is_main_document_loaded())
ADD_FAILURE();

callback();
}));

navigation_listener_.RunUntilUrlAndTitleEquals(page_url, "iframe loaded");
}

// Tests SetNavigationEventListener() immediately returns a NavigationEvent,
// even in the absence of a new navigation.
IN_PROC_BROWSER_TEST_F(FrameImplTest, ImmediateNavigationEvent) {
@@ -237,8 +237,10 @@ void NavigationControllerImpl::DidFinishLoad(

void NavigationControllerImpl::DidStartNavigation(
content::NavigationHandle* navigation_handle) {
if (navigation_handle->IsSameDocument())
if (!navigation_handle->IsInMainFrame() ||
navigation_handle->IsSameDocument()) {
return;
}

is_main_document_loaded_ = false;
OnNavigationEntryChanged();
@@ -0,0 +1,6 @@
<html>
<head><title>child frame</title</head>
<body>
I am a child.
</body>
</html>
@@ -0,0 +1,17 @@
<html>
<head><title>main frame</title></head>
<body>
<script>
// Create an iFrame in response to a nudge by the test harness (in the form
// of a posted message).
window.addEventListener('message', function(event) {
var iframe = document.createElement('iframe');
iframe.src = "child_frame.html";
iframe.onload = function() {
document.title = 'iframe loaded';
};
document.body.appendChild(iframe);
});
</script>
</body>
</html>

0 comments on commit 4a2ef92

Please sign in to comment.
You can’t perform that action at this time.