locale_feature_pod_controller_unittest.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2018 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 "ash/system/locale/locale_feature_pod_controller.h"
  5. #include <memory>
  6. #include <vector>
  7. #include "ash/public/cpp/locale_update_controller.h"
  8. #include "ash/shell.h"
  9. #include "ash/system/model/system_tray_model.h"
  10. #include "ash/system/unified/feature_pod_button.h"
  11. #include "ash/system/unified/unified_system_tray_controller.h"
  12. #include "ash/system/unified/unified_system_tray_model.h"
  13. #include "ash/test/ash_test_base.h"
  14. #include "base/memory/scoped_refptr.h"
  15. #include "base/strings/utf_string_conversions.h"
  16. namespace ash {
  17. namespace {
  18. class LocaleFeaturePodControllerTest : public NoSessionAshTestBase {
  19. public:
  20. LocaleFeaturePodControllerTest() = default;
  21. LocaleFeaturePodControllerTest(const LocaleFeaturePodControllerTest&) =
  22. delete;
  23. LocaleFeaturePodControllerTest& operator=(
  24. const LocaleFeaturePodControllerTest&) = delete;
  25. ~LocaleFeaturePodControllerTest() override = default;
  26. void SetUp() override {
  27. NoSessionAshTestBase::SetUp();
  28. tray_model_ = base::MakeRefCounted<UnifiedSystemTrayModel>(nullptr);
  29. tray_controller_ =
  30. std::make_unique<UnifiedSystemTrayController>(tray_model_.get());
  31. controller_ =
  32. std::make_unique<LocaleFeaturePodController>(tray_controller_.get());
  33. }
  34. void TearDown() override {
  35. controller_.reset();
  36. tray_controller_.reset();
  37. tray_model_.reset();
  38. NoSessionAshTestBase::TearDown();
  39. }
  40. protected:
  41. std::unique_ptr<LocaleFeaturePodController> controller_;
  42. private:
  43. scoped_refptr<UnifiedSystemTrayModel> tray_model_;
  44. std::unique_ptr<UnifiedSystemTrayController> tray_controller_;
  45. };
  46. TEST_F(LocaleFeaturePodControllerTest, ButtonVisibility) {
  47. constexpr char kDefaultLocaleIsoCode[] = "en-US";
  48. // The button is invisible if the locale list is unset.
  49. std::unique_ptr<FeaturePodButton> button;
  50. button.reset(controller_->CreateButton());
  51. EXPECT_FALSE(button->GetVisible());
  52. // The button is invisible if the locale list is empty.
  53. Shell::Get()->system_tray_model()->SetLocaleList({}, kDefaultLocaleIsoCode);
  54. button.reset(controller_->CreateButton());
  55. EXPECT_FALSE(button->GetVisible());
  56. // The button is visible if the locale list is non-empty.
  57. std::vector<LocaleInfo> locale_list;
  58. locale_list.emplace_back(kDefaultLocaleIsoCode, u"English (United States)");
  59. Shell::Get()->system_tray_model()->SetLocaleList(std::move(locale_list),
  60. kDefaultLocaleIsoCode);
  61. button.reset(controller_->CreateButton());
  62. EXPECT_TRUE(button->GetVisible());
  63. }
  64. } // namespace
  65. } // namespace ash