OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "chrome/browser/content_settings/host_content_settings_map.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map.h" |
10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
11 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" | 11 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
| 12 #include "chrome/browser/infobars/infobar_tab_helper.h" |
12 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 13 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
13 #include "chrome/browser/tab_contents/infobar.h" | 14 #include "chrome/browser/tab_contents/infobar.h" |
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
15 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 16 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" |
16 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
17 #include "content/browser/browser_thread.h" | 18 #include "content/browser/browser_thread.h" |
18 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h
" | 19 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h
" |
19 #include "content/browser/geolocation/location_arbitrator.h" | 20 #include "content/browser/geolocation/location_arbitrator.h" |
20 #include "content/browser/geolocation/location_provider.h" | 21 #include "content/browser/geolocation/location_provider.h" |
21 #include "content/browser/geolocation/mock_location_provider.h" | 22 #include "content/browser/geolocation/mock_location_provider.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 int process_id() { return contents()->render_view_host()->process()->id(); } | 95 int process_id() { return contents()->render_view_host()->process()->id(); } |
95 int process_id_for_tab(int tab) { | 96 int process_id_for_tab(int tab) { |
96 return extra_tabs_[tab]->tab_contents()->render_view_host()->process()-> | 97 return extra_tabs_[tab]->tab_contents()->render_view_host()->process()-> |
97 id(); | 98 id(); |
98 } | 99 } |
99 int render_id() { return contents()->render_view_host()->routing_id(); } | 100 int render_id() { return contents()->render_view_host()->routing_id(); } |
100 int render_id_for_tab(int tab) { | 101 int render_id_for_tab(int tab) { |
101 return extra_tabs_[tab]->tab_contents()->render_view_host()->routing_id(); | 102 return extra_tabs_[tab]->tab_contents()->render_view_host()->routing_id(); |
102 } | 103 } |
103 int bridge_id() const { return 42; } // Not relevant at this level. | 104 int bridge_id() const { return 42; } // Not relevant at this level. |
| 105 InfoBarTabHelper* infobar_tab_helper() { |
| 106 return contents_wrapper()->infobar_tab_helper(); |
| 107 } |
104 | 108 |
105 void CheckPermissionMessageSent(int bridge_id, bool allowed); | 109 void CheckPermissionMessageSent(int bridge_id, bool allowed); |
106 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); | 110 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); |
107 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, | 111 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, |
108 int bridge_id, | 112 int bridge_id, |
109 bool allowed); | 113 bool allowed); |
110 void AddNewTab(const GURL& url); | 114 void AddNewTab(const GURL& url); |
111 void CheckTabContentsState(const GURL& requesting_frame, | 115 void CheckTabContentsState(const GURL& requesting_frame, |
112 ContentSetting expected_content_setting); | 116 ContentSetting expected_content_setting); |
113 | 117 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 GeolocationArbitrator::SetDependencyFactoryForTest(NULL); | 208 GeolocationArbitrator::SetDependencyFactoryForTest(NULL); |
205 TabContentsWrapperTestHarness::TearDown(); | 209 TabContentsWrapperTestHarness::TearDown(); |
206 } | 210 } |
207 | 211 |
208 | 212 |
209 // Tests ---------------------------------------------------------------------- | 213 // Tests ---------------------------------------------------------------------- |
210 | 214 |
211 TEST_F(GeolocationPermissionContextTests, SinglePermission) { | 215 TEST_F(GeolocationPermissionContextTests, SinglePermission) { |
212 GURL requesting_frame("http://www.example.com/geolocation"); | 216 GURL requesting_frame("http://www.example.com/geolocation"); |
213 NavigateAndCommit(requesting_frame); | 217 NavigateAndCommit(requesting_frame); |
214 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 218 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); |
215 geolocation_permission_context_->RequestGeolocationPermission( | 219 geolocation_permission_context_->RequestGeolocationPermission( |
216 process_id(), render_id(), bridge_id(), requesting_frame); | 220 process_id(), render_id(), bridge_id(), requesting_frame); |
217 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); | 221 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); |
218 ConfirmInfoBarDelegate* infobar_0 = | 222 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> |
219 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 223 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
220 infobar_0->Cancel(); | 224 infobar_0->Cancel(); |
221 contents_wrapper()->RemoveInfoBar(infobar_0); | 225 infobar_tab_helper()->RemoveInfoBar(infobar_0); |
222 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 226 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
223 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 227 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
224 infobar_0->InfoBarClosed(); | 228 infobar_0->InfoBarClosed(); |
225 } | 229 } |
226 | 230 |
227 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { | 231 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { |
228 GURL requesting_frame_0("http://www.example.com/geolocation"); | 232 GURL requesting_frame_0("http://www.example.com/geolocation"); |
229 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 233 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
230 EXPECT_EQ(CONTENT_SETTING_ASK, | 234 EXPECT_EQ(CONTENT_SETTING_ASK, |
231 profile()->GetHostContentSettingsMap()->GetContentSetting( | 235 profile()->GetHostContentSettingsMap()->GetContentSetting( |
232 requesting_frame_0, | 236 requesting_frame_0, |
233 requesting_frame_0, | 237 requesting_frame_0, |
234 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 238 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
235 std::string())); | 239 std::string())); |
236 EXPECT_EQ(CONTENT_SETTING_ASK, | 240 EXPECT_EQ(CONTENT_SETTING_ASK, |
237 profile()->GetHostContentSettingsMap()->GetContentSetting( | 241 profile()->GetHostContentSettingsMap()->GetContentSetting( |
238 requesting_frame_1, | 242 requesting_frame_1, |
239 requesting_frame_0, | 243 requesting_frame_0, |
240 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 244 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
241 std::string())); | 245 std::string())); |
242 | 246 |
243 | 247 |
244 NavigateAndCommit(requesting_frame_0); | 248 NavigateAndCommit(requesting_frame_0); |
245 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 249 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); |
246 // Request permission for two frames. | 250 // Request permission for two frames. |
247 geolocation_permission_context_->RequestGeolocationPermission( | 251 geolocation_permission_context_->RequestGeolocationPermission( |
248 process_id(), render_id(), bridge_id(), requesting_frame_0); | 252 process_id(), render_id(), bridge_id(), requesting_frame_0); |
249 geolocation_permission_context_->RequestGeolocationPermission( | 253 geolocation_permission_context_->RequestGeolocationPermission( |
250 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); | 254 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); |
251 // Ensure only one infobar is created. | 255 // Ensure only one infobar is created. |
252 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); | 256 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); |
253 ConfirmInfoBarDelegate* infobar_0 = | 257 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> |
254 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 258 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
255 ASSERT_TRUE(infobar_0); | 259 ASSERT_TRUE(infobar_0); |
256 string16 text_0 = infobar_0->GetMessageText(); | 260 string16 text_0 = infobar_0->GetMessageText(); |
257 | 261 |
258 // Accept the first frame. | 262 // Accept the first frame. |
259 infobar_0->Accept(); | 263 infobar_0->Accept(); |
260 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | 264 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
261 CheckPermissionMessageSent(bridge_id(), true); | 265 CheckPermissionMessageSent(bridge_id(), true); |
262 | 266 |
263 contents_wrapper()->RemoveInfoBar(infobar_0); | 267 infobar_tab_helper()->RemoveInfoBar(infobar_0); |
264 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 268 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
265 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 269 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
266 closed_delegate_tracker_.Clear(); | 270 closed_delegate_tracker_.Clear(); |
267 infobar_0->InfoBarClosed(); | 271 infobar_0->InfoBarClosed(); |
268 // Now we should have a new infobar for the second frame. | 272 // Now we should have a new infobar for the second frame. |
269 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); | 273 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); |
270 | 274 |
271 ConfirmInfoBarDelegate* infobar_1 = | 275 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()-> |
272 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 276 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
273 ASSERT_TRUE(infobar_1); | 277 ASSERT_TRUE(infobar_1); |
274 string16 text_1 = infobar_1->GetMessageText(); | 278 string16 text_1 = infobar_1->GetMessageText(); |
275 EXPECT_NE(text_0, text_1); | 279 EXPECT_NE(text_0, text_1); |
276 | 280 |
277 // Cancel (block) this frame. | 281 // Cancel (block) this frame. |
278 infobar_1->Cancel(); | 282 infobar_1->Cancel(); |
279 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); | 283 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
280 CheckPermissionMessageSent(bridge_id() + 1, false); | 284 CheckPermissionMessageSent(bridge_id() + 1, false); |
281 contents_wrapper()->RemoveInfoBar(infobar_1); | 285 infobar_tab_helper()->RemoveInfoBar(infobar_1); |
282 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 286 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
283 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 287 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
284 infobar_1->InfoBarClosed(); | 288 infobar_1->InfoBarClosed(); |
285 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 289 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); |
286 // Ensure the persisted permissions are ok. | 290 // Ensure the persisted permissions are ok. |
287 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 291 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
288 profile()->GetHostContentSettingsMap()->GetContentSetting( | 292 profile()->GetHostContentSettingsMap()->GetContentSetting( |
289 requesting_frame_0, | 293 requesting_frame_0, |
290 requesting_frame_0, | 294 requesting_frame_0, |
291 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 295 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
292 std::string())); | 296 std::string())); |
293 | 297 |
294 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 298 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
295 profile()->GetHostContentSettingsMap()->GetContentSetting( | 299 profile()->GetHostContentSettingsMap()->GetContentSetting( |
(...skipping 15 matching lines...) Expand all Loading... |
311 | 315 |
312 EXPECT_EQ(CONTENT_SETTING_ASK, | 316 EXPECT_EQ(CONTENT_SETTING_ASK, |
313 profile()->GetHostContentSettingsMap()->GetContentSetting( | 317 profile()->GetHostContentSettingsMap()->GetContentSetting( |
314 requesting_frame_1, | 318 requesting_frame_1, |
315 requesting_frame_0, | 319 requesting_frame_0, |
316 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 320 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
317 std::string())); | 321 std::string())); |
318 | 322 |
319 | 323 |
320 NavigateAndCommit(requesting_frame_0); | 324 NavigateAndCommit(requesting_frame_0); |
321 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 325 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); |
322 // Request permission for two frames. | 326 // Request permission for two frames. |
323 geolocation_permission_context_->RequestGeolocationPermission( | 327 geolocation_permission_context_->RequestGeolocationPermission( |
324 process_id(), render_id(), bridge_id(), requesting_frame_0); | 328 process_id(), render_id(), bridge_id(), requesting_frame_0); |
325 geolocation_permission_context_->RequestGeolocationPermission( | 329 geolocation_permission_context_->RequestGeolocationPermission( |
326 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); | 330 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); |
327 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); | 331 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); |
328 | 332 |
329 ConfirmInfoBarDelegate* infobar_0 = | 333 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> |
330 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 334 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
331 ASSERT_TRUE(infobar_0); | 335 ASSERT_TRUE(infobar_0); |
332 string16 text_0 = infobar_0->GetMessageText(); | 336 string16 text_0 = infobar_0->GetMessageText(); |
333 | 337 |
334 // Simulate the frame going away, ensure the infobar for this frame | 338 // Simulate the frame going away, ensure the infobar for this frame |
335 // is removed and the next pending infobar is created. | 339 // is removed and the next pending infobar is created. |
336 geolocation_permission_context_->CancelGeolocationPermissionRequest( | 340 geolocation_permission_context_->CancelGeolocationPermissionRequest( |
337 process_id(), render_id(), bridge_id(), requesting_frame_0); | 341 process_id(), render_id(), bridge_id(), requesting_frame_0); |
338 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 342 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
339 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 343 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
340 closed_delegate_tracker_.Clear(); | 344 closed_delegate_tracker_.Clear(); |
341 infobar_0->InfoBarClosed(); | 345 infobar_0->InfoBarClosed(); |
342 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); | 346 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); |
343 | 347 |
344 ConfirmInfoBarDelegate* infobar_1 = | 348 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()-> |
345 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 349 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
346 ASSERT_TRUE(infobar_1); | 350 ASSERT_TRUE(infobar_1); |
347 string16 text_1 = infobar_1->GetMessageText(); | 351 string16 text_1 = infobar_1->GetMessageText(); |
348 EXPECT_NE(text_0, text_1); | 352 EXPECT_NE(text_0, text_1); |
349 | 353 |
350 // Allow this frame. | 354 // Allow this frame. |
351 infobar_1->Accept(); | 355 infobar_1->Accept(); |
352 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); | 356 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); |
353 CheckPermissionMessageSent(bridge_id() + 1, true); | 357 CheckPermissionMessageSent(bridge_id() + 1, true); |
354 contents_wrapper()->RemoveInfoBar(infobar_1); | 358 infobar_tab_helper()->RemoveInfoBar(infobar_1); |
355 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 359 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
356 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 360 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
357 infobar_1->InfoBarClosed(); | 361 infobar_1->InfoBarClosed(); |
358 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 362 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); |
359 // Ensure the persisted permissions are ok. | 363 // Ensure the persisted permissions are ok. |
360 EXPECT_EQ(CONTENT_SETTING_ASK, | 364 EXPECT_EQ(CONTENT_SETTING_ASK, |
361 profile()->GetHostContentSettingsMap()->GetContentSetting( | 365 profile()->GetHostContentSettingsMap()->GetContentSetting( |
362 requesting_frame_0, | 366 requesting_frame_0, |
363 requesting_frame_0, | 367 requesting_frame_0, |
364 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 368 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
365 std::string())); | 369 std::string())); |
366 | 370 |
367 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 371 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
368 profile()->GetHostContentSettingsMap()->GetContentSetting( | 372 profile()->GetHostContentSettingsMap()->GetContentSetting( |
369 requesting_frame_1, | 373 requesting_frame_1, |
370 requesting_frame_0, | 374 requesting_frame_0, |
371 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 375 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
372 std::string())); | 376 std::string())); |
373 } | 377 } |
374 | 378 |
375 TEST_F(GeolocationPermissionContextTests, InvalidURL) { | 379 TEST_F(GeolocationPermissionContextTests, InvalidURL) { |
376 GURL invalid_embedder; | 380 GURL invalid_embedder; |
377 GURL requesting_frame("about:blank"); | 381 GURL requesting_frame("about:blank"); |
378 NavigateAndCommit(invalid_embedder); | 382 NavigateAndCommit(invalid_embedder); |
379 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 383 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); |
380 geolocation_permission_context_->RequestGeolocationPermission( | 384 geolocation_permission_context_->RequestGeolocationPermission( |
381 process_id(), render_id(), bridge_id(), requesting_frame); | 385 process_id(), render_id(), bridge_id(), requesting_frame); |
382 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 386 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); |
383 CheckPermissionMessageSent(bridge_id(), false); | 387 CheckPermissionMessageSent(bridge_id(), false); |
384 } | 388 } |
385 | 389 |
386 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { | 390 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { |
387 GURL url_a("http://www.example.com/geolocation"); | 391 GURL url_a("http://www.example.com/geolocation"); |
388 GURL url_b("http://www.example-2.com/geolocation"); | 392 GURL url_b("http://www.example-2.com/geolocation"); |
389 NavigateAndCommit(url_a); | 393 NavigateAndCommit(url_a); |
390 AddNewTab(url_b); | 394 AddNewTab(url_b); |
391 AddNewTab(url_a); | 395 AddNewTab(url_a); |
392 | 396 |
393 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 397 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); |
394 geolocation_permission_context_->RequestGeolocationPermission( | 398 geolocation_permission_context_->RequestGeolocationPermission( |
395 process_id(), render_id(), bridge_id(), url_a); | 399 process_id(), render_id(), bridge_id(), url_a); |
396 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); | 400 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); |
397 | 401 |
398 geolocation_permission_context_->RequestGeolocationPermission( | 402 geolocation_permission_context_->RequestGeolocationPermission( |
399 process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_b); | 403 process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_b); |
400 EXPECT_EQ(1U, extra_tabs_[0]->infobar_count()); | 404 EXPECT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); |
401 | 405 |
402 geolocation_permission_context_->RequestGeolocationPermission( | 406 geolocation_permission_context_->RequestGeolocationPermission( |
403 process_id_for_tab(1), render_id_for_tab(1), bridge_id(), url_a); | 407 process_id_for_tab(1), render_id_for_tab(1), bridge_id(), url_a); |
404 ASSERT_EQ(1U, extra_tabs_[1]->infobar_count()); | 408 ASSERT_EQ(1U, extra_tabs_[1]->infobar_tab_helper()->infobar_count()); |
405 | 409 |
406 ConfirmInfoBarDelegate* removed_infobar = | 410 ConfirmInfoBarDelegate* removed_infobar = extra_tabs_[1]-> |
407 extra_tabs_[1]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 411 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
408 | 412 |
409 // Accept the first tab. | 413 // Accept the first tab. |
410 ConfirmInfoBarDelegate* infobar_0 = | 414 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> |
411 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 415 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
412 ASSERT_TRUE(infobar_0); | 416 ASSERT_TRUE(infobar_0); |
413 infobar_0->Accept(); | 417 infobar_0->Accept(); |
414 CheckPermissionMessageSent(bridge_id(), true); | 418 CheckPermissionMessageSent(bridge_id(), true); |
415 contents_wrapper()->RemoveInfoBar(infobar_0); | 419 infobar_tab_helper()->RemoveInfoBar(infobar_0); |
416 EXPECT_EQ(2U, closed_delegate_tracker_.size()); | 420 EXPECT_EQ(2U, closed_delegate_tracker_.size()); |
417 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 421 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
418 infobar_0->InfoBarClosed(); | 422 infobar_0->InfoBarClosed(); |
419 // Now the infobar for the tab with the same origin should have gone. | 423 // Now the infobar for the tab with the same origin should have gone. |
420 EXPECT_EQ(0U, extra_tabs_[1]->infobar_count()); | 424 EXPECT_EQ(0U, extra_tabs_[1]->infobar_tab_helper()->infobar_count()); |
421 CheckPermissionMessageSentForTab(1, bridge_id(), true); | 425 CheckPermissionMessageSentForTab(1, bridge_id(), true); |
422 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); | 426 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); |
423 closed_delegate_tracker_.Clear(); | 427 closed_delegate_tracker_.Clear(); |
424 // Destroy the infobar that has just been removed. | 428 // Destroy the infobar that has just been removed. |
425 removed_infobar->InfoBarClosed(); | 429 removed_infobar->InfoBarClosed(); |
426 | 430 |
427 // But the other tab should still have the info bar... | 431 // But the other tab should still have the info bar... |
428 ASSERT_EQ(1U, extra_tabs_[0]->infobar_count()); | 432 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); |
429 ConfirmInfoBarDelegate* infobar_1 = | 433 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> |
430 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 434 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
431 infobar_1->Cancel(); | 435 infobar_1->Cancel(); |
432 extra_tabs_[0]->RemoveInfoBar(infobar_1); | 436 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); |
433 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 437 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
434 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 438 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
435 infobar_1->InfoBarClosed(); | 439 infobar_1->InfoBarClosed(); |
436 | 440 |
437 extra_tabs_.reset(); | 441 extra_tabs_.reset(); |
438 } | 442 } |
439 | 443 |
440 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { | 444 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { |
441 GURL url_a("http://www.example.com/geolocation"); | 445 GURL url_a("http://www.example.com/geolocation"); |
442 GURL url_b("http://www.example-2.com/geolocation"); | 446 GURL url_b("http://www.example-2.com/geolocation"); |
443 NavigateAndCommit(url_a); | 447 NavigateAndCommit(url_a); |
444 AddNewTab(url_a); | 448 AddNewTab(url_a); |
445 | 449 |
446 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 450 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); |
447 geolocation_permission_context_->RequestGeolocationPermission( | 451 geolocation_permission_context_->RequestGeolocationPermission( |
448 process_id(), render_id(), bridge_id(), url_a); | 452 process_id(), render_id(), bridge_id(), url_a); |
449 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); | 453 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); |
450 | 454 |
451 geolocation_permission_context_->RequestGeolocationPermission( | 455 geolocation_permission_context_->RequestGeolocationPermission( |
452 process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_a); | 456 process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_a); |
453 EXPECT_EQ(1U, extra_tabs_[0]->infobar_count()); | 457 EXPECT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); |
454 | 458 |
455 geolocation_permission_context_->RequestGeolocationPermission( | 459 geolocation_permission_context_->RequestGeolocationPermission( |
456 process_id_for_tab(0), render_id_for_tab(0), bridge_id() + 1, url_b); | 460 process_id_for_tab(0), render_id_for_tab(0), bridge_id() + 1, url_b); |
457 ASSERT_EQ(1U, extra_tabs_[0]->infobar_count()); | 461 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); |
458 | 462 |
459 ConfirmInfoBarDelegate* removed_infobar = | 463 ConfirmInfoBarDelegate* removed_infobar = |
460 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 464 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
461 | 465 |
462 // Accept the second tab. | 466 // Accept the second tab. |
463 ConfirmInfoBarDelegate* infobar_0 = | 467 ConfirmInfoBarDelegate* infobar_0 = extra_tabs_[0]->infobar_tab_helper()-> |
464 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 468 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
465 ASSERT_TRUE(infobar_0); | 469 ASSERT_TRUE(infobar_0); |
466 infobar_0->Accept(); | 470 infobar_0->Accept(); |
467 CheckPermissionMessageSentForTab(0, bridge_id(), true); | 471 CheckPermissionMessageSentForTab(0, bridge_id(), true); |
468 extra_tabs_[0]->RemoveInfoBar(infobar_0); | 472 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_0); |
469 EXPECT_EQ(2U, closed_delegate_tracker_.size()); | 473 EXPECT_EQ(2U, closed_delegate_tracker_.size()); |
470 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 474 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
471 infobar_0->InfoBarClosed(); | 475 infobar_0->InfoBarClosed(); |
472 // Now the infobar for the tab with the same origin should have gone. | 476 // Now the infobar for the tab with the same origin should have gone. |
473 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 477 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); |
474 CheckPermissionMessageSent(bridge_id(), true); | 478 CheckPermissionMessageSent(bridge_id(), true); |
475 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); | 479 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); |
476 closed_delegate_tracker_.Clear(); | 480 closed_delegate_tracker_.Clear(); |
477 // Destroy the infobar that has just been removed. | 481 // Destroy the infobar that has just been removed. |
478 removed_infobar->InfoBarClosed(); | 482 removed_infobar->InfoBarClosed(); |
479 | 483 |
480 // And we should have the queued infobar displayed now. | 484 // And we should have the queued infobar displayed now. |
481 ASSERT_EQ(1U, extra_tabs_[0]->infobar_count()); | 485 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); |
482 | 486 |
483 // Accept the second infobar. | 487 // Accept the second infobar. |
484 ConfirmInfoBarDelegate* infobar_1 = | 488 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> |
485 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 489 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
486 ASSERT_TRUE(infobar_1); | 490 ASSERT_TRUE(infobar_1); |
487 infobar_1->Accept(); | 491 infobar_1->Accept(); |
488 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); | 492 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); |
489 extra_tabs_[0]->RemoveInfoBar(infobar_1); | 493 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); |
490 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 494 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
491 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 495 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
492 infobar_1->InfoBarClosed(); | 496 infobar_1->InfoBarClosed(); |
493 | 497 |
494 extra_tabs_.reset(); | 498 extra_tabs_.reset(); |
495 } | 499 } |
496 | 500 |
497 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { | 501 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { |
498 GURL requesting_frame_0("http://www.example.com/geolocation"); | 502 GURL requesting_frame_0("http://www.example.com/geolocation"); |
499 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 503 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
500 EXPECT_EQ( | 504 EXPECT_EQ( |
501 CONTENT_SETTING_ASK, | 505 CONTENT_SETTING_ASK, |
502 profile()->GetHostContentSettingsMap()->GetContentSetting( | 506 profile()->GetHostContentSettingsMap()->GetContentSetting( |
503 requesting_frame_0, | 507 requesting_frame_0, |
504 requesting_frame_0, | 508 requesting_frame_0, |
505 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 509 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
506 std::string())); | 510 std::string())); |
507 | 511 |
508 EXPECT_EQ( | 512 EXPECT_EQ( |
509 CONTENT_SETTING_ASK, | 513 CONTENT_SETTING_ASK, |
510 profile()->GetHostContentSettingsMap()->GetContentSetting( | 514 profile()->GetHostContentSettingsMap()->GetContentSetting( |
511 requesting_frame_1, | 515 requesting_frame_1, |
512 requesting_frame_0, | 516 requesting_frame_0, |
513 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 517 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
514 std::string())); | 518 std::string())); |
515 | 519 |
516 NavigateAndCommit(requesting_frame_0); | 520 NavigateAndCommit(requesting_frame_0); |
517 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 521 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); |
518 // Request permission for two frames. | 522 // Request permission for two frames. |
519 geolocation_permission_context_->RequestGeolocationPermission( | 523 geolocation_permission_context_->RequestGeolocationPermission( |
520 process_id(), render_id(), bridge_id(), requesting_frame_0); | 524 process_id(), render_id(), bridge_id(), requesting_frame_0); |
521 geolocation_permission_context_->RequestGeolocationPermission( | 525 geolocation_permission_context_->RequestGeolocationPermission( |
522 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); | 526 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); |
523 // Ensure only one infobar is created. | 527 // Ensure only one infobar is created. |
524 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); | 528 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); |
525 ConfirmInfoBarDelegate* infobar_0 = | 529 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> |
526 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 530 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
527 ASSERT_TRUE(infobar_0); | 531 ASSERT_TRUE(infobar_0); |
528 | 532 |
529 // Delete the tab contents. | 533 // Delete the tab contents. |
530 DeleteContents(); | 534 DeleteContents(); |
531 infobar_0->InfoBarClosed(); | 535 infobar_0->InfoBarClosed(); |
532 } | 536 } |
OLD | NEW |