0
Files
src/content/browser/child_process_launcher_browsertest.cc
Rakina Zata Amni e2d3131481 Remove nullchecks for NavigationController::GetLastCommittedEntry() etc
NavigationController's GetLastCommittedEntry(), GetVisibleEntry() and
related functions used to be able to return nullptr when no
navigation had committed. However, with InitialNavigationEntry
enabled, those NavigationControllers would have at least 1
NavigationEntry, the initial NavigationEntry, and those functions
will not return nullptr.

This CL updates documentation for those functions and removes code
that handles the null case, as they are not needed anymore.

Bug: 524208
Change-Id: Ifcc1f6569ebe50c68021cb7338bad438b0b62fad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3995872
Reviewed-by: Istiaque Ahmed <lazyboy@chromium.org>
Reviewed-by: Wez <wez@chromium.org>
Reviewed-by: Charlie Reis <creis@chromium.org>
Reviewed-by: Andrey Kosyakov <caseq@chromium.org>
Reviewed-by: Emily Stark <estark@chromium.org>
Reviewed-by: Basia Zimirska <basiaz@google.com>
Reviewed-by: Daniel Rubery <drubery@chromium.org>
Reviewed-by: Clark DuVall <cduvall@chromium.org>
Commit-Queue: Rakina Zata Amni <rakina@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Olesia Marukhno <olesiamarukhno@google.com>
Reviewed-by: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1073193}
2022-11-18 03:38:45 +00:00

101 lines
3.5 KiB
C++

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/memory/raw_ptr.h"
#include "build/build_config.h"
#include "content/browser/child_process_launcher.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/no_renderer_crashes_assertion.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/shell/browser/shell.h"
namespace {
class MockChildProcessLauncherClient
: public content::ChildProcessLauncher::Client {
public:
MockChildProcessLauncherClient()
: client_(nullptr), simulate_failure_(false) {}
void OnProcessLaunched() override {
if (simulate_failure_)
client_->OnProcessLaunchFailed(content::LAUNCH_RESULT_FAILURE);
else
client_->OnProcessLaunched();
}
void OnProcessLaunchFailed(int error_code) override {
client_->OnProcessLaunchFailed(error_code);
}
#if BUILDFLAG(IS_ANDROID)
bool CanUseWarmUpConnection() override { return true; }
#endif
raw_ptr<content::ChildProcessLauncher::Client> client_;
bool simulate_failure_;
};
} // namespace
namespace content {
class ChildProcessLauncherBrowserTest : public ContentBrowserTest {};
IN_PROC_BROWSER_TEST_F(ChildProcessLauncherBrowserTest, ChildSpawnFail) {
GURL url("about:blank");
Shell* window = shell();
MockChildProcessLauncherClient* client(nullptr);
// Navigate once and simulate a process failing to spawn.
TestNavigationObserver nav_observer1(window->web_contents(), 1);
client = new MockChildProcessLauncherClient;
window->LoadURL(url);
client->client_ =
static_cast<RenderProcessHostImpl*>(
window->web_contents()->GetPrimaryMainFrame()->GetProcess())
->child_process_launcher_->ReplaceClientForTest(client);
client->simulate_failure_ = true;
{
ScopedAllowRendererCrashes allow_renderer_crashes(shell());
nav_observer1.Wait();
}
delete client;
NavigationEntry* last_entry =
shell()->web_contents()->GetController().GetLastCommittedEntry();
// Make sure we didn't commit any navigation.
EXPECT_TRUE(last_entry->IsInitialEntry());
// Navigate again and let the process spawn correctly.
TestNavigationObserver nav_observer2(window->web_contents(), 1);
window->LoadURL(url);
nav_observer2.Wait();
last_entry = shell()->web_contents()->GetController().GetLastCommittedEntry();
// Make sure that we navigated to the proper URL.
ASSERT_FALSE(last_entry->IsInitialEntry());
EXPECT_EQ(last_entry->GetPageType(), PAGE_TYPE_NORMAL);
EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), url);
// Navigate again, using the same renderer.
url = GURL("data:text/html,dataurl");
TestNavigationObserver nav_observer3(window->web_contents(), 1);
window->LoadURL(url);
nav_observer3.Wait();
last_entry = shell()->web_contents()->GetController().GetLastCommittedEntry();
// Make sure that we navigated to the proper URL.
ASSERT_FALSE(last_entry->IsInitialEntry());
EXPECT_EQ(last_entry->GetPageType(), PAGE_TYPE_NORMAL);
EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), url);
}
} // namespace content