| Index: chrome/browser/metrics/desktop_engagement/desktop_engagement_service_unittest.cc
|
| diff --git a/chrome/browser/metrics/desktop_engagement/desktop_engagement_service_unittest.cc b/chrome/browser/metrics/desktop_engagement/desktop_engagement_service_unittest.cc
|
| deleted file mode 100644
|
| index f2b3365527faa561a5e7da683513bd88e63cc71a..0000000000000000000000000000000000000000
|
| --- a/chrome/browser/metrics/desktop_engagement/desktop_engagement_service_unittest.cc
|
| +++ /dev/null
|
| @@ -1,178 +0,0 @@
|
| -// Copyright 2016 The Chromium Authors. All rights reserved.
|
| -// Use of this source code is governed by a BSD-style license that can be
|
| -// found in the LICENSE file.
|
| -
|
| -#include "chrome/browser/metrics/desktop_engagement/desktop_engagement_service.h"
|
| -
|
| -#include "base/message_loop/message_loop.h"
|
| -#include "base/run_loop.h"
|
| -#include "base/test/histogram_tester.h"
|
| -#include "base/test/test_mock_time_task_runner.h"
|
| -#include "testing/gtest/include/gtest/gtest.h"
|
| -
|
| -// Mock class for |DesktopEngagementService| for testing.
|
| -class MockDesktopEngagementService : public metrics::DesktopEngagementService {
|
| - public:
|
| - MockDesktopEngagementService() {}
|
| -
|
| - bool is_timeout() const { return time_out_; }
|
| -
|
| - using metrics::DesktopEngagementService::OnAudioStart;
|
| - using metrics::DesktopEngagementService::OnAudioEnd;
|
| -
|
| - protected:
|
| - void OnTimerFired() override {
|
| - DesktopEngagementService::OnTimerFired();
|
| - time_out_ = true;
|
| - }
|
| -
|
| - private:
|
| - bool time_out_ = false;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(MockDesktopEngagementService);
|
| -};
|
| -
|
| -TEST(DesktopEngagementServiceTest, TestVisibility) {
|
| - base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT);
|
| - base::HistogramTester histogram_tester;
|
| -
|
| - MockDesktopEngagementService instance;
|
| -
|
| - // The browser becomes visible but it shouldn't start the session.
|
| - instance.OnVisibilityChanged(true);
|
| - EXPECT_FALSE(instance.in_session());
|
| - EXPECT_TRUE(instance.is_visible());
|
| - EXPECT_FALSE(instance.is_audio_playing());
|
| - histogram_tester.ExpectTotalCount("Session.TotalDuration", 0);
|
| -
|
| - instance.OnUserEvent();
|
| - EXPECT_TRUE(instance.in_session());
|
| - EXPECT_TRUE(instance.is_visible());
|
| - EXPECT_FALSE(instance.is_audio_playing());
|
| - histogram_tester.ExpectTotalCount("Session.TotalDuration", 0);
|
| -
|
| - // Even if there is a recent user event visibility change should end the
|
| - // session.
|
| - instance.OnUserEvent();
|
| - instance.OnUserEvent();
|
| - instance.OnVisibilityChanged(false);
|
| - EXPECT_FALSE(instance.in_session());
|
| - EXPECT_FALSE(instance.is_visible());
|
| - EXPECT_FALSE(instance.is_audio_playing());
|
| - histogram_tester.ExpectTotalCount("Session.TotalDuration", 1);
|
| -
|
| - // For the second time only visibility change should start the session.
|
| - instance.OnVisibilityChanged(true);
|
| - EXPECT_TRUE(instance.in_session());
|
| - EXPECT_TRUE(instance.is_visible());
|
| - EXPECT_FALSE(instance.is_audio_playing());
|
| - histogram_tester.ExpectTotalCount("Session.TotalDuration", 1);
|
| - instance.OnVisibilityChanged(false);
|
| - EXPECT_FALSE(instance.in_session());
|
| - EXPECT_FALSE(instance.is_visible());
|
| - EXPECT_FALSE(instance.is_audio_playing());
|
| - histogram_tester.ExpectTotalCount("Session.TotalDuration", 2);
|
| -}
|
| -
|
| -TEST(DesktopEngagementServiceTest, TestUserEvent) {
|
| - base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT);
|
| - base::HistogramTester histogram_tester;
|
| -
|
| - MockDesktopEngagementService instance;
|
| - instance.SetInactivityTimeoutForTesting(1);
|
| -
|
| - EXPECT_FALSE(instance.in_session());
|
| - EXPECT_FALSE(instance.is_visible());
|
| - EXPECT_FALSE(instance.is_audio_playing());
|
| - histogram_tester.ExpectTotalCount("Session.TotalDuration", 0);
|
| -
|
| - // User event doesn't go through if nothing is visible.
|
| - instance.OnUserEvent();
|
| - EXPECT_FALSE(instance.in_session());
|
| - EXPECT_FALSE(instance.is_visible());
|
| - EXPECT_FALSE(instance.is_audio_playing());
|
| - histogram_tester.ExpectTotalCount("Session.TotalDuration", 0);
|
| -
|
| - instance.OnVisibilityChanged(true);
|
| - instance.OnUserEvent();
|
| - EXPECT_TRUE(instance.in_session());
|
| - EXPECT_TRUE(instance.is_visible());
|
| - EXPECT_FALSE(instance.is_audio_playing());
|
| - histogram_tester.ExpectTotalCount("Session.TotalDuration", 0);
|
| -
|
| - // Wait until the session expires.
|
| - while (!instance.is_timeout()) {
|
| - base::RunLoop().RunUntilIdle();
|
| - }
|
| -
|
| - EXPECT_FALSE(instance.in_session());
|
| - EXPECT_TRUE(instance.is_visible());
|
| - EXPECT_FALSE(instance.is_audio_playing());
|
| - histogram_tester.ExpectTotalCount("Session.TotalDuration", 1);
|
| -}
|
| -
|
| -TEST(DesktopEngagementServiceTest, TestAudioEvent) {
|
| - base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT);
|
| - base::HistogramTester histogram_tester;
|
| -
|
| - MockDesktopEngagementService instance;
|
| - instance.SetInactivityTimeoutForTesting(1);
|
| -
|
| - instance.OnVisibilityChanged(true);
|
| - instance.OnAudioStart();
|
| - EXPECT_TRUE(instance.in_session());
|
| - EXPECT_TRUE(instance.is_visible());
|
| - EXPECT_TRUE(instance.is_audio_playing());
|
| - histogram_tester.ExpectTotalCount("Session.TotalDuration", 0);
|
| -
|
| - instance.OnVisibilityChanged(false);
|
| - EXPECT_TRUE(instance.in_session());
|
| - EXPECT_FALSE(instance.is_visible());
|
| - EXPECT_TRUE(instance.is_audio_playing());
|
| - histogram_tester.ExpectTotalCount("Session.TotalDuration", 0);
|
| -
|
| - instance.OnAudioEnd();
|
| - EXPECT_TRUE(instance.in_session());
|
| - EXPECT_FALSE(instance.is_visible());
|
| - EXPECT_FALSE(instance.is_audio_playing());
|
| - histogram_tester.ExpectTotalCount("Session.TotalDuration", 0);
|
| -
|
| - // Wait until the session expires.
|
| - while (!instance.is_timeout()) {
|
| - base::RunLoop().RunUntilIdle();
|
| - }
|
| -
|
| - EXPECT_FALSE(instance.in_session());
|
| - EXPECT_FALSE(instance.is_visible());
|
| - EXPECT_FALSE(instance.is_audio_playing());
|
| - histogram_tester.ExpectTotalCount("Session.TotalDuration", 1);
|
| -}
|
| -
|
| -TEST(DesktopEngagementServiceTest, TestTimeoutDiscount) {
|
| - base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT);
|
| - base::HistogramTester histogram_tester;
|
| - MockDesktopEngagementService instance;
|
| -
|
| - int inactivity_interval = 2;
|
| - instance.SetInactivityTimeoutForTesting(inactivity_interval);
|
| -
|
| - instance.OnVisibilityChanged(true);
|
| - base::TimeTicks before_session_start = base::TimeTicks::Now();
|
| - instance.OnUserEvent(); // This should start the session
|
| - histogram_tester.ExpectTotalCount("Session.TotalDuration", 0);
|
| -
|
| - // Wait until the session expires.
|
| - while (!instance.is_timeout()) {
|
| - base::RunLoop().RunUntilIdle();
|
| - }
|
| - base::TimeTicks after_session_end = base::TimeTicks::Now();
|
| -
|
| - histogram_tester.ExpectTotalCount("Session.TotalDuration", 1);
|
| - // The recorded value should be shorter than the specified inactivity
|
| - // interval.
|
| - base::Bucket bucket =
|
| - histogram_tester.GetAllSamples("Session.TotalDuration")[0];
|
| - EXPECT_LE(
|
| - bucket.min + inactivity_interval,
|
| - (after_session_end - before_session_start).InSeconds());
|
| -}
|
|
|