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

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

Issue 1337903002: permissions: remove PermissionQueueController and introduce PermissionInfoBarManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@callbacks-delegates
Patch Set: Fix compile failures Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/geolocation/geolocation_permission_context.h" 5 #include "chrome/browser/geolocation/geolocation_permission_context.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/id_map.h" 15 #include "base/id_map.h"
16 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
17 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
18 #include "base/test/simple_test_clock.h" 18 #include "base/test/simple_test_clock.h"
19 #include "base/time/clock.h" 19 #include "base/time/clock.h"
20 #include "chrome/browser/chrome_notification_types.h" 20 #include "chrome/browser/chrome_notification_types.h"
21 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 21 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
22 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 22 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
23 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" 23 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
24 #include "chrome/browser/infobars/infobar_service.h" 24 #include "chrome/browser/infobars/infobar_service.h"
25 #include "chrome/browser/permissions/permission_infobar_manager.h"
25 #include "chrome/browser/permissions/permission_request_id.h" 26 #include "chrome/browser/permissions/permission_request_id.h"
26 #include "chrome/browser/ui/website_settings/mock_permission_bubble_view.h" 27 #include "chrome/browser/ui/website_settings/mock_permission_bubble_view.h"
27 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 28 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
28 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" 29 #include "chrome/browser/ui/website_settings/permission_bubble_request.h"
29 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
30 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 31 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
31 #include "chrome/test/base/testing_profile.h" 32 #include "chrome/test/base/testing_profile.h"
32 #include "components/content_settings/core/browser/host_content_settings_map.h" 33 #include "components/content_settings/core/browser/host_content_settings_map.h"
33 #include "components/infobars/core/confirm_infobar_delegate.h" 34 #include "components/infobars/core/confirm_infobar_delegate.h"
34 #include "components/infobars/core/infobar.h" 35 #include "components/infobars/core/infobar.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 void TearDown() override; 120 void TearDown() override;
120 121
121 PermissionRequestID RequestID(int request_id); 122 PermissionRequestID RequestID(int request_id);
122 PermissionRequestID RequestIDForTab(int tab, int request_id); 123 PermissionRequestID RequestIDForTab(int tab, int request_id);
123 InfoBarService* infobar_service() { 124 InfoBarService* infobar_service() {
124 return InfoBarService::FromWebContents(web_contents()); 125 return InfoBarService::FromWebContents(web_contents());
125 } 126 }
126 InfoBarService* infobar_service_for_tab(int tab) { 127 InfoBarService* infobar_service_for_tab(int tab) {
127 return InfoBarService::FromWebContents(extra_tabs_[tab]); 128 return InfoBarService::FromWebContents(extra_tabs_[tab]);
128 } 129 }
130 PermissionInfoBarManager* infobar_manager() {
131 return PermissionInfoBarManager::FromWebContents(web_contents());
132 }
133 PermissionInfoBarManager* infobar_manager_for_tab(int tab) {
134 return PermissionInfoBarManager::FromWebContents(extra_tabs_[tab]);
135 }
129 136
130 void RequestGeolocationPermission(content::WebContents* web_contents, 137 void RequestGeolocationPermission(content::WebContents* web_contents,
131 const PermissionRequestID& id, 138 const PermissionRequestID& id,
132 const GURL& requesting_frame, 139 const GURL& requesting_frame,
133 bool user_gesture); 140 bool user_gesture);
134 141
135 void PermissionResponse(const PermissionRequestID& id, 142 void PermissionResponse(const PermissionRequestID& id,
136 ContentSetting content_setting); 143 ContentSetting content_setting);
137 void CheckPermissionMessageSent(int request_id, bool allowed); 144 void CheckPermissionMessageSent(int request_id, bool allowed);
138 void CheckPermissionMessageSentForTab(int tab, int request_id, bool allowed); 145 void CheckPermissionMessageSentForTab(int tab, int request_id, bool allowed);
139 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, 146 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process,
140 int request_id, 147 int request_id,
141 bool allowed); 148 bool allowed);
142 void AddNewTab(const GURL& url); 149 void AddNewTab(const GURL& url);
143 void CheckTabContentsState(const GURL& requesting_frame, 150 void CheckTabContentsState(const GURL& requesting_frame,
144 ContentSetting expected_content_setting); 151 ContentSetting expected_content_setting);
145 size_t GetBubblesQueueSize(PermissionBubbleManager* manager); 152 size_t GetBubblesQueueSize(PermissionBubbleManager* manager);
146 void AcceptBubble(PermissionBubbleManager* manager); 153 void AcceptBubble(PermissionBubbleManager* manager);
147 void DenyBubble(PermissionBubbleManager* manager); 154 void DenyBubble(PermissionBubbleManager* manager);
148 void CloseBubble(PermissionBubbleManager* manager); 155 void CloseBubble(PermissionBubbleManager* manager);
149 void BubbleManagerDocumentLoadCompleted(); 156 void BubbleManagerDocumentLoadCompleted();
150 void BubbleManagerDocumentLoadCompleted(content::WebContents* web_contents); 157 void BubbleManagerDocumentLoadCompleted(content::WebContents* web_contents);
151 ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1); 158 ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1);
152 bool BubbleEnabled() const; 159 bool BubbleEnabled() const;
153 size_t GetNumberOfPrompts(); 160 size_t GetNumberOfPrompts();
154 void AcceptPrompt(); 161 void AcceptPrompt();
155 base::string16 GetPromptText(); 162 base::string16 GetPromptText();
156 163
164 bool IsInfoBarShowPending(PermissionInfoBarManager* manager) const;
165 void ShowNextQueuedInfoBar(PermissionInfoBarManager* manager);
166
157 // owned by the browser context 167 // owned by the browser context
158 GeolocationPermissionContext* geolocation_permission_context_; 168 GeolocationPermissionContext* geolocation_permission_context_;
159 ClosedInfoBarTracker closed_infobar_tracker_; 169 ClosedInfoBarTracker closed_infobar_tracker_;
160 ScopedVector<content::WebContents> extra_tabs_; 170 ScopedVector<content::WebContents> extra_tabs_;
161 171
162 // A map between renderer child id and a pair represending the bridge id and 172 // A map between renderer child id and a pair represending the bridge id and
163 // whether the requested permission was allowed. 173 // whether the requested permission was allowed.
164 base::hash_map<int, std::pair<int, bool> > responses_; 174 base::hash_map<int, std::pair<int, bool> > responses_;
165 }; 175 };
166 176
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 241 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
232 content::NavigationEntry* entry = new_tab->GetController().GetPendingEntry(); 242 content::NavigationEntry* entry = new_tab->GetController().GetPendingEntry();
233 content::RenderFrameHostTester::For(new_tab->GetMainFrame()) 243 content::RenderFrameHostTester::For(new_tab->GetMainFrame())
234 ->SendNavigate(extra_tabs_.size() + 1, entry->GetUniqueID(), true, url); 244 ->SendNavigate(extra_tabs_.size() + 1, entry->GetUniqueID(), true, url);
235 245
236 // Set up required helpers, and make this be as "tabby" as the code requires. 246 // Set up required helpers, and make this be as "tabby" as the code requires.
237 #if defined(ENABLE_EXTENSIONS) 247 #if defined(ENABLE_EXTENSIONS)
238 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS); 248 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS);
239 #endif 249 #endif
240 InfoBarService::CreateForWebContents(new_tab); 250 InfoBarService::CreateForWebContents(new_tab);
251 PermissionInfoBarManager::CreateForWebContents(new_tab);
241 if (BubbleEnabled()) { 252 if (BubbleEnabled()) {
242 PermissionBubbleManager::CreateForWebContents(new_tab); 253 PermissionBubbleManager::CreateForWebContents(new_tab);
243 PermissionBubbleManager* permission_bubble_manager = 254 PermissionBubbleManager* permission_bubble_manager =
244 PermissionBubbleManager::FromWebContents(new_tab); 255 PermissionBubbleManager::FromWebContents(new_tab);
245 MockPermissionBubbleView::SetFactory(permission_bubble_manager, false); 256 MockPermissionBubbleView::SetFactory(permission_bubble_manager, false);
246 permission_bubble_manager->DisplayPendingRequests(); 257 permission_bubble_manager->DisplayPendingRequests();
247 } 258 }
248 259
249 extra_tabs_.push_back(new_tab); 260 extra_tabs_.push_back(new_tab);
250 } 261 }
(...skipping 15 matching lines...) Expand all
266 } 277 }
267 278
268 void GeolocationPermissionContextTests::SetUp() { 279 void GeolocationPermissionContextTests::SetUp() {
269 ChromeRenderViewHostTestHarness::SetUp(); 280 ChromeRenderViewHostTestHarness::SetUp();
270 281
271 // Set up required helpers, and make this be as "tabby" as the code requires. 282 // Set up required helpers, and make this be as "tabby" as the code requires.
272 #if defined(ENABLE_EXTENSIONS) 283 #if defined(ENABLE_EXTENSIONS)
273 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); 284 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS);
274 #endif 285 #endif
275 InfoBarService::CreateForWebContents(web_contents()); 286 InfoBarService::CreateForWebContents(web_contents());
287 PermissionInfoBarManager::CreateForWebContents(web_contents());
276 TabSpecificContentSettings::CreateForWebContents(web_contents()); 288 TabSpecificContentSettings::CreateForWebContents(web_contents());
277 geolocation_permission_context_ = 289 geolocation_permission_context_ =
278 GeolocationPermissionContextFactory::GetForProfile(profile()); 290 GeolocationPermissionContextFactory::GetForProfile(profile());
279 #if defined(OS_ANDROID) 291 #if defined(OS_ANDROID)
280 static_cast<GeolocationPermissionContextAndroid*>( 292 static_cast<GeolocationPermissionContextAndroid*>(
281 geolocation_permission_context_) 293 geolocation_permission_context_)
282 ->SetLocationSettingsForTesting( 294 ->SetLocationSettingsForTesting(
283 scoped_ptr<LocationSettings>(new MockLocationSettings())); 295 scoped_ptr<LocationSettings>(new MockLocationSettings()));
284 MockLocationSettings::SetLocationStatus(true, true); 296 MockLocationSettings::SetLocationStatus(true, true);
285 #endif 297 #endif
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 PermissionBubbleManager* manager = 381 PermissionBubbleManager* manager =
370 PermissionBubbleManager::FromWebContents(web_contents()); 382 PermissionBubbleManager::FromWebContents(web_contents());
371 return manager->requests_.front()->GetMessageText(); 383 return manager->requests_.front()->GetMessageText();
372 } 384 }
373 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 385 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
374 ConfirmInfoBarDelegate* infobar_delegate = 386 ConfirmInfoBarDelegate* infobar_delegate =
375 infobar->delegate()->AsConfirmInfoBarDelegate(); 387 infobar->delegate()->AsConfirmInfoBarDelegate();
376 return infobar_delegate->GetMessageText(); 388 return infobar_delegate->GetMessageText();
377 } 389 }
378 390
391 bool GeolocationPermissionContextTests::IsInfoBarShowPending(
392 PermissionInfoBarManager* manager) const {
393 return manager->is_show_pending_;
394 }
395
396 void GeolocationPermissionContextTests::ShowNextQueuedInfoBar(
397 PermissionInfoBarManager* manager) {
398 manager->ShowNextQueuedRequest();
399 }
400
379 // Tests ---------------------------------------------------------------------- 401 // Tests ----------------------------------------------------------------------
380 402
381 TEST_F(GeolocationPermissionContextTests, SinglePermissionInfobar) { 403 TEST_F(GeolocationPermissionContextTests, SinglePermissionInfobar) {
382 if (BubbleEnabled()) return; 404 if (BubbleEnabled()) return;
383 405
384 GURL requesting_frame("http://www.example.com/geolocation"); 406 GURL requesting_frame("http://www.example.com/geolocation");
385 NavigateAndCommit(requesting_frame); 407 NavigateAndCommit(requesting_frame);
386 EXPECT_EQ(0U, infobar_service()->infobar_count()); 408 EXPECT_EQ(0U, infobar_service()->infobar_count());
387 RequestGeolocationPermission( 409 RequestGeolocationPermission(
388 web_contents(), RequestID(0), requesting_frame, true); 410 web_contents(), RequestID(0), requesting_frame, true);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 AcceptPrompt(); 512 AcceptPrompt();
491 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); 513 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
492 CheckPermissionMessageSent(0, true); 514 CheckPermissionMessageSent(0, true);
493 515
494 if (!BubbleEnabled()) { 516 if (!BubbleEnabled()) {
495 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); 517 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0);
496 infobar_service()->RemoveInfoBar(infobar_0); 518 infobar_service()->RemoveInfoBar(infobar_0);
497 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 519 EXPECT_EQ(1U, closed_infobar_tracker_.size());
498 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); 520 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
499 closed_infobar_tracker_.Clear(); 521 closed_infobar_tracker_.Clear();
522
523 // Make the next request appear after having checked that it was posted
524 // to the event loop.
525 ASSERT_TRUE(IsInfoBarShowPending(infobar_manager()));
526 ShowNextQueuedInfoBar(infobar_manager());
500 } 527 }
501 528
502 // Now we should have a new infobar for the second frame. 529 // Now we should have a new infobar for the second frame.
503 ASSERT_EQ(1U, GetNumberOfPrompts()); 530 ASSERT_EQ(1U, GetNumberOfPrompts());
504 base::string16 text_1 = GetPromptText(); 531 base::string16 text_1 = GetPromptText();
505 532
506 // Check that the messages differ. 533 // Check that the messages differ.
507 EXPECT_NE(text_0, text_1); 534 EXPECT_NE(text_0, text_1);
508 535
509 // Cancel (block) this frame. 536 // Cancel (block) this frame.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 580
554 // Cleanup. 581 // Cleanup.
555 if (!BubbleEnabled()) { 582 if (!BubbleEnabled()) {
556 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 583 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
557 infobar_service()->RemoveInfoBar(infobar); 584 infobar_service()->RemoveInfoBar(infobar);
558 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 585 EXPECT_EQ(1U, closed_infobar_tracker_.size());
559 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); 586 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
560 } 587 }
561 } 588 }
562 589
563 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { 590 // TODO(felt): The bubble and (recently) the infobar are rejecting file://
564 // TODO(felt): The bubble is rejecting file:// permission requests. 591 // permission requests. Fix and enable this test. crbug.com/444047
565 // Fix and enable this test. crbug.com/444047 592 TEST_F(GeolocationPermissionContextTests, DISABLED_PermissionForFileScheme) {
566 if (BubbleEnabled()) return;
567
568 GURL requesting_frame("file://example/geolocation.html"); 593 GURL requesting_frame("file://example/geolocation.html");
569 NavigateAndCommit(requesting_frame); 594 NavigateAndCommit(requesting_frame);
570 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); 595 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
571 596
572 // Check permission is requested. 597 // Check permission is requested.
573 ASSERT_EQ(0U, GetNumberOfPrompts()); 598 ASSERT_EQ(0U, GetNumberOfPrompts());
574 RequestGeolocationPermission( 599 RequestGeolocationPermission(
575 web_contents(), RequestID(0), requesting_frame, true); 600 web_contents(), RequestID(0), requesting_frame, true);
576 EXPECT_EQ(1U, GetNumberOfPrompts()); 601 EXPECT_EQ(1U, GetNumberOfPrompts());
577 602
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 ASSERT_FALSE(text_0.empty()); 636 ASSERT_FALSE(text_0.empty());
612 637
613 // Simulate the frame going away; the request should be removed. 638 // Simulate the frame going away; the request should be removed.
614 if (BubbleEnabled()) { 639 if (BubbleEnabled()) {
615 PermissionBubbleManager* manager = 640 PermissionBubbleManager* manager =
616 PermissionBubbleManager::FromWebContents(web_contents()); 641 PermissionBubbleManager::FromWebContents(web_contents());
617 CloseBubble(manager); 642 CloseBubble(manager);
618 } else { 643 } else {
619 geolocation_permission_context_->CancelPermissionRequest(web_contents(), 644 geolocation_permission_context_->CancelPermissionRequest(web_contents(),
620 RequestID(0)); 645 RequestID(0));
646
647 // Make the next request appear after having checked that it was posted
648 // to the event loop.
649 ASSERT_TRUE(IsInfoBarShowPending(infobar_manager()));
650 ShowNextQueuedInfoBar(infobar_manager());
621 } 651 }
622 652
623 // Check that the next pending request is created correctly. 653 // Check that the next pending request is created correctly.
624 base::string16 text_1 = GetPromptText(); 654 base::string16 text_1 = GetPromptText();
625 EXPECT_NE(text_0, text_1); 655 EXPECT_NE(text_0, text_1);
626 656
627 // Allow this frame and check that it worked. 657 // Allow this frame and check that it worked.
628 AcceptPrompt(); 658 AcceptPrompt();
629 CheckTabContentsState(frame_1, CONTENT_SETTING_ALLOW); 659 CheckTabContentsState(frame_1, CONTENT_SETTING_ALLOW);
630 CheckPermissionMessageSent(1, true); 660 CheckPermissionMessageSent(1, true);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 // Accept the permission in tab A0. 718 // Accept the permission in tab A0.
689 if (BubbleEnabled()) { 719 if (BubbleEnabled()) {
690 AcceptBubble(manager_a0); 720 AcceptBubble(manager_a0);
691 } else { 721 } else {
692 infobars::InfoBar* infobar_a0 = infobar_service()->infobar_at(0); 722 infobars::InfoBar* infobar_a0 = infobar_service()->infobar_at(0);
693 ConfirmInfoBarDelegate* infobar_delegate_a0 = 723 ConfirmInfoBarDelegate* infobar_delegate_a0 =
694 infobar_a0->delegate()->AsConfirmInfoBarDelegate(); 724 infobar_a0->delegate()->AsConfirmInfoBarDelegate();
695 ASSERT_TRUE(infobar_delegate_a0); 725 ASSERT_TRUE(infobar_delegate_a0);
696 infobar_delegate_a0->Accept(); 726 infobar_delegate_a0->Accept();
697 infobar_service()->RemoveInfoBar(infobar_a0); 727 infobar_service()->RemoveInfoBar(infobar_a0);
698 EXPECT_EQ(2U, closed_infobar_tracker_.size()); 728 EXPECT_EQ(1U, closed_infobar_tracker_.size());
699 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a0)); 729 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a0));
700 } 730 }
701 CheckPermissionMessageSent(0, true); 731 CheckPermissionMessageSent(0, true);
702 // Because they're the same origin, this will cause tab A1's infobar to 732
703 // disappear. It does not cause the bubble to disappear: crbug.com/443013. 733 // Because they're the same origin, tab_a1's bubble/infobar should disappear.
704 // TODO(felt): Update this test when the bubble's behavior is changed. 734 // In the past, infobar used to disappear and bubble did not.
735 // Now both have a consistent behviour (albiet broken) of not removing
736 // the bubble/infobar: see crbug.com/443013.
737 // TODO(felt): Update this test when this behavior is changed.
705 if (BubbleEnabled()) 738 if (BubbleEnabled())
706 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); 739 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1));
707 else 740 else
708 CheckPermissionMessageSentForTab(1, 0, true); 741 EXPECT_EQ(1U, infobar_service_for_tab(1)->infobar_count());
709 742
710 // Either way, tab B should still have a pending permission request. 743 // Either way, tab B should still have a pending permission request.
711 if (BubbleEnabled()) 744 if (BubbleEnabled())
712 ASSERT_EQ(1U, GetBubblesQueueSize(manager_b)); 745 ASSERT_EQ(1U, GetBubblesQueueSize(manager_b));
713 else 746 else
714 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 747 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
715 } 748 }
716 749
717 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { 750 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
718 GURL url_a("http://www.example.com/geolocation"); 751 GURL url_a("http://www.example.com/geolocation");
(...skipping 28 matching lines...) Expand all
747 // Accept the first request in tab A1. 780 // Accept the first request in tab A1.
748 if (BubbleEnabled()) { 781 if (BubbleEnabled()) {
749 AcceptBubble(manager_a1); 782 AcceptBubble(manager_a1);
750 } else { 783 } else {
751 infobars::InfoBar* infobar_a1 = infobar_service_for_tab(0)->infobar_at(0); 784 infobars::InfoBar* infobar_a1 = infobar_service_for_tab(0)->infobar_at(0);
752 ConfirmInfoBarDelegate* infobar_delegate_a1 = 785 ConfirmInfoBarDelegate* infobar_delegate_a1 =
753 infobar_a1->delegate()->AsConfirmInfoBarDelegate(); 786 infobar_a1->delegate()->AsConfirmInfoBarDelegate();
754 ASSERT_TRUE(infobar_delegate_a1); 787 ASSERT_TRUE(infobar_delegate_a1);
755 infobar_delegate_a1->Accept(); 788 infobar_delegate_a1->Accept();
756 infobar_service_for_tab(0)->RemoveInfoBar(infobar_a1); 789 infobar_service_for_tab(0)->RemoveInfoBar(infobar_a1);
757 EXPECT_EQ(2U, closed_infobar_tracker_.size()); 790 EXPECT_EQ(1U, closed_infobar_tracker_.size());
758 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a1)); 791 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a1));
792
793 // Make the next request appear after having checked that it was posted
794 // to the event loop.
795 ASSERT_TRUE(IsInfoBarShowPending(infobar_manager_for_tab(0)));
796 ShowNextQueuedInfoBar(infobar_manager_for_tab(0));
759 } 797 }
760 CheckPermissionMessageSentForTab(0, 0, true); 798 CheckPermissionMessageSentForTab(0, 0, true);
761 799
762 // Because they're the same origin, this will cause tab A0's infobar to 800 // Because they're the same origin, tab_a0's bubble/infobar should disappear.
763 // disappear. It does not cause the bubble to disappear: crbug.com/443013. 801 // In the past, infobar used to disappear and bubble did not.
764 // TODO(felt): Update this test when the bubble's behavior is changed. 802 // Now both have a consistent behviour (albiet broken) of not removing
765 if (BubbleEnabled()) { 803 // the bubble/infobar: see crbug.com/443013.
804 // TODO(felt): Update this test when this behavior is changed.
805 if (BubbleEnabled())
766 EXPECT_EQ(1U, GetBubblesQueueSize(manager_a0)); 806 EXPECT_EQ(1U, GetBubblesQueueSize(manager_a0));
767 } else { 807 else
768 EXPECT_EQ(0U, infobar_service()->infobar_count()); 808 EXPECT_EQ(1U, infobar_service()->infobar_count());
769 CheckPermissionMessageSent(0, true);
770 }
771 809
772 // The second request should now be visible in tab A1. 810 // The second request should now be visible in tab A1.
773 if (BubbleEnabled()) 811 if (BubbleEnabled())
774 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); 812 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1));
775 else 813 else
776 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 814 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
777 815
778 // Accept the second request and check that it's gone. 816 // Accept the second request and check that it's gone.
779 if (BubbleEnabled()) { 817 if (BubbleEnabled()) {
780 AcceptBubble(manager_a1); 818 AcceptBubble(manager_a1);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 RequestGeolocationPermission( 940 RequestGeolocationPermission(
903 web_contents(), RequestID(0), requesting_frame_0, false); 941 web_contents(), RequestID(0), requesting_frame_0, false);
904 RequestGeolocationPermission( 942 RequestGeolocationPermission(
905 web_contents(), RequestID(1), requesting_frame_1, false); 943 web_contents(), RequestID(1), requesting_frame_1, false);
906 944
907 // Ensure only one infobar is created. 945 // Ensure only one infobar is created.
908 ASSERT_EQ(1U, GetNumberOfPrompts()); 946 ASSERT_EQ(1U, GetNumberOfPrompts());
909 947
910 // Accept the first frame. 948 // Accept the first frame.
911 AcceptPrompt(); 949 AcceptPrompt();
912 if (!BubbleEnabled()) 950 if (!BubbleEnabled()) {
913 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); 951 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0));
952
953 // Make the next request appear after having checked that it was posted
954 // to the event loop.
955 ASSERT_TRUE(IsInfoBarShowPending(infobar_manager()));
956 ShowNextQueuedInfoBar(infobar_manager());
957 }
914 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); 958 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
915 CheckPermissionMessageSent(0, true); 959 CheckPermissionMessageSent(0, true);
916 960
917 // Verify that accepting the first didn't accept because it's embedded 961 // Verify that accepting the first didn't accept because it's embedded
918 // in the other. 962 // in the other.
919 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), 963 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
920 requesting_frame_0.GetOrigin(), 964 requesting_frame_0.GetOrigin(),
921 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 965 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
922 10); 966 10);
923 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), 967 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
(...skipping 30 matching lines...) Expand all
954 // it is the embedder. 998 // it is the embedder.
955 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), 999 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
956 requesting_frame_0.GetOrigin(), 1000 requesting_frame_0.GetOrigin(),
957 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 1001 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
958 13); 1002 13);
959 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), 1003 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
960 requesting_frame_0.GetOrigin(), 1004 requesting_frame_0.GetOrigin(),
961 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 1005 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
962 11); 1006 11);
963 } 1007 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698