projector_session_impl_unittest.cc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 "ash/projector/model/projector_session_impl.h"
  5. #include "ash/constants/ash_features.h"
  6. #include "ash/projector/projector_metrics.h"
  7. #include "ash/public/cpp/projector/projector_session.h"
  8. #include "ash/test/ash_test_base.h"
  9. #include "base/dcheck_is_on.h"
  10. #include "base/test/metrics/histogram_tester.h"
  11. #include "base/test/scoped_feature_list.h"
  12. namespace ash {
  13. namespace {
  14. constexpr char kProjectorCreationFlowHistogramName[] =
  15. "Ash.Projector.CreationFlow.ClamshellMode";
  16. } // namespace
  17. class ProjectorSessionImplTest : public AshTestBase {
  18. public:
  19. ProjectorSessionImplTest() = default;
  20. ProjectorSessionImplTest(const ProjectorSessionImplTest&) = delete;
  21. ProjectorSessionImplTest& operator=(const ProjectorSessionImplTest&) = delete;
  22. // AshTestBase:
  23. void SetUp() override {
  24. scoped_feature_list_.InitWithFeatures(
  25. /*enabled_features=*/{features::kProjector,
  26. features::kProjectorManagedUser},
  27. /*disabled_features=*/{});
  28. AshTestBase::SetUp();
  29. session_ = static_cast<ProjectorSessionImpl*>(ProjectorSession::Get());
  30. }
  31. protected:
  32. base::test::ScopedFeatureList scoped_feature_list_;
  33. ProjectorSessionImpl* session_;
  34. };
  35. TEST_F(ProjectorSessionImplTest, Start) {
  36. base::HistogramTester histogram_tester;
  37. session_->Start("projector_data");
  38. histogram_tester.ExpectUniqueSample(kProjectorCreationFlowHistogramName,
  39. ProjectorCreationFlow::kSessionStarted,
  40. /*count=*/1);
  41. EXPECT_TRUE(session_->is_active());
  42. EXPECT_EQ("projector_data", session_->storage_dir());
  43. session_->Stop();
  44. EXPECT_FALSE(session_->is_active());
  45. histogram_tester.ExpectBucketCount(kProjectorCreationFlowHistogramName,
  46. ProjectorCreationFlow::kSessionStopped,
  47. /*count=*/1);
  48. histogram_tester.ExpectTotalCount(kProjectorCreationFlowHistogramName,
  49. /*count=*/2);
  50. }
  51. #if DCHECK_IS_ON()
  52. TEST_F(ProjectorSessionImplTest, OnlyOneProjectorSessionAllowed) {
  53. session_->Start("projector_data");
  54. EXPECT_DEATH_IF_SUPPORTED(session_->Start("projector_data"), "");
  55. }
  56. #endif
  57. } // namespace ash