File: web_app_test.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (66 lines) | stat: -rw-r--r-- 2,569 bytes parent folder | download | duplicates (4)
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();
}