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

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: Created 4 years, 5 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.
Alexei Svitkine (slow) 2016/07/26 19:20:36 Add an empty line after this please.
gayane -on leave until 09-2017 2016/07/26 21:41:19 Done.
4 #include "chrome/browser/metrics/desktop_engagement/audible_contents_tracker.h"
5
6 #include "base/path_service.h"
7 #include "chrome/test/base/in_process_browser_test.h"
8 #include "chrome/test/base/ui_test_utils.h"
9 #include "content/public/test/browser_test_base.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace {
Alexei Svitkine (slow) 2016/07/26 19:20:37 Empty line after this.
gayane -on leave until 09-2017 2016/07/26 21:41:19 Done.
13 // Observer for testing AudibleContentsTracker.
14 class MockAudibleContentsObserver
15 : public metrics::AudibleContentsTracker::Observer {
16 public:
17 MockAudibleContentsObserver() {}
18
19 // AudibleContentsTracker::Observer:
20 void OnAudioStart() override { is_audio_playing_ = true; }
21 void OnAudioEnd() override { is_audio_playing_ = false; }
22
23 bool IsAudioPlaying() { return is_audio_playing_; }
24
25 private:
26 bool is_audio_playing_ = false;
27
28 DISALLOW_COPY_AND_ASSIGN(MockAudibleContentsObserver);
29 };
30
31 } // namespace
32
33 class AudibleContentsTrackerTest : public InProcessBrowserTest {
34 public:
35 void SetUp() override {
36 observer_.reset(new MockAudibleContentsObserver());
37 tracker_.reset(new metrics::AudibleContentsTracker(observer()));
38 InProcessBrowserTest::SetUp();
39 }
40
41 void TearDown() override {
42 tracker_.reset();
43 observer_.reset();
44 InProcessBrowserTest::TearDown();
chrisha 2016/07/26 20:29:50 nit: Do this first, to keep setup and teardown sym
gayane -on leave until 09-2017 2016/07/26 21:41:19 Done.
45 }
46
47 MockAudibleContentsObserver* observer() const { return observer_.get(); }
48
49 private:
50 std::unique_ptr<MockAudibleContentsObserver> observer_ = nullptr;
51 std::unique_ptr<metrics::AudibleContentsTracker> tracker_ = nullptr;
52 };
Alexei Svitkine (slow) 2016/07/26 19:20:36 Nit: Add DISALLOW_ here too.
gayane -on leave until 09-2017 2016/07/26 21:41:19 Done.
53
54 IN_PROC_BROWSER_TEST_F(AudibleContentsTrackerTest, TestAudioNotifications) {
55 MockAudibleContentsObserver* audio_observer = observer();
56 EXPECT_FALSE(audio_observer->IsAudioPlaying());
57
58 // For serving audio.
59 ASSERT_TRUE(embedded_test_server()->Start());
60 base::FilePath test_data_dir;
61 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir));
62 embedded_test_server()->ServeFilesFromDirectory(
63 test_data_dir.AppendASCII("chrome/test/data/"));
64 ui_test_utils::NavigateToURL(
65 browser(), embedded_test_server()->GetURL("/autoplay_audio.html"));
66
67 // Wait until the audio starts.
68 while (!audio_observer->IsAudioPlaying()) {
69 base::RunLoop().RunUntilIdle();
70 }
71
72 // Wait until the audio stops.
73 while (audio_observer->IsAudioPlaying()) {
74 base::RunLoop().RunUntilIdle();
75 }
76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698