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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/metrics/desktop_engagement/audible_contents_tracker_browsertest.cc
diff --git a/chrome/browser/metrics/desktop_engagement/audible_contents_tracker_browsertest.cc b/chrome/browser/metrics/desktop_engagement/audible_contents_tracker_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..54abba17d9ca3e8ce99729df461abcce9b801585
--- /dev/null
+++ b/chrome/browser/metrics/desktop_engagement/audible_contents_tracker_browsertest.cc
@@ -0,0 +1,76 @@
+// 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.
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.
+#include "chrome/browser/metrics/desktop_engagement/audible_contents_tracker.h"
+
+#include "base/path_service.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/test/browser_test_base.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+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.
+// Observer for testing AudibleContentsTracker.
+class MockAudibleContentsObserver
+ : public metrics::AudibleContentsTracker::Observer {
+ public:
+ MockAudibleContentsObserver() {}
+
+ // AudibleContentsTracker::Observer:
+ void OnAudioStart() override { is_audio_playing_ = true; }
+ void OnAudioEnd() override { is_audio_playing_ = false; }
+
+ bool IsAudioPlaying() { return is_audio_playing_; }
+
+ private:
+ bool is_audio_playing_ = false;
+
+ DISALLOW_COPY_AND_ASSIGN(MockAudibleContentsObserver);
+};
+
+} // namespace
+
+class AudibleContentsTrackerTest : public InProcessBrowserTest {
+ public:
+ void SetUp() override {
+ observer_.reset(new MockAudibleContentsObserver());
+ tracker_.reset(new metrics::AudibleContentsTracker(observer()));
+ InProcessBrowserTest::SetUp();
+ }
+
+ void TearDown() override {
+ tracker_.reset();
+ observer_.reset();
+ 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.
+ }
+
+ MockAudibleContentsObserver* observer() const { return observer_.get(); }
+
+ private:
+ std::unique_ptr<MockAudibleContentsObserver> observer_ = nullptr;
+ std::unique_ptr<metrics::AudibleContentsTracker> tracker_ = nullptr;
+};
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.
+
+IN_PROC_BROWSER_TEST_F(AudibleContentsTrackerTest, TestAudioNotifications) {
+ MockAudibleContentsObserver* audio_observer = observer();
+ EXPECT_FALSE(audio_observer->IsAudioPlaying());
+
+ // For serving audio.
+ ASSERT_TRUE(embedded_test_server()->Start());
+ base::FilePath test_data_dir;
+ ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir));
+ embedded_test_server()->ServeFilesFromDirectory(
+ test_data_dir.AppendASCII("chrome/test/data/"));
+ ui_test_utils::NavigateToURL(
+ browser(), embedded_test_server()->GetURL("/autoplay_audio.html"));
+
+ // Wait until the audio starts.
+ while (!audio_observer->IsAudioPlaying()) {
+ base::RunLoop().RunUntilIdle();
+ }
+
+ // Wait until the audio stops.
+ while (audio_observer->IsAudioPlaying()) {
+ base::RunLoop().RunUntilIdle();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698