Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #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 { | |
| 13 // Observer for testing AudibleContentsTracker. | |
| 14 class MockAudibleContentsObserver | |
| 15 : public metrics::AudibleContentsTracker::Observer { | |
| 16 public: | |
| 17 MockAudibleContentsObserver() { new metrics::AudibleContentsTracker(this); } | |
|
chrisha
2016/07/22 19:54:56
The AudibleContentsTracker isn't owned by anyone a
gayane -on leave until 09-2017
2016/07/22 21:11:49
Moved to AudibleContentsTrackerTest
| |
| 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 AudibleContentsTrackerTest() { | |
| 36 observer_.reset(new MockAudibleContentsObserver()); | |
| 37 } | |
| 38 MockAudibleContentsObserver* GetObserver() { return observer_.get(); } | |
|
chrisha
2016/07/22 19:54:56
Just make this an accessor?
Mock.... observer() c
gayane -on leave until 09-2017
2016/07/22 21:11:49
Done.
| |
| 39 | |
|
chrisha
2016/07/22 19:54:56
I would do something like:
std::unique_ptr<MockAu
gayane -on leave until 09-2017
2016/07/22 21:11:49
Done.
| |
| 40 private: | |
| 41 std::unique_ptr<MockAudibleContentsObserver> observer_ = nullptr; | |
|
chrisha
2016/07/22 19:54:56
No std::unique_ptr<metrics::AudibleContentsTracker
gayane -on leave until 09-2017
2016/07/22 21:11:49
Done.
| |
| 42 }; | |
| 43 | |
| 44 IN_PROC_BROWSER_TEST_F(AudibleContentsTrackerTest, test) { | |
| 45 MockAudibleContentsObserver* observer = GetObserver(); | |
| 46 EXPECT_FALSE(observer->IsAudioPlaying()); | |
| 47 | |
| 48 // For serving audio. | |
| 49 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 50 base::FilePath test_data_dir; | |
| 51 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir)); | |
| 52 embedded_test_server()->ServeFilesFromDirectory( | |
| 53 test_data_dir.AppendASCII("chrome/test/data/")); | |
| 54 ui_test_utils::NavigateToURL( | |
| 55 browser(), embedded_test_server()->GetURL("/autoplay_audio.html")); | |
| 56 | |
| 57 // Wait until the audio starts. | |
| 58 while (!observer->IsAudioPlaying()) { | |
| 59 base::RunLoop().RunUntilIdle(); | |
| 60 } | |
| 61 | |
| 62 // Wait until the audio stops. | |
| 63 while (observer->IsAudioPlaying()) { | |
| 64 base::RunLoop().RunUntilIdle(); | |
| 65 } | |
| 66 } | |
| OLD | NEW |