TestBrowserThreadBundle to inherit from ScopedTaskEnvironment

This clarifies ownership of the ScopedTaskEnvironment (there is only one)
which makes it easier for the upcoming BrowserThreadScheduler work with
TestBrowserThreadBundle.  Because we need BrowserUIThreadScheduler and
ScopedTaskEnvironment to share a SequenceManager.

Most of this change is mechanical, the interesting changes are in
test_browser_thread_bundle.h, test_browser_thread_bundle.cc and
views_test_base.cc.

TBR=bartfab@chromium.org

Bug: 863341, 891670
Change-Id: I324665b19c6e89da42c05e7646ae41d9f1cd5e7b
Reviewed-on: https://chromium-review.googlesource.com/c/1352260
Reviewed-by: Alex Clarke <alexclarke@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: François Doray <fdoray@chromium.org>
Commit-Queue: Alex Clarke <alexclarke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#616622}
diff --git a/base/test/scoped_task_environment.cc b/base/test/scoped_task_environment.cc
index 49e91a3..2bc5607 100644
--- a/base/test/scoped_task_environment.cc
+++ b/base/test/scoped_task_environment.cc
@@ -297,7 +297,8 @@
     ExecutionMode execution_control_mode,
     NowSource now_source,
     NotATraitTag)
-    : execution_control_mode_(execution_control_mode),
+    : main_thread_type_(main_thread_type),
+      execution_control_mode_(execution_control_mode),
       mock_time_domain_(MockTimeDomain::Create(main_thread_type, now_source)),
       sequence_manager_(
           CreateSequenceManagerForMainThreadType(main_thread_type)),
@@ -314,6 +315,7 @@
       task_tracker_(new TestTaskTracker()) {
   CHECK(now_source == NowSource::REAL_TIME || mock_time_domain_)
       << "NowSource must be REAL_TIME unless we're using mock time";
+  CHECK(!base::ThreadTaskRunnerHandle::IsSet());
   CHECK(!TaskScheduler::GetInstance())
       << "Someone has already initialized TaskScheduler. If nothing in your "
          "test does so, then a test that ran earlier may have initialized one, "
@@ -385,14 +387,24 @@
   // on their main thread.
   ScopedAllowBaseSyncPrimitivesForTesting allow_waits_to_destroy_task_tracker;
   TaskScheduler::SetInstance(nullptr);
+  task_queue_ = nullptr;
+  NotifyDestructionObserversAndReleaseSequenceManager();
+}
+
+void ScopedTaskEnvironment::
+    NotifyDestructionObserversAndReleaseSequenceManager() {
+  // A derived classes may call this method early.
+  if (!sequence_manager_)
+    return;
 
   LifetimeObserver* observer = environment_lifetime_observer.Get().Get();
   if (observer)
     observer->OnScopedTaskEnvironmentDestroyed();
 
-  task_queue_ = nullptr;
   if (mock_time_domain_)
     sequence_manager_->UnregisterTimeDomain(mock_time_domain_.get());
+
+  sequence_manager_.reset();
 }
 
 scoped_refptr<sequence_manager::TaskQueue>
diff --git a/base/test/scoped_task_environment.h b/base/test/scoped_task_environment.h
index 8695da1..68816bdd 100644
--- a/base/test/scoped_task_environment.h
+++ b/base/test/scoped_task_environment.h
@@ -134,7 +134,7 @@
 
   // Waits until no undelayed TaskScheduler tasks remain. Then, unregisters the
   // TaskScheduler and the (Thread|Sequenced)TaskRunnerHandle.
-  ~ScopedTaskEnvironment();
+  virtual ~ScopedTaskEnvironment();
 
   class LifetimeObserver {
    public:
@@ -200,6 +200,16 @@
   // TaskRunner.
   TimeDelta NextMainThreadPendingTaskDelay() const;
 
+ protected:
+  MainThreadType main_thread_type() const { return main_thread_type_; }
+
+  ExecutionMode execution_control_mode() const {
+    return execution_control_mode_;
+  }
+
+  // Derived classes may need to control when the sequence manager goes away.
+  void NotifyDestructionObserversAndReleaseSequenceManager();
+
  private:
   class MockTimeDomain;
   class TestTaskTracker;
@@ -221,10 +231,11 @@
 
   scoped_refptr<sequence_manager::TaskQueue> CreateDefaultTaskQueue();
 
+  const MainThreadType main_thread_type_;
   const ExecutionMode execution_control_mode_;
 
   const std::unique_ptr<MockTimeDomain> mock_time_domain_;
-  const std::unique_ptr<sequence_manager::SequenceManager> sequence_manager_;
+  std::unique_ptr<sequence_manager::SequenceManager> sequence_manager_;
 
   scoped_refptr<sequence_manager::TaskQueue> task_queue_;
 
diff --git a/chrome/browser/browsing_data/browsing_data_appcache_helper_unittest.cc b/chrome/browser/browsing_data/browsing_data_appcache_helper_unittest.cc
index 5c91a8b..033b7b3 100644
--- a/chrome/browser/browsing_data/browsing_data_appcache_helper_unittest.cc
+++ b/chrome/browser/browsing_data/browsing_data_appcache_helper_unittest.cc
@@ -10,7 +10,6 @@
 #include "base/bind_helpers.h"
 #include "base/macros.h"
 #include "base/stl_util.h"
-#include "base/test/scoped_task_environment.h"
 #include "build/build_config.h"
 #include "chrome/test/base/testing_profile.h"
 #include "content/public/test/test_browser_thread_bundle.h"
@@ -44,19 +43,18 @@
 class CannedBrowsingDataAppCacheHelperTest : public testing::Test {
  public:
   CannedBrowsingDataAppCacheHelperTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::UI),
-        thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD) {}
+      : thread_bundle_(base::test::ScopedTaskEnvironment::MainThreadType::UI,
+                       base::test::ScopedTaskEnvironment::ExecutionMode::ASYNC,
+                       content::TestBrowserThreadBundle::REAL_IO_THREAD) {}
 
   void TearDown() override {
     // Make sure we run all pending tasks on IO thread before testing
     // profile is destructed.
     content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
-    scoped_task_environment_.RunUntilIdle();
+    thread_bundle_.RunUntilIdle();
   }
 
  protected:
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
   content::TestBrowserThreadBundle thread_bundle_;
   TestingProfile profile_;
 };
diff --git a/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge_unittest.cc b/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge_unittest.cc
index 146ea49..295d8704 100644
--- a/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge_unittest.cc
+++ b/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge_unittest.cc
@@ -25,7 +25,6 @@
 #include "components/arc/common/accessibility_helper.mojom.h"
 #include "components/exo/shell_surface.h"
 #include "components/exo/shell_surface_util.h"
-#include "content/public/test/test_browser_thread_bundle.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "ui/aura/window.h"
 #include "ui/display/display.h"
@@ -177,7 +176,6 @@
       arc_notification_surface_manager_;
 
  private:
-  content::TestBrowserThreadBundle thread_bundle_;
   std::unique_ptr<TestingProfile> testing_profile_;
   std::unique_ptr<ArcBridgeService> bridge_service_;
   std::unique_ptr<TestArcAccessibilityHelperBridge>
diff --git a/chrome/browser/chromeos/crostini/crostini_manager_unittest.cc b/chrome/browser/chromeos/crostini/crostini_manager_unittest.cc
index 2589c0b9..abb6520 100644
--- a/chrome/browser/chromeos/crostini/crostini_manager_unittest.cc
+++ b/chrome/browser/chromeos/crostini/crostini_manager_unittest.cc
@@ -8,7 +8,6 @@
 #include "base/bind.h"
 #include "base/memory/ptr_util.h"
 #include "base/run_loop.h"
-#include "base/test/scoped_task_environment.h"
 #include "chrome/browser/chromeos/crostini/crostini_util.h"
 #include "chrome/test/base/testing_profile.h"
 #include "chromeos/dbus/dbus_thread_manager.h"
@@ -132,9 +131,9 @@
   }
 
   CrostiniManagerTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::UI),
-        test_browser_thread_bundle_(
+      : test_browser_thread_bundle_(
+            base::test::ScopedTaskEnvironment::MainThreadType::UI,
+            base::test::ScopedTaskEnvironment::ExecutionMode::ASYNC,
             content::TestBrowserThreadBundle::REAL_IO_THREAD) {
     chromeos::DBusThreadManager::Initialize();
     fake_cicerone_client_ = static_cast<chromeos::FakeCiceroneClient*>(
@@ -173,7 +172,6 @@
   bool create_container_fails_callback_called_ = false;
 
  private:
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
   content::TestBrowserThreadBundle test_browser_thread_bundle_;
   DISALLOW_COPY_AND_ASSIGN(CrostiniManagerTest);
 };
diff --git a/chrome/browser/chromeos/crostini/crostini_share_path_unittest.cc b/chrome/browser/chromeos/crostini/crostini_share_path_unittest.cc
index 0001a67..db3d4d65 100644
--- a/chrome/browser/chromeos/crostini/crostini_share_path_unittest.cc
+++ b/chrome/browser/chromeos/crostini/crostini_share_path_unittest.cc
@@ -8,7 +8,6 @@
 #include "base/files/file_util.h"
 #include "base/run_loop.h"
 #include "base/test/scoped_feature_list.h"
-#include "base/test/scoped_task_environment.h"
 #include "chrome/browser/chromeos/crostini/crostini_manager.h"
 #include "chrome/browser/chromeos/crostini/crostini_pref_names.h"
 #include "chrome/browser/chromeos/crostini/crostini_util.h"
@@ -118,9 +117,9 @@
   }
 
   CrostiniSharePathTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::UI),
-        test_browser_thread_bundle_(
+      : test_browser_thread_bundle_(
+            base::test::ScopedTaskEnvironment::MainThreadType::UI,
+            base::test::ScopedTaskEnvironment::ExecutionMode::ASYNC,
             content::TestBrowserThreadBundle::REAL_IO_THREAD) {
     chromeos::DBusThreadManager::Initialize();
     fake_concierge_client_ = static_cast<chromeos::FakeConciergeClient*>(
@@ -192,7 +191,6 @@
   chromeos::FakeChromeUserManager user_manager;
 
  private:
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
   content::TestBrowserThreadBundle test_browser_thread_bundle_;
   DISALLOW_COPY_AND_ASSIGN(CrostiniSharePathTest);
 };
diff --git a/chrome/browser/chromeos/oauth2_token_service_delegate_unittest.cc b/chrome/browser/chromeos/oauth2_token_service_delegate_unittest.cc
index 035efd74..e471070 100644
--- a/chrome/browser/chromeos/oauth2_token_service_delegate_unittest.cc
+++ b/chrome/browser/chromeos/oauth2_token_service_delegate_unittest.cc
@@ -13,7 +13,6 @@
 #include "base/macros.h"
 #include "base/memory/scoped_refptr.h"
 #include "base/stl_util.h"
-#include "base/test/scoped_task_environment.h"
 #include "chromeos/account_manager/account_manager.h"
 #include "components/signin/core/browser/account_info.h"
 #include "components/signin/core/browser/account_tracker_service.h"
@@ -110,9 +109,7 @@
 
 class CrOSOAuthDelegateTest : public testing::Test {
  public:
-  CrOSOAuthDelegateTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
+  CrOSOAuthDelegateTest() {}
   ~CrOSOAuthDelegateTest() override = default;
 
  protected:
@@ -128,7 +125,7 @@
     account_manager_.Initialize(tmp_dir_.GetPath(),
                                 client_->GetURLLoaderFactory(),
                                 immediate_callback_runner_);
-    scoped_task_environment_.RunUntilIdle();
+    thread_bundle_.RunUntilIdle();
 
     account_tracker_service_.Initialize(&pref_service_, base::FilePath());
 
@@ -170,9 +167,6 @@
         GetValidTokenResponse("token", 3600));
   }
 
-  // Check base/test/scoped_task_environment.h. This must be the first member /
-  // declared before any member that cares about tasks.
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
   // Needed because
   // |content::GetNetworkConnectionTracker()->AddNetworkConnectionObserver| in
   // |ChromeOSOAuth2TokenServiceDelegate|'s constructor CHECKs that we are
@@ -292,11 +286,11 @@
       AccountManager::AccountKey{account1.gaia, ACCOUNT_TYPE_GAIA}, "token1");
   account_manager_.UpsertToken(
       AccountManager::AccountKey{account2.gaia, ACCOUNT_TYPE_GAIA}, "token2");
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 
   AccountManager account_manager;
   // AccountManager will not be fully initialized until
-  // |scoped_task_environment_.RunUntilIdle()| is called.
+  // |thread_bundle_.RunUntilIdle()| is called.
   account_manager.Initialize(tmp_dir_.GetPath(), client_->GetURLLoaderFactory(),
                              immediate_callback_runner_);
 
@@ -307,7 +301,7 @@
   TokenServiceObserver observer;
   delegate->AddObserver(&observer);
   // Wait until AccountManager is fully initialized.
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 
   // Tests
 
@@ -417,9 +411,9 @@
       delegate_->CreateAccessTokenFetcher(account_info_.account_id,
                                           delegate_->GetURLLoaderFactory(),
                                           &access_token_consumer));
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   fetcher->Start("client_id", "client_secret", scopes);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(0, access_token_consumer.num_access_token_fetch_success_);
   EXPECT_EQ(1, access_token_consumer.num_access_token_fetch_failure_);
   // Expect a positive backoff time.
@@ -431,7 +425,7 @@
       account_info_.account_id, delegate_->GetURLLoaderFactory(),
       &access_token_consumer));
   fetcher->Start("client_id", "client_secret", scopes);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(1, access_token_consumer.num_access_token_fetch_success_);
   EXPECT_EQ(1, access_token_consumer.num_access_token_fetch_failure_);
 }
@@ -454,9 +448,9 @@
       delegate_->CreateAccessTokenFetcher(account_info_.account_id,
                                           delegate_->GetURLLoaderFactory(),
                                           &access_token_consumer));
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   fetcher->Start("client_id", "client_secret", scopes);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(0, access_token_consumer.num_access_token_fetch_success_);
   EXPECT_EQ(1, access_token_consumer.num_access_token_fetch_failure_);
   // Expect a positive backoff time.
@@ -469,7 +463,7 @@
       account_info_.account_id, delegate_->GetURLLoaderFactory(),
       &access_token_consumer));
   fetcher->Start("client_id", "client_secret", scopes);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(1, access_token_consumer.num_access_token_fetch_success_);
   EXPECT_EQ(1, access_token_consumer.num_access_token_fetch_failure_);
 }
diff --git a/chrome/browser/chromeos/policy/app_install_event_logger_unittest.cc b/chrome/browser/chromeos/policy/app_install_event_logger_unittest.cc
index 3717ae0..11cdc8f5 100644
--- a/chrome/browser/chromeos/policy/app_install_event_logger_unittest.cc
+++ b/chrome/browser/chromeos/policy/app_install_event_logger_unittest.cc
@@ -7,7 +7,6 @@
 #include <stdint.h>
 
 #include "base/json/json_writer.h"
-#include "base/test/scoped_task_environment.h"
 #include "base/time/time.h"
 #include "base/values.h"
 #include "chrome/browser/prefs/browser_prefs.h"
