Commit caded4db authored by Sebastien Marchand's avatar Sebastien Marchand Committed by Commit Bot

Unfreeze tabs that receive WebLock or IndexedDB locks

Bug: 980533
Change-Id: I3c4f1e12e048ba953500d8f7173220e04da997ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1856879
Commit-Queue: Sébastien Marchand <sebmarchand@chromium.org>
Commit-Queue: François Doray <fdoray@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705224}
parent d56f9fb5
...@@ -425,11 +425,18 @@ void TabLifecycleUnitSource::TabLifecycleUnit::UpdateOriginTrialFreezePolicy( ...@@ -425,11 +425,18 @@ void TabLifecycleUnitSource::TabLifecycleUnit::UpdateOriginTrialFreezePolicy(
void TabLifecycleUnitSource::TabLifecycleUnit::SetIsHoldingWebLock( void TabLifecycleUnitSource::TabLifecycleUnit::SetIsHoldingWebLock(
bool is_holding_weblock) { bool is_holding_weblock) {
// Unfreeze the tab if it receive a lock while being frozen.
if (is_holding_weblock && IsFrozenOrPendingFreeze(GetState()))
Unfreeze();
is_holding_weblock_ = is_holding_weblock; is_holding_weblock_ = is_holding_weblock;
} }
void TabLifecycleUnitSource::TabLifecycleUnit::SetIsHoldingIndexedDBLock( void TabLifecycleUnitSource::TabLifecycleUnit::SetIsHoldingIndexedDBLock(
bool is_holding_indexeddb_lock) { bool is_holding_indexeddb_lock) {
// Unfreeze the tab if it receive a lock while being frozen.
if (is_holding_indexeddb_lock && IsFrozenOrPendingFreeze(GetState()))
Unfreeze();
is_holding_indexeddb_lock_ = is_holding_indexeddb_lock; is_holding_indexeddb_lock_ = is_holding_indexeddb_lock;
} }
......
...@@ -995,4 +995,62 @@ TEST_F(TabLifecycleUnitTest, CannotFreezeIfHoldingIndexedDBLock) { ...@@ -995,4 +995,62 @@ TEST_F(TabLifecycleUnitTest, CannotFreezeIfHoldingIndexedDBLock) {
tab_lifecycle_unit.SetIsHoldingIndexedDBLock(false); tab_lifecycle_unit.SetIsHoldingIndexedDBLock(false);
} }
TEST_F(TabLifecycleUnitTest, TabUnfreezeOnWebLockAcquisition) {
TabLifecycleUnit tab_lifecycle_unit(GetTabLifecycleUnitSource(), &observers_,
usage_clock_.get(), web_contents_,
tab_strip_model_.get());
TabLoadTracker::Get()->TransitionStateForTesting(web_contents_,
LoadingState::LOADED);
// Advance time enough that the tab is urgent discardable.
test_clock_.Advance(kBackgroundUrgentProtectionTime);
ExpectCanDiscardTrueAllReasons(&tab_lifecycle_unit);
DecisionDetails decision_details;
EXPECT_TRUE(tab_lifecycle_unit.CanFreeze(&decision_details));
// Freeze the tab.
EXPECT_CALL(observer_, OnFrozenStateChange(web_contents_, true));
tab_lifecycle_unit.Freeze();
::testing::Mock::VerifyAndClear(&observer_);
EXPECT_EQ(LifecycleUnitState::PENDING_FREEZE, tab_lifecycle_unit.GetState());
// Indicates that the tab has acquired a WebLock, this should unfreeze it.
EXPECT_CALL(observer_, OnFrozenStateChange(web_contents_, false));
tab_lifecycle_unit.SetIsHoldingWebLock(true);
::testing::Mock::VerifyAndClear(&observer_);
EXPECT_EQ(LifecycleUnitState::PENDING_UNFREEZE,
tab_lifecycle_unit.GetState());
tab_lifecycle_unit.SetIsHoldingWebLock(false);
}
TEST_F(TabLifecycleUnitTest, TabUnfreezeOnIndexedDBLockAcquisition) {
TabLifecycleUnit tab_lifecycle_unit(GetTabLifecycleUnitSource(), &observers_,
usage_clock_.get(), web_contents_,
tab_strip_model_.get());
TabLoadTracker::Get()->TransitionStateForTesting(web_contents_,
LoadingState::LOADED);
// Advance time enough that the tab is urgent discardable.
test_clock_.Advance(kBackgroundUrgentProtectionTime);
ExpectCanDiscardTrueAllReasons(&tab_lifecycle_unit);
DecisionDetails decision_details;
EXPECT_TRUE(tab_lifecycle_unit.CanFreeze(&decision_details));
// Freeze the tab.
EXPECT_CALL(observer_, OnFrozenStateChange(web_contents_, true));
tab_lifecycle_unit.Freeze();
::testing::Mock::VerifyAndClear(&observer_);
EXPECT_EQ(LifecycleUnitState::PENDING_FREEZE, tab_lifecycle_unit.GetState());
// Indicates that the tab has acquired a WebLock, this should unfreeze it.
EXPECT_CALL(observer_, OnFrozenStateChange(web_contents_, false));
tab_lifecycle_unit.SetIsHoldingIndexedDBLock(true);
::testing::Mock::VerifyAndClear(&observer_);
EXPECT_EQ(LifecycleUnitState::PENDING_UNFREEZE,
tab_lifecycle_unit.GetState());
tab_lifecycle_unit.SetIsHoldingIndexedDBLock(false);
}
} // namespace resource_coordinator } // namespace resource_coordinator
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