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

Side by Side Diff: chrome/browser/media/router/presentation_service_delegate_impl_unittest.cc

Issue 2569843002: Remove duplicated code in PresentationServiceDelegateImplTest (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/media/router/presentation_service_delegate_impl.h" 5 #include "chrome/browser/media/router/presentation_service_delegate_impl.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "chrome/browser/media/router/media_source.h" 8 #include "chrome/browser/media/router/media_source.h"
9 #include "chrome/browser/media/router/media_source_helper.h" 9 #include "chrome/browser/media/router/media_source_helper.h"
10 #include "chrome/browser/media/router/mock_media_router.h" 10 #include "chrome/browser/media/router/mock_media_router.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 MOCK_METHOD1(OnCreateConnectionError, 65 MOCK_METHOD1(OnCreateConnectionError,
66 void(const content::PresentationError& error)); 66 void(const content::PresentationError& error));
67 }; 67 };
68 68
69 class PresentationServiceDelegateImplTest 69 class PresentationServiceDelegateImplTest
70 : public ChromeRenderViewHostTestHarness { 70 : public ChromeRenderViewHostTestHarness {
71 public: 71 public:
72 PresentationServiceDelegateImplTest() 72 PresentationServiceDelegateImplTest()
73 : delegate_impl_(nullptr), 73 : delegate_impl_(nullptr),
74 presentation_url1_(kPresentationUrl1), 74 presentation_url1_(kPresentationUrl1),
75 presentation_url2_(kPresentationUrl2) {} 75 presentation_url2_(kPresentationUrl2),
76 source1_(MediaSourceForPresentationUrl(presentation_url1_)),
77 source2_(MediaSourceForPresentationUrl(presentation_url2_)),
78 listener1_(presentation_url1_),
79 listener2_(presentation_url2_) {}
76 80
77 void SetUp() override { 81 void SetUp() override {
78 ChromeRenderViewHostTestHarness::SetUp(); 82 ChromeRenderViewHostTestHarness::SetUp();
79 content::WebContents* wc = GetWebContents(); 83 content::WebContents* wc = GetWebContents();
80 ASSERT_TRUE(wc); 84 ASSERT_TRUE(wc);
81 PresentationServiceDelegateImpl::CreateForWebContents(wc); 85 PresentationServiceDelegateImpl::CreateForWebContents(wc);
82 delegate_impl_ = PresentationServiceDelegateImpl::FromWebContents(wc); 86 delegate_impl_ = PresentationServiceDelegateImpl::FromWebContents(wc);
83 delegate_impl_->SetMediaRouterForTest(&router_); 87 delegate_impl_->SetMediaRouterForTest(&router_);
84 presentation_urls_.push_back(presentation_url1_); 88 presentation_urls_.push_back(presentation_url1_);
89 SetMainFrame();
85 } 90 }
86 91
87 MOCK_METHOD1(OnDefaultPresentationStarted, 92 MOCK_METHOD1(OnDefaultPresentationStarted,
88 void(const content::PresentationSessionInfo& session_info)); 93 void(const content::PresentationSessionInfo& session_info));
89 94
90 protected: 95 protected:
91 virtual content::WebContents* GetWebContents() { return web_contents(); } 96 virtual content::WebContents* GetWebContents() { return web_contents(); }
92 97
93 void RunDefaultPresentationUrlCallbackTest(bool incognito) { 98 void RunDefaultPresentationUrlCallbackTest(bool incognito) {
94 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
95 ASSERT_TRUE(main_frame);
96 int render_process_id = main_frame->GetProcess()->GetID();
97 int routing_id = main_frame->GetRoutingID();
98
99 auto callback = base::Bind( 99 auto callback = base::Bind(
100 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, 100 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted,
101 base::Unretained(this)); 101 base::Unretained(this));
102 std::vector<std::string> urls({kPresentationUrl1}); 102 std::vector<std::string> urls({kPresentationUrl1});
103 delegate_impl_->SetDefaultPresentationUrls(render_process_id, routing_id, 103 delegate_impl_->SetDefaultPresentationUrls(main_frame_process_id_,
104 main_frame_routing_id_,
104 presentation_urls_, callback); 105 presentation_urls_, callback);
105 106
106 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); 107 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest());
107 PresentationRequest request = 108 PresentationRequest request =
108 delegate_impl_->GetDefaultPresentationRequest(); 109 delegate_impl_->GetDefaultPresentationRequest();
109 110
110 // Should not trigger callback since route response is error. 111 // Should not trigger callback since route response is error.
111 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( 112 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError(
112 "Error", RouteRequestResult::UNKNOWN_ERROR); 113 "Error", RouteRequestResult::UNKNOWN_ERROR);
113 delegate_impl_->OnRouteResponse(request, *result); 114 delegate_impl_->OnRouteResponse(request, *result);
114 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)); 115 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this));
115 116
116 // Should not trigger callback since request doesn't match. 117 // Should not trigger callback since request doesn't match.
117 PresentationRequest different_request( 118 PresentationRequest different_request(
118 RenderFrameHostId(100, 200), {presentation_url2_}, GURL(kFrameUrl)); 119 RenderFrameHostId(100, 200), {presentation_url2_}, GURL(kFrameUrl));
119 MediaRoute* media_route = new MediaRoute( 120 MediaRoute* media_route = new MediaRoute("differentRouteId", source2_,
120 "differentRouteId", MediaSourceForPresentationUrl(presentation_url2_), 121 "mediaSinkId", "", true, "", true);
121 "mediaSinkId", "", true, "", true);
122 media_route->set_incognito(incognito); 122 media_route->set_incognito(incognito);
123 result = RouteRequestResult::FromSuccess(base::WrapUnique(media_route), 123 result = RouteRequestResult::FromSuccess(base::WrapUnique(media_route),
124 "differentPresentationId"); 124 "differentPresentationId");
125 delegate_impl_->OnRouteResponse(different_request, *result); 125 delegate_impl_->OnRouteResponse(different_request, *result);
126 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this)); 126 EXPECT_TRUE(Mock::VerifyAndClearExpectations(this));
127 127
128 // Should trigger callback since request matches. 128 // Should trigger callback since request matches.
129 EXPECT_CALL(*this, OnDefaultPresentationStarted(_)).Times(1); 129 EXPECT_CALL(*this, OnDefaultPresentationStarted(_)).Times(1);
130 MediaRoute* media_route2 = new MediaRoute( 130 MediaRoute* media_route2 =
131 "routeId", MediaSourceForPresentationUrl(presentation_url1_), 131 new MediaRoute("routeId", source1_, "mediaSinkId", "", true, "", true);
132 "mediaSinkId", "", true, "", true);
133 media_route2->set_incognito(incognito); 132 media_route2->set_incognito(incognito);
134 result = RouteRequestResult::FromSuccess(base::WrapUnique(media_route2), 133 result = RouteRequestResult::FromSuccess(base::WrapUnique(media_route2),
135 "presentationId"); 134 "presentationId");
136 delegate_impl_->OnRouteResponse(request, *result); 135 delegate_impl_->OnRouteResponse(request, *result);
137 } 136 }
138 137
138 void SetMainFrame() {
139 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
140 ASSERT_TRUE(main_frame);
141 main_frame_process_id_ = main_frame->GetProcess()->GetID();
142 main_frame_routing_id_ = main_frame->GetRoutingID();
143 }
144
139 PresentationServiceDelegateImpl* delegate_impl_; 145 PresentationServiceDelegateImpl* delegate_impl_;
140 MockMediaRouter router_; 146 MockMediaRouter router_;
141 const GURL presentation_url1_; 147 const GURL presentation_url1_;
142 const GURL presentation_url2_; 148 const GURL presentation_url2_;
143 std::vector<GURL> presentation_urls_; 149 std::vector<GURL> presentation_urls_;
150
151 // |source1_| and |source2_| correspond to |presentation_url1_| and
152 // |presentation_url2_|, respectively.
153 MediaSource source1_;
154 MediaSource source2_;
155
156 // |listener1_| and |listener2_| correspond to |presentation_url1_| and
157 // |presentation_url2_|, respectively.
158 MockScreenAvailabilityListener listener1_;
159 MockScreenAvailabilityListener listener2_;
160
161 // Set in SetMainFrame().
162 int main_frame_process_id_;
163 int main_frame_routing_id_;
144 }; 164 };
145 165
146 class PresentationServiceDelegateImplIncognitoTest 166 class PresentationServiceDelegateImplIncognitoTest
147 : public PresentationServiceDelegateImplTest { 167 : public PresentationServiceDelegateImplTest {
148 public: 168 public:
149 PresentationServiceDelegateImplIncognitoTest() : 169 PresentationServiceDelegateImplIncognitoTest() :
150 incognito_web_contents_(nullptr) {} 170 incognito_web_contents_(nullptr) {}
151 171
152 protected: 172 protected:
153 content::WebContents* GetWebContents() override { 173 content::WebContents* GetWebContents() override {
(...skipping 11 matching lines...) Expand all
165 // require RenderViewHost, etc., that in turn are deleted by 185 // require RenderViewHost, etc., that in turn are deleted by
166 // RenderViewHostTestHarness::TearDown(). 186 // RenderViewHostTestHarness::TearDown().
167 delete incognito_web_contents_; 187 delete incognito_web_contents_;
168 PresentationServiceDelegateImplTest::TearDown(); 188 PresentationServiceDelegateImplTest::TearDown();
169 } 189 }
170 190
171 content::WebContents* incognito_web_contents_; 191 content::WebContents* incognito_web_contents_;
172 }; 192 };
173 193
174 TEST_F(PresentationServiceDelegateImplTest, AddScreenAvailabilityListener) { 194 TEST_F(PresentationServiceDelegateImplTest, AddScreenAvailabilityListener) {
175 MediaSource source1 = MediaSourceForPresentationUrl(presentation_url1_);
176 MediaSource source2 = MediaSourceForPresentationUrl(presentation_url2_);
177 MockScreenAvailabilityListener listener1(presentation_url1_);
178 MockScreenAvailabilityListener listener2(presentation_url2_);
179 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
180 ASSERT_TRUE(main_frame);
181 int render_process_id = main_frame->GetProcess()->GetID();
182 int render_frame_id1 = main_frame->GetRoutingID();
183
184 // Note that |render_frame_id2| does not correspond to a real frame. As a 195 // Note that |render_frame_id2| does not correspond to a real frame. As a
185 // result, the observer added with have an empty GURL as origin. 196 // result, the observer added with have an empty GURL as origin.
186 int render_frame_id2 = 2; 197 int render_frame_id2 = 2;
187 198
188 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)) 199 EXPECT_CALL(router_, RegisterMediaSinksObserver(_))
189 .Times(2) 200 .Times(2)
190 .WillRepeatedly(Return(true)); 201 .WillRepeatedly(Return(true));
191 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( 202 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener(
192 render_process_id, render_frame_id1, &listener1)); 203 main_frame_process_id_, main_frame_routing_id_, &listener1_));
193 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( 204 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener(
194 render_process_id, render_frame_id2, &listener2)); 205 main_frame_process_id_, render_frame_id2, &listener2_));
195 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest( 206 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest(
196 render_process_id, render_frame_id1, source1.id())) 207 main_frame_process_id_, main_frame_routing_id_, source1_.id()))
197 << "Mapping not found for " << source1.ToString(); 208 << "Mapping not found for " << source1_.ToString();
198 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest( 209 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest(
199 render_process_id, render_frame_id2, source2.id())) 210 main_frame_process_id_, render_frame_id2, source2_.id()))
200 << "Mapping not found for " << source2.ToString(); 211 << "Mapping not found for " << source2_.ToString();
201 212
202 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(2); 213 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(2);
203 delegate_impl_->RemoveScreenAvailabilityListener( 214 delegate_impl_->RemoveScreenAvailabilityListener(
204 render_process_id, render_frame_id1, &listener1); 215 main_frame_process_id_, main_frame_routing_id_, &listener1_);
205 delegate_impl_->RemoveScreenAvailabilityListener( 216 delegate_impl_->RemoveScreenAvailabilityListener(
206 render_process_id, render_frame_id2, &listener2); 217 main_frame_process_id_, render_frame_id2, &listener2_);
207 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( 218 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest(
208 render_process_id, render_frame_id1, source1.id())); 219 main_frame_process_id_, main_frame_routing_id_, source1_.id()));
209 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( 220 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest(
210 render_process_id, render_frame_id2, source2.id())); 221 main_frame_process_id_, render_frame_id2, source2_.id()));
211 } 222 }
212 223
213 TEST_F(PresentationServiceDelegateImplTest, AddMultipleListenersToFrame) { 224 TEST_F(PresentationServiceDelegateImplTest, AddMultipleListenersToFrame) {
214 ON_CALL(router_, RegisterMediaSinksObserver(_)).WillByDefault(Return(true)); 225 ON_CALL(router_, RegisterMediaSinksObserver(_)).WillByDefault(Return(true));
215 226
216 MediaSource source1 = MediaSourceForPresentationUrl(presentation_url1_);
217 MediaSource source2 = MediaSourceForPresentationUrl(presentation_url2_);
218 MockScreenAvailabilityListener listener1(presentation_url1_);
219 MockScreenAvailabilityListener listener2(presentation_url2_);
220 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
221 ASSERT_TRUE(main_frame);
222 int render_process_id = main_frame->GetProcess()->GetID();
223 int render_frame_id = main_frame->GetRoutingID();
224 227
225 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).Times(2); 228 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).Times(2);
226 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( 229 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener(
227 render_process_id, render_frame_id, &listener1)); 230 main_frame_process_id_, main_frame_routing_id_, &listener1_));
228 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( 231 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener(
229 render_process_id, render_frame_id, &listener2)); 232 main_frame_process_id_, main_frame_routing_id_, &listener2_));
230 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest( 233 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest(
231 render_process_id, render_frame_id, source1.id())) 234 main_frame_process_id_, main_frame_routing_id_, source1_.id()))
232 << "Mapping not found for " << source1.ToString(); 235 << "Mapping not found for " << source1_.ToString();
233 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest( 236 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest(
234 render_process_id, render_frame_id, source2.id())) 237 main_frame_process_id_, main_frame_routing_id_, source2_.id()))
235 << "Mapping not found for " << source2.ToString(); 238 << "Mapping not found for " << source2_.ToString();
236 239
237 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(2); 240 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(2);
238 delegate_impl_->RemoveScreenAvailabilityListener( 241 delegate_impl_->RemoveScreenAvailabilityListener(
239 render_process_id, render_frame_id, &listener1); 242 main_frame_process_id_, main_frame_routing_id_, &listener1_);
240 delegate_impl_->RemoveScreenAvailabilityListener( 243 delegate_impl_->RemoveScreenAvailabilityListener(
241 render_process_id, render_frame_id, &listener2); 244 main_frame_process_id_, main_frame_routing_id_, &listener2_);
242 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( 245 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest(
243 render_process_id, render_frame_id, source1.id())); 246 main_frame_process_id_, main_frame_routing_id_, source1_.id()));
244 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( 247 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest(
245 render_process_id, render_frame_id, source2.id())); 248 main_frame_process_id_, main_frame_routing_id_, source2_.id()));
246 } 249 }
247 250
248 TEST_F(PresentationServiceDelegateImplTest, AddSameListenerTwice) { 251 TEST_F(PresentationServiceDelegateImplTest, AddSameListenerTwice) {
249 MediaSource source1(MediaSourceForPresentationUrl(presentation_url1_));
250 MockScreenAvailabilityListener listener1(presentation_url1_);
251 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
252 ASSERT_TRUE(main_frame);
253 int render_process_id = main_frame->GetProcess()->GetID();
254 int render_frame_id = main_frame->GetRoutingID();
255
256 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(true)); 252 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(true));
257 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( 253 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener(
258 render_process_id, render_frame_id, &listener1)); 254 main_frame_process_id_, main_frame_routing_id_, &listener1_));
259 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( 255 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener(
260 render_process_id, render_frame_id, &listener1)); 256 main_frame_process_id_, main_frame_routing_id_, &listener1_));
261 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest( 257 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest(
262 render_process_id, render_frame_id, source1.id())); 258 main_frame_process_id_, main_frame_routing_id_, source1_.id()));
263 259
264 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(1); 260 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(1);
265 delegate_impl_->RemoveScreenAvailabilityListener(render_process_id, 261 delegate_impl_->RemoveScreenAvailabilityListener(
266 render_frame_id, &listener1); 262 main_frame_process_id_, main_frame_routing_id_, &listener1_);
267 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( 263 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest(
268 render_process_id, render_frame_id, source1.id())); 264 main_frame_process_id_, main_frame_routing_id_, source1_.id()));
269 } 265 }
270 266
271 // TODO(imcheng): Add a test to set default presentation URL in a different 267 // TODO(imcheng): Add a test to set default presentation URL in a different
272 // RenderFrameHost and verify that it is ignored. 268 // RenderFrameHost and verify that it is ignored.
273 TEST_F(PresentationServiceDelegateImplTest, SetDefaultPresentationUrl) { 269 TEST_F(PresentationServiceDelegateImplTest, SetDefaultPresentationUrl) {
274 EXPECT_FALSE(delegate_impl_->HasDefaultPresentationRequest()); 270 EXPECT_FALSE(delegate_impl_->HasDefaultPresentationRequest());
275 271
276 GURL frame_url(kFrameUrl); 272 GURL frame_url(kFrameUrl);
277 content::WebContentsTester::For(GetWebContents()) 273 content::WebContentsTester::For(GetWebContents())
278 ->NavigateAndCommit(frame_url); 274 ->NavigateAndCommit(frame_url);
279 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
280 ASSERT_TRUE(main_frame);
281 int render_process_id = main_frame->GetProcess()->GetID();
282 int routing_id = main_frame->GetRoutingID();
283 275
284 auto callback = base::Bind( 276 auto callback = base::Bind(
285 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, 277 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted,
286 base::Unretained(this)); 278 base::Unretained(this));
287 delegate_impl_->SetDefaultPresentationUrls(render_process_id, routing_id, 279 delegate_impl_->SetDefaultPresentationUrls(main_frame_process_id_,
280 main_frame_routing_id_,
288 presentation_urls_, callback); 281 presentation_urls_, callback);
289 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); 282 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest());
290 PresentationRequest request1 = 283 PresentationRequest request1 =
291 delegate_impl_->GetDefaultPresentationRequest(); 284 delegate_impl_->GetDefaultPresentationRequest();
292 EXPECT_EQ(presentation_url1_, request1.presentation_urls()[0]); 285 EXPECT_EQ(presentation_url1_, request1.presentation_urls()[0]);
293 EXPECT_EQ(RenderFrameHostId(render_process_id, routing_id), 286 EXPECT_EQ(RenderFrameHostId(main_frame_process_id_, main_frame_routing_id_),
294 request1.render_frame_host_id()); 287 request1.render_frame_host_id());
295 EXPECT_EQ(frame_url, request1.frame_url()); 288 EXPECT_EQ(frame_url, request1.frame_url());
296 289
297 // Set to a new default presentation URL 290 // Set to a new default presentation URL
298 std::vector<GURL> new_urls = {presentation_url2_}; 291 std::vector<GURL> new_urls = {presentation_url2_};
299 delegate_impl_->SetDefaultPresentationUrls(render_process_id, routing_id, 292 delegate_impl_->SetDefaultPresentationUrls(
300 new_urls, callback); 293 main_frame_process_id_, main_frame_routing_id_, new_urls, callback);
301 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); 294 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest());
302 PresentationRequest request2 = 295 PresentationRequest request2 =
303 delegate_impl_->GetDefaultPresentationRequest(); 296 delegate_impl_->GetDefaultPresentationRequest();
304 EXPECT_EQ(presentation_url2_, request2.presentation_urls()[0]); 297 EXPECT_EQ(presentation_url2_, request2.presentation_urls()[0]);
305 EXPECT_EQ(RenderFrameHostId(render_process_id, routing_id), 298 EXPECT_EQ(RenderFrameHostId(main_frame_process_id_, main_frame_routing_id_),
306 request2.render_frame_host_id()); 299 request2.render_frame_host_id());
307 EXPECT_EQ(frame_url, request2.frame_url()); 300 EXPECT_EQ(frame_url, request2.frame_url());
308 301
309 // Remove default presentation URL. 302 // Remove default presentation URL.
310 delegate_impl_->SetDefaultPresentationUrls(render_process_id, routing_id, 303 delegate_impl_->SetDefaultPresentationUrls(main_frame_process_id_,
304 main_frame_routing_id_,
311 std::vector<GURL>(), callback); 305 std::vector<GURL>(), callback);
312 EXPECT_FALSE(delegate_impl_->HasDefaultPresentationRequest()); 306 EXPECT_FALSE(delegate_impl_->HasDefaultPresentationRequest());
313 } 307 }
314 308
315 TEST_F(PresentationServiceDelegateImplTest, DefaultPresentationUrlCallback) { 309 TEST_F(PresentationServiceDelegateImplTest, DefaultPresentationUrlCallback) {
316 RunDefaultPresentationUrlCallbackTest(false); 310 RunDefaultPresentationUrlCallbackTest(false);
317 } 311 }
318 312
319 TEST_F(PresentationServiceDelegateImplIncognitoTest, 313 TEST_F(PresentationServiceDelegateImplIncognitoTest,
320 DefaultPresentationUrlCallback) { 314 DefaultPresentationUrlCallback) {
321 RunDefaultPresentationUrlCallbackTest(true); 315 RunDefaultPresentationUrlCallbackTest(true);
322 } 316 }
323 317
324 TEST_F(PresentationServiceDelegateImplTest, 318 TEST_F(PresentationServiceDelegateImplTest,
325 DefaultPresentationRequestObserver) { 319 DefaultPresentationRequestObserver) {
326 auto callback = base::Bind( 320 auto callback = base::Bind(
327 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted, 321 &PresentationServiceDelegateImplTest::OnDefaultPresentationStarted,
328 base::Unretained(this)); 322 base::Unretained(this));
329 323
330 StrictMock<MockDefaultPresentationRequestObserver> observer; 324 StrictMock<MockDefaultPresentationRequestObserver> observer;
331 delegate_impl_->AddDefaultPresentationRequestObserver(&observer); 325 delegate_impl_->AddDefaultPresentationRequestObserver(&observer);
332 326
333 GURL frame_url(kFrameUrl); 327 GURL frame_url(kFrameUrl);
334 content::WebContentsTester::For(GetWebContents()) 328 content::WebContentsTester::For(GetWebContents())
335 ->NavigateAndCommit(frame_url); 329 ->NavigateAndCommit(frame_url);
336 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
337 ASSERT_TRUE(main_frame);
338 int render_process_id = main_frame->GetProcess()->GetID();
339 int routing_id = main_frame->GetRoutingID();
340 330
341 std::vector<GURL> request1_urls = {presentation_url1_}; 331 std::vector<GURL> request1_urls = {presentation_url1_};
342 PresentationRequest observed_request1( 332 PresentationRequest observed_request1(
343 RenderFrameHostId(render_process_id, routing_id), request1_urls, 333 RenderFrameHostId(main_frame_process_id_, main_frame_routing_id_),
344 frame_url); 334 request1_urls, frame_url);
345 EXPECT_CALL(observer, OnDefaultPresentationChanged(Equals(observed_request1))) 335 EXPECT_CALL(observer, OnDefaultPresentationChanged(Equals(observed_request1)))
346 .Times(1); 336 .Times(1);
347 delegate_impl_->SetDefaultPresentationUrls(render_process_id, routing_id, 337 delegate_impl_->SetDefaultPresentationUrls(
348 request1_urls, callback); 338 main_frame_process_id_, main_frame_routing_id_, request1_urls, callback);
349 339
350 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); 340 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest());
351 PresentationRequest request1 = 341 PresentationRequest request1 =
352 delegate_impl_->GetDefaultPresentationRequest(); 342 delegate_impl_->GetDefaultPresentationRequest();
353 EXPECT_TRUE(request1.Equals(observed_request1)); 343 EXPECT_TRUE(request1.Equals(observed_request1));
354 344
355 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer)); 345 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer));
356 346
357 std::vector<GURL> request2_urls = {presentation_url2_}; 347 std::vector<GURL> request2_urls = {presentation_url2_};
358 PresentationRequest observed_request2( 348 PresentationRequest observed_request2(
359 RenderFrameHostId(render_process_id, routing_id), request2_urls, 349 RenderFrameHostId(main_frame_process_id_, main_frame_routing_id_),
360 frame_url); 350 request2_urls, frame_url);
361 EXPECT_CALL(observer, OnDefaultPresentationChanged(Equals(observed_request2))) 351 EXPECT_CALL(observer, OnDefaultPresentationChanged(Equals(observed_request2)))
362 .Times(1); 352 .Times(1);
363 delegate_impl_->SetDefaultPresentationUrls(render_process_id, routing_id, 353 delegate_impl_->SetDefaultPresentationUrls(
364 request2_urls, callback); 354 main_frame_process_id_, main_frame_routing_id_, request2_urls, callback);
365 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest()); 355 ASSERT_TRUE(delegate_impl_->HasDefaultPresentationRequest());
366 PresentationRequest request2 = 356 PresentationRequest request2 =
367 delegate_impl_->GetDefaultPresentationRequest(); 357 delegate_impl_->GetDefaultPresentationRequest();
368 EXPECT_TRUE(request2.Equals(observed_request2)); 358 EXPECT_TRUE(request2.Equals(observed_request2));
369 359
370 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer)); 360 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer));
371 361
372 // Remove default presentation URL. 362 // Remove default presentation URL.
373 EXPECT_CALL(observer, OnDefaultPresentationRemoved()).Times(1); 363 EXPECT_CALL(observer, OnDefaultPresentationRemoved()).Times(1);
374 delegate_impl_->SetDefaultPresentationUrls(render_process_id, routing_id, 364 delegate_impl_->SetDefaultPresentationUrls(main_frame_process_id_,
365 main_frame_routing_id_,
375 std::vector<GURL>(), callback); 366 std::vector<GURL>(), callback);
376 } 367 }
377 368
378 TEST_F(PresentationServiceDelegateImplTest, ListenForConnnectionStateChange) { 369 TEST_F(PresentationServiceDelegateImplTest, ListenForConnnectionStateChange) {
379 GURL frame_url(kFrameUrl); 370 GURL frame_url(kFrameUrl);
380 content::WebContentsTester::For(GetWebContents()) 371 content::WebContentsTester::For(GetWebContents())
381 ->NavigateAndCommit(frame_url); 372 ->NavigateAndCommit(frame_url);
382 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
383 ASSERT_TRUE(main_frame);
384 int render_process_id = main_frame->GetProcess()->GetID();
385 int routing_id = main_frame->GetRoutingID();
386 373
387 // Set up a PresentationConnection so we can listen to it. 374 // Set up a PresentationConnection so we can listen to it.
388 std::vector<MediaRouteResponseCallback> route_response_callbacks; 375 std::vector<MediaRouteResponseCallback> route_response_callbacks;
389 EXPECT_CALL(router_, JoinRoute(_, _, _, _, _, _, false)) 376 EXPECT_CALL(router_, JoinRoute(_, _, _, _, _, _, false))
390 .WillOnce(SaveArg<4>(&route_response_callbacks)); 377 .WillOnce(SaveArg<4>(&route_response_callbacks));
391 378
392 const std::string kPresentationId("pid"); 379 const std::string kPresentationId("pid");
393 presentation_urls_.push_back(GURL(kPresentationUrl3)); 380 presentation_urls_.push_back(GURL(kPresentationUrl3));
394 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; 381 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks;
395 delegate_impl_->JoinSession( 382 delegate_impl_->JoinSession(
396 render_process_id, routing_id, presentation_urls_, kPresentationId, 383 main_frame_process_id_, main_frame_routing_id_, presentation_urls_,
384 kPresentationId,
397 base::Bind(&MockCreatePresentationConnnectionCallbacks:: 385 base::Bind(&MockCreatePresentationConnnectionCallbacks::
398 OnCreateConnectionSuccess, 386 OnCreateConnectionSuccess,
399 base::Unretained(&mock_create_connection_callbacks)), 387 base::Unretained(&mock_create_connection_callbacks)),
400 base::Bind( 388 base::Bind(
401 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, 389 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError,
402 base::Unretained(&mock_create_connection_callbacks))); 390 base::Unretained(&mock_create_connection_callbacks)));
403 391
404 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionSuccess(_)) 392 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionSuccess(_))
405 .Times(1); 393 .Times(1);
406 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromSuccess( 394 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromSuccess(
407 base::MakeUnique<MediaRoute>( 395 base::MakeUnique<MediaRoute>("routeId", source1_, "mediaSinkId",
408 "routeId", MediaSourceForPresentationUrl(presentation_url1_), 396 "description", true, "", true),
409 "mediaSinkId", "description", true, "", true),
410 kPresentationId); 397 kPresentationId);
411 for (const auto& route_response_callback : route_response_callbacks) 398 for (const auto& route_response_callback : route_response_callbacks)
412 route_response_callback.Run(*result); 399 route_response_callback.Run(*result);
413 400
414 MockPresentationConnectionStateChangedCallback mock_callback; 401 MockPresentationConnectionStateChangedCallback mock_callback;
415 content::PresentationConnectionStateChangedCallback callback = 402 content::PresentationConnectionStateChangedCallback callback =
416 base::Bind(&MockPresentationConnectionStateChangedCallback::Run, 403 base::Bind(&MockPresentationConnectionStateChangedCallback::Run,
417 base::Unretained(&mock_callback)); 404 base::Unretained(&mock_callback));
418 content::PresentationSessionInfo connection(presentation_url1_, 405 content::PresentationSessionInfo connection(presentation_url1_,
419 kPresentationId); 406 kPresentationId);
420 EXPECT_CALL(router_, OnAddPresentationConnectionStateChangedCallbackInvoked( 407 EXPECT_CALL(router_, OnAddPresentationConnectionStateChangedCallbackInvoked(
421 Equals(callback))); 408 Equals(callback)));
422 delegate_impl_->ListenForConnectionStateChange(render_process_id, routing_id, 409 delegate_impl_->ListenForConnectionStateChange(
423 connection, callback); 410 main_frame_process_id_, main_frame_routing_id_, connection, callback);
424 } 411 }
425 412
426 TEST_F(PresentationServiceDelegateImplTest, Reset) { 413 TEST_F(PresentationServiceDelegateImplTest, Reset) {
427 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)) 414 EXPECT_CALL(router_, RegisterMediaSinksObserver(_))
428 .WillRepeatedly(Return(true)); 415 .WillRepeatedly(Return(true));
429 416
430 MediaSource source = MediaSourceForPresentationUrl(presentation_url1_);
431 MockScreenAvailabilityListener listener1(presentation_url1_);
432
433 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
434 ASSERT_TRUE(main_frame);
435 int render_process_id = main_frame->GetProcess()->GetID();
436 int render_frame_id = main_frame->GetRoutingID();
437
438 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener( 417 EXPECT_TRUE(delegate_impl_->AddScreenAvailabilityListener(
439 render_process_id, render_frame_id, &listener1)); 418 main_frame_process_id_, main_frame_routing_id_, &listener1_));
440 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest( 419 EXPECT_TRUE(delegate_impl_->HasScreenAvailabilityListenerForTest(
441 render_process_id, render_frame_id, source.id())); 420 main_frame_process_id_, main_frame_routing_id_, source1_.id()));
442 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(1); 421 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(1);
443 delegate_impl_->Reset(render_process_id, render_frame_id); 422 delegate_impl_->Reset(main_frame_process_id_, main_frame_routing_id_);
444 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest( 423 EXPECT_FALSE(delegate_impl_->HasScreenAvailabilityListenerForTest(
445 render_process_id, render_frame_id, source.id())); 424 main_frame_process_id_, main_frame_routing_id_, source1_.id()));
446 } 425 }
447 426
448 TEST_F(PresentationServiceDelegateImplTest, DelegateObservers) { 427 TEST_F(PresentationServiceDelegateImplTest, DelegateObservers) {
449 std::unique_ptr<PresentationServiceDelegateImpl> manager( 428 std::unique_ptr<PresentationServiceDelegateImpl> manager(
450 new PresentationServiceDelegateImpl(GetWebContents())); 429 new PresentationServiceDelegateImpl(GetWebContents()));
451 manager->SetMediaRouterForTest(&router_); 430 manager->SetMediaRouterForTest(&router_);
452 431
453 StrictMock<MockDelegateObserver> delegate_observer1; 432 StrictMock<MockDelegateObserver> delegate_observer1;
454 StrictMock<MockDelegateObserver> delegate_observer2; 433 StrictMock<MockDelegateObserver> delegate_observer2;
455 434
456 manager->AddObserver(123, 234, &delegate_observer1); 435 manager->AddObserver(123, 234, &delegate_observer1);
457 manager->AddObserver(345, 456, &delegate_observer2); 436 manager->AddObserver(345, 456, &delegate_observer2);
458 437
459 // Removes |delegate_observer2|. 438 // Removes |delegate_observer2|.
460 manager->RemoveObserver(345, 456); 439 manager->RemoveObserver(345, 456);
461 440
462 EXPECT_CALL(delegate_observer1, OnDelegateDestroyed()).Times(1); 441 EXPECT_CALL(delegate_observer1, OnDelegateDestroyed()).Times(1);
463 manager.reset(); 442 manager.reset();
464 } 443 }
465 444
466 TEST_F(PresentationServiceDelegateImplTest, SinksObserverCantRegister) { 445 TEST_F(PresentationServiceDelegateImplTest, SinksObserverCantRegister) {
467 MockScreenAvailabilityListener listener(presentation_url1_);
468 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
469 ASSERT_TRUE(main_frame);
470 int render_process_id = main_frame->GetProcess()->GetID();
471 int render_frame_id = main_frame->GetRoutingID();
472
473 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); 446 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false));
474 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported()); 447 EXPECT_CALL(listener1_, OnScreenAvailabilityNotSupported());
475 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( 448 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener(
476 render_process_id, render_frame_id, &listener)); 449 main_frame_process_id_, main_frame_routing_id_, &listener1_));
477 } 450 }
478 451
479 #if !defined(OS_ANDROID) 452 #if !defined(OS_ANDROID)
480 TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) { 453 TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) {
481 GURL frame_url(kFrameUrl); 454 GURL frame_url(kFrameUrl);
482 std::string origin(url::Origin(frame_url).Serialize()); 455 std::string origin(url::Origin(frame_url).Serialize());
483 content::WebContentsTester::For(GetWebContents()) 456 content::WebContentsTester::For(GetWebContents())
484 ->NavigateAndCommit(frame_url); 457 ->NavigateAndCommit(frame_url);
485 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
486 ASSERT_TRUE(main_frame);
487 int render_process_id = main_frame->GetProcess()->GetID();
488 int routing_id = main_frame->GetRoutingID();
489 458
490 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; 459 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks;
491 const std::string kPresentationId("auto-join"); 460 const std::string kPresentationId("auto-join");
492 ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId)); 461 ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId));
493 462
494 // Set the user preference for |origin| to prefer tab mirroring. 463 // Set the user preference for |origin| to prefer tab mirroring.
495 { 464 {
496 ListPrefUpdate update(profile()->GetPrefs(), 465 ListPrefUpdate update(profile()->GetPrefs(),
497 prefs::kMediaRouterTabMirroringSources); 466 prefs::kMediaRouterTabMirroringSources);
498 update->AppendIfNotPresent(base::MakeUnique<base::StringValue>(origin)); 467 update->AppendIfNotPresent(base::MakeUnique<base::StringValue>(origin));
499 } 468 }
500 469
501 // Auto-join requests should be rejected. 470 // Auto-join requests should be rejected.
502 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_)); 471 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_));
503 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0); 472 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0);
504 delegate_impl_->JoinSession( 473 delegate_impl_->JoinSession(
505 render_process_id, routing_id, presentation_urls_, kPresentationId, 474 main_frame_process_id_, main_frame_routing_id_, presentation_urls_,
475 kPresentationId,
506 base::Bind(&MockCreatePresentationConnnectionCallbacks:: 476 base::Bind(&MockCreatePresentationConnnectionCallbacks::
507 OnCreateConnectionSuccess, 477 OnCreateConnectionSuccess,
508 base::Unretained(&mock_create_connection_callbacks)), 478 base::Unretained(&mock_create_connection_callbacks)),
509 base::Bind( 479 base::Bind(
510 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, 480 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError,
511 base::Unretained(&mock_create_connection_callbacks))); 481 base::Unretained(&mock_create_connection_callbacks)));
512 482
513 // Remove the user preference for |origin|. 483 // Remove the user preference for |origin|.
514 { 484 {
515 ListPrefUpdate update(profile()->GetPrefs(), 485 ListPrefUpdate update(profile()->GetPrefs(),
516 prefs::kMediaRouterTabMirroringSources); 486 prefs::kMediaRouterTabMirroringSources);
517 update->Remove(base::StringValue(origin), nullptr); 487 update->Remove(base::StringValue(origin), nullptr);
518 } 488 }
519 489
520 // Auto-join requests should now go through. 490 // Auto-join requests should now go through.
521 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(1); 491 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(1);
522 delegate_impl_->JoinSession( 492 delegate_impl_->JoinSession(
523 render_process_id, routing_id, presentation_urls_, kPresentationId, 493 main_frame_process_id_, main_frame_routing_id_, presentation_urls_,
494 kPresentationId,
524 base::Bind(&MockCreatePresentationConnnectionCallbacks:: 495 base::Bind(&MockCreatePresentationConnnectionCallbacks::
525 OnCreateConnectionSuccess, 496 OnCreateConnectionSuccess,
526 base::Unretained(&mock_create_connection_callbacks)), 497 base::Unretained(&mock_create_connection_callbacks)),
527 base::Bind( 498 base::Bind(
528 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, 499 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError,
529 base::Unretained(&mock_create_connection_callbacks))); 500 base::Unretained(&mock_create_connection_callbacks)));
530 } 501 }
531 502
532 TEST_F(PresentationServiceDelegateImplIncognitoTest, AutoJoinRequest) { 503 TEST_F(PresentationServiceDelegateImplIncognitoTest, AutoJoinRequest) {
533 GURL frame_url(kFrameUrl); 504 GURL frame_url(kFrameUrl);
534 std::string origin(url::Origin(frame_url).Serialize()); 505 std::string origin(url::Origin(frame_url).Serialize());
535 content::WebContentsTester::For(GetWebContents()) 506 content::WebContentsTester::For(GetWebContents())
536 ->NavigateAndCommit(frame_url); 507 ->NavigateAndCommit(frame_url);
537 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
538 ASSERT_TRUE(main_frame);
539 int render_process_id = main_frame->GetProcess()->GetID();
540 int routing_id = main_frame->GetRoutingID();
541 508
542 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks; 509 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks;
543 const std::string kPresentationId("auto-join"); 510 const std::string kPresentationId("auto-join");
544 ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId)); 511 ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId));
545 512
546 // Set the user preference for |origin| to prefer tab mirroring. 513 // Set the user preference for |origin| to prefer tab mirroring.
547 { 514 {
548 ListPrefUpdate update(profile()->GetOffTheRecordProfile()->GetPrefs(), 515 ListPrefUpdate update(profile()->GetOffTheRecordProfile()->GetPrefs(),
549 prefs::kMediaRouterTabMirroringSources); 516 prefs::kMediaRouterTabMirroringSources);
550 update->AppendIfNotPresent(base::MakeUnique<base::StringValue>(origin)); 517 update->AppendIfNotPresent(base::MakeUnique<base::StringValue>(origin));
551 } 518 }
552 519
553 // Setting the pref in incognito shouldn't set it for the non-incognito 520 // Setting the pref in incognito shouldn't set it for the non-incognito
554 // profile. 521 // profile.
555 const base::ListValue* non_incognito_origins = 522 const base::ListValue* non_incognito_origins =
556 profile()->GetPrefs()->GetList(prefs::kMediaRouterTabMirroringSources); 523 profile()->GetPrefs()->GetList(prefs::kMediaRouterTabMirroringSources);
557 EXPECT_EQ(non_incognito_origins->Find(base::StringValue(origin)), 524 EXPECT_EQ(non_incognito_origins->Find(base::StringValue(origin)),
558 non_incognito_origins->end()); 525 non_incognito_origins->end());
559 526
560 // Auto-join requests should be rejected. 527 // Auto-join requests should be rejected.
561 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_)); 528 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_));
562 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0); 529 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0);
563 delegate_impl_->JoinSession( 530 delegate_impl_->JoinSession(
564 render_process_id, routing_id, presentation_urls_, kPresentationId, 531 main_frame_process_id_, main_frame_routing_id_, presentation_urls_,
532 kPresentationId,
565 base::Bind(&MockCreatePresentationConnnectionCallbacks:: 533 base::Bind(&MockCreatePresentationConnnectionCallbacks::
566 OnCreateConnectionSuccess, 534 OnCreateConnectionSuccess,
567 base::Unretained(&mock_create_connection_callbacks)), 535 base::Unretained(&mock_create_connection_callbacks)),
568 base::Bind( 536 base::Bind(
569 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, 537 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError,
570 base::Unretained(&mock_create_connection_callbacks))); 538 base::Unretained(&mock_create_connection_callbacks)));
571 539
572 // Remove the user preference for |origin| in incognito. 540 // Remove the user preference for |origin| in incognito.
573 { 541 {
574 ListPrefUpdate update(profile()->GetOffTheRecordProfile()->GetPrefs(), 542 ListPrefUpdate update(profile()->GetOffTheRecordProfile()->GetPrefs(),
575 prefs::kMediaRouterTabMirroringSources); 543 prefs::kMediaRouterTabMirroringSources);
576 update->Remove(base::StringValue(origin), nullptr); 544 update->Remove(base::StringValue(origin), nullptr);
577 } 545 }
578 546
579 // Auto-join requests should now go through. 547 // Auto-join requests should now go through.
580 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(1); 548 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(1);
581 delegate_impl_->JoinSession( 549 delegate_impl_->JoinSession(
582 render_process_id, routing_id, presentation_urls_, kPresentationId, 550 main_frame_process_id_, main_frame_routing_id_, presentation_urls_,
551 kPresentationId,
583 base::Bind(&MockCreatePresentationConnnectionCallbacks:: 552 base::Bind(&MockCreatePresentationConnnectionCallbacks::
584 OnCreateConnectionSuccess, 553 OnCreateConnectionSuccess,
585 base::Unretained(&mock_create_connection_callbacks)), 554 base::Unretained(&mock_create_connection_callbacks)),
586 base::Bind( 555 base::Bind(
587 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError, 556 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError,
588 base::Unretained(&mock_create_connection_callbacks))); 557 base::Unretained(&mock_create_connection_callbacks)));
589 } 558 }
590 #endif // !defined(OS_ANDROID) 559 #endif // !defined(OS_ANDROID)
591 560
592 } // namespace media_router 561 } // namespace media_router
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698