@@ -98,7 +97,7 @@
 class AppInstallEventLoggerTest : public testing::Test {
  protected:
   AppInstallEventLoggerTest()
-      : scoped_task_environment_(
+      : browser_thread_bundle_(
             base::test::ScopedTaskEnvironment::MainThreadType::UI,
             base::test::ScopedTaskEnvironment::ExecutionMode::QUEUED) {}
 
@@ -126,7 +125,7 @@
 
   void TearDown() override {
     logger_.reset();
-    scoped_task_environment_.RunUntilIdle();
+    browser_thread_bundle_.RunUntilIdle();
     chromeos::NetworkHandler::Shutdown();
     chromeos::DBusThreadManager::Shutdown();
     chromeos::disks::DiskMountManager::Shutdown();
@@ -163,7 +162,6 @@
     event_.set_event_type(em::AppInstallReportLogEvent::SUCCESS);
   }
 
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
   content::TestBrowserThreadBundle browser_thread_bundle_;
   TestingProfile profile_;
   TestingPrefServiceSimple pref_service_;
@@ -256,7 +254,7 @@
   EXPECT_CALL(*disk_mount_manager_, disks());
   EXPECT_CALL(delegate_,
               Add(std::set<std::string>{kPackageName}, MatchProto(event_)));
-  scoped_task_environment_.RunUntilIdle();
+  browser_thread_bundle_.RunUntilIdle();
 }
 
 // Adds an event without a timestamp, requesting that disk space information be
@@ -288,7 +286,7 @@
   EXPECT_CALL(delegate_, Add(std::set<std::string>{kPackageName},
                              MatchEventExceptTimestamp(event_)))
       .WillOnce(SaveTimestamp<1>(&timestamp));
-  scoped_task_environment_.RunUntilIdle();
+  browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_LE(before, timestamp);
   EXPECT_GE(after, timestamp);
@@ -347,7 +345,7 @@
   EXPECT_CALL(delegate_, Add(std::set<std::string>{kPackageName, kPackageName3},
                              MatchEventExceptTimestamp(event_)));
   EXPECT_CALL(*disk_mount_manager_, disks());
-  scoped_task_environment_.RunUntilIdle();
+  browser_thread_bundle_.RunUntilIdle();
   Mock::VerifyAndClearExpectations(&delegate_);
 
   // To avoid extra logging.
diff --git a/chrome/browser/chromeos/power/auto_screen_brightness/adapter_unittest.cc b/chrome/browser/chromeos/power/auto_screen_brightness/adapter_unittest.cc
index d9d3f39..24b50fe 100644
--- a/chrome/browser/chromeos/power/auto_screen_brightness/adapter_unittest.cc
+++ b/chrome/browser/chromeos/power/auto_screen_brightness/adapter_unittest.cc
@@ -118,9 +118,8 @@
 class AdapterTest : public testing::Test {
  public:
   AdapterTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME),
-        thread_bundle_(content::TestBrowserThreadBundle::PLAIN_MAINLOOP) {
+      : thread_bundle_(
+            base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME) {
     chromeos::DBusThreadManager::GetSetterForTesting()->SetPowerManagerClient(
         std::make_unique<chromeos::FakePowerManagerClient>());
     power_manager::SetBacklightBrightnessRequest request;
@@ -128,7 +127,7 @@
     chromeos::DBusThreadManager::Get()
         ->GetPowerManagerClient()
         ->SetScreenBrightness(request);
-    scoped_task_environment_.RunUntilIdle();
+    thread_bundle_.RunUntilIdle();
 
     chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
         &test_observer_);
@@ -187,8 +186,7 @@
         profile_.get(), &fake_als_reader_, &fake_brightness_monitor_,
         &fake_modeller_, nullptr /* metrics_reporter */,
         chromeos::DBusThreadManager::Get()->GetPowerManagerClient());
-    adapter_->SetTickClockForTesting(
-        scoped_task_environment_.GetMockTickClock());
+    adapter_->SetTickClockForTesting(thread_bundle_.GetMockTickClock());
   }
 
   void Init(AlsReader::AlsInitStatus als_reader_status,
@@ -201,11 +199,10 @@
     fake_brightness_monitor_.set_status(brightness_monitor_status);
     fake_modeller_.InitModellerWithCurves(global_curve, personal_curve);
     SetUpAdapter(params, brightness_set_by_policy);
-    scoped_task_environment_.RunUntilIdle();
+    thread_bundle_.RunUntilIdle();
   }
 
  protected:
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
   content::TestBrowserThreadBundle thread_bundle_;
 
   TestObserver test_observer_;
@@ -286,7 +283,7 @@
 
   fake_als_reader_.set_als_init_status(AlsReader::AlsInitStatus::kSuccess);
   fake_als_reader_.ReportReaderInitialized();
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(adapter_->GetStatusForTesting(), Adapter::Status::kSuccess);
   EXPECT_TRUE(adapter_->GetGlobalCurveForTesting());
   EXPECT_EQ(*adapter_->GetGlobalCurveForTesting(), *global_curve_);
@@ -316,7 +313,7 @@
 
   fake_brightness_monitor_.set_status(BrightnessMonitor::Status::kSuccess);
   fake_brightness_monitor_.ReportBrightnessMonitorInitialized();
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(adapter_->GetStatusForTesting(), Adapter::Status::kSuccess);
   EXPECT_TRUE(adapter_->GetGlobalCurveForTesting());
   EXPECT_EQ(*adapter_->GetGlobalCurveForTesting(), *global_curve_);
@@ -328,7 +325,7 @@
   fake_als_reader_.set_als_init_status(AlsReader::AlsInitStatus::kSuccess);
   fake_brightness_monitor_.set_status(BrightnessMonitor::Status::kSuccess);
   SetUpAdapter(default_params_);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(adapter_->GetStatusForTesting(), Adapter::Status::kInitializing);
 
   fake_modeller_.InitModellerWithCurves(base::nullopt, base::nullopt);
@@ -343,7 +340,7 @@
   fake_als_reader_.set_als_init_status(AlsReader::AlsInitStatus::kSuccess);
   fake_brightness_monitor_.set_status(BrightnessMonitor::Status::kSuccess);
   SetUpAdapter(default_params_);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(adapter_->GetStatusForTesting(), Adapter::Status::kInitializing);
 
   fake_modeller_.InitModellerWithCurves(global_curve_, personal_curve_);
@@ -367,38 +364,38 @@
 
   // Forward by 1sec because in real implementation, |first_als_time_| is zero
   // if there's no ALS reading received.
-  scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(1));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(1));
 
   // Brightness is changed after the 1st ALS reading comes in.
   fake_als_reader_.ReportAmbientLightUpdate(10);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(test_observer_.num_changes(), 1);
 
   // Another ALS value is received in 3 sec, but no brightness update is done.
-  scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(3));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(3));
   fake_als_reader_.ReportAmbientLightUpdate(20);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(test_observer_.num_changes(), 1);
 
   // |params.min_time_between_brightness_changes| has elapsed since we've made
   // the change, but there's no new ALS value, hence no brightness change is
   // triggered.
-  scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(10));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(10));
   EXPECT_EQ(test_observer_.num_changes(), 1);
 
   // A new ALS value triggers a brightness change.
   fake_als_reader_.ReportAmbientLightUpdate(40);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(test_observer_.num_changes(), 2);
 
   // Adapter is disabled after a user manual adjustment.
   fake_brightness_monitor_.ReportUserBrightnessChangeRequested();
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(adapter_->GetStatusForTesting(), Adapter::Status::kDisabled);
 
   // Another user manual adjustment came in.
   fake_brightness_monitor_.ReportUserBrightnessChangeRequested();
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(adapter_->GetStatusForTesting(), Adapter::Status::kDisabled);
 
 }
@@ -415,12 +412,12 @@
 
   // Adapter is disabled after a user manual adjustment.
   fake_brightness_monitor_.ReportUserBrightnessChangeRequested();
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(adapter_->GetStatusForTesting(), Adapter::Status::kDisabled);
 
   // Another user manual adjustment came in.
   fake_brightness_monitor_.ReportUserBrightnessChangeRequested();
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(adapter_->GetStatusForTesting(), Adapter::Status::kDisabled);
 }
 
@@ -435,12 +432,12 @@
   EXPECT_TRUE(adapter_->GetPersonalCurveForTesting());
   EXPECT_EQ(*adapter_->GetPersonalCurveForTesting(), *personal_curve_);
 
-  scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(1));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(1));
 
   // Brightness is changed after the 1st ALS value, and the thresholds are
   // changed.
   fake_als_reader_.ReportAmbientLightUpdate(20);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(test_observer_.num_changes(), 1);
   EXPECT_DOUBLE_EQ(adapter_->GetAverageAmbientForTesting(), 20);
   EXPECT_DOUBLE_EQ(adapter_->GetBrighteningThresholdForTesting(), 22);
@@ -448,7 +445,7 @@
 
   // A 2nd ALS comes in, but average ambient is within the thresholds, hence
   // brightness isn't changed and thresholds aren't updated.
-  scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(20));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(20));
   fake_als_reader_.ReportAmbientLightUpdate(21);
   EXPECT_EQ(1, test_observer_.num_changes());
   EXPECT_DOUBLE_EQ(adapter_->GetAverageAmbientForTesting(), (20 + 21) / 2.0);
@@ -466,7 +463,7 @@
   // A 4th ALS makes average value below the darkening threshold, hence
   // brightness is changed. Thresholds are also changed.
   fake_als_reader_.ReportAmbientLightUpdate(7);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(test_observer_.num_changes(), 2);
   const double expected_average_ambient = (20 + 21 + 15 + 7) / 4.0;
@@ -480,12 +477,12 @@
   // Next check |ambient_light_values_| has capacity
   // |Adapter::kNumberAmbientValuesToTrack|.
   fake_als_reader_.ReportAmbientLightUpdate(8);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_DOUBLE_EQ(adapter_->GetAverageAmbientForTesting(),
                    (20 + 21 + 15 + 7 + 8) / 5.0);
 
   fake_als_reader_.ReportAmbientLightUpdate(9);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 
   EXPECT_DOUBLE_EQ(adapter_->GetAverageAmbientForTesting(),
                    (21 + 15 + 7 + 8 + 9) / 5.0);
@@ -505,25 +502,25 @@
   EXPECT_TRUE(adapter_->GetPersonalCurveForTesting());
   EXPECT_EQ(*adapter_->GetPersonalCurveForTesting(), *personal_curve_);
 
-  scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(1));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(1));
 
   // Brightness is changed after the 1st ALS reading comes in.
   fake_als_reader_.ReportAmbientLightUpdate(10);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(test_observer_.num_changes(), 1);
 
   // Another ALS value is received in 1 sec, brightness is changed because it
   // exceeds immediate transition threshold.
-  scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(1));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(1));
   fake_als_reader_.ReportAmbientLightUpdate(17);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(test_observer_.num_changes(), 2);
 
   // Another ALS value is received in 2 sec, brightness is changed because it
   // exceeds immediate transition threshold.
-  scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(2));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(2));
   fake_als_reader_.ReportAmbientLightUpdate(1);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(test_observer_.num_changes(), 3);
 }
 
@@ -536,20 +533,20 @@
 
   EXPECT_EQ(adapter_->GetStatusForTesting(), Adapter::Status::kSuccess);
 
-  scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(1));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(1));
 
   // 1st ALS reading doesn't trigger a brightness change.
   fake_als_reader_.ReportAmbientLightUpdate(10);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(test_observer_.num_changes(), 0);
 
-  scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(5));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(5));
   EXPECT_EQ(test_observer_.num_changes(), 0);
 
   // 2nd ALS comes in so that we have |kAmbientLightShortHorizonSeconds| of
   // data, hence brightness is changed.
   fake_als_reader_.ReportAmbientLightUpdate(20);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(test_observer_.num_changes(), 1);
 }
 
@@ -565,17 +562,17 @@
 
   // ALS comes in but no brightness change is triggered because there is no
   // personal curve.
-  scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(1));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(1));
   fake_als_reader_.ReportAmbientLightUpdate(10);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(test_observer_.num_changes(), 0);
 
   // Personal curve is received.
-  scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(1));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(1));
   fake_modeller_.ReportModelTrained(*personal_curve_);
   EXPECT_EQ(test_observer_.num_changes(), 0);
   fake_als_reader_.ReportAmbientLightUpdate(20);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(test_observer_.num_changes(), 1);
   EXPECT_EQ(test_observer_.GetCause(),
             power_manager::BacklightBrightnessChange_Cause_MODEL);
@@ -598,9 +595,9 @@
 
   EXPECT_EQ(adapter_->GetStatusForTesting(), Adapter::Status::kSuccess);
 
-  scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(1));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(1));
   fake_als_reader_.ReportAmbientLightUpdate(10);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(test_observer_.num_changes(), 1);
   EXPECT_DOUBLE_EQ(adapter_->GetAverageAmbientForTesting(), 10);
 
@@ -610,10 +607,10 @@
                    expected_brightness_percent1);
 
   // A new personal curve is received but adapter still uses the global curve.
-  scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(20));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(20));
   fake_modeller_.ReportModelTrained(*personal_curve_);
   fake_als_reader_.ReportAmbientLightUpdate(20);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(test_observer_.num_changes(), 2);
   EXPECT_EQ(test_observer_.GetCause(),
             power_manager::BacklightBrightnessChange_Cause_MODEL);
@@ -634,9 +631,9 @@
 
   EXPECT_EQ(adapter_->GetStatusForTesting(), Adapter::Status::kSuccess);
 
-  scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(1));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(1));
   fake_als_reader_.ReportAmbientLightUpdate(10);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(test_observer_.num_changes(), 0);
 }
 
@@ -653,11 +650,11 @@
   EXPECT_TRUE(adapter_->GetGlobalCurveForTesting());
   EXPECT_TRUE(adapter_->GetPersonalCurveForTesting());
 
-  scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(1));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(1));
 
   // Brightness not changed after the 1st ALS reading comes in.
   fake_als_reader_.ReportAmbientLightUpdate(10);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(test_observer_.num_changes(), 0);
 }
 
diff --git a/chrome/browser/chromeos/power/auto_screen_brightness/modeller_impl_unittest.cc b/chrome/browser/chromeos/power/auto_screen_brightness/modeller_impl_unittest.cc
index d71dea1..87a40ab 100644
--- a/chrome/browser/chromeos/power/auto_screen_brightness/modeller_impl_unittest.cc
+++ b/chrome/browser/chromeos/power/auto_screen_brightness/modeller_impl_unittest.cc
@@ -175,9 +175,8 @@
 class ModellerImplTest : public testing::Test {
  public:
   ModellerImplTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME),
-        thread_bundle_(content::TestBrowserThreadBundle::PLAIN_MAINLOOP) {
+      : thread_bundle_(
+            base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME) {
     CHECK(temp_dir_.CreateUniqueTempDir());
     TestingProfile::Builder profile_builder;
     profile_builder.SetProfileName("testuser@gmail.com");
@@ -197,7 +196,7 @@
         std::make_unique<FakeTrainer>(is_trainer_configured,
                                       is_personal_curve_valid),
         base::SequencedTaskRunnerHandle::Get(),
-        scoped_task_environment_.GetMockTickClock());
+        thread_bundle_.GetMockTickClock());
 
     test_observer_ = std::make_unique<TestObserver>();
     modeller_->AddObserver(test_observer_.get());
@@ -210,7 +209,7 @@
     fake_als_reader_.set_als_init_status(als_reader_status);
     fake_brightness_monitor_.set_status(brightness_monitor_status);
     SetUpModeller(is_trainer_configured, is_personal_curve_valid);
-    scoped_task_environment_.RunUntilIdle();
+    thread_bundle_.RunUntilIdle();
   }
 
  protected:
@@ -227,7 +226,6 @@
         << " to " << curve_path;
   }
 
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
   content::TestBrowserThreadBundle thread_bundle_;
   base::HistogramTester histogram_tester_;
 
