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

Side by Side Diff: content/browser/renderer_host/media/media_stream_manager_unittest.cc

Issue 1159623009: content: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test build fix. Created 5 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/location.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/thread_task_runner_handle.h"
11 #include "content/browser/browser_thread_impl.h" 13 #include "content/browser/browser_thread_impl.h"
12 #include "content/browser/renderer_host/media/media_stream_manager.h" 14 #include "content/browser/renderer_host/media/media_stream_manager.h"
13 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 15 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
14 #include "content/common/media/media_stream_options.h" 16 #include "content/common/media/media_stream_options.h"
15 #include "content/public/common/content_switches.h" 17 #include "content/public/common/content_switches.h"
16 #include "content/public/test/test_browser_thread_bundle.h" 18 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "media/audio/audio_manager_base.h" 19 #include "media/audio/audio_manager_base.h"
18 #include "media/audio/fake_audio_log_factory.h" 20 #include "media/audio/fake_audio_log_factory.h"
19 #include "media/base/media_switches.h" 21 #include "media/base/media_switches.h"
20 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 72
71 private: 73 private:
72 media::FakeAudioLogFactory fake_audio_log_factory_; 74 media::FakeAudioLogFactory fake_audio_log_factory_;
73 DISALLOW_COPY_AND_ASSIGN(MockAudioManager); 75 DISALLOW_COPY_AND_ASSIGN(MockAudioManager);
74 }; 76 };
75 77
76 class MediaStreamManagerTest : public ::testing::Test { 78 class MediaStreamManagerTest : public ::testing::Test {
77 public: 79 public:
78 MediaStreamManagerTest() 80 MediaStreamManagerTest()
79 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 81 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
80 message_loop_(base::MessageLoopProxy::current()) { 82 task_runner_(base::ThreadTaskRunnerHandle::Get()) {
81 // Create our own MediaStreamManager. Use fake devices to run on the bots. 83 // Create our own MediaStreamManager. Use fake devices to run on the bots.
82 base::CommandLine::ForCurrentProcess()->AppendSwitch( 84 base::CommandLine::ForCurrentProcess()->AppendSwitch(
83 switches::kUseFakeDeviceForMediaStream); 85 switches::kUseFakeDeviceForMediaStream);
84 audio_manager_.reset(new MockAudioManager()); 86 audio_manager_.reset(new MockAudioManager());
85 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); 87 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get()));
86 } 88 }
87 89
88 virtual ~MediaStreamManagerTest() { 90 virtual ~MediaStreamManagerTest() {
89 } 91 }
90 92
91 MOCK_METHOD1(Response, void(int index)); 93 MOCK_METHOD1(Response, void(int index));
92 void ResponseCallback(int index, 94 void ResponseCallback(int index,
93 const MediaStreamDevices& devices, 95 const MediaStreamDevices& devices,
94 scoped_ptr<MediaStreamUIProxy> ui_proxy) { 96 scoped_ptr<MediaStreamUIProxy> ui_proxy) {
95 Response(index); 97 Response(index);
96 message_loop_->PostTask(FROM_HERE, run_loop_.QuitClosure()); 98 task_runner_->PostTask(FROM_HERE, run_loop_.QuitClosure());
97 } 99 }
98 100
99 protected: 101 protected:
100 std::string MakeMediaAccessRequest(int index) { 102 std::string MakeMediaAccessRequest(int index) {
101 const int render_process_id = 1; 103 const int render_process_id = 1;
102 const int render_frame_id = 1; 104 const int render_frame_id = 1;
103 const int page_request_id = 1; 105 const int page_request_id = 1;
104 const GURL security_origin; 106 const GURL security_origin;
105 MediaStreamManager::MediaRequestResponseCallback callback = 107 MediaStreamManager::MediaRequestResponseCallback callback =
106 base::Bind(&MediaStreamManagerTest::ResponseCallback, 108 base::Bind(&MediaStreamManagerTest::ResponseCallback,
107 base::Unretained(this), index); 109 base::Unretained(this), index);
108 StreamOptions options(true, true); 110 StreamOptions options(true, true);
109 return media_stream_manager_->MakeMediaAccessRequest(render_process_id, 111 return media_stream_manager_->MakeMediaAccessRequest(render_process_id,
110 render_frame_id, 112 render_frame_id,
111 page_request_id, 113 page_request_id,
112 options, 114 options,
113 security_origin, 115 security_origin,
114 callback); 116 callback);
115 } 117 }
116 118
117 scoped_ptr<media::AudioManager> audio_manager_; 119 scoped_ptr<media::AudioManager> audio_manager_;
118 scoped_ptr<MediaStreamManager> media_stream_manager_; 120 scoped_ptr<MediaStreamManager> media_stream_manager_;
119 content::TestBrowserThreadBundle thread_bundle_; 121 content::TestBrowserThreadBundle thread_bundle_;
120 scoped_refptr<base::MessageLoopProxy> message_loop_; 122 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
121 base::RunLoop run_loop_; 123 base::RunLoop run_loop_;
122 124
123 private: 125 private:
124 DISALLOW_COPY_AND_ASSIGN(MediaStreamManagerTest); 126 DISALLOW_COPY_AND_ASSIGN(MediaStreamManagerTest);
125 }; 127 };
126 128
127 TEST_F(MediaStreamManagerTest, MakeMediaAccessRequest) { 129 TEST_F(MediaStreamManagerTest, MakeMediaAccessRequest) {
128 MakeMediaAccessRequest(0); 130 MakeMediaAccessRequest(0);
129 131
130 // Expecting the callback will be triggered and quit the test. 132 // Expecting the callback will be triggered and quit the test.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 std::string label2 = MakeMediaAccessRequest(1); 176 std::string label2 = MakeMediaAccessRequest(1);
175 media_stream_manager_->CancelRequest(label1); 177 media_stream_manager_->CancelRequest(label1);
176 178
177 // Expecting the callback from the second request will be triggered and 179 // Expecting the callback from the second request will be triggered and
178 // quit the test. 180 // quit the test.
179 EXPECT_CALL(*this, Response(1)); 181 EXPECT_CALL(*this, Response(1));
180 run_loop_.Run(); 182 run_loop_.Run();
181 } 183 }
182 184
183 } // namespace content 185 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698