browser_profile_type_unittest.cc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/profile_metrics/browser_profile_type.h"
  5. #include "base/supports_user_data.h"
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. namespace {
  8. class FakeBrowserContext : public base::SupportsUserData {
  9. public:
  10. FakeBrowserContext() = default;
  11. ~FakeBrowserContext() override = default;
  12. };
  13. } // namespace
  14. namespace profile_metrics {
  15. class BrowserProfileTypeUnitTest : public testing::Test {
  16. public:
  17. BrowserProfileTypeUnitTest() = default;
  18. ~BrowserProfileTypeUnitTest() override = default;
  19. };
  20. TEST_F(BrowserProfileTypeUnitTest, AssignmentAndRetrieval) {
  21. for (int i = 0; i <= static_cast<int>(BrowserProfileType::kMaxValue); i++) {
  22. BrowserProfileType pt = static_cast<BrowserProfileType>(i);
  23. FakeBrowserContext browser_context;
  24. SetBrowserProfileType(&browser_context, pt);
  25. EXPECT_EQ(pt, GetBrowserProfileType(&browser_context));
  26. }
  27. }
  28. #if defined(GTEST_HAS_DEATH_TEST)
  29. TEST_F(BrowserProfileTypeUnitTest, UnassignedType) {
  30. FakeBrowserContext browser_context;
  31. EXPECT_DEATH(GetBrowserProfileType(&browser_context), "");
  32. }
  33. #endif
  34. } // namespace profile_metrics