@@ -277,7 +275,7 @@
 
   fake_als_reader_.set_als_init_status(AlsReader::AlsInitStatus::kDisabled);
   fake_als_reader_.ReportReaderInitialized();
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 
   test_observer_->CheckStatus(true /* is_model_initialized */,
                               base::nullopt /* global_curve */,
@@ -295,7 +293,7 @@
 
   fake_als_reader_.set_als_init_status(AlsReader::AlsInitStatus::kSuccess);
   fake_als_reader_.ReportReaderInitialized();
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 
   test_observer_->CheckStatus(true /* is_model_initialized */,
                               modeller_->GetGlobalCurveForTesting(),
@@ -330,7 +328,7 @@
 
   fake_brightness_monitor_.set_status(BrightnessMonitor::Status::kSuccess);
   fake_brightness_monitor_.ReportBrightnessMonitorInitialized();
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 
   test_observer_->CheckStatus(true /* is_model_initialized */,
                               modeller_->GetGlobalCurveForTesting(),
@@ -354,7 +352,7 @@
 
   WriteCurveToFile(curve);
 
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 
   Init(AlsReader::AlsInitStatus::kSuccess, BrightnessMonitor::Status::kSuccess);
 
@@ -374,7 +372,7 @@
 
   WriteCurveToFile(curve);
 
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 
   Init(AlsReader::AlsInitStatus::kSuccess, BrightnessMonitor::Status::kSuccess,
        true /* is_trainer_configured */, false /* is_personal_curve_valid */);
@@ -429,10 +427,8 @@
   for (size_t i = 0; i < modeller_->GetMaxTrainingDataPointsForTesting() - 1;
        ++i) {
     EXPECT_EQ(i, modeller_->NumberTrainingDataPointsForTesting());
-    scoped_task_environment_.FastForwardBy(
-        base::TimeDelta::FromMilliseconds(1));
-    const base::TimeTicks now =
-        scoped_task_environment_.GetMockTickClock()->NowTicks();
+    thread_bundle_.FastForwardBy(base::TimeDelta::FromMilliseconds(1));
+    const base::TimeTicks now = thread_bundle_.GetMockTickClock()->NowTicks();
     const int lux = i * 20;
     fake_als_reader_.ReportAmbientLightUpdate(lux);
     const double brightness_old = 10.0 + i;
@@ -448,16 +444,15 @@
             modeller_->NumberTrainingDataPointsForTesting());
 
   // Add one more data point to trigger the training early.
-  scoped_task_environment_.FastForwardBy(base::TimeDelta::FromMilliseconds(1));
-  const base::TimeTicks now =
-      scoped_task_environment_.GetMockTickClock()->NowTicks();
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromMilliseconds(1));
+  const base::TimeTicks now = thread_bundle_.GetMockTickClock()->NowTicks();
   const double brightness_old = 85;
   const double brightness_new = 95;
   modeller_->OnUserBrightnessChanged(brightness_old, brightness_new);
   expected_data.push_back({brightness_old, brightness_new,
                            ConvertToLog(modeller_->AverageAmbientForTesting()),
                            now});
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(0u, modeller_->NumberTrainingDataPointsForTesting());
 
@@ -482,10 +477,8 @@
   std::vector<TrainingDataPoint> expected_data;
   for (size_t i = 0; i < 10; ++i) {
     EXPECT_EQ(i, modeller_->NumberTrainingDataPointsForTesting());
-    scoped_task_environment_.FastForwardBy(
-        base::TimeDelta::FromMilliseconds(1));
-    const base::TimeTicks now =
-        scoped_task_environment_.GetMockTickClock()->NowTicks();
+    thread_bundle_.FastForwardBy(base::TimeDelta::FromMilliseconds(1));
+    const base::TimeTicks now = thread_bundle_.GetMockTickClock()->NowTicks();
     const int lux = i * 20;
     fake_als_reader_.ReportAmbientLightUpdate(lux);
     const double brightness_old = 10.0 + i;
@@ -498,30 +491,24 @@
 
   EXPECT_EQ(modeller_->NumberTrainingDataPointsForTesting(), 10u);
 
-  scoped_task_environment_.FastForwardBy(
-      modeller_->GetTrainingDelayForTesting() / 2);
+  thread_bundle_.FastForwardBy(modeller_->GetTrainingDelayForTesting() / 2);
   // A user activity is received, timer should be reset.
   const ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(0, 0),
                                    gfx::Point(0, 0), base::TimeTicks(), 0, 0);
   modeller_->OnUserActivity(&mouse_event);
 
-  scoped_task_environment_.FastForwardBy(
-      modeller_->GetTrainingDelayForTesting() / 3);
+  thread_bundle_.FastForwardBy(modeller_->GetTrainingDelayForTesting() / 3);
   EXPECT_EQ(modeller_->NumberTrainingDataPointsForTesting(), 10u);
 
   // Another user event is received.
   modeller_->OnUserActivity(&mouse_event);
 
   // After |training_delay_|/2, no training has started.
-  scoped_task_environment_.FastForwardBy(
-      modeller_->GetTrainingDelayForTesting() / 2);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.FastForwardBy(modeller_->GetTrainingDelayForTesting() / 2);
   EXPECT_EQ(modeller_->NumberTrainingDataPointsForTesting(), 10u);
 
   // After another |training_delay_|/2, training is scheduled.
-  scoped_task_environment_.FastForwardBy(
-      modeller_->GetTrainingDelayForTesting() / 2);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.FastForwardBy(modeller_->GetTrainingDelayForTesting() / 2);
 
   EXPECT_EQ(0u, modeller_->NumberTrainingDataPointsForTesting());
   const base::Optional<MonotoneCubicSpline>& result_curve =
@@ -598,7 +585,7 @@
   modeller_->OnUserActivity(&mouse_event);
 
   modeller_->OnUserBrightnessChanged(10, 20);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_EQ(0u, modeller_->NumberTrainingDataPointsForTesting());
   EXPECT_TRUE(test_observer_->trained_curve_received());
 }
diff --git a/chrome/browser/chromeos/system_logs/single_debug_daemon_log_source_unittest.cc b/chrome/browser/chromeos/system_logs/single_debug_daemon_log_source_unittest.cc
index 3a884e6..e377101b 100644
--- a/chrome/browser/chromeos/system_logs/single_debug_daemon_log_source_unittest.cc
+++ b/chrome/browser/chromeos/system_logs/single_debug_daemon_log_source_unittest.cc
@@ -10,7 +10,6 @@
 #include "base/bind.h"
 #include "base/macros.h"
 #include "base/run_loop.h"
-#include "base/test/scoped_task_environment.h"
 #include "chromeos/dbus/dbus_thread_manager.h"
 #include "chromeos/dbus/fake_debug_daemon_client.h"
 #include "content/public/test/test_browser_thread_bundle.h"
@@ -22,10 +21,7 @@
 
 class SingleDebugDaemonLogSourceTest : public ::testing::Test {
  public:
-  SingleDebugDaemonLogSourceTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::UI),
-        num_callback_calls_(0) {}
+  SingleDebugDaemonLogSourceTest() : num_callback_calls_(0) {}
 
   void SetUp() override {
     // Since no debug daemon will be available during a unit test, use
@@ -57,11 +53,7 @@
     response_ = *response;
   }
 
-  // For running scheduled tasks.
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
-
-  // Creates the necessary browser threads. Defined after
-  // |scoped_task_environment_| in order to use the MessageLoop it created.
+  // Creates the necessary browser threads.
   content::TestBrowserThreadBundle browser_thread_bundle_;
 
   // Used to verify that OnFetchComplete was called the correct number of times.
diff --git a/chrome/browser/chromeos/system_logs/single_log_file_log_source_unittest.cc b/chrome/browser/chromeos/system_logs/single_log_file_log_source_unittest.cc
index 1d2eb89..60c1a44 100644
--- a/chrome/browser/chromeos/system_logs/single_log_file_log_source_unittest.cc
+++ b/chrome/browser/chromeos/system_logs/single_log_file_log_source_unittest.cc
@@ -14,7 +14,6 @@
 #include "base/macros.h"
 #include "base/run_loop.h"
 #include "base/strings/string_split.h"
-#include "base/test/scoped_task_environment.h"
 #include "base/time/time.h"
 #include "content/public/test/test_browser_thread_bundle.h"
 #include "testing/gtest/include/gtest/gtest.h"
@@ -23,10 +22,7 @@
 
 class SingleLogFileLogSourceTest : public ::testing::Test {
  public:
-  SingleLogFileLogSourceTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::UI),
-        num_callback_calls_(0) {
+  SingleLogFileLogSourceTest() : num_callback_calls_(0) {
     InitializeTestLogDir();
   }
 
@@ -93,7 +89,7 @@
   void FetchFromSource() {
     source_->Fetch(base::Bind(&SingleLogFileLogSourceTest::OnFileRead,
                               base::Unretained(this)));
-    scoped_task_environment_.RunUntilIdle();
+    browser_thread_bundle_.RunUntilIdle();
   }
 
   // Callback for fetching logs from |source_|. Overwrites the previous stored
@@ -116,11 +112,7 @@
   const base::FilePath& log_file_path() const { return log_file_path_; }
 
  private:
-  // For running scheduled tasks.
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
-
-  // Creates the necessary browser threads. Defined after
-  // |scoped_task_environment_| in order to use the MessageLoop it created.
+  // Creates the necessary browser threads.
   content::TestBrowserThreadBundle browser_thread_bundle_;
 
   // Unit under test.
diff --git a/chrome/browser/extensions/api/image_writer_private/operation_unittest.cc b/chrome/browser/extensions/api/image_writer_private/operation_unittest.cc
index 2d3d0c3..4f9e77a 100644
--- a/chrome/browser/extensions/api/image_writer_private/operation_unittest.cc
+++ b/chrome/browser/extensions/api/image_writer_private/operation_unittest.cc
@@ -119,7 +119,7 @@
 
     // Cancel() will ensure we Shutdown() FakeImageWriterClient.
     operation_->Cancel();
-    scoped_task_environment_.RunUntilIdle();
+    thread_bundle_.RunUntilIdle();
 
     ImageWriterUnitTestBase::TearDown();
   }
diff --git a/chrome/browser/extensions/api/image_writer_private/removable_storage_provider_chromeos_unittest.cc b/chrome/browser/extensions/api/image_writer_private/removable_storage_provider_chromeos_unittest.cc
index bbbea6d..91fd7c8 100644
--- a/chrome/browser/extensions/api/image_writer_private/removable_storage_provider_chromeos_unittest.cc
+++ b/chrome/browser/extensions/api/image_writer_private/removable_storage_provider_chromeos_unittest.cc
@@ -6,7 +6,6 @@
 
 #include "base/bind.h"
 #include "base/run_loop.h"
-#include "base/test/scoped_task_environment.h"
 #include "chrome/browser/extensions/api/image_writer_private/removable_storage_provider.h"
 #include "chromeos/disks/mock_disk_mount_manager.h"
 #include "content/public/test/test_browser_thread_bundle.h"
@@ -35,9 +34,7 @@
 
 class RemovableStorageProviderChromeOsUnitTest : public testing::Test {
  public:
-  RemovableStorageProviderChromeOsUnitTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
+  RemovableStorageProviderChromeOsUnitTest() {}
   void SetUp() override {
     disk_mount_manager_mock_ = new MockDiskMountManager();
     DiskMountManager::InitializeForTesting(disk_mount_manager_mock_);
@@ -107,12 +104,9 @@
     EXPECT_EQ(capacity, device->capacity);
   }
 
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
+  content::TestBrowserThreadBundle thread_bundle_;
   MockDiskMountManager* disk_mount_manager_mock_;
   scoped_refptr<StorageDeviceList> devices_;
-
- private:
-  content::TestBrowserThreadBundle thread_bundle_;
 };
 
 }  // namespace
@@ -131,7 +125,7 @@
       base::Bind(&RemovableStorageProviderChromeOsUnitTest::DevicesCallback,
                  base::Unretained(this)));
 
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 
   ASSERT_EQ(2U, devices_->data.size());
 
@@ -152,7 +146,7 @@
       base::Bind(&RemovableStorageProviderChromeOsUnitTest::DevicesCallback,
                  base::Unretained(this)));
 
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 
   ASSERT_EQ(2U, devices_->data.size());
 
diff --git a/chrome/browser/extensions/api/image_writer_private/test_utils.cc b/chrome/browser/extensions/api/image_writer_private/test_utils.cc
index f6d4020..6415a69c 100644
--- a/chrome/browser/extensions/api/image_writer_private/test_utils.cc
+++ b/chrome/browser/extensions/api/image_writer_private/test_utils.cc
@@ -315,9 +315,9 @@
 }
 
 ImageWriterUnitTestBase::ImageWriterUnitTestBase()
-    : scoped_task_environment_(
-          base::test::ScopedTaskEnvironment::MainThreadType::UI),
-      thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD) {}
+    : thread_bundle_(base::test::ScopedTaskEnvironment::MainThreadType::UI,
+                     base::test::ScopedTaskEnvironment::ExecutionMode::ASYNC,
+                     content::TestBrowserThreadBundle::REAL_IO_THREAD) {}
 ImageWriterUnitTestBase::~ImageWriterUnitTestBase() {
 }
 
diff --git a/chrome/browser/extensions/api/image_writer_private/test_utils.h b/chrome/browser/extensions/api/image_writer_private/test_utils.h
index aa03979..ab9f77a 100644
--- a/chrome/browser/extensions/api/image_writer_private/test_utils.h
+++ b/chrome/browser/extensions/api/image_writer_private/test_utils.h
@@ -204,9 +204,6 @@
 
   ImageWriterTestUtils test_utils_;
 
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
-
- private:
   content::TestBrowserThreadBundle thread_bundle_;
 };
 
diff --git a/chrome/browser/extensions/external_registry_loader_win_unittest.cc b/chrome/browser/extensions/external_registry_loader_win_unittest.cc
index 6c11456..40143e6a 100644
--- a/chrome/browser/extensions/external_registry_loader_win_unittest.cc
+++ b/chrome/browser/extensions/external_registry_loader_win_unittest.cc
@@ -8,7 +8,6 @@
 #include "base/macros.h"
 #include "base/memory/ref_counted.h"
 #include "base/run_loop.h"
-#include "base/test/scoped_task_environment.h"
 #include "base/values.h"
 #include "content/public/test/test_browser_thread_bundle.h"
 #include "extensions/common/value_builder.h"
@@ -67,16 +66,13 @@
 
 class ExternalRegistryLoaderUnittest : public testing::Test {
  public:
-  ExternalRegistryLoaderUnittest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
+  ExternalRegistryLoaderUnittest() {}
   ~ExternalRegistryLoaderUnittest() override {}
 
  protected:
-  void RunUntilIdle() { scoped_task_environment_.RunUntilIdle(); }
+  void RunUntilIdle() { thread_bundle_.RunUntilIdle(); }
 
  private:
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
   content::TestBrowserThreadBundle thread_bundle_;
 
   DISALLOW_COPY_AND_ASSIGN(ExternalRegistryLoaderUnittest);
diff --git a/chrome/browser/google/google_search_domain_mixing_metrics_emitter_unittest.cc b/chrome/browser/google/google_search_domain_mixing_metrics_emitter_unittest.cc
index 322fbc9..4674699 100644
--- a/chrome/browser/google/google_search_domain_mixing_metrics_emitter_unittest.cc
+++ b/chrome/browser/google/google_search_domain_mixing_metrics_emitter_unittest.cc
@@ -6,7 +6,6 @@
 
 #include "base/files/scoped_temp_dir.h"
 #include "base/test/metrics/histogram_tester.h"
-#include "base/test/scoped_task_environment.h"
 #include "base/test/simple_test_clock.h"
 #include "base/timer/mock_timer.h"
 #include "components/history/core/browser/history_service.h"
@@ -20,9 +19,8 @@
 class GoogleSearchDomainMixingMetricsEmitterTest : public testing::Test {
  public:
   GoogleSearchDomainMixingMetricsEmitterTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME),
-        thread_bundle_(content::TestBrowserThreadBundle::PLAIN_MAINLOOP) {}
+      : thread_bundle_(
+            base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME) {}
 
   void SetUp() override {
     GoogleSearchDomainMixingMetricsEmitter::RegisterProfilePrefs(
@@ -44,7 +42,7 @@
     emitter_->SetTimerForTesting(std::move(timer));
 
     emitter_->SetUIThreadTaskRunnerForTesting(
-        scoped_task_environment_.GetMainThreadTaskRunner());
+        thread_bundle_.GetMainThreadTaskRunner());
   }
 
   // Sets up test history such that domain mixing metrics for the day starting
@@ -79,7 +77,6 @@
   }
 
  protected:
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
   content::TestBrowserThreadBundle thread_bundle_;
   TestingPrefServiceSimple prefs_;
   base::ScopedTempDir history_dir_;
@@ -107,7 +104,7 @@
   // The next metric calculation should be scheduled at 4am on the next day,
   // i.e. 16 hours from |now|.
   EXPECT_EQ(base::TimeDelta::FromHours(16),
-            scoped_task_environment_.NextMainThreadPendingTaskDelay());
+            thread_bundle_.NextMainThreadPendingTaskDelay());
 }
 
 TEST_F(GoogleSearchDomainMixingMetricsEmitterTest, Waits10SecondsAfterStart) {
@@ -121,7 +118,7 @@
   emitter_->Start();
 
   EXPECT_EQ(base::TimeDelta::FromSeconds(10),
-            scoped_task_environment_.NextMainThreadPendingTaskDelay());
+            thread_bundle_.NextMainThreadPendingTaskDelay());
 }
 
 TEST_F(GoogleSearchDomainMixingMetricsEmitterTest, WaitsUntilNeeded) {
@@ -136,7 +133,7 @@
   emitter_->Start();
 
   EXPECT_EQ(base::TimeDelta::FromHours(23),
-            scoped_task_environment_.NextMainThreadPendingTaskDelay());
+            thread_bundle_.NextMainThreadPendingTaskDelay());
 }
 
 TEST_F(GoogleSearchDomainMixingMetricsEmitterTest, EmitsMetricsOnStart) {
@@ -156,7 +153,7 @@
   emitter_->Start();
 
   base::HistogramTester tester;
-  scoped_task_environment_.FastForwardUntilNoTasksRemain();
+  thread_bundle_.FastForwardUntilNoTasksRemain();
   BlockUntilHistoryProcessesPendingRequests(history_service_.get());
   VerifyHistograms(tester);
 }
@@ -178,7 +175,7 @@
   emitter_->Start();
 
   // Wait for the first run to be done.
-  scoped_task_environment_.FastForwardUntilNoTasksRemain();
+  thread_bundle_.FastForwardUntilNoTasksRemain();
   BlockUntilHistoryProcessesPendingRequests(history_service_.get());
 
   // last_metrics_time is expected to have been incremented.
@@ -199,7 +196,7 @@
   timer_->Fire();
 
   base::HistogramTester tester;
-  scoped_task_environment_.FastForwardUntilNoTasksRemain();
+  thread_bundle_.FastForwardUntilNoTasksRemain();
   BlockUntilHistoryProcessesPendingRequests(history_service_.get());
   VerifyHistograms(tester);
 
diff --git a/chrome/browser/media/router/discovery/discovery_network_monitor_metric_observer_unittest.cc b/chrome/browser/media/router/discovery/discovery_network_monitor_metric_observer_unittest.cc
index 34b47d1..23ace4c 100644
--- a/chrome/browser/media/router/discovery/discovery_network_monitor_metric_observer_unittest.cc
+++ b/chrome/browser/media/router/discovery/discovery_network_monitor_metric_observer_unittest.cc
@@ -61,13 +61,12 @@
 class DiscoveryNetworkMonitorMetricObserverTest : public ::testing::Test {
  public:
   DiscoveryNetworkMonitorMetricObserverTest()
-      : scoped_task_environment_(
+      : thread_bundle_(
             base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME),
-        thread_bundle_(content::TestBrowserThreadBundle::PLAIN_MAINLOOP),
-        start_ticks_(scoped_task_environment_.NowTicks()),
+        start_ticks_(thread_bundle_.NowTicks()),
         metrics_(std::make_unique<MockMetrics>()),
         mock_metrics_(metrics_.get()),
-        metric_observer_(scoped_task_environment_.GetMockTickClock(),
+        metric_observer_(thread_bundle_.GetMockTickClock(),
                          std::move(metrics_)) {
     SetConnectionType(network::mojom::ConnectionType::CONNECTION_NONE);
   }
@@ -78,7 +77,6 @@
         connection_type);
   }
 
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
   content::TestBrowserThreadBundle thread_bundle_;
   base::TimeDelta time_advance_ = base::TimeDelta::FromMilliseconds(10);
   const base::TimeTicks start_ticks_;
@@ -166,8 +164,7 @@
   metric_observer_.OnNetworksChanged(
       DiscoveryNetworkMonitor::kNetworkIdDisconnected);
 
-  scoped_task_environment_.FastForwardUntilNoTasksRemain();
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.FastForwardUntilNoTasksRemain();
 }
 
 TEST_F(DiscoveryNetworkMonitorMetricObserverTest,
@@ -191,8 +188,7 @@
       RecordConnectionType(DiscoveryNetworkMonitorConnectionType::kEthernet));
   metric_observer_.OnNetworksChanged("network2");
 
-  scoped_task_environment_.FastForwardUntilNoTasksRemain();
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.FastForwardUntilNoTasksRemain();
 }
 
 TEST_F(DiscoveryNetworkMonitorMetricObserverTest,
@@ -209,8 +205,7 @@
       RecordConnectionType(DiscoveryNetworkMonitorConnectionType::kEthernet));
   metric_observer_.OnNetworksChanged("network2");
 
-  scoped_task_environment_.FastForwardUntilNoTasksRemain();
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.FastForwardUntilNoTasksRemain();
 }
 
 TEST_F(DiscoveryNetworkMonitorMetricObserverTest,
@@ -222,12 +217,12 @@
   SetConnectionType(network::mojom::ConnectionType::CONNECTION_ETHERNET);
   metric_observer_.OnNetworksChanged("network1");
 
-  scoped_task_environment_.FastForwardBy(time_advance_);
+  thread_bundle_.FastForwardBy(time_advance_);
   SetConnectionType(network::mojom::ConnectionType::CONNECTION_NONE);
   metric_observer_.OnNetworksChanged(
       DiscoveryNetworkMonitor::kNetworkIdDisconnected);
 
-  scoped_task_environment_.FastForwardBy(time_advance_);
+  thread_bundle_.FastForwardBy(time_advance_);
   SetConnectionType(network::mojom::ConnectionType::CONNECTION_ETHERNET);
   EXPECT_CALL(*mock_metrics_,
               RecordTimeBetweenNetworkChangeEvents(
@@ -237,8 +232,7 @@
       RecordConnectionType(DiscoveryNetworkMonitorConnectionType::kEthernet));
   metric_observer_.OnNetworksChanged("network2");
 
-  scoped_task_environment_.FastForwardUntilNoTasksRemain();
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.FastForwardUntilNoTasksRemain();
 }
 
 TEST_F(DiscoveryNetworkMonitorMetricObserverTest,
@@ -250,12 +244,12 @@
   SetConnectionType(network::mojom::ConnectionType::CONNECTION_ETHERNET);
   metric_observer_.OnNetworksChanged("network1");
 
-  scoped_task_environment_.FastForwardBy(time_advance_);
+  thread_bundle_.FastForwardBy(time_advance_);
   SetConnectionType(network::mojom::ConnectionType::CONNECTION_NONE);
   metric_observer_.OnNetworksChanged(
       DiscoveryNetworkMonitor::kNetworkIdDisconnected);
 
-  scoped_task_environment_.FastForwardBy(time_advance_);
+  thread_bundle_.FastForwardBy(time_advance_);
   EXPECT_CALL(*mock_metrics_,
               RecordTimeBetweenNetworkChangeEvents(
                   (start_ticks_ + time_advance_) - start_ticks_));
@@ -263,8 +257,7 @@
               RecordConnectionType(
                   DiscoveryNetworkMonitorConnectionType::kDisconnected));
 
-  scoped_task_environment_.FastForwardUntilNoTasksRemain();
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.FastForwardUntilNoTasksRemain();
 }
 
 TEST_F(DiscoveryNetworkMonitorMetricObserverTest,
@@ -276,13 +269,13 @@
   SetConnectionType(network::mojom::ConnectionType::CONNECTION_ETHERNET);
   metric_observer_.OnNetworksChanged("network1");
 
-  scoped_task_environment_.FastForwardBy(time_advance_);
-  const auto disconnect_ticks = scoped_task_environment_.NowTicks();
+  thread_bundle_.FastForwardBy(time_advance_);
+  const auto disconnect_ticks = thread_bundle_.NowTicks();
   SetConnectionType(network::mojom::ConnectionType::CONNECTION_NONE);
   metric_observer_.OnNetworksChanged(
       DiscoveryNetworkMonitor::kNetworkIdDisconnected);
 
-  scoped_task_environment_.FastForwardBy(time_advance_);
+  thread_bundle_.FastForwardBy(time_advance_);
   EXPECT_CALL(*mock_metrics_,
               RecordTimeBetweenNetworkChangeEvents(
                   (start_ticks_ + time_advance_) - start_ticks_));
@@ -290,11 +283,10 @@
               RecordConnectionType(
                   DiscoveryNetworkMonitorConnectionType::kDisconnected));
 
-  scoped_task_environment_.FastForwardUntilNoTasksRemain();
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.FastForwardUntilNoTasksRemain();
 
-  scoped_task_environment_.FastForwardBy(time_advance_);
-  const auto second_ethernet_ticks = scoped_task_environment_.NowTicks();
+  thread_bundle_.FastForwardBy(time_advance_);
+  const auto second_ethernet_ticks = thread_bundle_.NowTicks();
   EXPECT_CALL(*mock_metrics_, RecordTimeBetweenNetworkChangeEvents(
                                   second_ethernet_ticks - disconnect_ticks));
   EXPECT_CALL(
diff --git a/chrome/browser/media/router/issue_manager_unittest.cc b/chrome/browser/media/router/issue_manager_unittest.cc
index 23e5fd7..87c8f74 100644
--- a/chrome/browser/media/router/issue_manager_unittest.cc
+++ b/chrome/browser/media/router/issue_manager_unittest.cc
@@ -31,14 +31,12 @@
 class IssueManagerTest : public ::testing::Test {
  protected:
   IssueManagerTest()
-      : environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME),
-        thread_bundle_(content::TestBrowserThreadBundle::PLAIN_MAINLOOP) {
-    manager_.set_task_runner_for_test(environment_.GetMainThreadTaskRunner());
+      : thread_bundle_(
+            base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME) {
+    manager_.set_task_runner_for_test(thread_bundle_.GetMainThreadTaskRunner());
   }
   ~IssueManagerTest() override {}
 
-  base::test::ScopedTaskEnvironment environment_;
   content::TestBrowserThreadBundle thread_bundle_;
   IssueManager manager_;
 };
@@ -112,8 +110,8 @@
   EXPECT_CALL(observer, OnIssuesCleared()).Times(1);
   base::TimeDelta timeout = IssueManager::GetAutoDismissTimeout(issue_info1);
   EXPECT_FALSE(timeout.is_zero());
-  EXPECT_TRUE(environment_.MainThreadHasPendingTask());
-  environment_.FastForwardBy(timeout);
+  EXPECT_TRUE(thread_bundle_.MainThreadHasPendingTask());
+  thread_bundle_.FastForwardBy(timeout);
 
   EXPECT_CALL(observer, OnIssue(_)).Times(1);
   IssueInfo issue_info2 = CreateTestIssue(IssueInfo::Severity::WARNING);
@@ -122,9 +120,9 @@
   EXPECT_CALL(observer, OnIssuesCleared()).Times(1);
   timeout = IssueManager::GetAutoDismissTimeout(issue_info2);
   EXPECT_FALSE(timeout.is_zero());
-  EXPECT_TRUE(environment_.MainThreadHasPendingTask());
-  environment_.FastForwardBy(timeout);
-  EXPECT_FALSE(environment_.MainThreadHasPendingTask());
+  EXPECT_TRUE(thread_bundle_.MainThreadHasPendingTask());
+  thread_bundle_.FastForwardBy(timeout);
+  EXPECT_FALSE(thread_bundle_.MainThreadHasPendingTask());
 }
 
 TEST_F(IssueManagerTest, IssueAutoDismissNoopsIfAlreadyCleared) {
@@ -138,13 +136,13 @@
   ASSERT_TRUE(testing::Mock::VerifyAndClearExpectations(&observer));
 
   EXPECT_CALL(observer, OnIssuesCleared()).Times(1);
-  EXPECT_TRUE(environment_.MainThreadHasPendingTask());
+  EXPECT_TRUE(thread_bundle_.MainThreadHasPendingTask());
   manager_.ClearIssue(issue1.id());
 
   EXPECT_CALL(observer, OnIssuesCleared()).Times(0);
   base::TimeDelta timeout = IssueManager::GetAutoDismissTimeout(issue_info1);
   EXPECT_FALSE(timeout.is_zero());
-  EXPECT_FALSE(environment_.MainThreadHasPendingTask());
+  EXPECT_FALSE(thread_bundle_.MainThreadHasPendingTask());
 }
 
 TEST_F(IssueManagerTest, BlockingIssuesDoNotGetAutoDismissed) {
@@ -160,7 +158,7 @@
 
   base::TimeDelta timeout = IssueManager::GetAutoDismissTimeout(issue_info1);
   EXPECT_TRUE(timeout.is_zero());
-  EXPECT_FALSE(environment_.MainThreadHasPendingTask());
+  EXPECT_FALSE(thread_bundle_.MainThreadHasPendingTask());
 
   // FATAL issues are always blocking.
   IssueInfo issue_info2 = CreateTestIssue(IssueInfo::Severity::FATAL);
@@ -168,7 +166,7 @@
 
   timeout = IssueManager::GetAutoDismissTimeout(issue_info2);
   EXPECT_TRUE(timeout.is_zero());
-  EXPECT_FALSE(environment_.MainThreadHasPendingTask());
+  EXPECT_FALSE(thread_bundle_.MainThreadHasPendingTask());
 }
 
 TEST_F(IssueManagerTest, ClearNonBlockingIssues) {
diff --git a/chrome/browser/media/webrtc/native_desktop_media_list_unittest.cc b/chrome/browser/media/webrtc/native_desktop_media_list_unittest.cc
index bb892a6..e54a139 100644
--- a/chrome/browser/media/webrtc/native_desktop_media_list_unittest.cc
+++ b/chrome/browser/media/webrtc/native_desktop_media_list_unittest.cc
@@ -19,7 +19,6 @@
 #include "base/threading/thread_task_runner_handle.h"
 #include "chrome/browser/media/webrtc/desktop_media_list_observer.h"
 #include "chrome/test/views/chrome_views_test_base.h"
-#include "content/public/test/test_browser_thread_bundle.h"
 #include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h"
@@ -317,8 +316,6 @@
   }
 
  protected:
-  content::TestBrowserThreadBundle test_browser_thread_bundle_;
-
   // Must be listed before |model_|, so it's destroyed last.
   MockObserver observer_;
 
diff --git a/chrome/browser/media_galleries/mac/mtp_device_delegate_impl_mac_unittest.mm b/chrome/browser/media_galleries/mac/mtp_device_delegate_impl_mac_unittest.mm
index 0fa1af0..14eae35 100644
--- a/chrome/browser/media_galleries/mac/mtp_device_delegate_impl_mac_unittest.mm
+++ b/chrome/browser/media_galleries/mac/mtp_device_delegate_impl_mac_unittest.mm
@@ -14,7 +14,6 @@
 #include "base/macros.h"
 #include "base/strings/sys_string_conversions.h"
 #include "base/synchronization/waitable_event.h"
-#include "base/test/scoped_task_environment.h"
 #include "chrome/browser/media_galleries/mac/mtp_device_delegate_impl_mac.h"
 #include "components/storage_monitor/image_capture_device_manager.h"
 #include "components/storage_monitor/test_storage_monitor.h"
@@ -147,11 +146,7 @@
 
 class MTPDeviceDelegateImplMacTest : public testing::Test {
  public:
-  MTPDeviceDelegateImplMacTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::UI),
-        camera_(NULL),
-        delegate_(NULL) {}
+  MTPDeviceDelegateImplMacTest() : camera_(NULL), delegate_(NULL) {}
 
   void SetUp() override {
     storage_monitor::TestStorageMonitor* monitor =
@@ -233,7 +228,7 @@
       base::Bind(&MTPDeviceDelegateImplMacTest::OnError,
                  base::Unretained(this),
                  &wait));
-    scoped_task_environment_.RunUntilIdle();
+    test_browser_thread_bundle_.RunUntilIdle();
     EXPECT_TRUE(wait.IsSignaled());
     *info = info_;
     return error_;
@@ -248,7 +243,7 @@
                             base::Unretained(this), &wait),
         base::Bind(&MTPDeviceDelegateImplMacTest::OnError,
                    base::Unretained(this), &wait));
-    scoped_task_environment_.RunUntilIdle();
+    test_browser_thread_bundle_.RunUntilIdle();
     wait.Wait();
     return error_;
   }
@@ -266,13 +261,12 @@
         base::Bind(&MTPDeviceDelegateImplMacTest::OnError,
                    base::Unretained(this),
                    &wait));
-    scoped_task_environment_.RunUntilIdle();
+    test_browser_thread_bundle_.RunUntilIdle();
     wait.Wait();
     return error_;
   }
 
  protected:
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
   content::TestBrowserThreadBundle test_browser_thread_bundle_;
 
   base::ScopedTempDir temp_dir_;
@@ -341,7 +335,7 @@
   // Signal the delegate that no files are coming.
   delegate_->NoMoreItems();
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
   wait.Wait();
 
   EXPECT_EQ(base::File::FILE_OK, error_);
diff --git a/chrome/browser/media_galleries/media_galleries_preferences_unittest.cc b/chrome/browser/media_galleries/media_galleries_preferences_unittest.cc
index 194e7e88..797f419f 100644
--- a/chrome/browser/media_galleries/media_galleries_preferences_unittest.cc
+++ b/chrome/browser/media_galleries/media_galleries_preferences_unittest.cc
@@ -18,7 +18,6 @@
 #include "base/path_service.h"
 #include "base/run_loop.h"
 #include "base/strings/utf_string_conversions.h"
-#include "base/test/scoped_task_environment.h"
 #include "base/values.h"
 #include "build/build_config.h"
 #include "chrome/browser/extensions/test_extension_system.h"
@@ -111,10 +110,7 @@
       DeviceIdPrefIdsMap;
 
   MediaGalleriesPreferencesTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::UI),
-        profile_(new TestingProfile()),
-        default_galleries_count_(0) {}
+      : profile_(new TestingProfile()), default_galleries_count_(0) {}
 
   ~MediaGalleriesPreferencesTest() override {}
 
@@ -357,8 +353,6 @@
   MediaGalleriesPrefInfoMap expected_galleries_;
 
  private:
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
-
   // Needed for extension service & friends to work.
   content::TestBrowserThreadBundle thread_bundle_;
 
diff --git a/chrome/browser/notifications/notification_platform_bridge_win_unittest.cc b/chrome/browser/notifications/notification_platform_bridge_win_unittest.cc
index bd540fb5..4c1acf3 100644
--- a/chrome/browser/notifications/notification_platform_bridge_win_unittest.cc
+++ b/chrome/browser/notifications/notification_platform_bridge_win_unittest.cc
@@ -18,7 +18,6 @@
 #include "base/strings/string_number_conversions.h"
 #include "base/strings/stringprintf.h"
 #include "base/strings/utf_string_conversions.h"
-#include "base/test/scoped_task_environment.h"
 #include "base/win/scoped_com_initializer.h"
 #include "base/win/scoped_hstring.h"
 #include "base/win/windows_version.h"
@@ -50,9 +49,8 @@
 class NotificationPlatformBridgeWinTest : public testing::Test {
  public:
   NotificationPlatformBridgeWinTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME),
-        thread_bundle_(content::TestBrowserThreadBundle::PLAIN_MAINLOOP) {}
+      : thread_bundle_(
+            base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME) {}
 
   ~NotificationPlatformBridgeWinTest() override = default;
 
@@ -94,7 +92,6 @@
     return toast2;
   }
 
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
   content::TestBrowserThreadBundle thread_bundle_;
 
  private:
diff --git a/chrome/browser/password_manager/native_backend_gnome_x_unittest.cc b/chrome/browser/password_manager/native_backend_gnome_x_unittest.cc
index 0036cd8..5272869 100644
--- a/chrome/browser/password_manager/native_backend_gnome_x_unittest.cc
+++ b/chrome/browser/password_manager/native_backend_gnome_x_unittest.cc
@@ -16,7 +16,6 @@
 #include "base/strings/stringprintf.h"
 #include "base/strings/utf_string_conversions.h"
 #include "base/task_runner_util.h"
-#include "base/test/scoped_task_environment.h"
 #include "base/time/time.h"
 #include "chrome/browser/password_manager/native_backend_gnome_x.h"
 #include "chrome/test/base/testing_profile.h"
@@ -355,9 +354,7 @@
     SYNCED,
   };
 
-  NativeBackendGnomeTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
+  NativeBackendGnomeTest() {}
 
   void SetUp() override {
     ASSERT_TRUE(MockGnomeKeyringLoader::LoadMockGnomeKeyring());
@@ -514,7 +511,7 @@
                    target_form, &form_list),
         base::Bind(&CheckTrue));
 
-    scoped_task_environment_.RunUntilIdle();
+    test_browser_thread_bundle_.RunUntilIdle();
 
     EXPECT_EQ(1u, mock_keyring_items.size());
     if (mock_keyring_items.size() > 0)
@@ -559,7 +556,7 @@
                    m_facebook_lookup, &form_list),
         base::Bind(&CheckTrue));
 
-    scoped_task_environment_.RunUntilIdle();
+    test_browser_thread_bundle_.RunUntilIdle();
 
     EXPECT_EQ(1u, mock_keyring_items.size());
     EXPECT_EQ(1u, form_list.size());
@@ -574,7 +571,7 @@
         base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
                        base::Unretained(&backend), m_facebook));
 
-    scoped_task_environment_.RunUntilIdle();
+    test_browser_thread_bundle_.RunUntilIdle();
 
     EXPECT_EQ(2u, mock_keyring_items.size());
 
@@ -610,7 +607,7 @@
         break;
     }
 
-    scoped_task_environment_.RunUntilIdle();
+    test_browser_thread_bundle_.RunUntilIdle();
 
     EXPECT_EQ(2u, mock_keyring_items.size());
 
@@ -621,7 +618,7 @@
                    m_facebook_lookup, &form_list),
         base::Bind(&CheckTrue));
 
-    scoped_task_environment_.RunUntilIdle();
+    test_browser_thread_bundle_.RunUntilIdle();
 
     // There should be two results -- the exact one, and the PSL-matched one.
     EXPECT_EQ(2u, form_list.size());
@@ -640,7 +637,7 @@
                    PasswordStore::FormDigest(form_facebook_), &form_list),
         base::Bind(&CheckTrue));
 
-    scoped_task_environment_.RunUntilIdle();
+    test_browser_thread_bundle_.RunUntilIdle();
 
     // There should be two results -- the exact one, and the PSL-matched one.
     EXPECT_EQ(2u, form_list.size());
@@ -714,7 +711,7 @@
         base::Bind(&CheckPasswordChangesWithResult, &expected_changes,
                    &changes));
 
-    scoped_task_environment_.RunUntilIdle();
+    test_browser_thread_bundle_.RunUntilIdle();
 
     EXPECT_EQ(1u, mock_keyring_items.size());
     if (mock_keyring_items.size() > 0)
@@ -731,18 +728,11 @@
         base::Bind(&CheckPasswordChangesWithResult, &expected_changes,
                    &changes));
 
-    scoped_task_environment_.RunUntilIdle();
+    test_browser_thread_bundle_.RunUntilIdle();
 
     EXPECT_EQ(0u, mock_keyring_items.size());
   }
 
-  // Create the ScopedTaskEnvirnment first to ensure that
-  // CreateSequencedTaskRunnerWithTraits will work correctly. Then create also
-  // TestBrowserThreadBundle so that BrowserThread::UI has an associated
-  // TaskRunner. The order is important because the bundle can detect that the
-  // MessageLoop used by the environment exists and reuse it, but not vice
-  // versa.
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
   content::TestBrowserThreadBundle test_browser_thread_bundle_;
 
   // Provide some test forms to avoid having to set them up in each test.
@@ -765,7 +755,7 @@
           PasswordStoreChangeList(
               1, PasswordStoreChange(PasswordStoreChange::ADD, form_google_))));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(1u, mock_keyring_items.size());
   if (mock_keyring_items.size() > 0)
@@ -788,7 +778,7 @@
                  base::Unretained(&backend), &form_list),
       base::Bind(&CheckTrue));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   // Quick check that we got something back.
   EXPECT_EQ(1u, form_list.size());
@@ -898,7 +888,7 @@
       base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
                      base::Unretained(&backend), form_google_));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   PasswordForm new_form_google(form_google_);
   new_form_google.times_used = 1;
@@ -918,7 +908,7 @@
                  new_form_google, &changes),
       base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(1u, mock_keyring_items.size());
   if (mock_keyring_items.size() > 0)
@@ -934,7 +924,7 @@
       base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
                      base::Unretained(&backend), form_google_));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(1u, mock_keyring_items.size());
   if (mock_keyring_items.size() > 0)
@@ -949,7 +939,7 @@
                  form_google_, &changes),
       base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(0u, mock_keyring_items.size());
 }
@@ -964,7 +954,7 @@
       base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
                      base::Unretained(&backend), form_google_));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(1u, mock_keyring_items.size());
   if (mock_keyring_items.size() > 0)
@@ -982,7 +972,7 @@
                  form_google_, &changes),
       base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(0u, mock_keyring_items.size());
 }
@@ -997,7 +987,7 @@
       base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
                      base::Unretained(&backend), form_google_));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(1u, mock_keyring_items.size());
   if (mock_keyring_items.size() > 0)
@@ -1020,7 +1010,7 @@
                  base::Unretained(&backend), &form_list),
       base::Bind(&CheckTrue));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   // Quick check that we got something back.
   EXPECT_EQ(1u, form_list.size());
@@ -1040,7 +1030,7 @@
       base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
                      base::Unretained(&backend), form_google_));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(1u, mock_keyring_items.size());
   if (mock_keyring_items.size() > 0)
@@ -1055,7 +1045,7 @@
       base::Bind(&CheckPasswordChangesWithResult,
                  base::Owned(new PasswordStoreChangeList), &changes));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(1u, mock_keyring_items.size());
   if (mock_keyring_items.size() > 0)
@@ -1072,7 +1062,7 @@
       base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
                      base::Unretained(&backend), form_google_));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(1u, mock_keyring_items.size());
   if (mock_keyring_items.size() > 0)
@@ -1087,7 +1077,7 @@
                  form_google_, &changes),
       base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(1u, mock_keyring_items.size());
   if (mock_keyring_items.size() > 0)
@@ -1121,7 +1111,7 @@
                  form_google_),
       base::Bind(&CheckPasswordChanges, changes));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(1u, mock_keyring_items.size());
   if (mock_keyring_items.size() > 0)
@@ -1157,7 +1147,7 @@
                  observed_android_form, &form_list),
       base::Bind(&CheckTrue));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(1u, form_list.size());
   EXPECT_EQ(saved_android_form, *form_list[0]);
@@ -1186,7 +1176,7 @@
       base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
                      base::Unretained(&backend), form_facebook_));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(2u, mock_keyring_items.size());
   for (const auto& item : mock_keyring_items)
@@ -1211,7 +1201,7 @@
           &changes),
       base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(2u, mock_keyring_items.size());
   CheckStringAttribute(
@@ -1242,7 +1232,7 @@
       base::BindOnce(base::IgnoreResult(&NativeBackendGnome::AddLogin),
                      base::Unretained(&backend), form_google_));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   // Read the raw value back. Change the |unique_string| to
   // |unique_string_replacement| so the forms become unique.
@@ -1263,7 +1253,7 @@
                  base::Unretained(&backend), &form_list),
       base::Bind(&CheckTrue));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(1u, form_list.size());
   EXPECT_EQ(form_google_, *form_list[0]);
@@ -1294,7 +1284,7 @@
                  &form_list),
       base::Bind(&CheckTrue));
 
-  scoped_task_environment_.RunUntilIdle();
+  test_browser_thread_bundle_.RunUntilIdle();
 
   EXPECT_EQ(2u, form_list.size());
   EXPECT_THAT(form_list, UnorderedElementsAre(Pointee(form_google_),
diff --git a/chrome/browser/profiling_host/background_profiling_triggers_unittest.cc b/chrome/browser/profiling_host/background_profiling_triggers_unittest.cc
index 9c7e4680..333a25a 100644
--- a/chrome/browser/profiling_host/background_profiling_triggers_unittest.cc
+++ b/chrome/browser/profiling_host/background_profiling_triggers_unittest.cc
@@ -8,7 +8,6 @@
 #include <utility>
 #include <vector>
 
-#include "base/test/scoped_task_environment.h"
 #include "base/time/time.h"
 #include "build/build_config.h"
 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
@@ -98,9 +97,7 @@
 class BackgroundProfilingTriggersTest : public testing::Test {
  public:
   BackgroundProfilingTriggersTest()
-      : scoped_task_envrionment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::UI),
-        testing_profile_manager_(TestingBrowserProcess::GetGlobal()),
+      : testing_profile_manager_(TestingBrowserProcess::GetGlobal()),
         triggers_(&host_),
         is_metrics_enabled_(true) {}
 
@@ -118,8 +115,7 @@
   }
 
  protected:
-  base::test::ScopedTaskEnvironment scoped_task_envrionment_;
-  content::TestBrowserThreadBundle thread_bundle;
+  content::TestBrowserThreadBundle thread_bundle_;
   TestingProfileManager testing_profile_manager_;
 
   ProfilingProcessHost host_;
diff --git a/chrome/browser/ui/passwords/password_manager_presenter_unittest.cc b/chrome/browser/ui/passwords/password_manager_presenter_unittest.cc
index 3734188..7436fea 100644
--- a/chrome/browser/ui/passwords/password_manager_presenter_unittest.cc
+++ b/chrome/browser/ui/passwords/password_manager_presenter_unittest.cc
@@ -11,7 +11,6 @@
 #include "base/macros.h"
 #include "base/memory/scoped_refptr.h"
 #include "base/strings/utf_string_conversions.h"
-#include "base/test/scoped_task_environment.h"
 #include "build/build_config.h"
 #include "chrome/browser/password_manager/password_store_factory.h"
 #include "chrome/browser/ui/passwords/password_ui_view.h"
@@ -52,7 +51,7 @@
 
   ~PasswordManagerPresenterTest() override {
     store_->ShutdownOnUIThread();
-    scoped_task_environment_.RunUntilIdle();
+    thread_bundle_.RunUntilIdle();
   }
 
   void AddPasswordEntry(const GURL& origin,
@@ -76,15 +75,13 @@
 
   void UpdatePasswordLists() {
     mock_controller_.GetPasswordManagerPresenter()->UpdatePasswordLists();
-    scoped_task_environment_.RunUntilIdle();
+    thread_bundle_.RunUntilIdle();
   }
 
   MockPasswordUIView& GetUIController() { return mock_controller_; }
 
  private:
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
-  content::TestBrowserThreadBundle thread_bundle_{
-      content::TestBrowserThreadBundle::PLAIN_MAINLOOP};
+  content::TestBrowserThreadBundle thread_bundle_;
   TestingProfile profile_;
   MockPasswordUIView mock_controller_{&profile_};
   scoped_refptr<password_manager::PasswordStore> store_;
diff --git a/chrome/browser/ui/views/infobars/infobar_view_unittest.cc b/chrome/browser/ui/views/infobars/infobar_view_unittest.cc
index 57e7937..5e0fac3 100644
--- a/chrome/browser/ui/views/infobars/infobar_view_unittest.cc
+++ b/chrome/browser/ui/views/infobars/infobar_view_unittest.cc
@@ -8,7 +8,6 @@
 #include "chrome/browser/ui/views/infobars/infobar_container_view.h"
 #include "chrome/test/base/testing_profile.h"
 #include "chrome/test/views/chrome_views_test_base.h"
-#include "content/public/test/test_browser_thread_bundle.h"
 #include "content/public/test/test_web_contents_factory.h"
 
 class TestInfoBarDelegate : public infobars::InfoBarDelegate {
@@ -44,7 +43,6 @@
   }
 
  private:
-  content::TestBrowserThreadBundle thread_bundle_;
   TestingProfile profile_;
   content::TestWebContentsFactory web_contents_factory_;
   content::WebContents* web_contents_;
diff --git a/chrome/browser/ui/views/media_router/cast_dialog_no_sinks_view_unittest.cc b/chrome/browser/ui/views/media_router/cast_dialog_no_sinks_view_unittest.cc
index 587d95c..25bdb82 100644
--- a/chrome/browser/ui/views/media_router/cast_dialog_no_sinks_view_unittest.cc
+++ b/chrome/browser/ui/views/media_router/cast_dialog_no_sinks_view_unittest.cc
@@ -9,7 +9,6 @@
 #include "base/run_loop.h"
 #include "base/time/time.h"
 #include "chrome/test/views/chrome_views_test_base.h"
-#include "content/public/test/test_browser_thread_bundle.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace media_router {
@@ -33,7 +32,6 @@
   }
 
  private:
-  content::TestBrowserThreadBundle test_thread_bundle_;
   std::unique_ptr<CastDialogNoSinksView> no_sinks_view_;
 
   DISALLOW_COPY_AND_ASSIGN(CastDialogNoSinksViewTest);
diff --git a/chrome/browser/ui/views/media_router/cast_dialog_view_unittest.cc b/chrome/browser/ui/views/media_router/cast_dialog_view_unittest.cc
index e06f545..820b6f5 100644
--- a/chrome/browser/ui/views/media_router/cast_dialog_view_unittest.cc
+++ b/chrome/browser/ui/views/media_router/cast_dialog_view_unittest.cc
@@ -19,7 +19,6 @@
 #include "chrome/browser/ui/views/media_router/cast_dialog_sink_button.h"
 #include "chrome/grit/generated_resources.h"
 #include "chrome/test/views/chrome_views_test_base.h"
-#include "content/public/test/test_browser_thread_bundle.h"
 #include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "ui/base/l10n/l10n_util.h"
@@ -141,7 +140,6 @@
     return dialog_->sources_menu_runner_for_test();
   }
 
-  content::TestBrowserThreadBundle test_thread_bundle_;
   std::unique_ptr<views::Widget> anchor_widget_;
   MockCastDialogController controller_;
   CastDialogView* dialog_ = nullptr;
diff --git a/chrome/browser/ui/views/media_router/cast_toolbar_button_unittest.cc b/chrome/browser/ui/views/media_router/cast_toolbar_button_unittest.cc
index f4562f53..5f0ed1b2 100644
--- a/chrome/browser/ui/views/media_router/cast_toolbar_button_unittest.cc
+++ b/chrome/browser/ui/views/media_router/cast_toolbar_button_unittest.cc
@@ -17,7 +17,6 @@
 #include "chrome/test/base/testing_profile.h"
 #include "chrome/test/views/chrome_views_test_base.h"
 #include "components/vector_icons/vector_icons.h"
-#include "content/public/test/test_browser_thread_bundle.h"
 #include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "ui/events/base_event_utils.h"
@@ -98,7 +97,6 @@
     return gfx::Image(button_->GetImage(views::Button::STATE_NORMAL));
   }
 
-  content::TestBrowserThreadBundle thread_bundle_;
   std::unique_ptr<BrowserWindow> window_;
   std::unique_ptr<Browser> browser_;
   std::unique_ptr<CastToolbarButton> button_;
diff --git a/chrome/browser/ui/views/media_router/cloud_services_dialog_view_unittest.cc b/chrome/browser/ui/views/media_router/cloud_services_dialog_view_unittest.cc
index fd7ba75..29255df 100644
--- a/chrome/browser/ui/views/media_router/cloud_services_dialog_view_unittest.cc
+++ b/chrome/browser/ui/views/media_router/cloud_services_dialog_view_unittest.cc
@@ -10,7 +10,6 @@
 #include "chrome/test/base/test_browser_window.h"
 #include "chrome/test/base/testing_profile.h"
 #include "chrome/test/views/chrome_views_test_base.h"
-#include "content/public/test/test_browser_thread_bundle.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "ui/views/widget/widget.h"
 
@@ -65,7 +64,6 @@
                          prefs::kMediaRouterCloudServicesPrefSet));
   }
 
-  content::TestBrowserThreadBundle thread_bundle_;
   std::unique_ptr<BrowserWindow> window_;
   std::unique_ptr<Browser> browser_;
   std::unique_ptr<views::Widget> anchor_widget_;
diff --git a/chrome/browser/ui/views/omnibox/omnibox_result_view_unittest.cc b/chrome/browser/ui/views/omnibox/omnibox_result_view_unittest.cc
index 53b073f..0bd716f 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_result_view_unittest.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_result_view_unittest.cc
@@ -11,7 +11,6 @@
 #include "chrome/test/views/chrome_views_test_base.h"
 #include "components/omnibox/browser/omnibox_edit_model.h"
 #include "components/omnibox/browser/test_omnibox_client.h"
-#include "content/public/test/test_browser_thread_bundle.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "ui/accessibility/ax_node_data.h"
 #include "ui/events/event.h"
@@ -93,8 +92,6 @@
   OmniboxResultView* result_view() { return result_view_; }
 
  private:
-  content::TestBrowserThreadBundle test_browser_thread_bundle_;
-
   std::unique_ptr<OmniboxEditModel> edit_model_;
   std::unique_ptr<TestOmniboxPopupContentsView> popup_view_;
   OmniboxResultView* result_view_;
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views_unittest.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views_unittest.cc
index 2943ef3..8161fe4e 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views_unittest.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views_unittest.cc
@@ -27,7 +27,6 @@
 #include "components/omnibox/browser/omnibox_edit_model.h"
 #include "components/omnibox/browser/omnibox_field_trial.h"
 #include "components/omnibox/browser/test_location_bar_model.h"
-#include "content/public/test/test_browser_thread_bundle.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "third_party/metrics_proto/omnibox_event.pb.h"
 #include "ui/base/ime/input_method.h"
@@ -235,7 +234,6 @@
   }
 
  private:
-  content::TestBrowserThreadBundle thread_bundle_;
   TestingProfile profile_;
   TemplateURLServiceFactoryTestUtil util_;
   CommandUpdaterImpl command_updater_;
diff --git a/chrome/browser/ui/views/toolbar/toolbar_action_view_unittest.cc b/chrome/browser/ui/views/toolbar/toolbar_action_view_unittest.cc
index 76ccb01..ff27520 100644
--- a/chrome/browser/ui/views/toolbar/toolbar_action_view_unittest.cc
+++ b/chrome/browser/ui/views/toolbar/toolbar_action_view_unittest.cc
@@ -13,7 +13,6 @@
 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
 #include "chrome/test/base/testing_profile.h"
 #include "chrome/test/views/chrome_views_test_base.h"
-#include "content/public/test/test_browser_thread_bundle.h"
 #include "content/public/test/test_web_contents_factory.h"
 #include "ui/accessibility/ax_node_data.h"
 #include "ui/events/test/event_generator.h"
@@ -120,9 +119,6 @@
   views::Widget* widget() { return widget_; }
 
  private:
-  // Web contents need a UI thread and a TaskScheduler.
-  content::TestBrowserThreadBundle test_browser_thread_bundle_;
-
   // The widget managed by this test.
   views::Widget* widget_;
 
diff --git a/chrome/browser/ui/views/toolbar/toolbar_button_views_unittest.cc b/chrome/browser/ui/views/toolbar/toolbar_button_views_unittest.cc
index f1f71e2..2b5f47e 100644
--- a/chrome/browser/ui/views/toolbar/toolbar_button_views_unittest.cc
+++ b/chrome/browser/ui/views/toolbar/toolbar_button_views_unittest.cc
@@ -90,8 +90,6 @@
   ToolbarButtonViewsTest() {}
 
  private:
-  content::TestBrowserThreadBundle browser_thread_bundle_;
-
   DISALLOW_COPY_AND_ASSIGN(ToolbarButtonViewsTest);
 };
 
diff --git a/chrome/browser/ui/webui/about_ui_unittest.cc b/chrome/browser/ui/webui/about_ui_unittest.cc
index 73b4632..425b35c4 100644
--- a/chrome/browser/ui/webui/about_ui_unittest.cc
+++ b/chrome/browser/ui/webui/about_ui_unittest.cc
@@ -17,7 +17,6 @@
 #include "base/strings/string_piece.h"
 #include "base/strings/string_util.h"
 #include "base/task/post_task.h"
-#include "base/test/scoped_task_environment.h"
 #include "chrome/common/url_constants.h"
 #include "chrome/common/webui_url_constants.h"
 #include "chrome/test/base/scoped_browser_locale.h"
@@ -65,9 +64,7 @@
 // Base class for ChromeOS offline terms tests.
 class ChromeOSTermsTest : public testing::Test {
  protected:
-  ChromeOSTermsTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
+  ChromeOSTermsTest() {}
   ~ChromeOSTermsTest() override = default;
 
   void SetUp() override {
@@ -126,14 +123,13 @@
         request_url, std::move(wc_getter),
         base::BindRepeating(&TestDataReceiver::OnDataReceived,
                             base::Unretained(data_receiver)));
-    scoped_task_environment_.RunUntilIdle();
+    test_browser_thread_bundle_.RunUntilIdle();
   }
 
  private:
   base::ScopedTempDir root_dir_;
   base::FilePath arc_tos_dir_;
 
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
   content::TestBrowserThreadBundle test_browser_thread_bundle_;
 
   chromeos::system::ScopedFakeStatisticsProvider statistics_provider_;
diff --git a/chrome/browser/vr/speech_recognizer_unittest.cc b/chrome/browser/vr/speech_recognizer_unittest.cc
index 60613b1a..6a1b657 100644
--- a/chrome/browser/vr/speech_recognizer_unittest.cc
+++ b/chrome/browser/vr/speech_recognizer_unittest.cc
@@ -19,7 +19,6 @@
 #include "content/public/browser/speech_recognition_manager.h"
 #include "content/public/browser/speech_recognition_session_config.h"
 #include "content/public/browser/speech_recognition_session_context.h"
-#include "content/public/test/test_browser_thread_bundle.h"
 #include "services/network/public/cpp/shared_url_loader_factory.h"
 #include "services/network/test/test_url_loader_factory.h"
 #include "testing/gmock/include/gmock/gmock.h"
@@ -271,7 +270,6 @@
   }
 
  protected:
-  content::TestBrowserThreadBundle thread_bundle_;
   std::unique_ptr<FakeSpeechRecognitionManager>
       fake_speech_recognition_manager_;
   std::unique_ptr<MockBrowserUiInterface> ui_;
diff --git a/chrome/browser/vr/test/vr_test_suite.cc b/chrome/browser/vr/test/vr_test_suite.cc
index 6e95bee..351725a 100644
--- a/chrome/browser/vr/test/vr_test_suite.cc
+++ b/chrome/browser/vr/test/vr_test_suite.cc
@@ -8,8 +8,8 @@
 
 #include "base/files/file_util.h"
 #include "base/path_service.h"
-#include "base/test/scoped_task_environment.h"
 #include "build/build_config.h"
+#include "content/public/test/test_browser_thread_bundle.h"
 #include "mojo/core/embedder/embedder.h"
 #include "ui/base/material_design/material_design_controller.h"
 #include "ui/base/resource/resource_bundle.h"
@@ -24,9 +24,7 @@
 void VrTestSuite::Initialize() {
   base::TestSuite::Initialize();
 
-  scoped_task_environment_ =
-      std::make_unique<base::test::ScopedTaskEnvironment>(
-          base::test::ScopedTaskEnvironment::MainThreadType::UI);
+  thread_bundle_ = std::make_unique<content::TestBrowserThreadBundle>();
 
   mojo::core::Init();
 
diff --git a/chrome/browser/vr/test/vr_test_suite.h b/chrome/browser/vr/test/vr_test_suite.h
index 20662ed..e447f1c 100644
--- a/chrome/browser/vr/test/vr_test_suite.h
+++ b/chrome/browser/vr/test/vr_test_suite.h
@@ -7,11 +7,9 @@
 
 #include "base/test/test_suite.h"
 
-namespace base {
-namespace test {
-class ScopedTaskEnvironment;
-}  // namespace test
-}  // namespace base
+namespace content {
+class TestBrowserThreadBundle;
+}  // namespace content
 
 namespace vr {
 
@@ -25,7 +23,7 @@
   void Shutdown() override;
 
  private:
-  std::unique_ptr<base::test::ScopedTaskEnvironment> scoped_task_environment_;
+  std::unique_ptr<content::TestBrowserThreadBundle> thread_bundle_;
 
   DISALLOW_COPY_AND_ASSIGN(VrTestSuite);
 };
diff --git a/chrome/test/views/chrome_views_test_base.cc b/chrome/test/views/chrome_views_test_base.cc
index bdb29a46..e378e6b 100644
--- a/chrome/test/views/chrome_views_test_base.cc
+++ b/chrome/test/views/chrome_views_test_base.cc
@@ -5,8 +5,11 @@
 #include "chrome/test/views/chrome_views_test_base.h"
 
 #include "chrome/test/views/chrome_test_views_delegate.h"
+#include "content/public/test/test_browser_thread_bundle.h"
 
-ChromeViewsTestBase::ChromeViewsTestBase() {}
+ChromeViewsTestBase::ChromeViewsTestBase()
+    : views::ViewsTestBase(
+          std::make_unique<content::TestBrowserThreadBundle>()) {}
 
 ChromeViewsTestBase::~ChromeViewsTestBase() {}
 
diff --git a/components/cast_channel/cast_message_handler_unittest.cc b/components/cast_channel/cast_message_handler_unittest.cc
index f047e8c..42528e2 100644
--- a/components/cast_channel/cast_message_handler_unittest.cc
+++ b/components/cast_channel/cast_message_handler_unittest.cc
@@ -7,7 +7,6 @@
 #include "base/json/json_reader.h"
 #include "base/run_loop.h"
 #include "base/strings/stringprintf.h"
-#include "base/test/scoped_task_environment.h"
 #include "base/test/test_simple_task_runner.h"
 #include "components/cast_channel/cast_test_util.h"
 #include "content/public/test/test_browser_thread_bundle.h"
@@ -55,9 +54,8 @@
 class CastMessageHandlerTest : public testing::Test {
  public:
   CastMessageHandlerTest()
-      : environment_(
+      : thread_bundle_(
             base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME),
-        thread_bundle_(content::TestBrowserThreadBundle::PLAIN_MAINLOOP),
         cast_socket_service_(new base::TestSimpleTaskRunner()),
         handler_(&cast_socket_service_,
                  /* connector */ nullptr,
@@ -99,7 +97,6 @@
   }
 
  protected:
-  base::test::ScopedTaskEnvironment environment_;
   content::TestBrowserThreadBundle thread_bundle_;
   std::unique_ptr<base::RunLoop> run_loop_;
   MockCastSocketService cast_socket_service_;
@@ -229,7 +226,7 @@
                      base::Unretained(this)));
   EXPECT_CALL(*this, DoOnAppAvailability("ABCDEFAB",
                                          GetAppAvailabilityResult::kUnknown));
-  environment_.FastForwardBy(base::TimeDelta::FromSeconds(5));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(5));
 }
 
 TEST_F(CastMessageHandlerTest, AppAvailabilitySentOnlyOnceWhilePending) {
@@ -276,7 +273,7 @@
   })");
   OnMessage(response);
   // Wait for message to be parsed and handled.
-  environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 
   // Re-open virtual connection should cause message to be sent.
   EXPECT_CALL(*cast_socket_.mock_transport(), SendMessage(_, _));
@@ -344,7 +341,7 @@
             GetMessageType(virtual_connection_request));
   EXPECT_EQ(CastMessageType::kLaunch, GetMessageType(launch_session_request));
 
-  environment_.FastForwardBy(base::TimeDelta::FromSeconds(30));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(30));
   EXPECT_EQ(1, session_launch_response_count_);
 }
 
diff --git a/components/safe_browsing/db/whitelist_checker_client_unittest.cc b/components/safe_browsing/db/whitelist_checker_client_unittest.cc
index f2299cb..1ef5d18 100644
--- a/components/safe_browsing/db/whitelist_checker_client_unittest.cc
+++ b/components/safe_browsing/db/whitelist_checker_client_unittest.cc
@@ -47,9 +47,8 @@
 class WhitelistCheckerClientTest : public testing::Test {
  public:
   WhitelistCheckerClientTest()
-      : environment_(
+      : thread_bundle_(
             base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME),
-        thread_bundle_(content::TestBrowserThreadBundle::PLAIN_MAINLOOP),
         target_url_("http://foo.bar") {}
 
   void SetUp() override {
@@ -63,11 +62,10 @@
     // Verify no callback is remaining.
     // TODO(nparker): We should somehow EXPECT that no entry is remaining,
     // rather than just invoking it.
-    environment_.FastForwardUntilNoTasksRemain();
+    thread_bundle_.FastForwardUntilNoTasksRemain();
   }
 
  protected:
-  base::test::ScopedTaskEnvironment environment_;
   content::TestBrowserThreadBundle thread_bundle_;
 
   GURL target_url_;
@@ -118,11 +116,11 @@
   MockBoolCallback callback;
   WhitelistCheckerClient::StartCheckCsdWhitelist(database_manager_, target_url_,
                                                  callback.Get());
-  environment_.FastForwardBy(base::TimeDelta::FromSeconds(1));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(1));
   // No callback yet.
 
   EXPECT_CALL(callback, Run(true /* is_whitelisted */));
-  environment_.FastForwardBy(base::TimeDelta::FromSeconds(5));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(5));
 }
 
 }  // namespace safe_browsing
diff --git a/components/storage_monitor/image_capture_device_manager_unittest.mm b/components/storage_monitor/image_capture_device_manager_unittest.mm
index c21da1c..02e1726 100644
--- a/components/storage_monitor/image_capture_device_manager_unittest.mm
+++ b/components/storage_monitor/image_capture_device_manager_unittest.mm
@@ -11,7 +11,6 @@
 #include "base/mac/foundation_util.h"
 #include "base/mac/sdk_forward_declarations.h"
 #include "base/memory/weak_ptr.h"
-#include "base/test/scoped_task_environment.h"
 #include "components/storage_monitor/image_capture_device.h"
 #include "components/storage_monitor/image_capture_device_manager.h"
 #include "components/storage_monitor/test_storage_monitor.h"
