Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1368)

Side by Side Diff: chrome/browser/metrics/desktop_engagement/audible_contents_tracker_browsertest.cc

Issue 2142983002: Add desktop engagement metrics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments and fix mac bot Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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
5 #include "chrome/browser/metrics/desktop_engagement/audible_contents_tracker.h"
6
7 #include "base/path_service.h"
8 #include "chrome/test/base/in_process_browser_test.h"
9 #include "chrome/test/base/ui_test_utils.h"
10 #include "content/public/test/browser_test_base.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace {
14
15 // Observer for testing AudibleContentsTracker.
16 class MockAudibleContentsObserver
17 : public metrics::AudibleContentsTracker::Observer {
18 public:
19 MockAudibleContentsObserver() {}
20
21 // AudibleContentsTracker::Observer:
22 void OnAudioStart() override { is_audio_playing_ = true; }
23 void OnAudioEnd() override { is_audio_playing_ = false; }
24
25 bool IsAudioPlaying() { return is_audio_playing_; }
26
27 private:
28 bool is_audio_playing_ = false;
29
30 DISALLOW_COPY_AND_ASSIGN(MockAudibleContentsObserver);
31 };
32
33 } // namespace
34
35 class AudibleContentsTrackerTest : public InProcessBrowserTest {
36 public:
37 void SetUp() override {
38 observer_.reset(new MockAudibleContentsObserver());
39 tracker_.reset(new metrics::AudibleContentsTracker(observer()));
40 InProcessBrowserTest::SetUp();
41 }
42
43 void TearDown() override {
44 InProcessBrowserTest::TearDown();
45 tracker_.reset();
46 observer_.reset();
47 }
48
49 MockAudibleContentsObserver* observer() const { return observer_.get(); }
50
51 private:
52 std::unique_ptr<MockAudibleContentsObserver> observer_ = nullptr;
53 std::unique_ptr<metrics::AudibleContentsTracker> tracker_ = nullptr;
54
55 DISALLOW_COPY_AND_ASSIGN(AudibleContentsTrackerTest);
56 };
57
58 IN_PROC_BROWSER_TEST_F(AudibleContentsTrackerTest, TestAudioNotifications) {
59 MockAudibleContentsObserver* audio_observer = observer();
60 EXPECT_FALSE(audio_observer->IsAudioPlaying());
61
62 // For serving audio.
63 ASSERT_TRUE(embedded_test_server()->Start());
64 base::FilePath test_data_dir;
65 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir));
66 embedded_test_server()->ServeFilesFromDirectory(
67 test_data_dir.AppendASCII("chrome/test/data/"));
68 ui_test_utils::NavigateToURL(
69 browser(), embedded_test_server()->GetURL("/autoplay_audio.html"));
70
71 // Wait until the audio starts.
72 while (!audio_observer->IsAudioPlaying()) {
73 base::RunLoop().RunUntilIdle();
74 }
75
76 // Wait until the audio stops.
77 while (audio_observer->IsAudioPlaying()) {
78 base::RunLoop().RunUntilIdle();
79 }
80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698