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

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

Issue 4767001: Make TabContents own its infobar delegates.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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>
8
7 #include "base/scoped_vector.h" 9 #include "base/scoped_vector.h"
8 #include "chrome/browser/browser_thread.h" 10 #include "chrome/browser/browser_thread.h"
9 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" 11 #include "chrome/browser/geolocation/geolocation_content_settings_map.h"
10 #include "chrome/browser/geolocation/geolocation_permission_context.h" 12 #include "chrome/browser/geolocation/geolocation_permission_context.h"
11 #include "chrome/browser/geolocation/location_arbitrator.h" 13 #include "chrome/browser/geolocation/location_arbitrator.h"
12 #include "chrome/browser/geolocation/location_provider.h" 14 #include "chrome/browser/geolocation/location_provider.h"
13 #include "chrome/browser/geolocation/mock_location_provider.h" 15 #include "chrome/browser/geolocation/mock_location_provider.h"
14 #include "chrome/browser/renderer_host/mock_render_process_host.h" 16 #include "chrome/browser/renderer_host/mock_render_process_host.h"
15 #include "chrome/browser/renderer_host/test/test_render_view_host.h" 17 #include "chrome/browser/renderer_host/test/test_render_view_host.h"
16 #include "chrome/browser/tab_contents/infobar_delegate.h" 18 #include "chrome/browser/tab_contents/infobar_delegate.h"
17 #include "chrome/browser/tab_contents/test_tab_contents.h" 19 #include "chrome/browser/tab_contents/test_tab_contents.h"
18 #include "chrome/common/notification_details.h" 20 #include "chrome/common/notification_registrar.h"
19 #include "chrome/common/notification_type.h" 21 #include "chrome/common/notification_service.h"
20 #include "chrome/common/render_messages.h" 22 #include "chrome/common/render_messages.h"
21 #include "chrome/test/testing_profile.h" 23 #include "chrome/test/testing_profile.h"
22 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
23 25
24 // TestTabContents short-circuits TAB_CONTENTS_INFOBAR_REMOVED to call 26 // We need to track which infobars were closed.
25 // InfoBarClosed() directly. We need to observe it and call InfoBarClosed() 27 class ClosedDelegateTracker : public NotificationObserver {
26 // later.
27 class TestTabContentsWithPendingInfoBar : public TestTabContents {
28 public: 28 public:
29 TestTabContentsWithPendingInfoBar(Profile* profile, SiteInstance* instance) 29 ClosedDelegateTracker() {
30 : TestTabContents(profile, instance), 30 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
31 removed_infobar_delegate_(NULL) { 31 NotificationService::AllSources());
32 } 32 }
33 33
34 void Observe(NotificationType type, 34 virtual void Observe(NotificationType type,
35 const NotificationSource& source, 35 const NotificationSource& source,
36 const NotificationDetails& details) { 36 const NotificationDetails& details) {
37 // We need to special case TAB_CONTENTS_INFOBAR_REMOVED to track which 37 DCHECK(type.value == NotificationType::TAB_CONTENTS_INFOBAR_REMOVED);
38 // delegate was removed and avoid calling InfoBarClosed() supplied in the 38 removed_infobar_delegates_.insert(Details<InfoBarDelegate>(details).ptr());
39 // base class. All other notification types are delegated to the base class.
40 switch (type.value) {
41 case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED:
42 removed_infobar_delegate_ = Details<InfoBarDelegate>(details).ptr();
43 break;
44 default:
45 TestTabContents::Observe(type, source, details);
46 break;
47 }
48 } 39 }
49 40
50 InfoBarDelegate* removed_infobar_delegate_; 41 bool Contains(InfoBarDelegate* delegate) const {
42 return removed_infobar_delegates_.count(delegate) != 0;
43 }
44
45 size_t size() const {
46 return removed_infobar_delegates_.size();
47 }
48
49 void Clear() {
50 removed_infobar_delegates_.clear();
51 }
52
53 private:
54 NotificationRegistrar registrar_;
55 std::set<InfoBarDelegate*> removed_infobar_delegates_;
51 }; 56 };
52 57
53 // This class sets up GeolocationArbitrator and injects 58 // This class sets up GeolocationArbitrator.
54 // TestTabContentsWithPendingInfoBar.
55 class GeolocationPermissionContextTests : public RenderViewHostTestHarness { 59 class GeolocationPermissionContextTests : public RenderViewHostTestHarness {
56 public: 60 public:
57 GeolocationPermissionContextTests() 61 GeolocationPermissionContextTests()
58 : RenderViewHostTestHarness(), 62 : RenderViewHostTestHarness(),
59 ui_thread_(BrowserThread::UI, MessageLoop::current()), 63 ui_thread_(BrowserThread::UI, MessageLoop::current()) {
60 tab_contents_with_pending_infobar_(NULL) {
61 } 64 }
62 65
63 virtual ~GeolocationPermissionContextTests() { 66 virtual ~GeolocationPermissionContextTests() {
64 } 67 }
65 68
66 virtual void SetUp() { 69 virtual void SetUp() {
67 RenderViewHostTestHarness::SetUp(); 70 RenderViewHostTestHarness::SetUp();
68 GeolocationArbitrator::SetProviderFactoryForTest( 71 GeolocationArbitrator::SetProviderFactoryForTest(
69 &NewAutoSuccessMockNetworkLocationProvider); 72 &NewAutoSuccessMockNetworkLocationProvider);
70 SiteInstance* site_instance = contents_->GetSiteInstance();
71 tab_contents_with_pending_infobar_ =
72 new TestTabContentsWithPendingInfoBar(profile_.get(), site_instance);
73 contents_.reset(tab_contents_with_pending_infobar_);
74 geolocation_permission_context_ = 73 geolocation_permission_context_ =
75 new GeolocationPermissionContext(profile()); 74 new GeolocationPermissionContext(profile());
75 closed_delegate_tracker_.reset(new ClosedDelegateTracker());
76 } 76 }
77 77
78 virtual void TearDown() { 78 virtual void TearDown() {
79 closed_delegate_tracker_.reset();
80 GeolocationArbitrator::SetProviderFactoryForTest(NULL);
79 RenderViewHostTestHarness::TearDown(); 81 RenderViewHostTestHarness::TearDown();
80 GeolocationArbitrator::SetProviderFactoryForTest(NULL);
81 } 82 }
82 83
83 int process_id() { 84 int process_id() {
84 return contents()->render_view_host()->process()->id(); 85 return contents()->render_view_host()->process()->id();
85 } 86 }
86 int process_id_for_tab(int tab) { 87 int process_id_for_tab(int tab) {
87 return extra_tabs_[tab]->render_view_host()->process()->id(); 88 return extra_tabs_[tab]->render_view_host()->process()->id();
88 } 89 }
89 90
90 int render_id() { 91 int render_id() {
(...skipping 28 matching lines...) Expand all
119 ViewMsg_Geolocation_PermissionSet::ID); 120 ViewMsg_Geolocation_PermissionSet::ID);
120 ASSERT_TRUE(message); 121 ASSERT_TRUE(message);
121 ViewMsg_Geolocation_PermissionSet::Param param; 122 ViewMsg_Geolocation_PermissionSet::Param param;
122 ViewMsg_Geolocation_PermissionSet::Read(message, &param); 123 ViewMsg_Geolocation_PermissionSet::Read(message, &param);
123 EXPECT_EQ(bridge_id, param.a); 124 EXPECT_EQ(bridge_id, param.a);
124 EXPECT_EQ(allowed, param.b); 125 EXPECT_EQ(allowed, param.b);
125 process->sink().ClearMessages(); 126 process->sink().ClearMessages();
126 } 127 }
127 128
128 void AddNewTab(const GURL& url) { 129 void AddNewTab(const GURL& url) {
129 TestTabContentsWithPendingInfoBar* new_tab = 130 TabContents* new_tab =
130 new TestTabContentsWithPendingInfoBar(profile(), NULL); 131 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL);
131 new_tab->controller().LoadURL(url, GURL(), PageTransition::TYPED); 132 new_tab->controller().LoadURL(url, GURL(), PageTransition::TYPED);
132 static_cast<TestRenderViewHost*>(new_tab->render_manager()-> 133 static_cast<TestRenderViewHost*>(new_tab->render_manager()->
133 current_host())->SendNavigate(extra_tabs_.size() + 1, url); 134 current_host())->SendNavigate(extra_tabs_.size() + 1, url);
134 extra_tabs_.push_back(new_tab); 135 extra_tabs_.push_back(new_tab);
135 } 136 }
136 137
137 void CheckTabContentsState(const GURL& requesting_frame, 138 void CheckTabContentsState(const GURL& requesting_frame,
138 ContentSetting expected_content_setting) { 139 ContentSetting expected_content_setting) {
139 TabSpecificContentSettings* content_settings = 140 TabSpecificContentSettings* content_settings =
140 contents()->GetTabSpecificContentSettings(); 141 contents()->GetTabSpecificContentSettings();
141 const GeolocationSettingsState::StateMap& state_map = 142 const GeolocationSettingsState::StateMap& state_map =
142 content_settings->geolocation_settings_state().state_map(); 143 content_settings->geolocation_settings_state().state_map();
143 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin())); 144 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin()));
144 EXPECT_EQ(0U, state_map.count(requesting_frame)); 145 EXPECT_EQ(0U, state_map.count(requesting_frame));
145 GeolocationSettingsState::StateMap::const_iterator settings = 146 GeolocationSettingsState::StateMap::const_iterator settings =
146 state_map.find(requesting_frame.GetOrigin()); 147 state_map.find(requesting_frame.GetOrigin());
147 ASSERT_FALSE(settings == state_map.end()) 148 ASSERT_FALSE(settings == state_map.end())
148 << "geolocation state not found " << requesting_frame; 149 << "geolocation state not found " << requesting_frame;
149 EXPECT_EQ(expected_content_setting, settings->second); 150 EXPECT_EQ(expected_content_setting, settings->second);
150 } 151 }
151 152
152 protected: 153 protected:
153 BrowserThread ui_thread_; 154 BrowserThread ui_thread_;
154 TestTabContentsWithPendingInfoBar* tab_contents_with_pending_infobar_;
155 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; 155 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_;
156 ScopedVector<TestTabContentsWithPendingInfoBar> extra_tabs_; 156 scoped_ptr<ClosedDelegateTracker> closed_delegate_tracker_;
157 ScopedVector<TabContents> extra_tabs_;
157 }; 158 };
158 159
159 TEST_F(GeolocationPermissionContextTests, SinglePermission) { 160 TEST_F(GeolocationPermissionContextTests, SinglePermission) {
160 GURL requesting_frame("http://www.example.com/geolocation"); 161 GURL requesting_frame("http://www.example.com/geolocation");
161 NavigateAndCommit(requesting_frame); 162 NavigateAndCommit(requesting_frame);
162 EXPECT_EQ(0, contents()->infobar_delegate_count()); 163 EXPECT_EQ(0, contents()->infobar_delegate_count());
163 geolocation_permission_context_->RequestGeolocationPermission( 164 geolocation_permission_context_->RequestGeolocationPermission(
164 process_id(), render_id(), bridge_id(), requesting_frame); 165 process_id(), render_id(), bridge_id(), requesting_frame);
165 EXPECT_EQ(1, contents()->infobar_delegate_count()); 166 EXPECT_EQ(1, contents()->infobar_delegate_count());
166 } 167 }
(...skipping 23 matching lines...) Expand all
190 contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 191 contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
191 ASSERT_TRUE(infobar_0); 192 ASSERT_TRUE(infobar_0);
192 string16 text_0 = infobar_0->GetMessageText(); 193 string16 text_0 = infobar_0->GetMessageText();
193 194
194 // Accept the first frame. 195 // Accept the first frame.
195 infobar_0->Accept(); 196 infobar_0->Accept();
196 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); 197 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
197 CheckPermissionMessageSent(bridge_id(), true); 198 CheckPermissionMessageSent(bridge_id(), true);
198 199
199 contents()->RemoveInfoBar(infobar_0); 200 contents()->RemoveInfoBar(infobar_0);
200 EXPECT_EQ(infobar_0, 201 EXPECT_EQ(1U, closed_delegate_tracker_->size());
201 tab_contents_with_pending_infobar_->removed_infobar_delegate_); 202 EXPECT_TRUE(closed_delegate_tracker_->Contains(infobar_0));
202 infobar_0->InfoBarClosed(); 203 closed_delegate_tracker_->Clear();
203 // Now we should have a new infobar for the second frame. 204 // Now we should have a new infobar for the second frame.
204 EXPECT_EQ(1, contents()->infobar_delegate_count()); 205 EXPECT_EQ(1, contents()->infobar_delegate_count());
205 206
206 ConfirmInfoBarDelegate* infobar_1 = 207 ConfirmInfoBarDelegate* infobar_1 =
207 contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 208 contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
208 ASSERT_TRUE(infobar_1); 209 ASSERT_TRUE(infobar_1);
209 string16 text_1 = infobar_1->GetMessageText(); 210 string16 text_1 = infobar_1->GetMessageText();
210 EXPECT_NE(text_0, text_1); 211 EXPECT_NE(text_0, text_1);
211 212
212 // Cancel (block) this frame. 213 // Cancel (block) this frame.
213 infobar_1->Cancel(); 214 infobar_1->Cancel();
214 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); 215 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK);
215 CheckPermissionMessageSent(bridge_id() + 1, false); 216 CheckPermissionMessageSent(bridge_id() + 1, false);
216 contents()->RemoveInfoBar(infobar_1); 217 contents()->RemoveInfoBar(infobar_1);
217 EXPECT_EQ(infobar_1, 218 EXPECT_EQ(1U, closed_delegate_tracker_->size());
218 tab_contents_with_pending_infobar_->removed_infobar_delegate_); 219 EXPECT_TRUE(closed_delegate_tracker_->Contains(infobar_1));
219 infobar_1->InfoBarClosed();
220 EXPECT_EQ(0, contents()->infobar_delegate_count()); 220 EXPECT_EQ(0, contents()->infobar_delegate_count());
221 // Ensure the persisted permissions are ok. 221 // Ensure the persisted permissions are ok.
222 EXPECT_EQ( 222 EXPECT_EQ(
223 CONTENT_SETTING_ALLOW, 223 CONTENT_SETTING_ALLOW,
224 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 224 profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
225 requesting_frame_0, requesting_frame_0)); 225 requesting_frame_0, requesting_frame_0));
226 EXPECT_EQ( 226 EXPECT_EQ(
227 CONTENT_SETTING_BLOCK, 227 CONTENT_SETTING_BLOCK,
228 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 228 profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
229 requesting_frame_1, requesting_frame_0)); 229 requesting_frame_1, requesting_frame_0));
(...skipping 22 matching lines...) Expand all
252 252
253 ConfirmInfoBarDelegate* infobar_0 = 253 ConfirmInfoBarDelegate* infobar_0 =
254 contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 254 contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
255 ASSERT_TRUE(infobar_0); 255 ASSERT_TRUE(infobar_0);
256 string16 text_0 = infobar_0->GetMessageText(); 256 string16 text_0 = infobar_0->GetMessageText();
257 257
258 // Simulate the frame going away, ensure the infobar for this frame 258 // Simulate the frame going away, ensure the infobar for this frame
259 // is removed and the next pending infobar is created. 259 // is removed and the next pending infobar is created.
260 geolocation_permission_context_->CancelGeolocationPermissionRequest( 260 geolocation_permission_context_->CancelGeolocationPermissionRequest(
261 process_id(), render_id(), bridge_id(), requesting_frame_0); 261 process_id(), render_id(), bridge_id(), requesting_frame_0);
262 EXPECT_EQ(infobar_0, 262 EXPECT_EQ(1U, closed_delegate_tracker_->size());
263 tab_contents_with_pending_infobar_->removed_infobar_delegate_); 263 EXPECT_TRUE(closed_delegate_tracker_->Contains(infobar_0));
264 infobar_0->InfoBarClosed(); 264 closed_delegate_tracker_->Clear();
265 EXPECT_EQ(1, contents()->infobar_delegate_count()); 265 EXPECT_EQ(1, contents()->infobar_delegate_count());
266 266
267 ConfirmInfoBarDelegate* infobar_1 = 267 ConfirmInfoBarDelegate* infobar_1 =
268 contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 268 contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
269 ASSERT_TRUE(infobar_1); 269 ASSERT_TRUE(infobar_1);
270 string16 text_1 = infobar_1->GetMessageText(); 270 string16 text_1 = infobar_1->GetMessageText();
271 EXPECT_NE(text_0, text_1); 271 EXPECT_NE(text_0, text_1);
272 272
273 // Allow this frame. 273 // Allow this frame.
274 infobar_1->Accept(); 274 infobar_1->Accept();
275 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); 275 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW);
276 CheckPermissionMessageSent(bridge_id() + 1, true); 276 CheckPermissionMessageSent(bridge_id() + 1, true);
277 contents()->RemoveInfoBar(infobar_1); 277 contents()->RemoveInfoBar(infobar_1);
278 EXPECT_EQ(infobar_1, 278 EXPECT_EQ(1U, closed_delegate_tracker_->size());
279 tab_contents_with_pending_infobar_->removed_infobar_delegate_); 279 EXPECT_TRUE(closed_delegate_tracker_->Contains(infobar_1));
280 infobar_1->InfoBarClosed();
281 EXPECT_EQ(0, contents()->infobar_delegate_count()); 280 EXPECT_EQ(0, contents()->infobar_delegate_count());
282 // Ensure the persisted permissions are ok. 281 // Ensure the persisted permissions are ok.
283 EXPECT_EQ( 282 EXPECT_EQ(
284 CONTENT_SETTING_ASK, 283 CONTENT_SETTING_ASK,
285 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 284 profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
286 requesting_frame_0, requesting_frame_0)); 285 requesting_frame_0, requesting_frame_0));
287 EXPECT_EQ( 286 EXPECT_EQ(
288 CONTENT_SETTING_ALLOW, 287 CONTENT_SETTING_ALLOW,
289 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 288 profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
290 requesting_frame_1, requesting_frame_0)); 289 requesting_frame_1, requesting_frame_0));
291 } 290 }
292 291
293 TEST_F(GeolocationPermissionContextTests, StopUpdating) { 292 TEST_F(GeolocationPermissionContextTests, StopUpdating) {
294 GURL requesting_frame("http://www.example.com/geolocation"); 293 GURL requesting_frame("http://www.example.com/geolocation");
295 NavigateAndCommit(requesting_frame); 294 NavigateAndCommit(requesting_frame);
296 EXPECT_EQ(0, contents()->infobar_delegate_count()); 295 EXPECT_EQ(0, contents()->infobar_delegate_count());
297 geolocation_permission_context_->RequestGeolocationPermission( 296 geolocation_permission_context_->RequestGeolocationPermission(
298 process_id(), render_id(), bridge_id(), requesting_frame); 297 process_id(), render_id(), bridge_id(), requesting_frame);
299 EXPECT_EQ(1, contents()->infobar_delegate_count()); 298 EXPECT_EQ(1, contents()->infobar_delegate_count());
300 ConfirmInfoBarDelegate* infobar_0 = 299 ConfirmInfoBarDelegate* infobar_0 =
301 contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 300 contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
302 ASSERT_TRUE(infobar_0); 301 ASSERT_TRUE(infobar_0);
303 302
304 geolocation_permission_context_->StopUpdatingRequested( 303 geolocation_permission_context_->StopUpdatingRequested(
305 process_id(), render_id(), bridge_id()); 304 process_id(), render_id(), bridge_id());
306 EXPECT_EQ(infobar_0, 305 EXPECT_EQ(1U, closed_delegate_tracker_->size());
307 tab_contents_with_pending_infobar_->removed_infobar_delegate_); 306 EXPECT_TRUE(closed_delegate_tracker_->Contains(infobar_0));
308 infobar_0->InfoBarClosed();
309 EXPECT_EQ(0, contents()->infobar_delegate_count()); 307 EXPECT_EQ(0, contents()->infobar_delegate_count());
310 EXPECT_EQ( 308 EXPECT_EQ(CONTENT_SETTING_ASK,
311 CONTENT_SETTING_ASK, 309 profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
312 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 310 requesting_frame, requesting_frame));
313 requesting_frame, requesting_frame));
314 } 311 }
315 312
316 TEST_F(GeolocationPermissionContextTests, InvalidURL) { 313 TEST_F(GeolocationPermissionContextTests, InvalidURL) {
317 GURL invalid_embedder; 314 GURL invalid_embedder;
318 GURL requesting_frame("about:blank"); 315 GURL requesting_frame("about:blank");
319 NavigateAndCommit(invalid_embedder); 316 NavigateAndCommit(invalid_embedder);
320 EXPECT_EQ(0, contents()->infobar_delegate_count()); 317 EXPECT_EQ(0, contents()->infobar_delegate_count());
321 geolocation_permission_context_->RequestGeolocationPermission( 318 geolocation_permission_context_->RequestGeolocationPermission(
322 process_id(), render_id(), bridge_id(), requesting_frame); 319 process_id(), render_id(), bridge_id(), requesting_frame);
323 EXPECT_EQ(0, contents()->infobar_delegate_count()); 320 EXPECT_EQ(0, contents()->infobar_delegate_count());
(...skipping 23 matching lines...) Expand all
347 ConfirmInfoBarDelegate* removed_infobar = 344 ConfirmInfoBarDelegate* removed_infobar =
348 extra_tabs_[1]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 345 extra_tabs_[1]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
349 346
350 // Accept the first tab. 347 // Accept the first tab.
351 ConfirmInfoBarDelegate* infobar_0 = 348 ConfirmInfoBarDelegate* infobar_0 =
352 contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 349 contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
353 ASSERT_TRUE(infobar_0); 350 ASSERT_TRUE(infobar_0);
354 infobar_0->Accept(); 351 infobar_0->Accept();
355 CheckPermissionMessageSent(bridge_id(), true); 352 CheckPermissionMessageSent(bridge_id(), true);
356 contents()->RemoveInfoBar(infobar_0); 353 contents()->RemoveInfoBar(infobar_0);
357 EXPECT_EQ(infobar_0, 354 EXPECT_EQ(2U, closed_delegate_tracker_->size());
358 tab_contents_with_pending_infobar_->removed_infobar_delegate_); 355 EXPECT_TRUE(closed_delegate_tracker_->Contains(infobar_0));
359 infobar_0->InfoBarClosed();
360 // Now the infobar for the tab with the same origin should have gone. 356 // Now the infobar for the tab with the same origin should have gone.
361 EXPECT_EQ(0, extra_tabs_[1]->infobar_delegate_count()); 357 EXPECT_EQ(0, extra_tabs_[1]->infobar_delegate_count());
362 CheckPermissionMessageSentForTab(1, bridge_id(), true); 358 CheckPermissionMessageSentForTab(1, bridge_id(), true);
363 // Destroy the infobar that has just been removed. 359 EXPECT_TRUE(closed_delegate_tracker_->Contains(removed_infobar));
364 removed_infobar->InfoBarClosed();
365 360
366 // But the other tab should still have the info bar... 361 // But the other tab should still have the info bar...
367 EXPECT_EQ(1, extra_tabs_[0]->infobar_delegate_count()); 362 EXPECT_EQ(1, extra_tabs_[0]->infobar_delegate_count());
368 extra_tabs_.reset(); 363 extra_tabs_.reset();
369 } 364 }
370 365
371 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { 366 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
372 GURL url_a("http://www.example.com/geolocation"); 367 GURL url_a("http://www.example.com/geolocation");
373 GURL url_b("http://www.example-2.com/geolocation"); 368 GURL url_b("http://www.example-2.com/geolocation");
374 NavigateAndCommit(url_a); 369 NavigateAndCommit(url_a);
(...skipping 15 matching lines...) Expand all
390 ConfirmInfoBarDelegate* removed_infobar = 385 ConfirmInfoBarDelegate* removed_infobar =
391 contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 386 contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
392 387
393 // Accept the second tab. 388 // Accept the second tab.
394 ConfirmInfoBarDelegate* infobar_0 = 389 ConfirmInfoBarDelegate* infobar_0 =
395 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 390 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
396 ASSERT_TRUE(infobar_0); 391 ASSERT_TRUE(infobar_0);
397 infobar_0->Accept(); 392 infobar_0->Accept();
398 CheckPermissionMessageSentForTab(0, bridge_id(), true); 393 CheckPermissionMessageSentForTab(0, bridge_id(), true);
399 extra_tabs_[0]->RemoveInfoBar(infobar_0); 394 extra_tabs_[0]->RemoveInfoBar(infobar_0);
400 EXPECT_EQ(infobar_0, 395 EXPECT_EQ(2U, closed_delegate_tracker_->size());
401 extra_tabs_[0]->removed_infobar_delegate_); 396 EXPECT_TRUE(closed_delegate_tracker_->Contains(infobar_0));
402 infobar_0->InfoBarClosed();
403 // Now the infobar for the tab with the same origin should have gone. 397 // Now the infobar for the tab with the same origin should have gone.
404 EXPECT_EQ(0, contents()->infobar_delegate_count()); 398 EXPECT_EQ(0, contents()->infobar_delegate_count());
405 CheckPermissionMessageSent(bridge_id(), true); 399 CheckPermissionMessageSent(bridge_id(), true);
406 // Destroy the infobar that has just been removed. 400 EXPECT_TRUE(closed_delegate_tracker_->Contains(removed_infobar));
407 removed_infobar->InfoBarClosed(); 401 closed_delegate_tracker_->Clear();
408 402
409 // And we should have the queued infobar displayed now. 403 // And we should have the queued infobar displayed now.
410 EXPECT_EQ(1, extra_tabs_[0]->infobar_delegate_count()); 404 EXPECT_EQ(1, extra_tabs_[0]->infobar_delegate_count());
411 405
412 // Accept the second infobar. 406 // Accept the second infobar.
413 ConfirmInfoBarDelegate* infobar_1 = 407 ConfirmInfoBarDelegate* infobar_1 =
414 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 408 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
415 ASSERT_TRUE(infobar_1); 409 ASSERT_TRUE(infobar_1);
416 infobar_1->Accept(); 410 infobar_1->Accept();
417 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); 411 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true);
418 extra_tabs_[0]->RemoveInfoBar(infobar_1); 412 extra_tabs_[0]->RemoveInfoBar(infobar_1);
419 EXPECT_EQ(infobar_1, 413 EXPECT_EQ(1U, closed_delegate_tracker_->size());
420 extra_tabs_[0]->removed_infobar_delegate_); 414 EXPECT_TRUE(closed_delegate_tracker_->Contains(infobar_1));
421 infobar_1->InfoBarClosed();
422 415
423 extra_tabs_.reset(); 416 extra_tabs_.reset();
424 } 417 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698