@@ -239,9 +238,7 @@
 
 class ImageCaptureDeviceManagerTest : public testing::Test {
  public:
-  ImageCaptureDeviceManagerTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
+  ImageCaptureDeviceManagerTest() {}
 
   void SetUp() override { monitor_ = TestStorageMonitor::CreateAndInstall(); }
 
@@ -266,10 +263,9 @@
                   moreGoing:NO];
   }
 
-  void RunUntilIdle() { scoped_task_environment_.RunUntilIdle(); }
+  void RunUntilIdle() { thread_bundle_.RunUntilIdle(); }
 
  protected:
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
   content::TestBrowserThreadBundle thread_bundle_;
   TestStorageMonitor* monitor_;
   TestCameraListener listener_;
diff --git a/components/storage_monitor/media_storage_util_unittest.cc b/components/storage_monitor/media_storage_util_unittest.cc
index ba7386d..1ede541 100644
--- a/components/storage_monitor/media_storage_util_unittest.cc
+++ b/components/storage_monitor/media_storage_util_unittest.cc
@@ -10,7 +10,6 @@
 #include "base/run_loop.h"
 #include "base/strings/utf_string_conversions.h"
 #include "base/task/post_task.h"
-#include "base/test/scoped_task_environment.h"
 #include "components/storage_monitor/media_storage_util.h"
 #include "components/storage_monitor/removable_device_constants.h"
 #include "components/storage_monitor/storage_monitor.h"
@@ -28,9 +27,7 @@
 
 class MediaStorageUtilTest : public testing::Test {
  public:
-  MediaStorageUtilTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
+  MediaStorageUtilTest() {}
   ~MediaStorageUtilTest() override {}
 
   // Verify mounted device type.
@@ -69,10 +66,9 @@
     TestStorageMonitor::Destroy();
   }
 
-  void RunUntilIdle() { scoped_task_environment_.RunUntilIdle(); }
+  void RunUntilIdle() { test_browser_thread_bundle_.RunUntilIdle(); }
 
  private:
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
   content::TestBrowserThreadBundle test_browser_thread_bundle_;
   TestStorageMonitor* monitor_;
   base::ScopedTempDir scoped_temp_dir_;
diff --git a/components/storage_monitor/storage_monitor_chromeos_unittest.cc b/components/storage_monitor/storage_monitor_chromeos_unittest.cc
index 8edfbfc..2ecc82cd 100644
--- a/components/storage_monitor/storage_monitor_chromeos_unittest.cc
+++ b/components/storage_monitor/storage_monitor_chromeos_unittest.cc
@@ -150,8 +150,6 @@
   StorageMonitor::EjectStatus status_;
 
  private:
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
-
   content::TestBrowserThreadBundle thread_bundle_;
 
   // Temporary directory for created test data.
@@ -166,9 +164,7 @@
 StorageMonitorCrosTest::StorageMonitorCrosTest()
     : monitor_(NULL),
       disk_mount_manager_mock_(NULL),
-      status_(StorageMonitor::EJECT_FAILURE),
-      scoped_task_environment_(
-          base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
+      status_(StorageMonitor::EJECT_FAILURE) {}
 
 StorageMonitorCrosTest::~StorageMonitorCrosTest() {
 }
@@ -197,7 +193,7 @@
 
   disk_mount_manager_mock_ = NULL;
   DiskMountManager::Shutdown();
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 }
 
 void StorageMonitorCrosTest::MountDevice(
@@ -217,7 +213,7 @@
         true /* on_removable_device */, kFileSystemType);
   }
   monitor_->OnMountEvent(DiskMountManager::MOUNTING, error_code, mount_info);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 }
 
 void StorageMonitorCrosTest::UnmountDevice(
@@ -226,7 +222,7 @@
   monitor_->OnMountEvent(DiskMountManager::UNMOUNTING, error_code, mount_info);
   if (error_code == chromeos::MOUNT_ERROR_NONE)
     disk_mount_manager_mock_->RemoveDiskEntryForMountDevice(mount_info);
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 }
 
 uint64_t StorageMonitorCrosTest::GetDeviceStorageSize(
diff --git a/components/sync/engine_impl/sync_scheduler_impl_unittest.cc b/components/sync/engine_impl/sync_scheduler_impl_unittest.cc
index 51d71d5..9f36862 100644
--- a/components/sync/engine_impl/sync_scheduler_impl_unittest.cc
+++ b/components/sync/engine_impl/sync_scheduler_impl_unittest.cc
@@ -303,6 +303,13 @@
   base::test::ScopedTaskEnvironment task_environment_;
 
  private:
+  static const base::TickClock* tick_clock_;
+  static base::TimeTicks GetMockTimeTicks() {
+    if (!tick_clock_)
+      return base::TimeTicks();
+    return tick_clock_->NowTicks();
+  }
+
   syncable::Directory* directory() {
     return test_user_share_.user_share()->directory.get();
   }
@@ -321,6 +328,8 @@
   base::WeakPtrFactory<SyncSchedulerImplTest> weak_ptr_factory_;
 };
 
+const base::TickClock* SyncSchedulerImplTest::tick_clock_ = nullptr;
+
 void RecordSyncShareImpl(SyncShareTimes* times) {
   times->push_back(TimeTicks::Now());
 }
diff --git a/content/browser/appcache/appcache_fuzzer.cc b/content/browser/appcache/appcache_fuzzer.cc
index a1701d6..64822bba 100644
--- a/content/browser/appcache/appcache_fuzzer.cc
+++ b/content/browser/appcache/appcache_fuzzer.cc
@@ -7,7 +7,6 @@
 #include "base/no_destructor.h"
 #include "base/task/post_task.h"
 #include "base/test/scoped_feature_list.h"
-#include "base/test/scoped_task_environment.h"
 #include "content/browser/appcache/appcache_dispatcher_host.h"
 #include "content/browser/appcache/appcache_fuzzer.pb.h"
 #include "content/browser/appcache/chrome_appcache_service.h"
@@ -26,10 +25,7 @@
 namespace {
 
 struct Env {
-  Env()
-      : scoped_task_environment(
-            base::test::ScopedTaskEnvironment::MainThreadType::IO),
-        thread_bundle(TestBrowserThreadBundle::Options::IO_MAINLOOP) {
+  Env() : thread_bundle(base::test::ScopedTaskEnvironment::MainThreadType::IO) {
     base::CommandLine::Init(0, nullptr);
     logging::SetMinLogLevel(logging::LOG_FATAL);
     mojo::core::Init();
@@ -58,10 +54,9 @@
                        /*resource_context=*/nullptr,
                        /*request_context_getter=*/nullptr,
                        /*special_storage_policy=*/nullptr));
-    scoped_task_environment.RunUntilIdle();
+    thread_bundle.RunUntilIdle();
   }
 
-  base::test::ScopedTaskEnvironment scoped_task_environment;
   TestBrowserThreadBundle thread_bundle;
   base::test::ScopedFeatureList feature_list;
   scoped_refptr<ChromeAppCacheService> appcache_service;
@@ -226,7 +221,7 @@
         break;
       }
       case fuzzing::proto::Command::kRunUntilIdle: {
-        SingletonEnv().scoped_task_environment.RunUntilIdle();
+        SingletonEnv().thread_bundle.RunUntilIdle();
         break;
       }
       case fuzzing::proto::Command::COMMAND_NOT_SET: {
@@ -238,7 +233,7 @@
   host.reset();
   // TODO(nedwilliamson): Investigate removing this or reinitializing
   // the appcache service as a fuzzer command.
-  SingletonEnv().scoped_task_environment.RunUntilIdle();
+  SingletonEnv().thread_bundle.RunUntilIdle();
 }
 
 }  // namespace content
diff --git a/content/browser/appcache/chrome_appcache_service_unittest.cc b/content/browser/appcache/chrome_appcache_service_unittest.cc
index c8489b69..3e89e9b 100644
--- a/content/browser/appcache/chrome_appcache_service_unittest.cc
+++ b/content/browser/appcache/chrome_appcache_service_unittest.cc
@@ -12,7 +12,6 @@
 #include "base/run_loop.h"
 #include "base/single_thread_task_runner.h"
 #include "base/task/post_task.h"
-#include "base/test/scoped_task_environment.h"
 #include "base/threading/thread_task_runner_handle.h"
 #include "content/browser/appcache/appcache_database.h"
 #include "content/browser/appcache/appcache_storage_impl.h"
@@ -44,12 +43,10 @@
 class ChromeAppCacheServiceTest : public testing::Test {
  public:
   ChromeAppCacheServiceTest()
-      : scoped_task_environment_(
-            base::test::ScopedTaskEnvironment::MainThreadType::IO),
+      : thread_bundle_(base::test::ScopedTaskEnvironment::MainThreadType::IO),
         kProtectedManifestURL(kProtectedManifest),
         kNormalManifestURL(kNormalManifest),
-        kSessionOnlyManifestURL(kSessionOnlyManifest),
-        thread_bundle_(TestBrowserThreadBundle::Options::IO_MAINLOOP) {}
+        kSessionOnlyManifestURL(kSessionOnlyManifest) {}
 
  protected:
   scoped_refptr<ChromeAppCacheService> CreateAppCacheServiceImpl(
@@ -57,14 +54,13 @@
       bool init_storage);
   void InsertDataIntoAppCache(ChromeAppCacheService* appcache_service);
 
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
+  TestBrowserThreadBundle thread_bundle_;
   base::ScopedTempDir temp_dir_;
   const GURL kProtectedManifestURL;
   const GURL kNormalManifestURL;
   const GURL kSessionOnlyManifestURL;
 
  private:
-  TestBrowserThreadBundle thread_bundle_;
   TestBrowserContext browser_context_;
 };
 
@@ -86,14 +82,14 @@
           base::RetainedRef(browser_context_.GetRequestContext()),
           mock_policy));
   // Steps needed to initialize the storage of AppCache data.
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   if (init_storage) {
     AppCacheStorageImpl* storage =
         static_cast<AppCacheStorageImpl*>(
             appcache_service->storage());
     storage->database_->db_connection();
     storage->disk_cache();
-    scoped_task_environment_.RunUntilIdle();
+    thread_bundle_.RunUntilIdle();
   }
   return appcache_service;
 }
@@ -131,7 +127,7 @@
 
   // Test: delete the ChromeAppCacheService
   appcache_service = nullptr;
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 
   // Recreate the appcache (for reading the data back)
   appcache_service = CreateAppCacheServiceImpl(appcache_path, false);
@@ -153,7 +149,7 @@
 
   // Delete and let cleanup tasks run prior to returning.
   appcache_service = nullptr;
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 }
 
 TEST_F(ChromeAppCacheServiceTest, SaveSessionState) {
@@ -173,7 +169,7 @@
 
   // Test: delete the ChromeAppCacheService
   appcache_service = nullptr;
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 
   // Recreate the appcache (for reading the data back)
   appcache_service = CreateAppCacheServiceImpl(appcache_path, false);
@@ -195,7 +191,7 @@
 
   // Delete and let cleanup tasks run prior to returning.
   appcache_service = nullptr;
-  scoped_task_environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 }
 
 }  // namespace content
diff --git a/content/browser/scheduler/browser_task_executor_unittest.cc b/content/browser/scheduler/browser_task_executor_unittest.cc
index 433a701..980c2236 100644
--- a/content/browser/scheduler/browser_task_executor_unittest.cc
+++ b/content/browser/scheduler/browser_task_executor_unittest.cc
@@ -51,10 +51,8 @@
     std::vector<TaskEntry> tasks_;
   };
 
-  base::test::ScopedTaskEnvironment environment_{
-      base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME};
   TestBrowserThreadBundle thread_bundle_{
-      TestBrowserThreadBundle::PLAIN_MAINLOOP};
+      base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME};
   AfterStartupBrowserClient browser_client_;
   ContentBrowserClient* old_browser_client_;
 };
@@ -92,7 +90,7 @@
       FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_BLOCKING},
       base::BindOnce(&SetBoolFlag, base::Unretained(&ran_user_blocking)));
 
-  environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
 
   EXPECT_FALSE(ran_best_effort);
   EXPECT_TRUE(ran_user_visible);
@@ -127,33 +125,34 @@
   // AfterStartupTaskRunner.
   EXPECT_EQ(browser_client_.tasks_.size(), 2u);
 
-  EXPECT_EQ(environment_.GetPendingMainThreadTaskCount(), 0u);
+  EXPECT_EQ(thread_bundle_.GetPendingMainThreadTaskCount(), 0u);
 
   // Emulate startup complete after 1 sec - this should post the two tasks to
   // the UI thread.
-  environment_.FastForwardBy(base::TimeDelta::FromSeconds(1));
+  thread_bundle_.FastForwardBy(base::TimeDelta::FromSeconds(1));
   browser_client_.RunTasks();
-  EXPECT_EQ(environment_.GetPendingMainThreadTaskCount(), 2u);
+  EXPECT_EQ(thread_bundle_.GetPendingMainThreadTaskCount(), 2u);
 
   // Run the two tasks including the first BEST_EFFORT task posted as immediate.
   // The three other BEST_EFFORT tasks should remain since they are delayed
   // tasks. They should have been posted with their original delays.
-  environment_.RunUntilIdle();
+  thread_bundle_.RunUntilIdle();
   EXPECT_TRUE(ran_first_task);
-  EXPECT_EQ(environment_.GetPendingMainThreadTaskCount(), 3u);
+  EXPECT_EQ(thread_bundle_.GetPendingMainThreadTaskCount(), 3u);
 
   // Run the delayed tasks one by one.
   for (size_t pending_tasks = 3; pending_tasks > 0; pending_tasks--) {
-    EXPECT_EQ(environment_.NextMainThreadPendingTaskDelay(),
+    EXPECT_EQ(thread_bundle_.NextMainThreadPendingTaskDelay(),
               base::TimeDelta::FromMilliseconds(100));
-    environment_.FastForwardBy(base::TimeDelta::FromMilliseconds(100));
-    EXPECT_EQ(environment_.GetPendingMainThreadTaskCount(), pending_tasks - 1u);
+    thread_bundle_.FastForwardBy(base::TimeDelta::FromMilliseconds(100));
+    EXPECT_EQ(thread_bundle_.GetPendingMainThreadTaskCount(),
+              pending_tasks - 1u);
   }
 
   // Posting another BEST_EFFORT task should bypass the browser_client_.
   ui_best_effort_runner->PostTask(FROM_HERE, base::DoNothing());
   EXPECT_EQ(browser_client_.tasks_.size(), 0u);
-  EXPECT_EQ(environment_.GetPendingMainThreadTaskCount(), 1u);
+  EXPECT_EQ(thread_bundle_.GetPendingMainThreadTaskCount(), 1u);
 }
 
 }  // namespace content
diff --git a/content/public/test/test_browser_thread_bundle.cc b/content/public/test/test_browser_thread_bundle.cc
index c28e2411..77db4f2 100644
--- a/content/public/test/test_browser_thread_bundle.cc
+++ b/content/public/test/test_browser_thread_bundle.cc
@@ -8,7 +8,6 @@
 #include "base/message_loop/message_loop_current.h"
 #include "base/run_loop.h"
 #include "base/task/post_task.h"
-#include "base/test/scoped_task_environment.h"
 #include "base/threading/thread_task_runner_handle.h"
 #include "content/browser/after_startup_task_utils.h"
 #include "content/browser/scheduler/browser_task_executor.h"
@@ -36,14 +35,40 @@
 
 }  // namespace
 
