[session restore tests] Add test for back-to-back min window restores
Adds a test that closes and restores the browser twice, checking that the minimized window remains minimized after each restore. Test: interactive_ui_tests \ --gtest_filter=SessionRestoreInteractiveTest.RestoreMinimizedWindowTwice Change-Id: I03f97a7b02e7ce882d24089fe2b27f05d7df40d6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2911441 Commit-Queue: Jayson Adams <shrike@chromium.org> Reviewed-by: Scott Violet <sky@chromium.org> Cr-Commit-Position: refs/heads/master@{#886816}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
bb1b5389cd
commit
32fb052f24
@ -40,7 +40,7 @@ class SessionRestoreInteractiveTest : public InProcessBrowserTest {
|
||||
return InProcessBrowserTest::SetUpUserDataDirectory();
|
||||
}
|
||||
|
||||
Browser* QuitBrowserAndRestore(Browser* browser, int expected_tab_count) {
|
||||
Browser* QuitBrowserAndRestore(Browser* browser) {
|
||||
Profile* profile = browser->profile();
|
||||
|
||||
// Close the browser.
|
||||
@ -73,6 +73,49 @@ class SessionRestoreInteractiveTest : public InProcessBrowserTest {
|
||||
return new_browser;
|
||||
}
|
||||
|
||||
void QuitMultiWindowBrowserAndRestore(Profile* profile) {
|
||||
auto keep_alive = std::make_unique<ScopedKeepAlive>(
|
||||
KeepAliveOrigin::SESSION_RESTORE, KeepAliveRestartOption::DISABLED);
|
||||
auto profile_keep_alive = std::make_unique<ScopedProfileKeepAlive>(
|
||||
profile, ProfileKeepAliveOrigin::kBrowserWindow);
|
||||
|
||||
int normal_window_counter = 0;
|
||||
int minimized_window_counter = 0;
|
||||
|
||||
// Pretend to "close the browser."
|
||||
SessionServiceFactory::ShutdownForProfile(profile);
|
||||
while (Browser* browser = BrowserList::GetInstance()->GetLastActive()) {
|
||||
if (browser->window()->IsMinimized()) {
|
||||
minimized_window_counter++;
|
||||
} else {
|
||||
normal_window_counter++;
|
||||
}
|
||||
CloseBrowserSynchronously(browser);
|
||||
}
|
||||
|
||||
// Now trigger a restore. We need to start up the services again
|
||||
// before restoring.
|
||||
SessionServiceFactory::GetForProfileForSessionRestore(profile);
|
||||
|
||||
SessionRestore::RestoreSession(profile, nullptr,
|
||||
SessionRestore::SYNCHRONOUS, {});
|
||||
|
||||
for (Browser* browser : *(BrowserList::GetInstance())) {
|
||||
WaitForTabsToLoad(browser);
|
||||
if (browser->window()->IsMinimized()) {
|
||||
minimized_window_counter--;
|
||||
} else {
|
||||
normal_window_counter--;
|
||||
}
|
||||
}
|
||||
|
||||
keep_alive.reset();
|
||||
profile_keep_alive.reset();
|
||||
|
||||
EXPECT_EQ(0, normal_window_counter);
|
||||
EXPECT_EQ(0, minimized_window_counter);
|
||||
}
|
||||
|
||||
void WaitForTabsToLoad(Browser* browser) {
|
||||
for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
|
||||
content::WebContents* contents =
|
||||
@ -94,7 +137,7 @@ class SessionRestoreInteractiveTest : public InProcessBrowserTest {
|
||||
IN_PROC_BROWSER_TEST_F(SessionRestoreInteractiveTest, MAYBE_FocusOnLaunch) {
|
||||
ui_test_utils::NavigateToURL(browser(), url1_);
|
||||
|
||||
Browser* new_browser = QuitBrowserAndRestore(browser(), 1);
|
||||
Browser* new_browser = QuitBrowserAndRestore(browser());
|
||||
ASSERT_EQ(1u, BrowserList::GetInstance()->size());
|
||||
ASSERT_EQ(url1_,
|
||||
new_browser->tab_strip_model()->GetActiveWebContents()->GetURL());
|
||||
@ -121,7 +164,7 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreInteractiveTest,
|
||||
browser()->window()->Minimize();
|
||||
|
||||
// Restart and session restore the tabs.
|
||||
Browser* restored = QuitBrowserAndRestore(browser(), 3);
|
||||
Browser* restored = QuitBrowserAndRestore(browser());
|
||||
EXPECT_EQ(1, restored->tab_strip_model()->count());
|
||||
|
||||
// Expect the window to be visible.
|
||||
@ -130,3 +173,31 @@ IN_PROC_BROWSER_TEST_F(SessionRestoreInteractiveTest,
|
||||
EXPECT_TRUE(restored->window()->IsActive());
|
||||
EXPECT_TRUE(restored->window()->IsVisible());
|
||||
}
|
||||
|
||||
#if defined(OS_MAC)
|
||||
#define MAYBE_RestoreMinimizedWindowTwice RestoreMinimizedWindowTwice
|
||||
#else
|
||||
#define MAYBE_RestoreMinimizedWindowTwice DISABLED_RestoreMinimizedWindowTwice
|
||||
#endif
|
||||
// Verify that in restoring a browser with a normal and minimized window twice,
|
||||
// the minimized window remains minimized. Guards against a regression
|
||||
// introduced in the fix for https://crbug.com/1204517. This test fails on
|
||||
// Linux and Windows - see https://crbug.com/1213497.
|
||||
IN_PROC_BROWSER_TEST_F(SessionRestoreInteractiveTest,
|
||||
MAYBE_RestoreMinimizedWindowTwice) {
|
||||
Profile* profile = browser()->profile();
|
||||
|
||||
// Create a second browser.
|
||||
CreateBrowser(browser()->profile());
|
||||
|
||||
// Minimize the first browser window.
|
||||
browser()->window()->Minimize();
|
||||
|
||||
EXPECT_EQ(2u, BrowserList::GetInstance()->size());
|
||||
|
||||
// Quit and restore.
|
||||
QuitMultiWindowBrowserAndRestore(profile);
|
||||
|
||||
// Quit and restore a second time.
|
||||
QuitMultiWindowBrowserAndRestore(profile);
|
||||
}
|
||||
|
Reference in New Issue
Block a user