1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/web_applications/test/web_app_test.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/web_applications/test/debug_info_printer.h"
#include "chrome/browser/web_applications/test/fake_web_app_provider.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
WebAppTest::~WebAppTest() = default;
void WebAppTest::SetUp() {
ASSERT_TRUE(testing_profile_manager_.SetUp());
profile_ = testing_profile_manager_.CreateTestingProfile(
TestingProfile::kDefaultProfileUserName, /*testing_factories=*/{},
shared_url_loader_factory_);
content::RenderViewHostTestHarness::SetUp();
}
void WebAppTest::TearDown() {
// Manually shut down the provider and subsystems so that async tasks are
// stopped. Without this, async tasks may still be holding onto WebContents
// instances, which is checked for in
// `content::RenderViewHostTestHarness::TearDown()`. Note:
// `DeleteAllTestingProfiles` doesn't actually destruct profiles and therefore
// doesn't Shutdown keyed services like the provider.
fake_provider().Shutdown();
os_integration_test_override_.reset();
if (testing::Test::HasFailure()) {
base::TimeDelta log_time = base::TimeTicks::Now() - start_time_;
web_app::test::LogDebugInfoToConsole(
testing_profile_manager_.profile_manager()->GetLoadedProfiles(),
log_time);
}
// RenderViewHostTestHarness::TearDown destroys the TaskEnvironment. We need
// to destroy profiles before that happens, and web contents need to be
// destroyed before profiles are destroyed.
DeleteContents();
// Make sure that we flush any messages related to WebContentsImpl
// destruction before we destroy the profiles.
base::RunLoop().RunUntilIdle();
testing_profile_manager_.DeleteAllTestingProfiles();
content::RenderViewHostTestHarness::TearDown();
}
content::BrowserContext* WebAppTest::GetBrowserContext() {
return profile();
}
web_app::WebAppProvider& WebAppTest::provider() const {
return *web_app::WebAppProvider::GetForWebApps(profile());
}
web_app::FakeWebAppProvider& WebAppTest::fake_provider() const {
return *web_app::FakeWebAppProvider::Get(profile());
}
web_app::OsIntegrationTestOverrideImpl& WebAppTest::fake_os_integration()
const {
return os_integration_test_override_->test_override();
}
|