OLD | NEW |
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" |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
13 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 13 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
14 #include "chrome/browser/content_settings/host_content_settings_map.h" | 14 #include "chrome/browser/content_settings/host_content_settings_map.h" |
15 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 15 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
16 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" | 16 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
17 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_facto
ry.h" | 17 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_facto
ry.h" |
| 18 #include "chrome/browser/geolocation/geolocation_permission_request_id.h" |
18 #include "chrome/browser/infobars/infobar.h" | 19 #include "chrome/browser/infobars/infobar.h" |
19 #include "chrome/browser/infobars/infobar_tab_helper.h" | 20 #include "chrome/browser/infobars/infobar_tab_helper.h" |
20 #include "chrome/browser/view_type_utils.h" | 21 #include "chrome/browser/view_type_utils.h" |
21 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
23 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
24 #include "content/public/browser/navigation_details.h" | 25 #include "content/public/browser/navigation_details.h" |
25 #include "content/public/browser/notification_registrar.h" | 26 #include "content/public/browser/notification_registrar.h" |
26 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
28 #include "content/public/test/mock_render_process_host.h" | 29 #include "content/public/test/mock_render_process_host.h" |
29 #include "content/public/test/test_browser_thread.h" | 30 #include "content/public/test/test_browser_thread.h" |
30 #include "content/public/test/test_renderer_host.h" | 31 #include "content/public/test/test_renderer_host.h" |
31 #include "content/public/test/web_contents_tester.h" | 32 #include "content/public/test/web_contents_tester.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
33 | 34 |
34 #if defined(OS_ANDROID) | 35 #if defined(OS_ANDROID) |
35 #include "chrome/browser/prefs/pref_service.h" | 36 #include "chrome/browser/prefs/pref_service.h" |
36 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
37 #endif | 38 #endif |
38 | 39 |
39 using content::BrowserThread; | |
40 using content::MockRenderProcessHost; | 40 using content::MockRenderProcessHost; |
41 using content::RenderViewHostTester; | 41 |
42 using content::WebContents; | |
43 using content::WebContentsTester; | |
44 | 42 |
45 // ClosedDelegateTracker ------------------------------------------------------ | 43 // ClosedDelegateTracker ------------------------------------------------------ |
46 | 44 |
47 // We need to track which infobars were closed. | 45 // We need to track which infobars were closed. |
48 class ClosedDelegateTracker : public content::NotificationObserver { | 46 class ClosedDelegateTracker : public content::NotificationObserver { |
49 public: | 47 public: |
50 ClosedDelegateTracker(); | 48 ClosedDelegateTracker(); |
51 virtual ~ClosedDelegateTracker(); | 49 virtual ~ClosedDelegateTracker(); |
52 | 50 |
53 // content::NotificationObserver: | 51 // content::NotificationObserver: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 84 } |
87 | 85 |
88 bool ClosedDelegateTracker::Contains(InfoBarDelegate* delegate) const { | 86 bool ClosedDelegateTracker::Contains(InfoBarDelegate* delegate) const { |
89 return removed_infobar_delegates_.count(delegate) != 0; | 87 return removed_infobar_delegates_.count(delegate) != 0; |
90 } | 88 } |
91 | 89 |
92 void ClosedDelegateTracker::Clear() { | 90 void ClosedDelegateTracker::Clear() { |
93 removed_infobar_delegates_.clear(); | 91 removed_infobar_delegates_.clear(); |
94 } | 92 } |
95 | 93 |
| 94 |
96 // GeolocationPermissionContextTests ------------------------------------------ | 95 // GeolocationPermissionContextTests ------------------------------------------ |
97 | 96 |
98 // This class sets up GeolocationArbitrator. | 97 // This class sets up GeolocationArbitrator. |
99 class GeolocationPermissionContextTests | 98 class GeolocationPermissionContextTests |
100 : public ChromeRenderViewHostTestHarness { | 99 : public ChromeRenderViewHostTestHarness { |
101 public: | 100 public: |
102 GeolocationPermissionContextTests(); | 101 GeolocationPermissionContextTests(); |
103 | 102 |
104 protected: | 103 protected: |
105 virtual ~GeolocationPermissionContextTests(); | 104 virtual ~GeolocationPermissionContextTests(); |
106 | 105 |
107 int process_id() { | 106 GeolocationPermissionRequestID RequestID(int bridge_id); |
108 return web_contents()->GetRenderProcessHost()->GetID(); | 107 GeolocationPermissionRequestID RequestIDForTab(int tab, int bridge_id); |
109 } | |
110 int process_id_for_tab(int tab) { | |
111 return extra_tabs_[tab]->GetRenderProcessHost()->GetID(); | |
112 } | |
113 int render_id() { | |
114 return web_contents()->GetRenderViewHost()->GetRoutingID(); | |
115 } | |
116 int render_id_for_tab(int tab) { | |
117 return extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(); | |
118 } | |
119 int bridge_id() const { return 42; } // Not relevant at this level. | |
120 InfoBarTabHelper* infobar_tab_helper() { | 108 InfoBarTabHelper* infobar_tab_helper() { |
121 return InfoBarTabHelper::FromWebContents(web_contents()); | 109 return InfoBarTabHelper::FromWebContents(web_contents()); |
122 } | 110 } |
123 InfoBarTabHelper* infobar_tab_helper_for_tab(int tab) { | 111 InfoBarTabHelper* infobar_tab_helper_for_tab(int tab) { |
124 return InfoBarTabHelper::FromWebContents(extra_tabs_[tab]); | 112 return InfoBarTabHelper::FromWebContents(extra_tabs_[tab]); |
125 } | 113 } |
126 | 114 |
127 void RequestGeolocationPermission(int render_process_id, | 115 void RequestGeolocationPermission(const GeolocationPermissionRequestID& id, |
128 int render_view_id, | |
129 int bridge_id, | |
130 const GURL& requesting_frame); | 116 const GURL& requesting_frame); |
131 void PermissionResponse(int render_process_id, | 117 void CancelGeolocationPermissionRequest( |
132 int render_view_id, | 118 const GeolocationPermissionRequestID& id, |
133 int bridge_id, | 119 const GURL& requesting_frame); |
| 120 void PermissionResponse(const GeolocationPermissionRequestID& id, |
134 bool allowed); | 121 bool allowed); |
135 void CheckPermissionMessageSent(int bridge_id, bool allowed); | 122 void CheckPermissionMessageSent(int bridge_id, bool allowed); |
136 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); | 123 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); |
137 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, | 124 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, |
138 int bridge_id, | 125 int bridge_id, |
139 bool allowed); | 126 bool allowed); |
140 void AddNewTab(const GURL& url); | 127 void AddNewTab(const GURL& url); |
141 void CheckTabContentsState(const GURL& requesting_frame, | 128 void CheckTabContentsState(const GURL& requesting_frame, |
142 ContentSetting expected_content_setting); | 129 ContentSetting expected_content_setting); |
143 | 130 |
144 scoped_refptr<ChromeGeolocationPermissionContext> | 131 scoped_refptr<ChromeGeolocationPermissionContext> |
145 geolocation_permission_context_; | 132 geolocation_permission_context_; |
146 ClosedDelegateTracker closed_delegate_tracker_; | 133 ClosedDelegateTracker closed_delegate_tracker_; |
147 ScopedVector<WebContents> extra_tabs_; | 134 ScopedVector<content::WebContents> extra_tabs_; |
148 | 135 |
149 private: | 136 private: |
150 // ChromeRenderViewHostTestHarness: | 137 // ChromeRenderViewHostTestHarness: |
151 virtual void SetUp() OVERRIDE; | 138 virtual void SetUp() OVERRIDE; |
152 virtual void TearDown() OVERRIDE; | 139 virtual void TearDown() OVERRIDE; |
153 | 140 |
154 content::TestBrowserThread ui_thread_; | 141 content::TestBrowserThread ui_thread_; |
155 content::TestBrowserThread db_thread_; | 142 content::TestBrowserThread db_thread_; |
156 | 143 |
157 // A map between renderer child id and a pair represending the bridge id and | 144 // A map between renderer child id and a pair represending the bridge id and |
158 // whether the requested permission was allowed. | 145 // whether the requested permission was allowed. |
159 base::hash_map<int, std::pair<int, bool> > responses_; | 146 base::hash_map<int, std::pair<int, bool> > responses_; |
160 }; | 147 }; |
161 | 148 |
162 GeolocationPermissionContextTests::GeolocationPermissionContextTests() | 149 GeolocationPermissionContextTests::GeolocationPermissionContextTests() |
163 : ChromeRenderViewHostTestHarness(), | 150 : ChromeRenderViewHostTestHarness(), |
164 ui_thread_(BrowserThread::UI, MessageLoop::current()), | 151 ui_thread_(content::BrowserThread::UI, MessageLoop::current()), |
165 db_thread_(BrowserThread::DB) { | 152 db_thread_(content::BrowserThread::DB) { |
166 } | 153 } |
167 | 154 |
168 GeolocationPermissionContextTests::~GeolocationPermissionContextTests() { | 155 GeolocationPermissionContextTests::~GeolocationPermissionContextTests() { |
169 } | 156 } |
170 | 157 |
| 158 GeolocationPermissionRequestID GeolocationPermissionContextTests::RequestID( |
| 159 int bridge_id) { |
| 160 return GeolocationPermissionRequestID( |
| 161 web_contents()->GetRenderProcessHost()->GetID(), |
| 162 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 163 bridge_id); |
| 164 } |
| 165 |
| 166 GeolocationPermissionRequestID |
| 167 GeolocationPermissionContextTests::RequestIDForTab(int tab, int bridge_id) { |
| 168 return GeolocationPermissionRequestID( |
| 169 extra_tabs_[tab]->GetRenderProcessHost()->GetID(), |
| 170 extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(), |
| 171 bridge_id); |
| 172 } |
| 173 |
171 void GeolocationPermissionContextTests::RequestGeolocationPermission( | 174 void GeolocationPermissionContextTests::RequestGeolocationPermission( |
172 int render_process_id, | 175 const GeolocationPermissionRequestID& id, |
173 int render_view_id, | |
174 int bridge_id, | |
175 const GURL& requesting_frame) { | 176 const GURL& requesting_frame) { |
176 geolocation_permission_context_->RequestGeolocationPermission( | 177 geolocation_permission_context_->RequestGeolocationPermission( |
177 render_process_id, render_view_id, bridge_id, requesting_frame, | 178 id.render_process_id(), id.render_view_id(), id.bridge_id(), |
| 179 requesting_frame, |
178 base::Bind(&GeolocationPermissionContextTests::PermissionResponse, | 180 base::Bind(&GeolocationPermissionContextTests::PermissionResponse, |
179 base::Unretained(this), | 181 base::Unretained(this), id)); |
180 render_process_id, | 182 } |
181 render_view_id, | 183 |
182 bridge_id)); | 184 void GeolocationPermissionContextTests::CancelGeolocationPermissionRequest( |
| 185 const GeolocationPermissionRequestID& id, |
| 186 const GURL& requesting_frame) { |
| 187 geolocation_permission_context_->CancelGeolocationPermissionRequest( |
| 188 id.render_process_id(), id.render_view_id(), id.bridge_id(), |
| 189 requesting_frame); |
183 } | 190 } |
184 | 191 |
185 void GeolocationPermissionContextTests::PermissionResponse( | 192 void GeolocationPermissionContextTests::PermissionResponse( |
186 int render_process_id, | 193 const GeolocationPermissionRequestID& id, |
187 int render_view_id, | |
188 int bridge_id, | |
189 bool allowed) { | 194 bool allowed) { |
190 responses_[render_process_id] = std::make_pair(bridge_id, allowed); | 195 responses_[id.render_process_id()] = std::make_pair(id.bridge_id(), allowed); |
191 } | 196 } |
192 | 197 |
193 void GeolocationPermissionContextTests::CheckPermissionMessageSent( | 198 void GeolocationPermissionContextTests::CheckPermissionMessageSent( |
194 int bridge_id, | 199 int bridge_id, |
195 bool allowed) { | 200 bool allowed) { |
196 CheckPermissionMessageSentInternal(process(), bridge_id, allowed); | 201 CheckPermissionMessageSentInternal(process(), bridge_id, allowed); |
197 } | 202 } |
198 | 203 |
199 void GeolocationPermissionContextTests::CheckPermissionMessageSentForTab( | 204 void GeolocationPermissionContextTests::CheckPermissionMessageSentForTab( |
200 int tab, | 205 int tab, |
201 int bridge_id, | 206 int bridge_id, |
202 bool allowed) { | 207 bool allowed) { |
203 CheckPermissionMessageSentInternal(static_cast<MockRenderProcessHost*>( | 208 CheckPermissionMessageSentInternal(static_cast<MockRenderProcessHost*>( |
204 extra_tabs_[tab]->GetRenderProcessHost()), | 209 extra_tabs_[tab]->GetRenderProcessHost()), |
205 bridge_id, allowed); | 210 bridge_id, allowed); |
206 } | 211 } |
207 | 212 |
208 void GeolocationPermissionContextTests::CheckPermissionMessageSentInternal( | 213 void GeolocationPermissionContextTests::CheckPermissionMessageSentInternal( |
209 MockRenderProcessHost* process, | 214 MockRenderProcessHost* process, |
210 int bridge_id, | 215 int bridge_id, |
211 bool allowed) { | 216 bool allowed) { |
212 ASSERT_EQ(responses_.count(process->GetID()), 1U); | 217 ASSERT_EQ(responses_.count(process->GetID()), 1U); |
213 EXPECT_EQ(bridge_id, responses_[process->GetID()].first); | 218 EXPECT_EQ(bridge_id, responses_[process->GetID()].first); |
214 EXPECT_EQ(allowed, responses_[process->GetID()].second); | 219 EXPECT_EQ(allowed, responses_[process->GetID()].second); |
215 responses_.erase(process->GetID()); | 220 responses_.erase(process->GetID()); |
216 } | 221 } |
217 | 222 |
218 void GeolocationPermissionContextTests::AddNewTab(const GURL& url) { | 223 void GeolocationPermissionContextTests::AddNewTab(const GURL& url) { |
219 WebContents* new_tab = | 224 content::WebContents* new_tab = |
220 WebContents::Create(profile(), NULL, MSG_ROUTING_NONE, NULL); | 225 content::WebContents::Create(profile(), NULL, MSG_ROUTING_NONE, NULL); |
221 new_tab->GetController().LoadURL( | 226 new_tab->GetController().LoadURL( |
222 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 227 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
223 RenderViewHostTester::For(new_tab->GetRenderViewHost())-> | 228 content::RenderViewHostTester::For(new_tab->GetRenderViewHost())-> |
224 SendNavigate(extra_tabs_.size() + 1, url); | 229 SendNavigate(extra_tabs_.size() + 1, url); |
225 | 230 |
226 // Set up required helpers, and make this be as "tabby" as the code requires. | 231 // Set up required helpers, and make this be as "tabby" as the code requires. |
227 chrome::SetViewType(new_tab, chrome::VIEW_TYPE_TAB_CONTENTS); | 232 chrome::SetViewType(new_tab, chrome::VIEW_TYPE_TAB_CONTENTS); |
228 InfoBarTabHelper::CreateForWebContents(new_tab); | 233 InfoBarTabHelper::CreateForWebContents(new_tab); |
229 | 234 |
230 extra_tabs_.push_back(new_tab); | 235 extra_tabs_.push_back(new_tab); |
231 } | 236 } |
232 | 237 |
233 void GeolocationPermissionContextTests::CheckTabContentsState( | 238 void GeolocationPermissionContextTests::CheckTabContentsState( |
(...skipping 24 matching lines...) Expand all Loading... |
258 geolocation_permission_context_ = | 263 geolocation_permission_context_ = |
259 ChromeGeolocationPermissionContextFactory::Create(profile()); | 264 ChromeGeolocationPermissionContextFactory::Create(profile()); |
260 } | 265 } |
261 | 266 |
262 void GeolocationPermissionContextTests::TearDown() { | 267 void GeolocationPermissionContextTests::TearDown() { |
263 extra_tabs_.clear(); | 268 extra_tabs_.clear(); |
264 ChromeRenderViewHostTestHarness::TearDown(); | 269 ChromeRenderViewHostTestHarness::TearDown(); |
265 // Schedule another task on the DB thread to notify us that it's safe to | 270 // Schedule another task on the DB thread to notify us that it's safe to |
266 // carry on with the test. | 271 // carry on with the test. |
267 base::WaitableEvent done(false, false); | 272 base::WaitableEvent done(false, false); |
268 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 273 content::BrowserThread::PostTask( |
| 274 content::BrowserThread::DB, FROM_HERE, |
269 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | 275 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
270 done.Wait(); | 276 done.Wait(); |
271 db_thread_.Stop(); | 277 db_thread_.Stop(); |
272 } | 278 } |
273 | 279 |
274 | 280 |
275 // Tests ---------------------------------------------------------------------- | 281 // Tests ---------------------------------------------------------------------- |
276 | 282 |
277 TEST_F(GeolocationPermissionContextTests, SinglePermission) { | 283 TEST_F(GeolocationPermissionContextTests, SinglePermission) { |
278 GURL requesting_frame("http://www.example.com/geolocation"); | 284 GURL requesting_frame("http://www.example.com/geolocation"); |
279 NavigateAndCommit(requesting_frame); | 285 NavigateAndCommit(requesting_frame); |
280 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 286 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
281 RequestGeolocationPermission( | 287 RequestGeolocationPermission(RequestID(0), requesting_frame); |
282 process_id(), render_id(), bridge_id(), requesting_frame); | |
283 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 288 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
284 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> | 289 ConfirmInfoBarDelegate* infobar_0 = |
285 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 290 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
286 infobar_0->Cancel(); | 291 infobar_0->Cancel(); |
287 infobar_tab_helper()->RemoveInfoBar(infobar_0); | 292 infobar_tab_helper()->RemoveInfoBar(infobar_0); |
288 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 293 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
289 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 294 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
290 infobar_0->InfoBarClosed(); | 295 infobar_0->InfoBarClosed(); |
291 } | 296 } |
292 | 297 |
293 #if defined(OS_ANDROID) | 298 #if defined(OS_ANDROID) |
294 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { | 299 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { |
295 profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 300 profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
296 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 301 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
297 CONTENT_SETTING_ALLOW); | 302 CONTENT_SETTING_ALLOW); |
298 | 303 |
299 // Check that the request is denied with preference disabled, | 304 // Check that the request is denied with preference disabled, |
300 // even though the default policy allows it. | 305 // even though the default policy allows it. |
301 GURL requesting_frame("http://www.example.com/geolocation"); | 306 GURL requesting_frame("http://www.example.com/geolocation"); |
302 NavigateAndCommit(requesting_frame); | 307 NavigateAndCommit(requesting_frame); |
303 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 308 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
304 profile()->GetPrefs()->SetBoolean(prefs::kGeolocationEnabled, false); | 309 profile()->GetPrefs()->SetBoolean(prefs::kGeolocationEnabled, false); |
305 RequestGeolocationPermission( | 310 RequestGeolocationPermission(RequestID(0), requesting_frame); |
306 process_id(), render_id(), bridge_id(), requesting_frame); | |
307 ASSERT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 311 ASSERT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
308 CheckPermissionMessageSent(bridge_id(), false); | 312 CheckPermissionMessageSent(0, false); |
309 | 313 |
310 // Reenable the preference and check that the request now goes though. | 314 // Reenable the preference and check that the request now goes though. |
311 profile()->GetPrefs()->SetBoolean(prefs::kGeolocationEnabled, true); | 315 profile()->GetPrefs()->SetBoolean(prefs::kGeolocationEnabled, true); |
312 RequestGeolocationPermission( | 316 RequestGeolocationPermission(RequestID(1), requesting_frame); |
313 process_id(), render_id(), bridge_id() + 1, requesting_frame); | |
314 ASSERT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 317 ASSERT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
315 CheckPermissionMessageSent(bridge_id() + 1, true); | 318 CheckPermissionMessageSent(1, true); |
316 } | 319 } |
317 #endif | 320 #endif |
318 | 321 |
319 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { | 322 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { |
320 GURL requesting_frame_0("http://www.example.com/geolocation"); | 323 GURL requesting_frame_0("http://www.example.com/geolocation"); |
321 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 324 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
322 EXPECT_EQ(CONTENT_SETTING_ASK, | 325 EXPECT_EQ(CONTENT_SETTING_ASK, |
323 profile()->GetHostContentSettingsMap()->GetContentSetting( | 326 profile()->GetHostContentSettingsMap()->GetContentSetting( |
324 requesting_frame_0, | 327 requesting_frame_0, |
325 requesting_frame_0, | 328 requesting_frame_0, |
326 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 329 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
327 std::string())); | 330 std::string())); |
328 EXPECT_EQ(CONTENT_SETTING_ASK, | 331 EXPECT_EQ(CONTENT_SETTING_ASK, |
329 profile()->GetHostContentSettingsMap()->GetContentSetting( | 332 profile()->GetHostContentSettingsMap()->GetContentSetting( |
330 requesting_frame_1, | 333 requesting_frame_1, |
331 requesting_frame_0, | 334 requesting_frame_0, |
332 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 335 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
333 std::string())); | 336 std::string())); |
334 | 337 |
335 | 338 |
336 NavigateAndCommit(requesting_frame_0); | 339 NavigateAndCommit(requesting_frame_0); |
337 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 340 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
338 // Request permission for two frames. | 341 // Request permission for two frames. |
339 RequestGeolocationPermission( | 342 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
340 process_id(), render_id(), bridge_id(), requesting_frame_0); | 343 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
341 RequestGeolocationPermission( | |
342 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); | |
343 // Ensure only one infobar is created. | 344 // Ensure only one infobar is created. |
344 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 345 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
345 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> | 346 ConfirmInfoBarDelegate* infobar_0 = |
346 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 347 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
347 ASSERT_TRUE(infobar_0); | 348 ASSERT_TRUE(infobar_0); |
348 string16 text_0 = infobar_0->GetMessageText(); | 349 string16 text_0 = infobar_0->GetMessageText(); |
349 | 350 |
350 // Accept the first frame. | 351 // Accept the first frame. |
351 infobar_0->Accept(); | 352 infobar_0->Accept(); |
352 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | 353 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
353 CheckPermissionMessageSent(bridge_id(), true); | 354 CheckPermissionMessageSent(0, true); |
354 | 355 |
355 infobar_tab_helper()->RemoveInfoBar(infobar_0); | 356 infobar_tab_helper()->RemoveInfoBar(infobar_0); |
356 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 357 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
357 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 358 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
358 closed_delegate_tracker_.Clear(); | 359 closed_delegate_tracker_.Clear(); |
359 infobar_0->InfoBarClosed(); | 360 infobar_0->InfoBarClosed(); |
360 // Now we should have a new infobar for the second frame. | 361 // Now we should have a new infobar for the second frame. |
361 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 362 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
362 | 363 |
363 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()-> | 364 ConfirmInfoBarDelegate* infobar_1 = |
364 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 365 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
365 ASSERT_TRUE(infobar_1); | 366 ASSERT_TRUE(infobar_1); |
366 string16 text_1 = infobar_1->GetMessageText(); | 367 string16 text_1 = infobar_1->GetMessageText(); |
367 EXPECT_NE(text_0, text_1); | 368 EXPECT_NE(text_0, text_1); |
368 | 369 |
369 // Cancel (block) this frame. | 370 // Cancel (block) this frame. |
370 infobar_1->Cancel(); | 371 infobar_1->Cancel(); |
371 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); | 372 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
372 CheckPermissionMessageSent(bridge_id() + 1, false); | 373 CheckPermissionMessageSent(1, false); |
373 infobar_tab_helper()->RemoveInfoBar(infobar_1); | 374 infobar_tab_helper()->RemoveInfoBar(infobar_1); |
374 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 375 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
375 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 376 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
376 infobar_1->InfoBarClosed(); | 377 infobar_1->InfoBarClosed(); |
377 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 378 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
378 // Ensure the persisted permissions are ok. | 379 // Ensure the persisted permissions are ok. |
379 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 380 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
380 profile()->GetHostContentSettingsMap()->GetContentSetting( | 381 profile()->GetHostContentSettingsMap()->GetContentSetting( |
381 requesting_frame_0, | 382 requesting_frame_0, |
382 requesting_frame_0, | 383 requesting_frame_0, |
(...skipping 22 matching lines...) Expand all Loading... |
405 profile()->GetHostContentSettingsMap()->GetContentSetting( | 406 profile()->GetHostContentSettingsMap()->GetContentSetting( |
406 requesting_frame_1, | 407 requesting_frame_1, |
407 requesting_frame_0, | 408 requesting_frame_0, |
408 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 409 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
409 std::string())); | 410 std::string())); |
410 | 411 |
411 | 412 |
412 NavigateAndCommit(requesting_frame_0); | 413 NavigateAndCommit(requesting_frame_0); |
413 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 414 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
414 // Request permission for two frames. | 415 // Request permission for two frames. |
415 RequestGeolocationPermission( | 416 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
416 process_id(), render_id(), bridge_id(), requesting_frame_0); | 417 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
417 RequestGeolocationPermission( | |
418 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); | |
419 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 418 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
420 | 419 |
421 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> | 420 ConfirmInfoBarDelegate* infobar_0 = |
422 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 421 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
423 ASSERT_TRUE(infobar_0); | 422 ASSERT_TRUE(infobar_0); |
424 string16 text_0 = infobar_0->GetMessageText(); | 423 string16 text_0 = infobar_0->GetMessageText(); |
425 | 424 |
426 // Simulate the frame going away, ensure the infobar for this frame | 425 // Simulate the frame going away, ensure the infobar for this frame |
427 // is removed and the next pending infobar is created. | 426 // is removed and the next pending infobar is created. |
428 geolocation_permission_context_->CancelGeolocationPermissionRequest( | 427 CancelGeolocationPermissionRequest(RequestID(0), requesting_frame_0); |
429 process_id(), render_id(), bridge_id(), requesting_frame_0); | |
430 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 428 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
431 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 429 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
432 closed_delegate_tracker_.Clear(); | 430 closed_delegate_tracker_.Clear(); |
433 infobar_0->InfoBarClosed(); | 431 infobar_0->InfoBarClosed(); |
434 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 432 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
435 | 433 |
436 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()-> | 434 ConfirmInfoBarDelegate* infobar_1 = |
437 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 435 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
438 ASSERT_TRUE(infobar_1); | 436 ASSERT_TRUE(infobar_1); |
439 string16 text_1 = infobar_1->GetMessageText(); | 437 string16 text_1 = infobar_1->GetMessageText(); |
440 EXPECT_NE(text_0, text_1); | 438 EXPECT_NE(text_0, text_1); |
441 | 439 |
442 // Allow this frame. | 440 // Allow this frame. |
443 infobar_1->Accept(); | 441 infobar_1->Accept(); |
444 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); | 442 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); |
445 CheckPermissionMessageSent(bridge_id() + 1, true); | 443 CheckPermissionMessageSent(1, true); |
446 infobar_tab_helper()->RemoveInfoBar(infobar_1); | 444 infobar_tab_helper()->RemoveInfoBar(infobar_1); |
447 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 445 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
448 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 446 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
449 infobar_1->InfoBarClosed(); | 447 infobar_1->InfoBarClosed(); |
450 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 448 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
451 // Ensure the persisted permissions are ok. | 449 // Ensure the persisted permissions are ok. |
452 EXPECT_EQ(CONTENT_SETTING_ASK, | 450 EXPECT_EQ(CONTENT_SETTING_ASK, |
453 profile()->GetHostContentSettingsMap()->GetContentSetting( | 451 profile()->GetHostContentSettingsMap()->GetContentSetting( |
454 requesting_frame_0, | 452 requesting_frame_0, |
455 requesting_frame_0, | 453 requesting_frame_0, |
456 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 454 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
457 std::string())); | 455 std::string())); |
458 | 456 |
459 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 457 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
460 profile()->GetHostContentSettingsMap()->GetContentSetting( | 458 profile()->GetHostContentSettingsMap()->GetContentSetting( |
461 requesting_frame_1, | 459 requesting_frame_1, |
462 requesting_frame_0, | 460 requesting_frame_0, |
463 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 461 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
464 std::string())); | 462 std::string())); |
465 } | 463 } |
466 | 464 |
467 TEST_F(GeolocationPermissionContextTests, InvalidURL) { | 465 TEST_F(GeolocationPermissionContextTests, InvalidURL) { |
468 GURL invalid_embedder("about:blank"); | 466 GURL invalid_embedder("about:blank"); |
469 GURL requesting_frame; | 467 GURL requesting_frame; |
470 NavigateAndCommit(invalid_embedder); | 468 NavigateAndCommit(invalid_embedder); |
471 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 469 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
472 RequestGeolocationPermission( | 470 RequestGeolocationPermission(RequestID(0), requesting_frame); |
473 process_id(), render_id(), bridge_id(), requesting_frame); | |
474 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 471 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
475 CheckPermissionMessageSent(bridge_id(), false); | 472 CheckPermissionMessageSent(0, false); |
476 } | 473 } |
477 | 474 |
478 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { | 475 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { |
479 GURL url_a("http://www.example.com/geolocation"); | 476 GURL url_a("http://www.example.com/geolocation"); |
480 GURL url_b("http://www.example-2.com/geolocation"); | 477 GURL url_b("http://www.example-2.com/geolocation"); |
481 NavigateAndCommit(url_a); | 478 NavigateAndCommit(url_a); |
482 AddNewTab(url_b); | 479 AddNewTab(url_b); |
483 AddNewTab(url_a); | 480 AddNewTab(url_a); |
484 | 481 |
485 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 482 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
486 RequestGeolocationPermission( | 483 RequestGeolocationPermission(RequestID(0), url_a); |
487 process_id(), render_id(), bridge_id(), url_a); | |
488 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 484 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
489 | 485 |
490 RequestGeolocationPermission( | 486 RequestGeolocationPermission(RequestIDForTab(0, 0), url_b); |
491 process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_b); | |
492 EXPECT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); | 487 EXPECT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); |
493 | 488 |
494 RequestGeolocationPermission( | 489 RequestGeolocationPermission(RequestIDForTab(1, 0), url_a); |
495 process_id_for_tab(1), render_id_for_tab(1), bridge_id(), url_a); | |
496 ASSERT_EQ(1U, infobar_tab_helper_for_tab(1)->GetInfoBarCount()); | 490 ASSERT_EQ(1U, infobar_tab_helper_for_tab(1)->GetInfoBarCount()); |
497 | 491 |
498 ConfirmInfoBarDelegate* removed_infobar = infobar_tab_helper_for_tab(1)-> | 492 ConfirmInfoBarDelegate* removed_infobar = infobar_tab_helper_for_tab(1)-> |
499 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 493 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
500 | 494 |
501 // Accept the first tab. | 495 // Accept the first tab. |
502 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> | 496 ConfirmInfoBarDelegate* infobar_0 = |
503 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 497 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
504 ASSERT_TRUE(infobar_0); | 498 ASSERT_TRUE(infobar_0); |
505 infobar_0->Accept(); | 499 infobar_0->Accept(); |
506 CheckPermissionMessageSent(bridge_id(), true); | 500 CheckPermissionMessageSent(0, true); |
507 infobar_tab_helper()->RemoveInfoBar(infobar_0); | 501 infobar_tab_helper()->RemoveInfoBar(infobar_0); |
508 EXPECT_EQ(2U, closed_delegate_tracker_.size()); | 502 EXPECT_EQ(2U, closed_delegate_tracker_.size()); |
509 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 503 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
510 infobar_0->InfoBarClosed(); | 504 infobar_0->InfoBarClosed(); |
511 // Now the infobar for the tab with the same origin should have gone. | 505 // Now the infobar for the tab with the same origin should have gone. |
512 EXPECT_EQ(0U, infobar_tab_helper_for_tab(1)->GetInfoBarCount()); | 506 EXPECT_EQ(0U, infobar_tab_helper_for_tab(1)->GetInfoBarCount()); |
513 CheckPermissionMessageSentForTab(1, bridge_id(), true); | 507 CheckPermissionMessageSentForTab(1, 0, true); |
514 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); | 508 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); |
515 closed_delegate_tracker_.Clear(); | 509 closed_delegate_tracker_.Clear(); |
516 // Destroy the infobar that has just been removed. | 510 // Destroy the infobar that has just been removed. |
517 removed_infobar->InfoBarClosed(); | 511 removed_infobar->InfoBarClosed(); |
518 | 512 |
519 // But the other tab should still have the info bar... | 513 // But the other tab should still have the info bar... |
520 ASSERT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); | 514 ASSERT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); |
521 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper_for_tab(0)-> | 515 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper_for_tab(0)-> |
522 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 516 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
523 infobar_1->Cancel(); | 517 infobar_1->Cancel(); |
524 infobar_tab_helper_for_tab(0)->RemoveInfoBar(infobar_1); | 518 infobar_tab_helper_for_tab(0)->RemoveInfoBar(infobar_1); |
525 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 519 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
526 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 520 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
527 infobar_1->InfoBarClosed(); | 521 infobar_1->InfoBarClosed(); |
528 } | 522 } |
529 | 523 |
530 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { | 524 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { |
531 GURL url_a("http://www.example.com/geolocation"); | 525 GURL url_a("http://www.example.com/geolocation"); |
532 GURL url_b("http://www.example-2.com/geolocation"); | 526 GURL url_b("http://www.example-2.com/geolocation"); |
533 NavigateAndCommit(url_a); | 527 NavigateAndCommit(url_a); |
534 AddNewTab(url_a); | 528 AddNewTab(url_a); |
535 | 529 |
536 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 530 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
537 RequestGeolocationPermission( | 531 RequestGeolocationPermission(RequestID(0), url_a); |
538 process_id(), render_id(), bridge_id(), url_a); | |
539 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 532 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
540 | 533 |
541 RequestGeolocationPermission( | 534 RequestGeolocationPermission(RequestIDForTab(0, 0), url_a); |
542 process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_a); | |
543 EXPECT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); | 535 EXPECT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); |
544 | 536 |
545 RequestGeolocationPermission( | 537 RequestGeolocationPermission(RequestIDForTab(0, 1), url_b); |
546 process_id_for_tab(0), render_id_for_tab(0), bridge_id() + 1, url_b); | |
547 ASSERT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); | 538 ASSERT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); |
548 | 539 |
549 ConfirmInfoBarDelegate* removed_infobar = | 540 ConfirmInfoBarDelegate* removed_infobar = |
550 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 541 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
551 | 542 |
552 // Accept the second tab. | 543 // Accept the second tab. |
553 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper_for_tab(0)-> | 544 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper_for_tab(0)-> |
554 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 545 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
555 ASSERT_TRUE(infobar_0); | 546 ASSERT_TRUE(infobar_0); |
556 infobar_0->Accept(); | 547 infobar_0->Accept(); |
557 CheckPermissionMessageSentForTab(0, bridge_id(), true); | 548 CheckPermissionMessageSentForTab(0, 0, true); |
558 infobar_tab_helper_for_tab(0)->RemoveInfoBar(infobar_0); | 549 infobar_tab_helper_for_tab(0)->RemoveInfoBar(infobar_0); |
559 EXPECT_EQ(2U, closed_delegate_tracker_.size()); | 550 EXPECT_EQ(2U, closed_delegate_tracker_.size()); |
560 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 551 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
561 infobar_0->InfoBarClosed(); | 552 infobar_0->InfoBarClosed(); |
562 // Now the infobar for the tab with the same origin should have gone. | 553 // Now the infobar for the tab with the same origin should have gone. |
563 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 554 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
564 CheckPermissionMessageSent(bridge_id(), true); | 555 CheckPermissionMessageSent(0, true); |
565 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); | 556 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); |
566 closed_delegate_tracker_.Clear(); | 557 closed_delegate_tracker_.Clear(); |
567 // Destroy the infobar that has just been removed. | 558 // Destroy the infobar that has just been removed. |
568 removed_infobar->InfoBarClosed(); | 559 removed_infobar->InfoBarClosed(); |
569 | 560 |
570 // And we should have the queued infobar displayed now. | 561 // And we should have the queued infobar displayed now. |
571 ASSERT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); | 562 ASSERT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); |
572 | 563 |
573 // Accept the second infobar. | 564 // Accept the second infobar. |
574 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper_for_tab(0)-> | 565 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper_for_tab(0)-> |
575 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 566 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
576 ASSERT_TRUE(infobar_1); | 567 ASSERT_TRUE(infobar_1); |
577 infobar_1->Accept(); | 568 infobar_1->Accept(); |
578 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); | 569 CheckPermissionMessageSentForTab(0, 1, true); |
579 infobar_tab_helper_for_tab(0)->RemoveInfoBar(infobar_1); | 570 infobar_tab_helper_for_tab(0)->RemoveInfoBar(infobar_1); |
580 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 571 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
581 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 572 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
582 infobar_1->InfoBarClosed(); | 573 infobar_1->InfoBarClosed(); |
583 } | 574 } |
584 | 575 |
585 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { | 576 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { |
586 GURL requesting_frame_0("http://www.example.com/geolocation"); | 577 GURL requesting_frame_0("http://www.example.com/geolocation"); |
587 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 578 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
588 EXPECT_EQ( | 579 EXPECT_EQ( |
589 CONTENT_SETTING_ASK, | 580 CONTENT_SETTING_ASK, |
590 profile()->GetHostContentSettingsMap()->GetContentSetting( | 581 profile()->GetHostContentSettingsMap()->GetContentSetting( |
591 requesting_frame_0, | 582 requesting_frame_0, |
592 requesting_frame_0, | 583 requesting_frame_0, |
593 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 584 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
594 std::string())); | 585 std::string())); |
595 | 586 |
596 EXPECT_EQ( | 587 EXPECT_EQ( |
597 CONTENT_SETTING_ASK, | 588 CONTENT_SETTING_ASK, |
598 profile()->GetHostContentSettingsMap()->GetContentSetting( | 589 profile()->GetHostContentSettingsMap()->GetContentSetting( |
599 requesting_frame_1, | 590 requesting_frame_1, |
600 requesting_frame_0, | 591 requesting_frame_0, |
601 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 592 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
602 std::string())); | 593 std::string())); |
603 | 594 |
604 NavigateAndCommit(requesting_frame_0); | 595 NavigateAndCommit(requesting_frame_0); |
605 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 596 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
606 // Request permission for two frames. | 597 // Request permission for two frames. |
607 RequestGeolocationPermission( | 598 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
608 process_id(), render_id(), bridge_id(), requesting_frame_0); | 599 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
609 RequestGeolocationPermission( | |
610 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); | |
611 // Ensure only one infobar is created. | 600 // Ensure only one infobar is created. |
612 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 601 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
613 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> | 602 ConfirmInfoBarDelegate* infobar_0 = |
614 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 603 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
615 ASSERT_TRUE(infobar_0); | 604 ASSERT_TRUE(infobar_0); |
616 | 605 |
617 // Delete the tab contents. | 606 // Delete the tab contents. |
618 DeleteContents(); | 607 DeleteContents(); |
619 infobar_0->InfoBarClosed(); | 608 infobar_0->InfoBarClosed(); |
620 | 609 |
621 // During contents destruction, the infobar will have been closed, and a | 610 // During contents destruction, the infobar will have been closed, and the |
622 // second (with it's own new delegate) will have been created. In Chromium, | 611 // pending request should have been cleared without an infobar being created. |
623 // this would be properly deleted by the InfoBarContainer, but in this unit | 612 ASSERT_EQ(1U, closed_delegate_tracker_.size()); |
624 // test, the closest thing we have to that is the ClosedDelegateTracker. | |
625 ASSERT_EQ(2U, closed_delegate_tracker_.size()); | |
626 ASSERT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 613 ASSERT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
627 closed_delegate_tracker_.removed_infobar_delegates_.erase(infobar_0); | |
628 (*closed_delegate_tracker_.removed_infobar_delegates_.begin())-> | |
629 InfoBarClosed(); | |
630 } | 614 } |
631 | 615 |
632 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { | 616 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { |
633 GURL requesting_frame_0("http://www.example.com/geolocation"); | 617 GURL requesting_frame_0("http://www.example.com/geolocation"); |
634 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 618 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
635 NavigateAndCommit(requesting_frame_0); | 619 NavigateAndCommit(requesting_frame_0); |
636 NavigateAndCommit(requesting_frame_1); | 620 NavigateAndCommit(requesting_frame_1); |
637 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 621 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
638 // Go back: navigate to a pending entry before requesting geolocation | 622 // Go back: navigate to a pending entry before requesting geolocation |
639 // permission. | 623 // permission. |
640 web_contents()->GetController().GoBack(); | 624 web_contents()->GetController().GoBack(); |
641 // Request permission for the committed frame (not the pending one). | 625 // Request permission for the committed frame (not the pending one). |
642 RequestGeolocationPermission( | 626 RequestGeolocationPermission(RequestID(0), requesting_frame_1); |
643 process_id(), render_id(), bridge_id(), requesting_frame_1); | |
644 // Ensure the infobar is created. | 627 // Ensure the infobar is created. |
645 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 628 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
646 InfoBarDelegate* infobar_0 = infobar_tab_helper()->GetInfoBarDelegateAt(0); | 629 InfoBarDelegate* infobar_0 = infobar_tab_helper()->GetInfoBarDelegateAt(0); |
647 ASSERT_TRUE(infobar_0); | 630 ASSERT_TRUE(infobar_0); |
648 // Ensure the infobar is not yet expired. | 631 // Ensure the infobar is not yet expired. |
649 content::LoadCommittedDetails details; | 632 content::LoadCommittedDetails details; |
650 details.entry = web_contents()->GetController().GetLastCommittedEntry(); | 633 details.entry = web_contents()->GetController().GetLastCommittedEntry(); |
651 ASSERT_FALSE(infobar_0->ShouldExpire(details)); | 634 ASSERT_FALSE(infobar_0->ShouldExpire(details)); |
652 // Commit the "GoBack()" above, and ensure the infobar is now expired. | 635 // Commit the "GoBack()" above, and ensure the infobar is now expired. |
653 WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 636 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
654 details.entry = web_contents()->GetController().GetLastCommittedEntry(); | 637 details.entry = web_contents()->GetController().GetLastCommittedEntry(); |
655 ASSERT_TRUE(infobar_0->ShouldExpire(details)); | 638 ASSERT_TRUE(infobar_0->ShouldExpire(details)); |
656 | 639 |
657 // Delete the tab contents. | 640 // Delete the tab contents. |
658 DeleteContents(); | 641 DeleteContents(); |
659 infobar_0->InfoBarClosed(); | 642 infobar_0->InfoBarClosed(); |
660 } | 643 } |
OLD | NEW |