-TestBrowserThreadBundle::TestBrowserThreadBundle()
-    : TestBrowserThreadBundle(DEFAULT) {}
+TestBrowserThreadBundle::TestBrowserThreadBundle(
+    base::test::ScopedTaskEnvironment::MainThreadType main_thread_type,
+    base::test::ScopedTaskEnvironment::ExecutionMode execution_control_mode,
+    int options)
+    : base::test::ScopedTaskEnvironment(main_thread_type,
+                                        execution_control_mode),
+      options_(options),
+      threads_created_(false) {
+  // Infer |options_| from |main_thread_type|.
+  switch (main_thread_type) {
+    case base::test::ScopedTaskEnvironment::MainThreadType::DEFAULT:
+    case base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME:
+      options_ |= TestBrowserThreadBundle::PLAIN_MAINLOOP;
+      break;
+    case base::test::ScopedTaskEnvironment::MainThreadType::IO:
+      options_ |= TestBrowserThreadBundle::IO_MAINLOOP;
+      break;
+    case base::test::ScopedTaskEnvironment::MainThreadType::UI:
+    case base::test::ScopedTaskEnvironment::MainThreadType::UI_MOCK_TIME:
+      break;
 
-TestBrowserThreadBundle::TestBrowserThreadBundle(int options)
-    : options_(options), threads_created_(false) {
+    default:
+      NOTREACHED();
+  }
+
   Init();
 }
 
+TestBrowserThreadBundle::TestBrowserThreadBundle(int options)
+    : TestBrowserThreadBundle(
+          GetThreadTypeFromOptions(options),
+          base::test::ScopedTaskEnvironment::ExecutionMode::ASYNC,
+          options) {}
+
 TestBrowserThreadBundle::~TestBrowserThreadBundle() {
   CHECK(threads_created_);
 
@@ -57,13 +82,11 @@
   ui_thread_->Stop();
   base::RunLoop().RunUntilIdle();
 
-  // Skip the following step when TaskScheduler isn't managed by this
-  // TestBrowserThreadBundle, otherwise it can hang (e.g.
-  // RunAllTasksUntilIdle() hangs when the TaskScheduler is managed
-  // by an external ScopedTaskEnvironment with ExecutionMode::QUEUED). This is
-  // fine as (1) it's rare and (2) it mimics production where BrowserThreads are
-  // shutdown before TaskScheduler.
-  if (scoped_task_environment_) {
+  // Skip the following steps when RunAllTasksUntilIdle might result in a hang
+  // (ExecutionMode::QUEUED) or for MainThreadType::MOCK_TIME where we haven't
+  // enforced there being no pending tasks.
+  if (main_thread_type() != MainThreadType::MOCK_TIME &&
+      execution_control_mode() != ExecutionMode::QUEUED) {
     // This is required to ensure we run all remaining MessageLoop and
     // TaskScheduler tasks in an atomic step. This is a bit different than
     // production where the main thread is not flushed after it's done running
@@ -72,15 +95,14 @@
     // blocked upon it could make a test flaky whereas by flushing we guarantee
     // it will blow up).
     RunAllTasksUntilIdle();
-    CHECK(!scoped_task_environment_->MainThreadHasPendingTask());
+    CHECK(!MainThreadHasPendingTask());
   }
 
   BrowserTaskExecutor::ResetForTesting();
 
-  // |scoped_task_environment_| needs to explicitly go away before fake threads
-  // in order for DestructionObservers hooked to the main MessageLoop to be able
-  // to invoke BrowserThread::CurrentlyOn() -- ref. ~TestBrowserThread().
-  scoped_task_environment_.reset();
+  // Run DestructionObservers before our fake threads go away to ensure
+  // BrowserThread::CurrentlyOn() returns the results expected by the observers.
+  NotifyDestructionObserversAndReleaseSequenceManager();
 
 #if defined(OS_WIN)
   com_initializer_.reset();
@@ -109,15 +131,6 @@
 
   BrowserTaskExecutor::Create();
 
-  // Create the ScopedTaskEnvironment if it doesn't already exist. A
-  // ScopedTaskEnvironment may already exist if this TestBrowserThreadBundle is
-  // instantiated in a test whose parent fixture provides a
-  // ScopedTaskEnvironment.
-  if (!base::ThreadTaskRunnerHandle::IsSet()) {
-    scoped_task_environment_ =
-        std::make_unique<base::test::ScopedTaskEnvironment>(
-            GetThreadTypeFromOptions(options_));
-  }
   if (options_ & IO_MAINLOOP)
     CHECK(base::MessageLoopCurrentForIO::IsSet());
   else if (!(options_ & PLAIN_MAINLOOP))
@@ -149,10 +162,6 @@
   SetBrowserStartupIsCompleteForTesting();
 }
 
-void TestBrowserThreadBundle::RunUntilIdle() {
-  scoped_task_environment_->RunUntilIdle();
-}
-
 void TestBrowserThreadBundle::RunIOThreadUntilIdle() {
   // Use a RunLoop to run until idle if already on BrowserThread::IO (which is
   // the main thread unless using Options::REAL_IO_THREAD).
diff --git a/content/public/test/test_browser_thread_bundle.h b/content/public/test/test_browser_thread_bundle.h
index 84348a1..9eb42916 100644
--- a/content/public/test/test_browser_thread_bundle.h
+++ b/content/public/test/test_browser_thread_bundle.h
@@ -85,12 +85,10 @@
 #include <memory>
 
 #include "base/macros.h"
+#include "base/test/scoped_task_environment.h"
 #include "build/build_config.h"
 
 namespace base {
-namespace test {
-class ScopedTaskEnvironment;
-}  // namespace test
 #if defined(OS_WIN)
 namespace win {
 class ScopedCOMInitializer;
@@ -104,7 +102,7 @@
 
 // Note: to drive these threads (e.g. run all tasks until idle), see
 // content/public/test/test_utils.h.
-class TestBrowserThreadBundle {
+class TestBrowserThreadBundle : public base::test::ScopedTaskEnvironment {
  public:
   // Used to specify the type of MessageLoop that backs the UI thread, and
   // which of the named BrowserThreads should be backed by a real
@@ -123,9 +121,17 @@
     PLAIN_MAINLOOP = 1 << 3,
   };
 
-  TestBrowserThreadBundle();
+  // Deprecated.
   explicit TestBrowserThreadBundle(int options);
 
+  // |options| here to support REAL_IO_THREAD & DONT_CREATE_BROWSER_THREADS.
+  TestBrowserThreadBundle(
+      base::test::ScopedTaskEnvironment::MainThreadType main_thread_type =
+          base::test::ScopedTaskEnvironment::MainThreadType::UI,
+      base::test::ScopedTaskEnvironment::ExecutionMode execution_control_mode =
+          base::test::ScopedTaskEnvironment::ExecutionMode::ASYNC,
+      int options = DEFAULT);
+
   // Creates browser threads; should only be called from other classes if the
   // DONT_CREATE_BROWSER_THREADS option was used when the bundle was created.
   void CreateBrowserThreads();
@@ -145,19 +151,17 @@
   //   KickoffAsyncFoo(run_loop.QuitClosure());
   //   run_loop.Run();
   //
-  void RunUntilIdle();
 
   // Flush the IO thread. Replacement for RunLoop::RunUntilIdle() for tests that
   // have a REAL_IO_THREAD. As with RunUntilIdle() above, prefer using
   // RunLoop+QuitClosure() to await an async condition.
   void RunIOThreadUntilIdle();
 
-  ~TestBrowserThreadBundle();
+  ~TestBrowserThreadBundle() override;
 
  private:
   void Init();
 
-  std::unique_ptr<base::test::ScopedTaskEnvironment> scoped_task_environment_;
   std::unique_ptr<TestBrowserThread> ui_thread_;
   std::unique_ptr<TestBrowserThread> io_thread_;
 
diff --git a/content/public/test/test_browser_thread_bundle_unittest.cc b/content/public/test/test_browser_thread_bundle_unittest.cc
index 2ffe38f4..9233eee 100644
--- a/content/public/test/test_browser_thread_bundle_unittest.cc
+++ b/content/public/test/test_browser_thread_bundle_unittest.cc
@@ -7,7 +7,6 @@
 #include "base/atomicops.h"
 #include "base/bind_helpers.h"
 #include "base/task/post_task.h"
-#include "base/test/scoped_task_environment.h"
 #include "content/public/browser/browser_task_traits.h"
 #include "content/public/browser/browser_thread.h"
 #include "testing/gtest/include/gtest/gtest.h"
@@ -16,33 +15,6 @@
 
 namespace content {
 
-TEST(TestBrowserThreadBundleTest,
-     ScopedTaskEnvironmentAndTestBrowserThreadBundle) {
-  ScopedTaskEnvironment scoped_task_environment(
-      ScopedTaskEnvironment::MainThreadType::UI);
-  TestBrowserThreadBundle test_browser_thread_bundle;
-  base::PostTaskAndReply(FROM_HERE, base::DoNothing(), base::BindOnce([]() {
-                           DCHECK_CURRENTLY_ON(BrowserThread::UI);
-                         }));
-  scoped_task_environment.RunUntilIdle();
-}
-
-// Regression test to verify that ~TestBrowserThreadBundle() doesn't hang when
-// the TaskScheduler is owned by a QUEUED ScopedTaskEnvironment with pending
-// tasks.
-TEST(TestBrowserThreadBundleTest,
-     QueuedScopedTaskEnvironmentAndTestBrowserThreadBundle) {
-  ScopedTaskEnvironment queued_scoped_task_environment(
-      ScopedTaskEnvironment::MainThreadType::UI,
-      ScopedTaskEnvironment::ExecutionMode::QUEUED);
-  base::PostTask(FROM_HERE, base::DoNothing());
-
-  {
-    TestBrowserThreadBundle test_browser_thread_bundle;
-    DCHECK_CURRENTLY_ON(BrowserThread::UI);
-  }  // Would hang here prior to fix.
-}
-
 namespace {
 
 // TestBrowserThreadBundleTest.RunUntilIdle will run kNumTasks tasks that will
diff --git a/content/renderer/render_thread_impl_browsertest.cc b/content/renderer/render_thread_impl_browsertest.cc
index 52ea7a4..6d72076 100644
--- a/content/renderer/render_thread_impl_browsertest.cc
+++ b/content/renderer/render_thread_impl_browsertest.cc
@@ -16,7 +16,6 @@
 #include "base/location.h"
 #include "base/macros.h"
 #include "base/memory/discardable_memory.h"
-#include "base/message_loop/message_loop.h"
 #include "base/metrics/field_trial.h"
 #include "base/run_loop.h"
 #include "base/single_thread_task_runner.h"
@@ -153,34 +152,12 @@
 
 class RenderThreadImplBrowserTest : public testing::Test {
  public:
-  // Managing our own main MessageLoop also forces us to manage our own
-  // TaskScheduler. This ensures a basic TaskScheduler is in scope during this
-  // test.
-  class TestTaskScheduler {
-   public:
-    TestTaskScheduler() {
-      base::TaskScheduler::CreateAndStartWithDefaultParams(
-          "RenderThreadImplBrowserTest");
-    }
-
-    ~TestTaskScheduler() {
-      base::TaskScheduler::GetInstance()->Shutdown();
-      base::TaskScheduler::GetInstance()->JoinForTesting();
-      base::TaskScheduler::SetInstance(nullptr);
-    }
-
-   private:
-    DISALLOW_COPY_AND_ASSIGN(TestTaskScheduler);
-  };
-
   RenderThreadImplBrowserTest() : field_trial_list_(nullptr) {}
 
   void SetUp() override {
     content_renderer_client_.reset(new ContentRendererClient());
     SetRendererClientForTesting(content_renderer_client_.get());
 
-    main_message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI));
-    test_task_scheduler_.reset(new TestTaskScheduler);
     browser_threads_.reset(
         new TestBrowserThreadBundle(TestBrowserThreadBundle::REAL_IO_THREAD));
     scoped_refptr<base::SingleThreadTaskRunner> io_task_runner =
@@ -263,8 +240,6 @@
   TestContentClientInitializer content_client_initializer_;
   std::unique_ptr<ContentRendererClient> content_renderer_client_;
 
-  std::unique_ptr<base::MessageLoop> main_message_loop_;
-  std::unique_ptr<TestTaskScheduler> test_task_scheduler_;
   std::unique_ptr<TestBrowserThreadBundle> browser_threads_;
   std::unique_ptr<TestServiceManagerContext> shell_context_;
   std::unique_ptr<ChildConnection> child_connection_;
@@ -302,9 +277,11 @@
 // Disabled under LeakSanitizer due to memory leaks.
 TEST_F(RenderThreadImplBrowserTest,
        WILL_LEAK(NonResourceDispatchIPCTasksDontGoThroughScheduler)) {
+  // This seems to deflake the test on Android.
+  browser_threads_->RunIOThreadUntilIdle();
+
   // NOTE other than not being a resource message, the actual message is
   // unimportant.
-
   sender()->Send(new TestMsg_QuitRunLoop());
 
   run_loop_->Run();
diff --git a/ui/views/controls/webview/webview_unittest.cc b/ui/views/controls/webview/webview_unittest.cc
index 27be01b..3b4b95b1 100644
--- a/ui/views/controls/webview/webview_unittest.cc
+++ b/ui/views/controls/webview/webview_unittest.cc
@@ -125,7 +125,9 @@
 // Provides functionality to test a WebView.
 class WebViewUnitTest : public views::test::WidgetTest {
  public:
-  WebViewUnitTest() = default;
+  WebViewUnitTest()
+      : views::test::WidgetTest(
+            std::make_unique<content::TestBrowserThreadBundle>()) {}
 
   ~WebViewUnitTest() override {}
 
@@ -187,7 +189,6 @@
   }
 
  private:
-  content::TestBrowserThreadBundle test_browser_thread_bundle_;
   content::RenderViewHostTestEnabler rvh_enabler_;
   std::unique_ptr<content::TestBrowserContext> browser_context_;
   content::TestContentBrowserClient test_browser_client_;
diff --git a/ui/views/test/views_test_base.cc b/ui/views/test/views_test_base.cc
index 7f0542d..633235b 100644
--- a/ui/views/test/views_test_base.cc
+++ b/ui/views/test/views_test_base.cc
@@ -46,9 +46,9 @@
 
 }  // namespace
 
-ViewsTestBase::ViewsTestBase()
-    : scoped_task_environment_(
-          base::test::ScopedTaskEnvironment::MainThreadType::UI),
+ViewsTestBase::ViewsTestBase(
+    std::unique_ptr<ScopedTaskEnvironment> scoped_task_environment)
+    : scoped_task_environment_(std::move(scoped_task_environment)),
       setup_called_(false),
       teardown_called_(false),
       has_compositing_manager_(InitializeVisuals()) {}
diff --git a/ui/views/test/views_test_base.h b/ui/views/test/views_test_base.h
index 7702736..88a0b8c 100644
--- a/ui/views/test/views_test_base.h
+++ b/ui/views/test/views_test_base.h
@@ -26,7 +26,13 @@
 // to drive UI events and takes care of OLE initialization for windows.
 class ViewsTestBase : public PlatformTest {
  public:
-  ViewsTestBase();
+  using ScopedTaskEnvironment = base::test::ScopedTaskEnvironment;
+
+  explicit ViewsTestBase(
+      std::unique_ptr<ScopedTaskEnvironment> scoped_task_environment =
+          std::make_unique<ScopedTaskEnvironment>(
+              ScopedTaskEnvironment::MainThreadType::UI));
+
   ~ViewsTestBase() override;
 
   // Returns true if running aura-mus in a client configuration (not the window
@@ -63,7 +69,7 @@
   gfx::NativeWindow GetContext();
 
  private:
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
+  std::unique_ptr<ScopedTaskEnvironment> scoped_task_environment_;
   std::unique_ptr<TestViewsDelegate> views_delegate_for_setup_;
   std::unique_ptr<ScopedViewsTestHelper> test_helper_;
   bool setup_called_;
diff --git a/ui/views/test/widget_test.cc b/ui/views/test/widget_test.cc
index 91f1691..95f83fe2 100644
--- a/ui/views/test/widget_test.cc
+++ b/ui/views/test/widget_test.cc
@@ -30,7 +30,9 @@
   widget->CloseNow();
 }
 
-WidgetTest::WidgetTest() {}
+WidgetTest::WidgetTest(
+    std::unique_ptr<ScopedTaskEnvironment> scoped_task_environment)
+    : ViewsTestBase(std::move(scoped_task_environment)) {}
 WidgetTest::~WidgetTest() {}
 
 Widget* WidgetTest::CreateTopLevelPlatformWidget() {
diff --git a/ui/views/test/widget_test.h b/ui/views/test/widget_test.h
index 2e871d9..3a3c082 100644
--- a/ui/views/test/widget_test.h
+++ b/ui/views/test/widget_test.h
@@ -44,7 +44,10 @@
 
   using WidgetAutoclosePtr = std::unique_ptr<Widget, WidgetCloser>;
 
-  WidgetTest();
+  explicit WidgetTest(
+      std::unique_ptr<ScopedTaskEnvironment> scoped_task_environment =
+          std::make_unique<ScopedTaskEnvironment>(
+              ScopedTaskEnvironment::MainThreadType::UI));
   ~WidgetTest() override;
 
   // Create Widgets with |native_widget| in InitParams set to an instance of