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

Side by Side Diff: content/browser/media/audio_stream_monitor_unittest.cc

Issue 670623002: Change base::TickClock to a ref counted class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@audio_redesign
Patch Set: y Created 6 years, 2 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/media/audio_stream_monitor.h" 5 #include "content/browser/media/audio_stream_monitor.h"
6 6
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 23 matching lines...) Expand all
34 class MockWebContentsDelegate : public WebContentsDelegate { 34 class MockWebContentsDelegate : public WebContentsDelegate {
35 public: 35 public:
36 MOCK_METHOD2(NavigationStateChanged, 36 MOCK_METHOD2(NavigationStateChanged,
37 void(const WebContents* source, InvalidateTypes changed_flags)); 37 void(const WebContents* source, InvalidateTypes changed_flags));
38 }; 38 };
39 39
40 } // namespace 40 } // namespace
41 41
42 class AudioStreamMonitorTest : public RenderViewHostTestHarness { 42 class AudioStreamMonitorTest : public RenderViewHostTestHarness {
43 public: 43 public:
44 AudioStreamMonitorTest() { 44 AudioStreamMonitorTest()
45 : monitor_(NULL), clock_(new base::SimpleTestTickClock()) {
45 // Start |clock_| at non-zero. 46 // Start |clock_| at non-zero.
46 clock_.Advance(base::TimeDelta::FromSeconds(1000000)); 47 clock_->Advance(base::TimeDelta::FromSeconds(1000000));
47 } 48 }
48 49
49 virtual void SetUp() override { 50 virtual void SetUp() override {
50 RenderViewHostTestHarness::SetUp(); 51 RenderViewHostTestHarness::SetUp();
51 52
52 WebContentsImpl* web_contents = reinterpret_cast<WebContentsImpl*>( 53 WebContentsImpl* web_contents = reinterpret_cast<WebContentsImpl*>(
53 RenderViewHostTestHarness::web_contents()); 54 RenderViewHostTestHarness::web_contents());
54 web_contents->SetDelegate(&mock_web_contents_delegate_); 55 web_contents->SetDelegate(&mock_web_contents_delegate_);
55 monitor_ = web_contents->audio_stream_monitor(); 56 monitor_ = web_contents->audio_stream_monitor();
56 const_cast<base::TickClock*&>(monitor_->clock_) = &clock_; 57 monitor_->set_clock_for_testing(clock_);
57 } 58 }
58 59
59 base::TimeTicks GetTestClockTime() { return clock_.NowTicks(); } 60 base::TimeTicks GetTestClockTime() { return clock_->NowTicks(); }
60 61
61 void AdvanceClock(const base::TimeDelta& delta) { clock_.Advance(delta); } 62 void AdvanceClock(const base::TimeDelta& delta) { clock_->Advance(delta); }
62 63
63 AudioStreamMonitor::ReadPowerAndClipCallback CreatePollCallback( 64 AudioStreamMonitor::ReadPowerAndClipCallback CreatePollCallback(
64 int stream_id) { 65 int stream_id) {
65 return base::Bind( 66 return base::Bind(
66 &AudioStreamMonitorTest::ReadPower, base::Unretained(this), stream_id); 67 &AudioStreamMonitorTest::ReadPower, base::Unretained(this), stream_id);
67 } 68 }
68 69
69 void SetStreamPower(int stream_id, float power) { 70 void SetStreamPower(int stream_id, float power) {
70 current_power_[stream_id] = power; 71 current_power_[stream_id] = power;
71 } 72 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 137
137 void ExpectIsNotifyingForToggleOn() { 138 void ExpectIsNotifyingForToggleOn() {
138 EXPECT_TRUE(monitor_->WasRecentlyAudible()); 139 EXPECT_TRUE(monitor_->WasRecentlyAudible());
139 } 140 }
140 141
141 void ExpectIsNotifyingForToggleOff() { 142 void ExpectIsNotifyingForToggleOff() {
142 EXPECT_FALSE(monitor_->WasRecentlyAudible()); 143 EXPECT_FALSE(monitor_->WasRecentlyAudible());
143 } 144 }
144 145
145 MockWebContentsDelegate mock_web_contents_delegate_; 146 MockWebContentsDelegate mock_web_contents_delegate_;
146 base::SimpleTestTickClock clock_; 147 scoped_refptr<base::SimpleTestTickClock> clock_;
147 std::map<int, float> current_power_; 148 std::map<int, float> current_power_;
148 149
149 DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitorTest); 150 DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitorTest);
150 }; 151 };
151 152
152 // Tests that AudioStreamMonitor is polling while it has a 153 // Tests that AudioStreamMonitor is polling while it has a
153 // ReadPowerAndClipCallback, and is not polling at other times. 154 // ReadPowerAndClipCallback, and is not polling at other times.
154 TEST_F(AudioStreamMonitorTest, PollsWhenProvidedACallback) { 155 TEST_F(AudioStreamMonitorTest, PollsWhenProvidedACallback) {
155 EXPECT_FALSE(monitor_->WasRecentlyAudible()); 156 EXPECT_FALSE(monitor_->WasRecentlyAudible());
156 ExpectIsPolling(kRenderProcessId, kStreamId, false); 157 ExpectIsPolling(kRenderProcessId, kStreamId, false);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 StartMonitoring( 289 StartMonitoring(
289 kAnotherRenderProcessId, kStreamId, CreatePollCallback(kStreamId)); 290 kAnotherRenderProcessId, kStreamId, CreatePollCallback(kStreamId));
290 ExpectIsPolling(kRenderProcessId, kStreamId, true); 291 ExpectIsPolling(kRenderProcessId, kStreamId, true);
291 ExpectIsPolling(kAnotherRenderProcessId, kStreamId, true); 292 ExpectIsPolling(kAnotherRenderProcessId, kStreamId, true);
292 StopMonitoring(kAnotherRenderProcessId, kStreamId); 293 StopMonitoring(kAnotherRenderProcessId, kStreamId);
293 ExpectIsPolling(kRenderProcessId, kStreamId, true); 294 ExpectIsPolling(kRenderProcessId, kStreamId, true);
294 ExpectIsPolling(kAnotherRenderProcessId, kStreamId, false); 295 ExpectIsPolling(kAnotherRenderProcessId, kStreamId, false);
295 } 296 }
296 297
297 } // namespace content 298 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/audio_stream_monitor.cc ('k') | content/renderer/media/render_media_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698