Commit c739123c authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

Reland "Re-enable TabManagerTest.DiscardTabsWithMinimizedAndOccludedWindows."

This is a reland of a79e01b5
In this reland, tests do not run in debug builds as the multiple
navigations cause time outs.

Original change's description:
> Re-enable TabManagerTest.DiscardTabsWithMinimizedAndOccludedWindows.
>
> The crash stack on the bug is in non-TabManager code. Let's see if
> the test passes when re-enabled.
>
> This CL also:
> - Splits the test in 2 tests to avoid timing out (local tests show
>   that we can time out when having too many navigations in the same
>   test).
> - On ChromeOS, allows discarding of the active tab in the last focused
>   browser window if that window is not visible. Previously, the active
>   tab in the last focused browser window was not discardable, even if
>   the window was not visible.
>
> Bug: 772839
> Change-Id: I18552a16361c8beb4d48409227b727a40cc40ec7
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1972570
> Commit-Queue: Chris Hamilton <chrisha@chromium.org>
> Auto-Submit: François Doray <fdoray@chromium.org>
> Reviewed-by: Chris Hamilton <chrisha@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#728572}

TBR=chrisha@chromium.org

Bug: 772839
Change-Id: I17e41e176028f76ff09cb9fac60b8ffe51b36132
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2001240Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Commit-Queue: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#731671}
parent 9b806ed8
......@@ -1048,6 +1048,15 @@ void TabLifecycleUnitSource::TabLifecycleUnit::DidStartLoading() {
void TabLifecycleUnitSource::TabLifecycleUnit::OnVisibilityChanged(
content::Visibility visibility) {
// Ensure that the tab is not considered focused when not visible.
//
// TabLifeycleUnitSource calls SetFocused(false) when focus changes to another
// tab. The code below is also required to cover the case where the focused
// tab is hidden but no other tab is focused, which can happen when the
// focused window is minimized or occluded.
if (visibility != content::Visibility::VISIBLE)
SetFocused(false);
OnLifecycleUnitVisibilityChanged(visibility);
}
......
......@@ -1490,71 +1490,80 @@ Browser* CreateBrowserWithTabs(int num_tabs) {
} // namespace
// Flaky on Linux. Times out on Windows and Mac debug builds.
// http://crbug.com/772839.
#if defined(OS_LINUX) || \
((defined(OS_WIN) || defined(OS_MACOSX)) && !defined(NDEBUG))
#define MAYBE_DiscardTabsWithMinimizedAndOccludedWindows \
DISABLED_DiscardTabsWithMinimizedAndOccludedWindows
// Do not run in debug builds to avoid timeouts due to multiple navigations.
#if !defined(NDEBUG)
#define MAYBE_DiscardTabsWithMinimizedWindow \
DISABLED_DiscardTabsWithMinimizedWindow
#else
#define MAYBE_DiscardTabsWithMinimizedAndOccludedWindows \
DiscardTabsWithMinimizedAndOccludedWindows
#define MAYBE_DiscardTabsWithMinimizedWindow DiscardTabsWithMinimizedWindow
#endif
IN_PROC_BROWSER_TEST_F(TabManagerTest,
MAYBE_DiscardTabsWithMinimizedAndOccludedWindows) {
// Covered by |browser2|.
Browser* browser1 = browser();
EnsureTabsInBrowser(browser1, 2);
browser1->window()->SetBounds(gfx::Rect(10, 10, 10, 10));
// Covers |browser1|.
Browser* browser2 = CreateBrowserWithTabs(2);
EXPECT_NE(browser1, browser2);
browser2->window()->SetBounds(gfx::Rect(0, 0, 100, 100));
// Active browser.
Browser* browser3 = CreateBrowserWithTabs(2);
EXPECT_NE(browser1, browser3);
EXPECT_NE(browser2, browser3);
browser3->window()->SetBounds(gfx::Rect(110, 0, 100, 100));
IN_PROC_BROWSER_TEST_F(TabManagerTest, DiscardTabsWithMinimizedWindow) {
// Minimized browser.
Browser* browser4 = CreateBrowserWithTabs(2);
browser4->window()->Minimize();
EXPECT_NE(browser1, browser4);
EXPECT_NE(browser2, browser4);
EXPECT_NE(browser3, browser4);
EnsureTabsInBrowser(browser(), 2);
browser()->window()->Minimize();
// Other browser that will be last active. This browser exists because the
// last active tab cannot be discarded on
// Advance time so everything is urgent discardable.
test_clock_.Advance(kBackgroundUrgentProtectionTime);
for (int i = 0; i < 8; ++i)
tab_manager()->DiscardTab(LifecycleUnitDiscardReason::PROACTIVE);
for (int i = 0; i < 2; ++i)
tab_manager()->DiscardTab(LifecycleUnitDiscardReason::URGENT);
base::RunLoop().RunUntilIdle();
// On ChromeOS, active tabs are discarded if their window is non-visible. On
// other platforms, they are never discarded.
#if defined(OS_CHROMEOS)
EXPECT_TRUE(IsTabDiscarded(browser1->tab_strip_model()->GetWebContentsAt(0)));
EXPECT_FALSE(
IsTabDiscarded(browser2->tab_strip_model()->GetWebContentsAt(0)));
EXPECT_FALSE(
IsTabDiscarded(browser3->tab_strip_model()->GetWebContentsAt(0)));
EXPECT_TRUE(IsTabDiscarded(browser4->tab_strip_model()->GetWebContentsAt(0)));
EXPECT_TRUE(
IsTabDiscarded(browser()->tab_strip_model()->GetWebContentsAt(0)));
#else
EXPECT_FALSE(
IsTabDiscarded(browser1->tab_strip_model()->GetWebContentsAt(0)));
EXPECT_FALSE(
IsTabDiscarded(browser2->tab_strip_model()->GetWebContentsAt(0)));
EXPECT_FALSE(
IsTabDiscarded(browser3->tab_strip_model()->GetWebContentsAt(0)));
IsTabDiscarded(browser()->tab_strip_model()->GetWebContentsAt(0)));
#endif
// Non-active tabs can be discarded on all platforms.
EXPECT_TRUE(
IsTabDiscarded(browser()->tab_strip_model()->GetWebContentsAt(1)));
}
// Do not run in debug builds to avoid timeouts due to multiple navigations.
#if !defined(NDEBUG)
#define MAYBE_DiscardTabsWithOccludedWindow \
DISABLED_DiscardTabsWithOccludedWindow
#else
#define MAYBE_DiscardTabsWithOccludedWindow DiscardTabsWithOccludedWindow
#endif
IN_PROC_BROWSER_TEST_F(TabManagerTest, DiscardTabsWithOccludedWindow) {
// Occluded browser.
EnsureTabsInBrowser(browser(), 2);
browser()->window()->SetBounds(gfx::Rect(10, 10, 10, 10));
// Other browser that covers the occluded browser.
Browser* other_browser = CreateBrowserWithTabs(1);
EXPECT_NE(other_browser, browser());
other_browser->window()->SetBounds(gfx::Rect(0, 0, 100, 100));
// Advance time so everything is urgent discardable.
test_clock_.Advance(kBackgroundUrgentProtectionTime);
for (int i = 0; i < 3; ++i)
tab_manager()->DiscardTab(LifecycleUnitDiscardReason::URGENT);
base::RunLoop().RunUntilIdle();
// On ChromeOS, active tabs are discarded if their window is non-visible. On
// other platforms, they are never discarded.
#if defined(OS_CHROMEOS)
EXPECT_TRUE(
IsTabDiscarded(browser()->tab_strip_model()->GetWebContentsAt(0)));
#else
EXPECT_FALSE(
IsTabDiscarded(browser4->tab_strip_model()->GetWebContentsAt(0)));
IsTabDiscarded(browser()->tab_strip_model()->GetWebContentsAt(0)));
#endif
// Non-active tabs can be discarded on all platforms.
EXPECT_TRUE(IsTabDiscarded(browser1->tab_strip_model()->GetWebContentsAt(1)));
EXPECT_TRUE(IsTabDiscarded(browser2->tab_strip_model()->GetWebContentsAt(1)));
EXPECT_TRUE(IsTabDiscarded(browser3->tab_strip_model()->GetWebContentsAt(1)));
EXPECT_TRUE(IsTabDiscarded(browser4->tab_strip_model()->GetWebContentsAt(1)));
EXPECT_TRUE(
IsTabDiscarded(browser()->tab_strip_model()->GetWebContentsAt(1)));
}
IN_PROC_BROWSER_TEST_F(TabManagerTest, UnfreezeTabOnNavigationEvent) {
......
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