Commit 85a5c06a authored by Sebastien Marchand's avatar Sebastien Marchand Committed by Commit Bot

Remove usage of TestMockTimeTaskRunner in TabLifecycleUnitSourceTest.


Change-Id: Id956ce360927ac6c3d81280614a739449dc3b9ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1903686Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Commit-Queue: Sébastien Marchand <sebmarchand@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713448}
parent 3c89a359
......@@ -12,7 +12,6 @@
#include "chrome/browser/resource_coordinator/local_site_characteristics_webcontents_observer.h"
#include "chrome/browser/resource_coordinator/tab_helper.h"
#include "chrome/browser/resource_coordinator/tab_manager_features.h"
#include "components/performance_manager/performance_manager_impl.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/system_connector.h"
......@@ -94,11 +93,6 @@ void NoopLocalSiteCharacteristicsDatabase::GetDatabaseSize(
std::move(callback).Run(base::nullopt, base::nullopt);
}
ChromeTestHarnessWithLocalDB::ChromeTestHarnessWithLocalDB() {
scoped_feature_list_.InitAndEnableFeature(
features::kSiteCharacteristicsDatabase);
}
ChromeTestHarnessWithLocalDB::~ChromeTestHarnessWithLocalDB() = default;
void ChromeTestHarnessWithLocalDB::SetUp() {
......@@ -125,5 +119,10 @@ void ChromeTestHarnessWithLocalDB::TearDown() {
ChromeRenderViewHostTestHarness::TearDown();
}
void ChromeTestHarnessWithLocalDB::EnableFeatures() {
scoped_feature_list_.InitAndEnableFeature(
features::kSiteCharacteristicsDatabase);
}
} // namespace testing
} // namespace resource_coordinator
......@@ -14,6 +14,7 @@
#include "chrome/browser/resource_coordinator/local_site_characteristics_data_store_factory.h"
#include "chrome/browser/resource_coordinator/local_site_characteristics_database.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "components/performance_manager/performance_manager_impl.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace content {
......@@ -90,7 +91,15 @@ class NoopLocalSiteCharacteristicsDatabase
// Site Characteristics Database is initialized.
class ChromeTestHarnessWithLocalDB : public ChromeRenderViewHostTestHarness {
public:
ChromeTestHarnessWithLocalDB();
// Construct a ChromeTestHarnessWithLocalDB with zero or more arguments
// passed to ChromeRenderViewHostTestHarness.
template <typename... TaskEnvironmentTraits>
explicit ChromeTestHarnessWithLocalDB(TaskEnvironmentTraits&&... traits)
: ChromeRenderViewHostTestHarness(
std::forward<TaskEnvironmentTraits>(traits)...) {
EnableFeatures();
}
~ChromeTestHarnessWithLocalDB() override;
protected:
......@@ -98,6 +107,9 @@ class ChromeTestHarnessWithLocalDB : public ChromeRenderViewHostTestHarness {
void TearDown() override;
private:
// Configures |scoped_feature_list_|.
void EnableFeatures();
base::test::ScopedFeatureList scoped_feature_list_;
std::unique_ptr<performance_manager::PerformanceManagerImpl>
performance_manager_;
......
......@@ -10,9 +10,7 @@
#include "base/bind.h"
#include "base/macros.h"
#include "base/message_loop/message_loop_current.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/test/test_mock_time_task_runner.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/resource_coordinator/lifecycle_unit.h"
......@@ -98,11 +96,9 @@ class TabLifecycleUnitSourceTest
: public testing::ChromeTestHarnessWithLocalDB {
protected:
TabLifecycleUnitSourceTest()
: scoped_context_(
std::make_unique<base::TestMockTimeTaskRunner::ScopedContext>(
task_runner_)),
scoped_set_tick_clock_for_testing_(task_runner_->GetMockTickClock()) {
base::MessageLoopCurrent::Get()->SetTaskRunner(task_runner_);
: testing::ChromeTestHarnessWithLocalDB(
base::test::SingleThreadTaskEnvironment::TimeSource::MOCK_TIME) {
task_runner_ = task_environment()->GetMainThreadTaskRunner();
}
void SetUp() override {
......@@ -124,8 +120,7 @@ class TabLifecycleUnitSourceTest
tab_strip_model_->CloseAllTabs();
tab_strip_model_.reset();
task_runner_->RunUntilIdle();
scoped_context_.reset();
task_environment()->RunUntilIdle();
ChromeTestHarnessWithLocalDB::TearDown();
}
......@@ -140,7 +135,7 @@ class TabLifecycleUnitSourceTest
source_->SetFocusedTabStripModelForTesting(tab_strip_model_.get());
// Add a foreground tab to the tab strip.
task_runner_->FastForwardBy(kShortDelay);
task_environment()->FastForwardBy(kShortDelay);
auto time_before_first_tab = NowTicks();
EXPECT_CALL(source_observer_, OnLifecycleUnitCreated(::testing::_))
.WillOnce(::testing::Invoke([&](LifecycleUnit* lifecycle_unit) {
......@@ -160,13 +155,14 @@ class TabLifecycleUnitSourceTest
::testing::Mock::VerifyAndClear(&source_observer_);
EXPECT_TRUE(source_->GetTabLifecycleUnitExternal(raw_first_web_contents));
base::RepeatingClosure run_loop_cb = base::BindRepeating(
&base::TestMockTimeTaskRunner::RunUntilIdle, task_runner_);
&base::test::SingleThreadTaskEnvironment::RunUntilIdle,
base::Unretained(task_environment()));
testing::WaitForLocalDBEntryToBeInitialized(raw_first_web_contents,
run_loop_cb);
testing::ExpireLocalDBObservationWindows(raw_first_web_contents);
// Add another foreground tab to the focused tab strip.
task_runner_->FastForwardBy(kShortDelay);
task_environment()->FastForwardBy(kShortDelay);
auto time_before_second_tab = NowTicks();
EXPECT_CALL(source_observer_, OnLifecycleUnitCreated(::testing::_))
.WillOnce(::testing::Invoke([&](LifecycleUnit* lifecycle_unit) {
......@@ -209,7 +205,7 @@ class TabLifecycleUnitSourceTest
second_lifecycle_unit->GetLastFocusedTime();
// Add a background tab to the focused tab strip.
task_runner_->FastForwardBy(kShortDelay);
task_environment()->FastForwardBy(kShortDelay);
LifecycleUnit* third_lifecycle_unit = nullptr;
EXPECT_CALL(source_observer_, OnLifecycleUnitCreated(::testing::_))
.WillOnce(::testing::Invoke([&](LifecycleUnit* lifecycle_unit) {
......@@ -262,7 +258,7 @@ class TabLifecycleUnitSourceTest
if (reason == LifecycleUnitDiscardReason::PROACTIVE) {
EXPECT_EQ(LifecycleUnitState::PENDING_DISCARD,
lifecycle_unit->GetState());
task_runner_->FastForwardBy(kProactiveDiscardFreezeTimeout);
task_environment()->FastForwardBy(kProactiveDiscardFreezeTimeout);
}
EXPECT_EQ(LifecycleUnitState::DISCARDED, lifecycle_unit->GetState());
}
......@@ -276,7 +272,7 @@ class TabLifecycleUnitSourceTest
&second_lifecycle_unit);
// Advance time so tabs are urgent discardable.
task_runner_->AdvanceMockTickClock(kBackgroundUrgentProtectionTime);
task_environment()->AdvanceClock(kBackgroundUrgentProtectionTime);
// Detach the non-active tab. Verify that it can no longer be discarded.
ExpectCanDiscardTrueAllReasons(first_lifecycle_unit);
......@@ -328,7 +324,7 @@ class TabLifecycleUnitSourceTest
->SetLastActiveTime(kDummyLastActiveTime);
// Advance time so tabs are urgent discardable.
task_runner_->AdvanceMockTickClock(kBackgroundUrgentProtectionTime);
task_environment()->AdvanceClock(kBackgroundUrgentProtectionTime);
// Discard the tab.
EXPECT_EQ(LifecycleUnitState::ACTIVE,
......@@ -361,7 +357,7 @@ class TabLifecycleUnitSourceTest
tab_strip_model_->GetWebContentsAt(0);
// Advance time so tabs are urgent discardable.
task_runner_->AdvanceMockTickClock(kBackgroundUrgentProtectionTime);
task_environment()->AdvanceClock(kBackgroundUrgentProtectionTime);
// Discard the tab.
EXPECT_EQ(LifecycleUnitState::ACTIVE,
......@@ -400,7 +396,7 @@ class TabLifecycleUnitSourceTest
tab_strip_model_->GetWebContentsAt(0);
// Advance time so tabs are urgent discardable.
task_runner_->AdvanceMockTickClock(kBackgroundUrgentProtectionTime);
task_environment()->AdvanceClock(kBackgroundUrgentProtectionTime);
// Discard the tab.
EXPECT_EQ(LifecycleUnitState::ACTIVE,
......@@ -435,9 +431,7 @@ class TabLifecycleUnitSourceTest
::testing::StrictMock<MockLifecycleUnitSourceObserver> source_observer_;
::testing::StrictMock<MockTabLifecycleObserver> tab_observer_;
std::unique_ptr<TabStripModel> tab_strip_model_;
scoped_refptr<base::TestMockTimeTaskRunner> task_runner_ =
base::MakeRefCounted<base::TestMockTimeTaskRunner>();
std::unique_ptr<base::TestMockTimeTaskRunner::ScopedContext> scoped_context_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
private:
std::unique_ptr<content::WebContents> CreateAndNavigateWebContents() {
......@@ -453,7 +447,6 @@ class TabLifecycleUnitSourceTest
}
TestTabStripModelDelegate tab_strip_model_delegate_;
ScopedSetTickClockForTesting scoped_set_tick_clock_for_testing_;
DISALLOW_COPY_AND_ASSIGN(TabLifecycleUnitSourceTest);
};
......@@ -475,7 +468,7 @@ TEST_F(TabLifecycleUnitSourceTest, SwitchTabInFocusedTabStrip) {
&second_lifecycle_unit);
// Activate the first tab.
task_runner_->FastForwardBy(kShortDelay);
task_environment()->FastForwardBy(kShortDelay);
auto time_before_activate = NowTicks();
tab_strip_model_->ActivateTabAt(0, {TabStripModel::GestureType::kOther});
EXPECT_TRUE(IsFocused(first_lifecycle_unit));
......@@ -493,7 +486,7 @@ TEST_F(TabLifecycleUnitSourceTest, CloseTabInFocusedTabStrip) {
&second_lifecycle_unit);
// Close the second tab. The first tab should be focused.
task_runner_->FastForwardBy(kShortDelay);
task_environment()->FastForwardBy(kShortDelay);
::testing::StrictMock<MockLifecycleUnitObserver> second_observer;
second_lifecycle_unit->AddObserver(&second_observer);
EXPECT_CALL(second_observer, OnLifecycleUnitDestroyed(second_lifecycle_unit));
......@@ -727,10 +720,10 @@ TEST_F(TabLifecycleUnitSourceTest, CannotFreezeADiscardedTab) {
&foreground_lifecycle_unit);
content::WebContents* initial_web_contents =
tab_strip_model_->GetWebContentsAt(0);
task_runner_->FastForwardBy(kShortDelay);
task_environment()->FastForwardBy(kShortDelay);
// Advance time so tabs are urgent discardable.
task_runner_->AdvanceMockTickClock(kBackgroundUrgentProtectionTime);
task_environment()->AdvanceClock(kBackgroundUrgentProtectionTime);
// Discard the tab.
EXPECT_EQ(LifecycleUnitState::ACTIVE, background_lifecycle_unit->GetState());
......
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