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

Side by Side Diff: chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc

Issue 10830353: Introduce InfoBarTabService API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to review comments, merge to LKGR Created 8 years, 4 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 | Annotate | Revision Log
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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/hash_tables.h" 10 #include "base/hash_tables.h"
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 done.Wait(); 253 done.Wait();
254 db_thread_.Stop(); 254 db_thread_.Stop();
255 } 255 }
256 256
257 257
258 // Tests ---------------------------------------------------------------------- 258 // Tests ----------------------------------------------------------------------
259 259
260 TEST_F(GeolocationPermissionContextTests, SinglePermission) { 260 TEST_F(GeolocationPermissionContextTests, SinglePermission) {
261 GURL requesting_frame("http://www.example.com/geolocation"); 261 GURL requesting_frame("http://www.example.com/geolocation");
262 NavigateAndCommit(requesting_frame); 262 NavigateAndCommit(requesting_frame);
263 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 263 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount());
264 RequestGeolocationPermission( 264 RequestGeolocationPermission(
265 process_id(), render_id(), bridge_id(), requesting_frame); 265 process_id(), render_id(), bridge_id(), requesting_frame);
266 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); 266 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount());
267 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> 267 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()->
268 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 268 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
269 infobar_0->Cancel(); 269 infobar_0->Cancel();
270 infobar_tab_helper()->RemoveInfoBar(infobar_0); 270 infobar_tab_helper()->RemoveInfoBar(infobar_0);
271 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 271 EXPECT_EQ(1U, closed_delegate_tracker_.size());
272 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); 272 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
273 infobar_0->InfoBarClosed(); 273 infobar_0->InfoBarClosed();
274 } 274 }
275 275
276 #if defined(OS_ANDROID) 276 #if defined(OS_ANDROID)
277 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { 277 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) {
278 profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( 278 profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
279 CONTENT_SETTINGS_TYPE_GEOLOCATION, 279 CONTENT_SETTINGS_TYPE_GEOLOCATION,
280 CONTENT_SETTING_ALLOW); 280 CONTENT_SETTING_ALLOW);
281 281
282 // Check that the request is denied with preference disabled, 282 // Check that the request is denied with preference disabled,
283 // even though the default policy allows it. 283 // even though the default policy allows it.
284 GURL requesting_frame("http://www.example.com/geolocation"); 284 GURL requesting_frame("http://www.example.com/geolocation");
285 NavigateAndCommit(requesting_frame); 285 NavigateAndCommit(requesting_frame);
286 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 286 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount());
287 profile()->GetPrefs()->SetBoolean(prefs::kGeolocationEnabled, false); 287 profile()->GetPrefs()->SetBoolean(prefs::kGeolocationEnabled, false);
288 RequestGeolocationPermission( 288 RequestGeolocationPermission(
289 process_id(), render_id(), bridge_id(), requesting_frame); 289 process_id(), render_id(), bridge_id(), requesting_frame);
290 ASSERT_EQ(0U, infobar_tab_helper()->infobar_count()); 290 ASSERT_EQ(0U, infobar_tab_helper()->GetInfoBarCount());
291 CheckPermissionMessageSent(bridge_id(), false); 291 CheckPermissionMessageSent(bridge_id(), false);
292 292
293 // Reenable the preference and check that the request now goes though. 293 // Reenable the preference and check that the request now goes though.
294 profile()->GetPrefs()->SetBoolean(prefs::kGeolocationEnabled, true); 294 profile()->GetPrefs()->SetBoolean(prefs::kGeolocationEnabled, true);
295 RequestGeolocationPermission( 295 RequestGeolocationPermission(
296 process_id(), render_id(), bridge_id() + 1, requesting_frame); 296 process_id(), render_id(), bridge_id() + 1, requesting_frame);
297 ASSERT_EQ(0U, infobar_tab_helper()->infobar_count()); 297 ASSERT_EQ(0U, infobar_tab_helper()->GetInfoBarCount());
298 CheckPermissionMessageSent(bridge_id() + 1, true); 298 CheckPermissionMessageSent(bridge_id() + 1, true);
299 } 299 }
300 #endif 300 #endif
301 301
302 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { 302 TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
303 GURL requesting_frame_0("http://www.example.com/geolocation"); 303 GURL requesting_frame_0("http://www.example.com/geolocation");
304 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 304 GURL requesting_frame_1("http://www.example-2.com/geolocation");
305 EXPECT_EQ(CONTENT_SETTING_ASK, 305 EXPECT_EQ(CONTENT_SETTING_ASK,
306 profile()->GetHostContentSettingsMap()->GetContentSetting( 306 profile()->GetHostContentSettingsMap()->GetContentSetting(
307 requesting_frame_0, 307 requesting_frame_0,
308 requesting_frame_0, 308 requesting_frame_0,
309 CONTENT_SETTINGS_TYPE_GEOLOCATION, 309 CONTENT_SETTINGS_TYPE_GEOLOCATION,
310 std::string())); 310 std::string()));
311 EXPECT_EQ(CONTENT_SETTING_ASK, 311 EXPECT_EQ(CONTENT_SETTING_ASK,
312 profile()->GetHostContentSettingsMap()->GetContentSetting( 312 profile()->GetHostContentSettingsMap()->GetContentSetting(
313 requesting_frame_1, 313 requesting_frame_1,
314 requesting_frame_0, 314 requesting_frame_0,
315 CONTENT_SETTINGS_TYPE_GEOLOCATION, 315 CONTENT_SETTINGS_TYPE_GEOLOCATION,
316 std::string())); 316 std::string()));
317 317
318 318
319 NavigateAndCommit(requesting_frame_0); 319 NavigateAndCommit(requesting_frame_0);
320 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 320 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount());
321 // Request permission for two frames. 321 // Request permission for two frames.
322 RequestGeolocationPermission( 322 RequestGeolocationPermission(
323 process_id(), render_id(), bridge_id(), requesting_frame_0); 323 process_id(), render_id(), bridge_id(), requesting_frame_0);
324 RequestGeolocationPermission( 324 RequestGeolocationPermission(
325 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); 325 process_id(), render_id(), bridge_id() + 1, requesting_frame_1);
326 // Ensure only one infobar is created. 326 // Ensure only one infobar is created.
327 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); 327 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount());
328 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> 328 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()->
329 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 329 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
330 ASSERT_TRUE(infobar_0); 330 ASSERT_TRUE(infobar_0);
331 string16 text_0 = infobar_0->GetMessageText(); 331 string16 text_0 = infobar_0->GetMessageText();
332 332
333 // Accept the first frame. 333 // Accept the first frame.
334 infobar_0->Accept(); 334 infobar_0->Accept();
335 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); 335 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
336 CheckPermissionMessageSent(bridge_id(), true); 336 CheckPermissionMessageSent(bridge_id(), true);
337 337
338 infobar_tab_helper()->RemoveInfoBar(infobar_0); 338 infobar_tab_helper()->RemoveInfoBar(infobar_0);
339 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 339 EXPECT_EQ(1U, closed_delegate_tracker_.size());
340 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); 340 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
341 closed_delegate_tracker_.Clear(); 341 closed_delegate_tracker_.Clear();
342 infobar_0->InfoBarClosed(); 342 infobar_0->InfoBarClosed();
343 // Now we should have a new infobar for the second frame. 343 // Now we should have a new infobar for the second frame.
344 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); 344 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount());
345 345
346 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()-> 346 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()->
347 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 347 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
348 ASSERT_TRUE(infobar_1); 348 ASSERT_TRUE(infobar_1);
349 string16 text_1 = infobar_1->GetMessageText(); 349 string16 text_1 = infobar_1->GetMessageText();
350 EXPECT_NE(text_0, text_1); 350 EXPECT_NE(text_0, text_1);
351 351
352 // Cancel (block) this frame. 352 // Cancel (block) this frame.
353 infobar_1->Cancel(); 353 infobar_1->Cancel();
354 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); 354 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK);
355 CheckPermissionMessageSent(bridge_id() + 1, false); 355 CheckPermissionMessageSent(bridge_id() + 1, false);
356 infobar_tab_helper()->RemoveInfoBar(infobar_1); 356 infobar_tab_helper()->RemoveInfoBar(infobar_1);
357 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 357 EXPECT_EQ(1U, closed_delegate_tracker_.size());
358 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); 358 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
359 infobar_1->InfoBarClosed(); 359 infobar_1->InfoBarClosed();
360 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 360 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount());
361 // Ensure the persisted permissions are ok. 361 // Ensure the persisted permissions are ok.
362 EXPECT_EQ(CONTENT_SETTING_ALLOW, 362 EXPECT_EQ(CONTENT_SETTING_ALLOW,
363 profile()->GetHostContentSettingsMap()->GetContentSetting( 363 profile()->GetHostContentSettingsMap()->GetContentSetting(
364 requesting_frame_0, 364 requesting_frame_0,
365 requesting_frame_0, 365 requesting_frame_0,
366 CONTENT_SETTINGS_TYPE_GEOLOCATION, 366 CONTENT_SETTINGS_TYPE_GEOLOCATION,
367 std::string())); 367 std::string()));
368 368
369 EXPECT_EQ(CONTENT_SETTING_BLOCK, 369 EXPECT_EQ(CONTENT_SETTING_BLOCK,
370 profile()->GetHostContentSettingsMap()->GetContentSetting( 370 profile()->GetHostContentSettingsMap()->GetContentSetting(
(...skipping 15 matching lines...) Expand all
386 386
387 EXPECT_EQ(CONTENT_SETTING_ASK, 387 EXPECT_EQ(CONTENT_SETTING_ASK,
388 profile()->GetHostContentSettingsMap()->GetContentSetting( 388 profile()->GetHostContentSettingsMap()->GetContentSetting(
389 requesting_frame_1, 389 requesting_frame_1,
390 requesting_frame_0, 390 requesting_frame_0,
391 CONTENT_SETTINGS_TYPE_GEOLOCATION, 391 CONTENT_SETTINGS_TYPE_GEOLOCATION,
392 std::string())); 392 std::string()));
393 393
394 394
395 NavigateAndCommit(requesting_frame_0); 395 NavigateAndCommit(requesting_frame_0);
396 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 396 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount());
397 // Request permission for two frames. 397 // Request permission for two frames.
398 RequestGeolocationPermission( 398 RequestGeolocationPermission(
399 process_id(), render_id(), bridge_id(), requesting_frame_0); 399 process_id(), render_id(), bridge_id(), requesting_frame_0);
400 RequestGeolocationPermission( 400 RequestGeolocationPermission(
401 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); 401 process_id(), render_id(), bridge_id() + 1, requesting_frame_1);
402 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); 402 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount());
403 403
404 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> 404 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()->
405 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 405 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
406 ASSERT_TRUE(infobar_0); 406 ASSERT_TRUE(infobar_0);
407 string16 text_0 = infobar_0->GetMessageText(); 407 string16 text_0 = infobar_0->GetMessageText();
408 408
409 // Simulate the frame going away, ensure the infobar for this frame 409 // Simulate the frame going away, ensure the infobar for this frame
410 // is removed and the next pending infobar is created. 410 // is removed and the next pending infobar is created.
411 geolocation_permission_context_->CancelGeolocationPermissionRequest( 411 geolocation_permission_context_->CancelGeolocationPermissionRequest(
412 process_id(), render_id(), bridge_id(), requesting_frame_0); 412 process_id(), render_id(), bridge_id(), requesting_frame_0);
413 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 413 EXPECT_EQ(1U, closed_delegate_tracker_.size());
414 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); 414 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
415 closed_delegate_tracker_.Clear(); 415 closed_delegate_tracker_.Clear();
416 infobar_0->InfoBarClosed(); 416 infobar_0->InfoBarClosed();
417 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); 417 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount());
418 418
419 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()-> 419 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()->
420 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 420 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
421 ASSERT_TRUE(infobar_1); 421 ASSERT_TRUE(infobar_1);
422 string16 text_1 = infobar_1->GetMessageText(); 422 string16 text_1 = infobar_1->GetMessageText();
423 EXPECT_NE(text_0, text_1); 423 EXPECT_NE(text_0, text_1);
424 424
425 // Allow this frame. 425 // Allow this frame.
426 infobar_1->Accept(); 426 infobar_1->Accept();
427 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); 427 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW);
428 CheckPermissionMessageSent(bridge_id() + 1, true); 428 CheckPermissionMessageSent(bridge_id() + 1, true);
429 infobar_tab_helper()->RemoveInfoBar(infobar_1); 429 infobar_tab_helper()->RemoveInfoBar(infobar_1);
430 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 430 EXPECT_EQ(1U, closed_delegate_tracker_.size());
431 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); 431 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
432 infobar_1->InfoBarClosed(); 432 infobar_1->InfoBarClosed();
433 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 433 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount());
434 // Ensure the persisted permissions are ok. 434 // Ensure the persisted permissions are ok.
435 EXPECT_EQ(CONTENT_SETTING_ASK, 435 EXPECT_EQ(CONTENT_SETTING_ASK,
436 profile()->GetHostContentSettingsMap()->GetContentSetting( 436 profile()->GetHostContentSettingsMap()->GetContentSetting(
437 requesting_frame_0, 437 requesting_frame_0,
438 requesting_frame_0, 438 requesting_frame_0,
439 CONTENT_SETTINGS_TYPE_GEOLOCATION, 439 CONTENT_SETTINGS_TYPE_GEOLOCATION,
440 std::string())); 440 std::string()));
441 441
442 EXPECT_EQ(CONTENT_SETTING_ALLOW, 442 EXPECT_EQ(CONTENT_SETTING_ALLOW,
443 profile()->GetHostContentSettingsMap()->GetContentSetting( 443 profile()->GetHostContentSettingsMap()->GetContentSetting(
444 requesting_frame_1, 444 requesting_frame_1,
445 requesting_frame_0, 445 requesting_frame_0,
446 CONTENT_SETTINGS_TYPE_GEOLOCATION, 446 CONTENT_SETTINGS_TYPE_GEOLOCATION,
447 std::string())); 447 std::string()));
448 } 448 }
449 449
450 TEST_F(GeolocationPermissionContextTests, InvalidURL) { 450 TEST_F(GeolocationPermissionContextTests, InvalidURL) {
451 GURL invalid_embedder("about:blank"); 451 GURL invalid_embedder("about:blank");
452 GURL requesting_frame; 452 GURL requesting_frame;
453 NavigateAndCommit(invalid_embedder); 453 NavigateAndCommit(invalid_embedder);
454 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 454 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount());
455 RequestGeolocationPermission( 455 RequestGeolocationPermission(
456 process_id(), render_id(), bridge_id(), requesting_frame); 456 process_id(), render_id(), bridge_id(), requesting_frame);
457 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 457 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount());
458 CheckPermissionMessageSent(bridge_id(), false); 458 CheckPermissionMessageSent(bridge_id(), false);
459 } 459 }
460 460
461 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { 461 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
462 GURL url_a("http://www.example.com/geolocation"); 462 GURL url_a("http://www.example.com/geolocation");
463 GURL url_b("http://www.example-2.com/geolocation"); 463 GURL url_b("http://www.example-2.com/geolocation");
464 NavigateAndCommit(url_a); 464 NavigateAndCommit(url_a);
465 AddNewTab(url_b); 465 AddNewTab(url_b);
466 AddNewTab(url_a); 466 AddNewTab(url_a);
467 467
468 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 468 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount());
469 RequestGeolocationPermission( 469 RequestGeolocationPermission(
470 process_id(), render_id(), bridge_id(), url_a); 470 process_id(), render_id(), bridge_id(), url_a);
471 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); 471 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount());
472 472
473 RequestGeolocationPermission( 473 RequestGeolocationPermission(
474 process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_b); 474 process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_b);
475 EXPECT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); 475 EXPECT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->GetInfoBarCount());
476 476
477 RequestGeolocationPermission( 477 RequestGeolocationPermission(
478 process_id_for_tab(1), render_id_for_tab(1), bridge_id(), url_a); 478 process_id_for_tab(1), render_id_for_tab(1), bridge_id(), url_a);
479 ASSERT_EQ(1U, extra_tabs_[1]->infobar_tab_helper()->infobar_count()); 479 ASSERT_EQ(1U, extra_tabs_[1]->infobar_tab_helper()->GetInfoBarCount());
480 480
481 ConfirmInfoBarDelegate* removed_infobar = extra_tabs_[1]-> 481 ConfirmInfoBarDelegate* removed_infobar = extra_tabs_[1]->
482 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 482 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
483 483
484 // Accept the first tab. 484 // Accept the first tab.
485 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> 485 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()->
486 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 486 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
487 ASSERT_TRUE(infobar_0); 487 ASSERT_TRUE(infobar_0);
488 infobar_0->Accept(); 488 infobar_0->Accept();
489 CheckPermissionMessageSent(bridge_id(), true); 489 CheckPermissionMessageSent(bridge_id(), true);
490 infobar_tab_helper()->RemoveInfoBar(infobar_0); 490 infobar_tab_helper()->RemoveInfoBar(infobar_0);
491 EXPECT_EQ(2U, closed_delegate_tracker_.size()); 491 EXPECT_EQ(2U, closed_delegate_tracker_.size());
492 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); 492 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
493 infobar_0->InfoBarClosed(); 493 infobar_0->InfoBarClosed();
494 // Now the infobar for the tab with the same origin should have gone. 494 // Now the infobar for the tab with the same origin should have gone.
495 EXPECT_EQ(0U, extra_tabs_[1]->infobar_tab_helper()->infobar_count()); 495 EXPECT_EQ(0U, extra_tabs_[1]->infobar_tab_helper()->GetInfoBarCount());
496 CheckPermissionMessageSentForTab(1, bridge_id(), true); 496 CheckPermissionMessageSentForTab(1, bridge_id(), true);
497 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); 497 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar));
498 closed_delegate_tracker_.Clear(); 498 closed_delegate_tracker_.Clear();
499 // Destroy the infobar that has just been removed. 499 // Destroy the infobar that has just been removed.
500 removed_infobar->InfoBarClosed(); 500 removed_infobar->InfoBarClosed();
501 501
502 // But the other tab should still have the info bar... 502 // But the other tab should still have the info bar...
503 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); 503 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->GetInfoBarCount());
504 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> 504 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()->
505 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 505 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
506 infobar_1->Cancel(); 506 infobar_1->Cancel();
507 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); 507 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1);
508 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 508 EXPECT_EQ(1U, closed_delegate_tracker_.size());
509 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); 509 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
510 infobar_1->InfoBarClosed(); 510 infobar_1->InfoBarClosed();
511 } 511 }
512 512
513 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { 513 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
514 GURL url_a("http://www.example.com/geolocation"); 514 GURL url_a("http://www.example.com/geolocation");
515 GURL url_b("http://www.example-2.com/geolocation"); 515 GURL url_b("http://www.example-2.com/geolocation");
516 NavigateAndCommit(url_a); 516 NavigateAndCommit(url_a);
517 AddNewTab(url_a); 517 AddNewTab(url_a);
518 518
519 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 519 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount());
520 RequestGeolocationPermission( 520 RequestGeolocationPermission(
521 process_id(), render_id(), bridge_id(), url_a); 521 process_id(), render_id(), bridge_id(), url_a);
522 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); 522 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount());
523 523
524 RequestGeolocationPermission( 524 RequestGeolocationPermission(
525 process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_a); 525 process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_a);
526 EXPECT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); 526 EXPECT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->GetInfoBarCount());
527 527
528 RequestGeolocationPermission( 528 RequestGeolocationPermission(
529 process_id_for_tab(0), render_id_for_tab(0), bridge_id() + 1, url_b); 529 process_id_for_tab(0), render_id_for_tab(0), bridge_id() + 1, url_b);
530 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); 530 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->GetInfoBarCount());
531 531
532 ConfirmInfoBarDelegate* removed_infobar = 532 ConfirmInfoBarDelegate* removed_infobar =
533 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 533 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
534 534
535 // Accept the second tab. 535 // Accept the second tab.
536 ConfirmInfoBarDelegate* infobar_0 = extra_tabs_[0]->infobar_tab_helper()-> 536 ConfirmInfoBarDelegate* infobar_0 = extra_tabs_[0]->infobar_tab_helper()->
537 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 537 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
538 ASSERT_TRUE(infobar_0); 538 ASSERT_TRUE(infobar_0);
539 infobar_0->Accept(); 539 infobar_0->Accept();
540 CheckPermissionMessageSentForTab(0, bridge_id(), true); 540 CheckPermissionMessageSentForTab(0, bridge_id(), true);
541 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_0); 541 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_0);
542 EXPECT_EQ(2U, closed_delegate_tracker_.size()); 542 EXPECT_EQ(2U, closed_delegate_tracker_.size());
543 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); 543 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
544 infobar_0->InfoBarClosed(); 544 infobar_0->InfoBarClosed();
545 // Now the infobar for the tab with the same origin should have gone. 545 // Now the infobar for the tab with the same origin should have gone.
546 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 546 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount());
547 CheckPermissionMessageSent(bridge_id(), true); 547 CheckPermissionMessageSent(bridge_id(), true);
548 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); 548 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar));
549 closed_delegate_tracker_.Clear(); 549 closed_delegate_tracker_.Clear();
550 // Destroy the infobar that has just been removed. 550 // Destroy the infobar that has just been removed.
551 removed_infobar->InfoBarClosed(); 551 removed_infobar->InfoBarClosed();
552 552
553 // And we should have the queued infobar displayed now. 553 // And we should have the queued infobar displayed now.
554 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); 554 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->GetInfoBarCount());
555 555
556 // Accept the second infobar. 556 // Accept the second infobar.
557 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> 557 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()->
558 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 558 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
559 ASSERT_TRUE(infobar_1); 559 ASSERT_TRUE(infobar_1);
560 infobar_1->Accept(); 560 infobar_1->Accept();
561 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); 561 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true);
562 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); 562 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1);
563 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 563 EXPECT_EQ(1U, closed_delegate_tracker_.size());
564 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); 564 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
(...skipping 13 matching lines...) Expand all
578 578
579 EXPECT_EQ( 579 EXPECT_EQ(
580 CONTENT_SETTING_ASK, 580 CONTENT_SETTING_ASK,
581 profile()->GetHostContentSettingsMap()->GetContentSetting( 581 profile()->GetHostContentSettingsMap()->GetContentSetting(
582 requesting_frame_1, 582 requesting_frame_1,
583 requesting_frame_0, 583 requesting_frame_0,
584 CONTENT_SETTINGS_TYPE_GEOLOCATION, 584 CONTENT_SETTINGS_TYPE_GEOLOCATION,
585 std::string())); 585 std::string()));
586 586
587 NavigateAndCommit(requesting_frame_0); 587 NavigateAndCommit(requesting_frame_0);
588 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 588 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount());
589 // Request permission for two frames. 589 // Request permission for two frames.
590 RequestGeolocationPermission( 590 RequestGeolocationPermission(
591 process_id(), render_id(), bridge_id(), requesting_frame_0); 591 process_id(), render_id(), bridge_id(), requesting_frame_0);
592 RequestGeolocationPermission( 592 RequestGeolocationPermission(
593 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); 593 process_id(), render_id(), bridge_id() + 1, requesting_frame_1);
594 // Ensure only one infobar is created. 594 // Ensure only one infobar is created.
595 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); 595 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount());
596 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> 596 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()->
597 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 597 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
598 ASSERT_TRUE(infobar_0); 598 ASSERT_TRUE(infobar_0);
599 599
600 // Delete the tab contents. 600 // Delete the tab contents.
601 DeleteContents(); 601 DeleteContents();
602 infobar_0->InfoBarClosed(); 602 infobar_0->InfoBarClosed();
603 603
604 // During contents destruction, the infobar will have been closed, and a 604 // During contents destruction, the infobar will have been closed, and a
605 // second (with it's own new delegate) will have been created. In Chromium, 605 // second (with it's own new delegate) will have been created. In Chromium,
606 // this would be properly deleted by the InfoBarContainer, but in this unit 606 // this would be properly deleted by the InfoBarContainer, but in this unit
607 // test, the closest thing we have to that is the ClosedDelegateTracker. 607 // test, the closest thing we have to that is the ClosedDelegateTracker.
608 ASSERT_EQ(2U, closed_delegate_tracker_.size()); 608 ASSERT_EQ(2U, closed_delegate_tracker_.size());
609 ASSERT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); 609 ASSERT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
610 closed_delegate_tracker_.removed_infobar_delegates_.erase(infobar_0); 610 closed_delegate_tracker_.removed_infobar_delegates_.erase(infobar_0);
611 (*closed_delegate_tracker_.removed_infobar_delegates_.begin())-> 611 (*closed_delegate_tracker_.removed_infobar_delegates_.begin())->
612 InfoBarClosed(); 612 InfoBarClosed();
613 } 613 }
614 614
615 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { 615 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) {
616 GURL requesting_frame_0("http://www.example.com/geolocation"); 616 GURL requesting_frame_0("http://www.example.com/geolocation");
617 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 617 GURL requesting_frame_1("http://www.example-2.com/geolocation");
618 NavigateAndCommit(requesting_frame_0); 618 NavigateAndCommit(requesting_frame_0);
619 NavigateAndCommit(requesting_frame_1); 619 NavigateAndCommit(requesting_frame_1);
620 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 620 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount());
621 // Go back: navigate to a pending entry before requesting geolocation 621 // Go back: navigate to a pending entry before requesting geolocation
622 // permission. 622 // permission.
623 contents()->GetController().GoBack(); 623 contents()->GetController().GoBack();
624 // Request permission for the committed frame (not the pending one). 624 // Request permission for the committed frame (not the pending one).
625 RequestGeolocationPermission( 625 RequestGeolocationPermission(
626 process_id(), render_id(), bridge_id(), requesting_frame_1); 626 process_id(), render_id(), bridge_id(), requesting_frame_1);
627 // Ensure the infobar is created. 627 // Ensure the infobar is created.
628 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); 628 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount());
629 InfoBarDelegate* infobar_0 = infobar_tab_helper()->GetInfoBarDelegateAt(0); 629 InfoBarDelegate* infobar_0 = infobar_tab_helper()->GetInfoBarDelegateAt(0);
630 ASSERT_TRUE(infobar_0); 630 ASSERT_TRUE(infobar_0);
631 // Ensure the infobar is not yet expired. 631 // Ensure the infobar is not yet expired.
632 content::LoadCommittedDetails details; 632 content::LoadCommittedDetails details;
633 details.entry = contents()->GetController().GetLastCommittedEntry(); 633 details.entry = contents()->GetController().GetLastCommittedEntry();
634 ASSERT_FALSE(infobar_0->ShouldExpire(details)); 634 ASSERT_FALSE(infobar_0->ShouldExpire(details));
635 // Commit the "GoBack()" above, and ensure the infobar is now expired. 635 // Commit the "GoBack()" above, and ensure the infobar is now expired.
636 WebContentsTester::For(contents())->CommitPendingNavigation(); 636 WebContentsTester::For(contents())->CommitPendingNavigation();
637 details.entry = contents()->GetController().GetLastCommittedEntry(); 637 details.entry = contents()->GetController().GetLastCommittedEntry();
638 ASSERT_TRUE(infobar_0->ShouldExpire(details)); 638 ASSERT_TRUE(infobar_0->ShouldExpire(details));
639 639
640 // Delete the tab contents. 640 // Delete the tab contents.
641 DeleteContents(); 641 DeleteContents();
642 infobar_0->InfoBarClosed(); 642 infobar_0->InfoBarClosed();
643 } 643 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698