Commit 224ed3cd authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Add InProcessBrowserTest::CreateGuestBrowser.

A function is added to create Guest test browsers and existing use cases
are updated.

Bug: 1125474, 1061637
Change-Id: I56c8a11d409f5b0fb2a6baf25447f4e7c535b644
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2474697Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818356}
parent 0ef8e04d
......@@ -159,19 +159,6 @@ void UnblockOnProfileCreation(base::RunLoop* run_loop,
}
#endif // !defined(OS_ANDROID)
#if !defined(OS_ANDROID)
Profile* CreateGuestProfile() {
ProfileManager* profile_manager = g_browser_process->profile_manager();
base::FilePath new_path = profile_manager->GetGuestProfilePath();
base::RunLoop run_loop;
profile_manager->CreateProfileAsync(
new_path, base::Bind(&UnblockOnProfileCreation, &run_loop),
base::string16(), std::string());
run_loop.Run();
return profile_manager->GetProfileByPath(new_path);
}
#endif // !defined(OS_ANDROID)
// A helper object for overriding metrics enabled state.
class MetricsConsentOverride {
public:
......@@ -500,10 +487,8 @@ IN_PROC_BROWSER_TEST_F(UkmBrowserTest, RegularPlusGuestCheck) {
EXPECT_TRUE(ukm_test_helper.IsRecordingEnabled());
uint64_t original_client_id = ukm_test_helper.GetClientId();
// Create browser for guest profile. Only "off the record" browsers may be
// opened in this mode.
Profile* guest_profile = CreateGuestProfile();
Browser* guest_browser = CreateIncognitoBrowser(guest_profile);
// Create browser for guest profile.
Browser* guest_browser = InProcessBrowserTest::CreateGuestBrowser();
EXPECT_FALSE(ukm_test_helper.IsRecordingEnabled());
CloseBrowserSynchronously(guest_browser);
......
......@@ -20,30 +20,6 @@
#include "ui/gfx/animation/animation.h"
#include "ui/gfx/animation/animation_test_api.h"
// TODO(crbug.com/1061637): Clean this and the same code in ukm_browsertest.
// Maybe move them to InProcessBrowserTest.
namespace {
void UnblockOnProfileCreation(base::RunLoop* run_loop,
Profile* profile,
Profile::CreateStatus status) {
if (status == Profile::CREATE_STATUS_INITIALIZED)
run_loop->Quit();
}
Profile* CreateGuestProfile() {
ProfileManager* profile_manager = g_browser_process->profile_manager();
base::FilePath new_path = profile_manager->GetGuestProfilePath();
base::RunLoop run_loop;
profile_manager->CreateProfileAsync(
new_path, base::BindRepeating(&UnblockOnProfileCreation, &run_loop),
base::string16(), std::string());
run_loop.Run();
return profile_manager->GetProfileByPath(new_path);
}
} // namespace
// The param is whether to use the highlight in the container.
class ToolbarAccountIconContainerViewBrowserTest : public InProcessBrowserTest {
public:
......@@ -108,9 +84,7 @@ IN_PROC_BROWSER_TEST_F(ToolbarAccountIconContainerViewBrowserTest,
IN_PROC_BROWSER_TEST_F(ToolbarAccountIconContainerViewBrowserTest,
ShouldUpdateHighlightInGuestWindow) {
Profile* guest_profile = CreateGuestProfile();
Browser* guest_browser = CreateIncognitoBrowser(guest_profile);
ASSERT_TRUE(guest_browser->profile()->IsGuestSession());
Browser* guest_browser = InProcessBrowserTest::CreateGuestBrowser();
ToolbarAccountIconContainerView* container_view =
BrowserView::GetBrowserViewForBrowser(guest_browser)
->toolbar()
......
......@@ -154,6 +154,17 @@ FakeDeviceSyncImplFactory* GetFakeDeviceSyncImplFactory() {
}
#endif // defined(OS_CHROMEOS)
#if !defined(OS_ANDROID)
// An observer that returns back to test code after a new profile is
// initialized.
void UnblockOnProfileCreation(base::RunLoop* run_loop,
Profile* profile,
Profile::CreateStatus status) {
if (status == Profile::CREATE_STATUS_INITIALIZED)
run_loop->Quit();
}
#endif
} // namespace
// static
......@@ -486,6 +497,29 @@ Browser* InProcessBrowserTest::CreateBrowserForApp(const std::string& app_name,
}
#endif // !defined(OS_MAC)
#if !defined(OS_ANDROID)
Browser* InProcessBrowserTest::CreateGuestBrowser() {
// Get Guest profile.
ProfileManager* profile_manager = g_browser_process->profile_manager();
base::FilePath guest_path = profile_manager->GetGuestProfilePath();
base::RunLoop run_loop;
profile_manager->CreateProfileAsync(
guest_path, base::Bind(&UnblockOnProfileCreation, &run_loop),
base::string16(), std::string());
run_loop.Run();
Profile* profile = profile_manager->GetProfileByPath(guest_path);
if (!profile->IsEphemeralGuestProfile())
profile = profile->GetPrimaryOTRProfile();
// Create browser and add tab.
Browser* browser = new Browser(Browser::CreateParams(profile, true));
AddBlankTabAndShow(browser);
return browser;
}
#endif
void InProcessBrowserTest::AddBlankTabAndShow(Browser* browser) {
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
......
......@@ -227,6 +227,11 @@ class InProcessBrowserTest : public content::BrowserTestBase {
// is omitted, the currently active profile will be used.
Browser* CreateIncognitoBrowser(Profile* profile = nullptr);
#if !defined(OS_ANDROID)
// Similar to |CreateBrowser|, but creates a Guest browser.
Browser* CreateGuestBrowser();
#endif
// Creates a browser for a popup window with a single tab (about:blank), waits
// for the tab to finish loading, and shows the browser.
Browser* CreateBrowserForPopup(Profile* profile);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment