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 6993030: Move GeolocationPermissionContextUnittest from subclassing TabContentsWrapper to merely observing... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
6
5 #include "base/memory/scoped_vector.h" 7 #include "base/memory/scoped_vector.h"
6 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 8 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
7 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" 9 #include "chrome/browser/geolocation/geolocation_content_settings_map.h"
8 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 10 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
10 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" 12 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
11 #include "chrome/test/testing_profile.h" 13 #include "chrome/test/testing_profile.h"
12 #include "content/browser/browser_thread.h" 14 #include "content/browser/browser_thread.h"
13 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h " 15 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h "
14 #include "content/browser/geolocation/geolocation_permission_context.h" 16 #include "content/browser/geolocation/geolocation_permission_context.h"
15 #include "content/browser/geolocation/location_arbitrator.h" 17 #include "content/browser/geolocation/location_arbitrator.h"
16 #include "content/browser/geolocation/location_provider.h" 18 #include "content/browser/geolocation/location_provider.h"
17 #include "content/browser/geolocation/mock_location_provider.h" 19 #include "content/browser/geolocation/mock_location_provider.h"
18 #include "content/browser/renderer_host/mock_render_process_host.h" 20 #include "content/browser/renderer_host/mock_render_process_host.h"
19 #include "content/browser/tab_contents/test_tab_contents.h" 21 #include "content/browser/tab_contents/test_tab_contents.h"
20 #include "content/common/geolocation_messages.h" 22 #include "content/common/geolocation_messages.h"
21 #include "content/common/notification_details.h"
22 #include "content/common/notification_registrar.h" 23 #include "content/common/notification_registrar.h"
23 #include "content/common/notification_source.h" 24 #include "content/common/notification_service.h"
24 #include "content/common/notification_type.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 26
27 // TestTabContentsWithPendingInfoBar ------------------------------------------ 27 // ClosedDelegateTracker ------------------------------------------------------
28 28
29 namespace { 29 namespace {
30 30
31 // TestTabContents short-circuits TAB_CONTENTS_INFOBAR_REMOVED to call 31 // We need to track which infobars were closed.
32 // InfoBarClosed() directly. We need to observe it and call InfoBarClosed() 32 class ClosedDelegateTracker : public NotificationObserver {
33 // later.
34 class TestTabContentsWithPendingInfoBar : public TabContentsWrapper {
35 public: 33 public:
36 TestTabContentsWithPendingInfoBar(Profile* profile, SiteInstance* instance); 34 ClosedDelegateTracker();
37 virtual ~TestTabContentsWithPendingInfoBar(); 35 virtual ~ClosedDelegateTracker();
38 36
39 // TabContentsWrapper: 37 // NotificationObserver:
40 virtual void Observe(NotificationType type, 38 virtual void Observe(NotificationType type,
41 const NotificationSource& source, 39 const NotificationSource& source,
42 const NotificationDetails& details); 40 const NotificationDetails& details);
43 41
44 InfoBarDelegate* removed_infobar_delegate_; 42 size_t size() const {
43 return removed_infobar_delegates_.size();
44 }
45
46 bool Contains(InfoBarDelegate* delegate) const;
47 void Clear();
48
49 private:
45 NotificationRegistrar registrar_; 50 NotificationRegistrar registrar_;
51 std::set<InfoBarDelegate*> removed_infobar_delegates_;
46 }; 52 };
47 53
48 TestTabContentsWithPendingInfoBar::TestTabContentsWithPendingInfoBar( 54 ClosedDelegateTracker::ClosedDelegateTracker() {
49 Profile* profile,
50 SiteInstance* instance)
51 : TabContentsWrapper(
52 new TabContents(profile, instance, MSG_ROUTING_NONE, NULL, NULL)),
53 removed_infobar_delegate_(NULL) {
54 Source<TabContentsWrapper> source(this);
55 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, 55 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
56 source); 56 NotificationService::AllSources());
57 } 57 }
58 58
59 TestTabContentsWithPendingInfoBar::~TestTabContentsWithPendingInfoBar() { 59 ClosedDelegateTracker::~ClosedDelegateTracker() {
60 } 60 }
61 61
62 void TestTabContentsWithPendingInfoBar::Observe( 62 void ClosedDelegateTracker::Observe(NotificationType type,
63 NotificationType type, 63 const NotificationSource& source,
64 const NotificationSource& source, 64 const NotificationDetails& details) {
65 const NotificationDetails& details) { 65 DCHECK(type.value == NotificationType::TAB_CONTENTS_INFOBAR_REMOVED);
66 if (type.value == NotificationType::TAB_CONTENTS_INFOBAR_REMOVED) { 66 removed_infobar_delegates_.insert(
67 removed_infobar_delegate_ = 67 Details<std::pair<InfoBarDelegate*, bool> >(details)->first);
68 Details<std::pair<InfoBarDelegate*, bool> >(details)->first; 68 }
69 } else { 69
70 TabContentsWrapper::Observe(type, source, details); 70 bool ClosedDelegateTracker::Contains(InfoBarDelegate* delegate) const {
71 } 71 return removed_infobar_delegates_.count(delegate) != 0;
72 }
73
74 void ClosedDelegateTracker::Clear() {
75 removed_infobar_delegates_.clear();
72 } 76 }
73 77
74 } // namespace 78 } // namespace
75 79
76 80
77 // GeolocationPermissionContextTests ------------------------------------------ 81 // GeolocationPermissionContextTests ------------------------------------------
78 82
79 // This class sets up GeolocationArbitrator. 83 // This class sets up GeolocationArbitrator.
80 class GeolocationPermissionContextTests : public TabContentsWrapperTestHarness { 84 class GeolocationPermissionContextTests : public TabContentsWrapperTestHarness {
81 public: 85 public:
82 GeolocationPermissionContextTests(); 86 GeolocationPermissionContextTests();
83 87
84 protected: 88 protected:
85 virtual ~GeolocationPermissionContextTests(); 89 virtual ~GeolocationPermissionContextTests();
86 90
87 int process_id() { return contents()->render_view_host()->process()->id(); } 91 int process_id() { return contents()->render_view_host()->process()->id(); }
88 int process_id_for_tab(int tab) { 92 int process_id_for_tab(int tab) {
89 return extra_tabs_[tab]->render_view_host()->process()->id(); 93 return extra_tabs_[tab]->tab_contents()->render_view_host()->process()->
94 id();
90 } 95 }
91 int render_id() { return contents()->render_view_host()->routing_id(); } 96 int render_id() { return contents()->render_view_host()->routing_id(); }
92 int render_id_for_tab(int tab) { 97 int render_id_for_tab(int tab) {
93 return extra_tabs_[tab]->render_view_host()->routing_id(); 98 return extra_tabs_[tab]->tab_contents()->render_view_host()->routing_id();
94 } 99 }
95 int bridge_id() const { return 42; } // Not relevant at this level. 100 int bridge_id() const { return 42; } // Not relevant at this level.
96 101
97 void CheckPermissionMessageSent(int bridge_id, bool allowed); 102 void CheckPermissionMessageSent(int bridge_id, bool allowed);
98 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); 103 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed);
99 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, 104 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process,
100 int bridge_id, 105 int bridge_id,
101 bool allowed); 106 bool allowed);
102 void AddNewTab(const GURL& url); 107 void AddNewTab(const GURL& url);
103 void CheckTabContentsState(const GURL& requesting_frame, 108 void CheckTabContentsState(const GURL& requesting_frame,
104 ContentSetting expected_content_setting); 109 ContentSetting expected_content_setting);
105 110
106 TestTabContentsWithPendingInfoBar* tab_contents_with_pending_infobar_;
107 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; 111 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_;
108 ScopedVector<TestTabContentsWithPendingInfoBar> extra_tabs_; 112 ClosedDelegateTracker closed_delegate_tracker_;
113 ScopedVector<TabContentsWrapper> extra_tabs_;
109 114
110 private: 115 private:
111 // TabContentsWrapperTestHarness: 116 // TabContentsWrapperTestHarness:
112 virtual void SetUp(); 117 virtual void SetUp();
113 virtual void TearDown(); 118 virtual void TearDown();
114 119
115 BrowserThread ui_thread_; 120 BrowserThread ui_thread_;
116 scoped_refptr<GeolocationArbitratorDependencyFactory> dependency_factory_; 121 scoped_refptr<GeolocationArbitratorDependencyFactory> dependency_factory_;
117 }; 122 };
118 123
119 GeolocationPermissionContextTests::GeolocationPermissionContextTests() 124 GeolocationPermissionContextTests::GeolocationPermissionContextTests()
120 : tab_contents_with_pending_infobar_(NULL), 125 : TabContentsWrapperTestHarness(),
121 ui_thread_(BrowserThread::UI, MessageLoop::current()), 126 ui_thread_(BrowserThread::UI, MessageLoop::current()),
122 dependency_factory_( 127 dependency_factory_(
123 new GeolocationArbitratorDependencyFactoryWithLocationProvider( 128 new GeolocationArbitratorDependencyFactoryWithLocationProvider(
124 &NewAutoSuccessMockNetworkLocationProvider)) { 129 &NewAutoSuccessMockNetworkLocationProvider)) {
125 } 130 }
126 131
127 GeolocationPermissionContextTests::~GeolocationPermissionContextTests() { 132 GeolocationPermissionContextTests::~GeolocationPermissionContextTests() {
128 } 133 }
129 134
130 void GeolocationPermissionContextTests::CheckPermissionMessageSent( 135 void GeolocationPermissionContextTests::CheckPermissionMessageSent(
131 int bridge_id, 136 int bridge_id,
132 bool allowed) { 137 bool allowed) {
133 CheckPermissionMessageSentInternal(process(), bridge_id, allowed); 138 CheckPermissionMessageSentInternal(process(), bridge_id, allowed);
134 } 139 }
135 140
136 void GeolocationPermissionContextTests::CheckPermissionMessageSentForTab( 141 void GeolocationPermissionContextTests::CheckPermissionMessageSentForTab(
137 int tab, 142 int tab,
138 int bridge_id, 143 int bridge_id,
139 bool allowed) { 144 bool allowed) {
140 CheckPermissionMessageSentInternal(static_cast<MockRenderProcessHost*>( 145 CheckPermissionMessageSentInternal(static_cast<MockRenderProcessHost*>(
141 extra_tabs_[tab]->render_view_host()->process()), bridge_id, allowed); 146 extra_tabs_[tab]->tab_contents()->render_view_host()->process()),
147 bridge_id, allowed);
142 } 148 }
143 149
144 void GeolocationPermissionContextTests::CheckPermissionMessageSentInternal( 150 void GeolocationPermissionContextTests::CheckPermissionMessageSentInternal(
145 MockRenderProcessHost* process, 151 MockRenderProcessHost* process,
146 int bridge_id, 152 int bridge_id,
147 bool allowed) { 153 bool allowed) {
148 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); 154 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
149 MessageLoop::current()->Run(); 155 MessageLoop::current()->Run();
150 const IPC::Message* message = process->sink().GetFirstMessageMatching( 156 const IPC::Message* message = process->sink().GetFirstMessageMatching(
151 GeolocationMsg_PermissionSet::ID); 157 GeolocationMsg_PermissionSet::ID);
152 ASSERT_TRUE(message); 158 ASSERT_TRUE(message);
153 GeolocationMsg_PermissionSet::Param param; 159 GeolocationMsg_PermissionSet::Param param;
154 GeolocationMsg_PermissionSet::Read(message, &param); 160 GeolocationMsg_PermissionSet::Read(message, &param);
155 EXPECT_EQ(bridge_id, param.a); 161 EXPECT_EQ(bridge_id, param.a);
156 EXPECT_EQ(allowed, param.b); 162 EXPECT_EQ(allowed, param.b);
157 process->sink().ClearMessages(); 163 process->sink().ClearMessages();
158 } 164 }
159 165
160 void GeolocationPermissionContextTests::AddNewTab(const GURL& url) { 166 void GeolocationPermissionContextTests::AddNewTab(const GURL& url) {
161 TestTabContentsWithPendingInfoBar* new_tab = 167 TabContents* new_tab =
162 new TestTabContentsWithPendingInfoBar(profile(), NULL); 168 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL);
163 new_tab->controller().LoadURL(url, GURL(), PageTransition::TYPED); 169 new_tab->controller().LoadURL(url, GURL(), PageTransition::TYPED);
164 static_cast<TestRenderViewHost*>(new_tab->tab_contents()->render_manager()-> 170 static_cast<TestRenderViewHost*>(new_tab->render_manager()->current_host())->
165 current_host())->SendNavigate(extra_tabs_.size() + 1, url); 171 SendNavigate(extra_tabs_.size() + 1, url);
166 extra_tabs_.push_back(new_tab); 172 extra_tabs_.push_back(new TabContentsWrapper(new_tab));
167 } 173 }
168 174
169 void GeolocationPermissionContextTests::CheckTabContentsState( 175 void GeolocationPermissionContextTests::CheckTabContentsState(
170 const GURL& requesting_frame, 176 const GURL& requesting_frame,
171 ContentSetting expected_content_setting) { 177 ContentSetting expected_content_setting) {
172 TabSpecificContentSettings* content_settings = 178 TabSpecificContentSettings* content_settings =
173 contents_wrapper()->content_settings(); 179 contents_wrapper()->content_settings();
174 const GeolocationSettingsState::StateMap& state_map = 180 const GeolocationSettingsState::StateMap& state_map =
175 content_settings->geolocation_settings_state().state_map(); 181 content_settings->geolocation_settings_state().state_map();
176 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin())); 182 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin()));
177 EXPECT_EQ(0U, state_map.count(requesting_frame)); 183 EXPECT_EQ(0U, state_map.count(requesting_frame));
178 GeolocationSettingsState::StateMap::const_iterator settings = 184 GeolocationSettingsState::StateMap::const_iterator settings =
179 state_map.find(requesting_frame.GetOrigin()); 185 state_map.find(requesting_frame.GetOrigin());
180 ASSERT_FALSE(settings == state_map.end()) 186 ASSERT_FALSE(settings == state_map.end())
181 << "geolocation state not found " << requesting_frame; 187 << "geolocation state not found " << requesting_frame;
182 EXPECT_EQ(expected_content_setting, settings->second); 188 EXPECT_EQ(expected_content_setting, settings->second);
183 } 189 }
184 190
185 void GeolocationPermissionContextTests::SetUp() { 191 void GeolocationPermissionContextTests::SetUp() {
186 TabContentsWrapperTestHarness::SetUp(); 192 TabContentsWrapperTestHarness::SetUp();
187 GeolocationArbitrator::SetDependencyFactoryForTest( 193 GeolocationArbitrator::SetDependencyFactoryForTest(
188 dependency_factory_.get()); 194 dependency_factory_.get());
189 SiteInstance* site_instance = contents()->GetSiteInstance();
190 tab_contents_with_pending_infobar_ =
191 new TestTabContentsWithPendingInfoBar(profile_.get(), site_instance);
192 SetContentsWrapper(tab_contents_with_pending_infobar_);
193 geolocation_permission_context_ = 195 geolocation_permission_context_ =
194 new GeolocationPermissionContext(profile()); 196 new GeolocationPermissionContext(profile());
195 } 197 }
196 198
197 void GeolocationPermissionContextTests::TearDown() { 199 void GeolocationPermissionContextTests::TearDown() {
198 GeolocationArbitrator::SetDependencyFactoryForTest(NULL); 200 GeolocationArbitrator::SetDependencyFactoryForTest(NULL);
199 TabContentsWrapperTestHarness::TearDown(); 201 TabContentsWrapperTestHarness::TearDown();
200 } 202 }
201 203
202 204
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 236 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
235 ASSERT_TRUE(infobar_0); 237 ASSERT_TRUE(infobar_0);
236 string16 text_0 = infobar_0->GetMessageText(); 238 string16 text_0 = infobar_0->GetMessageText();
237 239
238 // Accept the first frame. 240 // Accept the first frame.
239 infobar_0->Accept(); 241 infobar_0->Accept();
240 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); 242 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
241 CheckPermissionMessageSent(bridge_id(), true); 243 CheckPermissionMessageSent(bridge_id(), true);
242 244
243 contents_wrapper()->RemoveInfoBar(infobar_0); 245 contents_wrapper()->RemoveInfoBar(infobar_0);
244 EXPECT_EQ(infobar_0, 246 EXPECT_EQ(1U, closed_delegate_tracker_.size());
245 tab_contents_with_pending_infobar_->removed_infobar_delegate_); 247 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
248 closed_delegate_tracker_.Clear();
246 infobar_0->InfoBarClosed(); 249 infobar_0->InfoBarClosed();
247 // Now we should have a new infobar for the second frame. 250 // Now we should have a new infobar for the second frame.
248 EXPECT_EQ(1U, contents_wrapper()->infobar_count()); 251 EXPECT_EQ(1U, contents_wrapper()->infobar_count());
249 252
250 ConfirmInfoBarDelegate* infobar_1 = 253 ConfirmInfoBarDelegate* infobar_1 =
251 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 254 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
252 ASSERT_TRUE(infobar_1); 255 ASSERT_TRUE(infobar_1);
253 string16 text_1 = infobar_1->GetMessageText(); 256 string16 text_1 = infobar_1->GetMessageText();
254 EXPECT_NE(text_0, text_1); 257 EXPECT_NE(text_0, text_1);
255 258
256 // Cancel (block) this frame. 259 // Cancel (block) this frame.
257 infobar_1->Cancel(); 260 infobar_1->Cancel();
258 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); 261 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK);
259 CheckPermissionMessageSent(bridge_id() + 1, false); 262 CheckPermissionMessageSent(bridge_id() + 1, false);
260 contents_wrapper()->RemoveInfoBar(infobar_1); 263 contents_wrapper()->RemoveInfoBar(infobar_1);
261 EXPECT_EQ(infobar_1, 264 EXPECT_EQ(1U, closed_delegate_tracker_.size());
262 tab_contents_with_pending_infobar_->removed_infobar_delegate_); 265 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
263 infobar_1->InfoBarClosed(); 266 infobar_1->InfoBarClosed();
264 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); 267 EXPECT_EQ(0U, contents_wrapper()->infobar_count());
265 // Ensure the persisted permissions are ok. 268 // Ensure the persisted permissions are ok.
266 EXPECT_EQ(CONTENT_SETTING_ALLOW, 269 EXPECT_EQ(CONTENT_SETTING_ALLOW,
267 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 270 profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
268 requesting_frame_0, requesting_frame_0)); 271 requesting_frame_0, requesting_frame_0));
269 EXPECT_EQ(CONTENT_SETTING_BLOCK, 272 EXPECT_EQ(CONTENT_SETTING_BLOCK,
270 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 273 profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
271 requesting_frame_1, requesting_frame_0)); 274 requesting_frame_1, requesting_frame_0));
272 } 275 }
(...skipping 19 matching lines...) Expand all
292 295
293 ConfirmInfoBarDelegate* infobar_0 = 296 ConfirmInfoBarDelegate* infobar_0 =
294 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 297 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
295 ASSERT_TRUE(infobar_0); 298 ASSERT_TRUE(infobar_0);
296 string16 text_0 = infobar_0->GetMessageText(); 299 string16 text_0 = infobar_0->GetMessageText();
297 300
298 // Simulate the frame going away, ensure the infobar for this frame 301 // Simulate the frame going away, ensure the infobar for this frame
299 // is removed and the next pending infobar is created. 302 // is removed and the next pending infobar is created.
300 geolocation_permission_context_->CancelGeolocationPermissionRequest( 303 geolocation_permission_context_->CancelGeolocationPermissionRequest(
301 process_id(), render_id(), bridge_id(), requesting_frame_0); 304 process_id(), render_id(), bridge_id(), requesting_frame_0);
302 EXPECT_EQ(infobar_0, 305 EXPECT_EQ(1U, closed_delegate_tracker_.size());
303 tab_contents_with_pending_infobar_->removed_infobar_delegate_); 306 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
307 closed_delegate_tracker_.Clear();
304 infobar_0->InfoBarClosed(); 308 infobar_0->InfoBarClosed();
305 EXPECT_EQ(1U, contents_wrapper()->infobar_count()); 309 EXPECT_EQ(1U, contents_wrapper()->infobar_count());
306 310
307 ConfirmInfoBarDelegate* infobar_1 = 311 ConfirmInfoBarDelegate* infobar_1 =
308 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 312 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
309 ASSERT_TRUE(infobar_1); 313 ASSERT_TRUE(infobar_1);
310 string16 text_1 = infobar_1->GetMessageText(); 314 string16 text_1 = infobar_1->GetMessageText();
311 EXPECT_NE(text_0, text_1); 315 EXPECT_NE(text_0, text_1);
312 316
313 // Allow this frame. 317 // Allow this frame.
314 infobar_1->Accept(); 318 infobar_1->Accept();
315 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); 319 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW);
316 CheckPermissionMessageSent(bridge_id() + 1, true); 320 CheckPermissionMessageSent(bridge_id() + 1, true);
317 contents_wrapper()->RemoveInfoBar(infobar_1); 321 contents_wrapper()->RemoveInfoBar(infobar_1);
318 EXPECT_EQ(infobar_1, 322 EXPECT_EQ(1U, closed_delegate_tracker_.size());
319 tab_contents_with_pending_infobar_->removed_infobar_delegate_); 323 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
320 infobar_1->InfoBarClosed(); 324 infobar_1->InfoBarClosed();
321 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); 325 EXPECT_EQ(0U, contents_wrapper()->infobar_count());
322 // Ensure the persisted permissions are ok. 326 // Ensure the persisted permissions are ok.
323 EXPECT_EQ(CONTENT_SETTING_ASK, 327 EXPECT_EQ(CONTENT_SETTING_ASK,
324 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 328 profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
325 requesting_frame_0, requesting_frame_0)); 329 requesting_frame_0, requesting_frame_0));
326 EXPECT_EQ(CONTENT_SETTING_ALLOW, 330 EXPECT_EQ(CONTENT_SETTING_ALLOW,
327 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 331 profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
328 requesting_frame_1, requesting_frame_0)); 332 requesting_frame_1, requesting_frame_0));
329 } 333 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 ConfirmInfoBarDelegate* removed_infobar = 366 ConfirmInfoBarDelegate* removed_infobar =
363 extra_tabs_[1]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 367 extra_tabs_[1]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
364 368
365 // Accept the first tab. 369 // Accept the first tab.
366 ConfirmInfoBarDelegate* infobar_0 = 370 ConfirmInfoBarDelegate* infobar_0 =
367 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 371 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
368 ASSERT_TRUE(infobar_0); 372 ASSERT_TRUE(infobar_0);
369 infobar_0->Accept(); 373 infobar_0->Accept();
370 CheckPermissionMessageSent(bridge_id(), true); 374 CheckPermissionMessageSent(bridge_id(), true);
371 contents_wrapper()->RemoveInfoBar(infobar_0); 375 contents_wrapper()->RemoveInfoBar(infobar_0);
372 EXPECT_EQ(infobar_0, 376 EXPECT_EQ(2U, closed_delegate_tracker_.size());
373 tab_contents_with_pending_infobar_->removed_infobar_delegate_); 377 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
374 infobar_0->InfoBarClosed(); 378 infobar_0->InfoBarClosed();
375 // Now the infobar for the tab with the same origin should have gone. 379 // Now the infobar for the tab with the same origin should have gone.
376 EXPECT_EQ(0U, extra_tabs_[1]->infobar_count()); 380 EXPECT_EQ(0U, extra_tabs_[1]->infobar_count());
377 CheckPermissionMessageSentForTab(1, bridge_id(), true); 381 CheckPermissionMessageSentForTab(1, bridge_id(), true);
382 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar));
378 // Destroy the infobar that has just been removed. 383 // Destroy the infobar that has just been removed.
379 removed_infobar->InfoBarClosed(); 384 removed_infobar->InfoBarClosed();
380 385
381 // But the other tab should still have the info bar... 386 // But the other tab should still have the info bar...
382 EXPECT_EQ(1U, extra_tabs_[0]->infobar_count()); 387 EXPECT_EQ(1U, extra_tabs_[0]->infobar_count());
383 extra_tabs_.reset(); 388 extra_tabs_.reset();
384 } 389 }
385 390
386 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { 391 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
387 GURL url_a("http://www.example.com/geolocation"); 392 GURL url_a("http://www.example.com/geolocation");
(...skipping 17 matching lines...) Expand all
405 ConfirmInfoBarDelegate* removed_infobar = 410 ConfirmInfoBarDelegate* removed_infobar =
406 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 411 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
407 412
408 // Accept the second tab. 413 // Accept the second tab.
409 ConfirmInfoBarDelegate* infobar_0 = 414 ConfirmInfoBarDelegate* infobar_0 =
410 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 415 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
411 ASSERT_TRUE(infobar_0); 416 ASSERT_TRUE(infobar_0);
412 infobar_0->Accept(); 417 infobar_0->Accept();
413 CheckPermissionMessageSentForTab(0, bridge_id(), true); 418 CheckPermissionMessageSentForTab(0, bridge_id(), true);
414 extra_tabs_[0]->RemoveInfoBar(infobar_0); 419 extra_tabs_[0]->RemoveInfoBar(infobar_0);
415 EXPECT_EQ(infobar_0, 420 EXPECT_EQ(2U, closed_delegate_tracker_.size());
416 extra_tabs_[0]->removed_infobar_delegate_); 421 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
417 infobar_0->InfoBarClosed(); 422 infobar_0->InfoBarClosed();
418 // 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.
419 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); 424 EXPECT_EQ(0U, contents_wrapper()->infobar_count());
420 CheckPermissionMessageSent(bridge_id(), true); 425 CheckPermissionMessageSent(bridge_id(), true);
426 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar));
427 closed_delegate_tracker_.Clear();
421 // Destroy the infobar that has just been removed. 428 // Destroy the infobar that has just been removed.
422 removed_infobar->InfoBarClosed(); 429 removed_infobar->InfoBarClosed();
423 430
424 // And we should have the queued infobar displayed now. 431 // And we should have the queued infobar displayed now.
425 EXPECT_EQ(1U, extra_tabs_[0]->infobar_count()); 432 EXPECT_EQ(1U, extra_tabs_[0]->infobar_count());
426 433
427 // Accept the second infobar. 434 // Accept the second infobar.
428 ConfirmInfoBarDelegate* infobar_1 = 435 ConfirmInfoBarDelegate* infobar_1 =
429 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 436 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
430 ASSERT_TRUE(infobar_1); 437 ASSERT_TRUE(infobar_1);
431 infobar_1->Accept(); 438 infobar_1->Accept();
432 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); 439 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true);
433 extra_tabs_[0]->RemoveInfoBar(infobar_1); 440 extra_tabs_[0]->RemoveInfoBar(infobar_1);
434 EXPECT_EQ(infobar_1, 441 EXPECT_EQ(1U, closed_delegate_tracker_.size());
435 extra_tabs_[0]->removed_infobar_delegate_); 442 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
436 infobar_1->InfoBarClosed(); 443 infobar_1->InfoBarClosed();
437 444
438 extra_tabs_.reset(); 445 extra_tabs_.reset();
439 } 446 }
440 447
441 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { 448 TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
442 GURL requesting_frame_0("http://www.example.com/geolocation"); 449 GURL requesting_frame_0("http://www.example.com/geolocation");
443 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 450 GURL requesting_frame_1("http://www.example-2.com/geolocation");
444 EXPECT_EQ( 451 EXPECT_EQ(
445 CONTENT_SETTING_ASK, 452 CONTENT_SETTING_ASK,
(...skipping 14 matching lines...) Expand all
460 // Ensure only one infobar is created. 467 // Ensure only one infobar is created.
461 EXPECT_EQ(1U, contents_wrapper()->infobar_count()); 468 EXPECT_EQ(1U, contents_wrapper()->infobar_count());
462 ConfirmInfoBarDelegate* infobar_0 = 469 ConfirmInfoBarDelegate* infobar_0 =
463 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 470 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
464 ASSERT_TRUE(infobar_0); 471 ASSERT_TRUE(infobar_0);
465 string16 text_0 = infobar_0->GetMessageText(); 472 string16 text_0 = infobar_0->GetMessageText();
466 473
467 // Delete the tab contents. 474 // Delete the tab contents.
468 DeleteContents(); 475 DeleteContents();
469 } 476 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698