OLD | NEW |
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/macros.h" | 8 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" |
10 #include "content/browser/browser_thread_impl.h" | 11 #include "content/browser/browser_thread_impl.h" |
11 #include "content/browser/renderer_host/media/media_stream_settings_requester.h" | 12 #include "content/browser/renderer_host/media/media_stream_settings_requester.h" |
12 #include "content/browser/renderer_host/media/media_stream_ui_controller.h" | 13 #include "content/browser/renderer_host/media/media_stream_ui_controller.h" |
13 #include "content/common/media/media_stream_options.h" | 14 #include "content/common/media/media_stream_options.h" |
14 #include "content/public/common/media_stream_request.h" | 15 #include "content/public/common/media_stream_request.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 using testing::_; | 19 using testing::_; |
19 | 20 |
(...skipping 25 matching lines...) Expand all Loading... |
45 protected: | 46 protected: |
46 virtual void SetUp() { | 47 virtual void SetUp() { |
47 message_loop_.reset(new base::MessageLoopForIO); | 48 message_loop_.reset(new base::MessageLoopForIO); |
48 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, | 49 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, |
49 message_loop_.get())); | 50 message_loop_.get())); |
50 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, | 51 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, |
51 message_loop_.get())); | 52 message_loop_.get())); |
52 ui_controller_.reset(new MediaStreamUIController(this)); | 53 ui_controller_.reset(new MediaStreamUIController(this)); |
53 } | 54 } |
54 | 55 |
55 virtual void TearDown() { | 56 virtual void TearDown() { base::RunLoop().RunUntilIdle(); } |
56 message_loop_->RunUntilIdle(); | |
57 } | |
58 | 57 |
59 void CreateDummyRequest(const std::string& label, bool audio, bool video) { | 58 void CreateDummyRequest(const std::string& label, bool audio, bool video) { |
60 int dummy_render_process_id = 1; | 59 int dummy_render_process_id = 1; |
61 int dummy_render_view_id = 1; | 60 int dummy_render_view_id = 1; |
62 StreamOptions components(audio, video ); | 61 StreamOptions components(audio, video ); |
63 GURL security_origin; | 62 GURL security_origin; |
64 ui_controller_->MakeUIRequest(label, | 63 ui_controller_->MakeUIRequest(label, |
65 dummy_render_process_id, | 64 dummy_render_process_id, |
66 dummy_render_view_id, | 65 dummy_render_view_id, |
67 components, | 66 components, |
(...skipping 30 matching lines...) Expand all Loading... |
98 | 97 |
99 TEST_F(MediaStreamDeviceUIControllerTest, HandleRequestUsingFakeUI) { | 98 TEST_F(MediaStreamDeviceUIControllerTest, HandleRequestUsingFakeUI) { |
100 ui_controller_->UseFakeUI(std::unique_ptr<MediaStreamUI>()); | 99 ui_controller_->UseFakeUI(std::unique_ptr<MediaStreamUI>()); |
101 | 100 |
102 const std::string label = "label"; | 101 const std::string label = "label"; |
103 CreateDummyRequest(label, true, true); | 102 CreateDummyRequest(label, true, true); |
104 | 103 |
105 // Remove the current request, it should not crash. | 104 // Remove the current request, it should not crash. |
106 EXPECT_CALL(*this, DevicesAccepted(label, _)); | 105 EXPECT_CALL(*this, DevicesAccepted(label, _)); |
107 | 106 |
108 message_loop_->RunUntilIdle(); | 107 base::RunLoop().RunUntilIdle(); |
109 | 108 |
110 ui_controller_->NotifyUIIndicatorDevicesClosed(label); | 109 ui_controller_->NotifyUIIndicatorDevicesClosed(label); |
111 } | 110 } |
112 | 111 |
113 TEST_F(MediaStreamDeviceUIControllerTest, CreateRequestsAndCancelTheFirst) { | 112 TEST_F(MediaStreamDeviceUIControllerTest, CreateRequestsAndCancelTheFirst) { |
114 ui_controller_->UseFakeUI(std::unique_ptr<MediaStreamUI>()); | 113 ui_controller_->UseFakeUI(std::unique_ptr<MediaStreamUI>()); |
115 | 114 |
116 // Create the first audio request. | 115 // Create the first audio request. |
117 const std::string label_1 = "label_1"; | 116 const std::string label_1 = "label_1"; |
118 CreateDummyRequest(label_1, true, false); | 117 CreateDummyRequest(label_1, true, false); |
119 | 118 |
120 // Create the second video request. | 119 // Create the second video request. |
121 const std::string label_2 = "label_2"; | 120 const std::string label_2 = "label_2"; |
122 CreateDummyRequest(label_2, false, true); | 121 CreateDummyRequest(label_2, false, true); |
123 | 122 |
124 // Create the third audio and video request. | 123 // Create the third audio and video request. |
125 const std::string label_3 = "label_3"; | 124 const std::string label_3 = "label_3"; |
126 CreateDummyRequest(label_3, true, true); | 125 CreateDummyRequest(label_3, true, true); |
127 | 126 |
128 // Remove the first request which has been brought to the UI. | 127 // Remove the first request which has been brought to the UI. |
129 ui_controller_->CancelUIRequest(label_1); | 128 ui_controller_->CancelUIRequest(label_1); |
130 | 129 |
131 // We should get callbacks from the rest of the requests. | 130 // We should get callbacks from the rest of the requests. |
132 EXPECT_CALL(*this, DevicesAccepted(label_2, _)); | 131 EXPECT_CALL(*this, DevicesAccepted(label_2, _)); |
133 EXPECT_CALL(*this, DevicesAccepted(label_3, _)); | 132 EXPECT_CALL(*this, DevicesAccepted(label_3, _)); |
134 | 133 |
135 message_loop_->RunUntilIdle(); | 134 base::RunLoop().RunUntilIdle(); |
136 | 135 |
137 ui_controller_->NotifyUIIndicatorDevicesClosed(label_2); | 136 ui_controller_->NotifyUIIndicatorDevicesClosed(label_2); |
138 ui_controller_->NotifyUIIndicatorDevicesClosed(label_3); | 137 ui_controller_->NotifyUIIndicatorDevicesClosed(label_3); |
139 } | 138 } |
140 | 139 |
141 TEST_F(MediaStreamDeviceUIControllerTest, CreateRequestsAndCancelTheLast) { | 140 TEST_F(MediaStreamDeviceUIControllerTest, CreateRequestsAndCancelTheLast) { |
142 ui_controller_->UseFakeUI(std::unique_ptr<MediaStreamUI>()); | 141 ui_controller_->UseFakeUI(std::unique_ptr<MediaStreamUI>()); |
143 | 142 |
144 // Create the first audio request. | 143 // Create the first audio request. |
145 const std::string label_1 = "label_1"; | 144 const std::string label_1 = "label_1"; |
146 CreateDummyRequest(label_1, true, false); | 145 CreateDummyRequest(label_1, true, false); |
147 | 146 |
148 // Create the second video request. | 147 // Create the second video request. |
149 const std::string label_2 = "label_2"; | 148 const std::string label_2 = "label_2"; |
150 CreateDummyRequest(label_2, false, true); | 149 CreateDummyRequest(label_2, false, true); |
151 | 150 |
152 // Create the third audio and video request. | 151 // Create the third audio and video request. |
153 const std::string label_3 = "label_3"; | 152 const std::string label_3 = "label_3"; |
154 CreateDummyRequest(label_3, true, true); | 153 CreateDummyRequest(label_3, true, true); |
155 | 154 |
156 // Remove the last request which is pending in the queue. | 155 // Remove the last request which is pending in the queue. |
157 ui_controller_->CancelUIRequest(label_3); | 156 ui_controller_->CancelUIRequest(label_3); |
158 | 157 |
159 // We should get callbacks from the rest of the requests. | 158 // We should get callbacks from the rest of the requests. |
160 EXPECT_CALL(*this, DevicesAccepted(label_1, _)); | 159 EXPECT_CALL(*this, DevicesAccepted(label_1, _)); |
161 EXPECT_CALL(*this, DevicesAccepted(label_2, _)); | 160 EXPECT_CALL(*this, DevicesAccepted(label_2, _)); |
162 | 161 |
163 message_loop_->RunUntilIdle(); | 162 base::RunLoop().RunUntilIdle(); |
164 | 163 |
165 ui_controller_->NotifyUIIndicatorDevicesClosed(label_1); | 164 ui_controller_->NotifyUIIndicatorDevicesClosed(label_1); |
166 ui_controller_->NotifyUIIndicatorDevicesClosed(label_2); | 165 ui_controller_->NotifyUIIndicatorDevicesClosed(label_2); |
167 } | 166 } |
168 | 167 |
169 } // namespace content | 168 } // namespace content |
OLD | NEW |