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 "chrome/browser/geolocation/geolocation_permission_context.h" | 5 #include "chrome/browser/geolocation/geolocation_permission_context.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
16 #include "base/test/simple_test_clock.h" | 16 #include "base/test/simple_test_clock.h" |
17 #include "base/time/clock.h" | 17 #include "base/time/clock.h" |
18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
19 #include "chrome/browser/content_settings/host_content_settings_map.h" | 19 #include "chrome/browser/content_settings/host_content_settings_map.h" |
20 #include "chrome/browser/content_settings/permission_request_id.h" | 20 #include "chrome/browser/content_settings/permission_request_id.h" |
21 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 21 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
22 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" | 22 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" |
23 #include "chrome/browser/infobars/infobar_service.h" | 23 #include "chrome/browser/infobars/infobar_service.h" |
| 24 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 25 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
| 26 #include "chrome/browser/ui/website_settings/permission_bubble_view.h" |
24 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 27 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
25 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" |
26 #include "components/infobars/core/confirm_infobar_delegate.h" | 29 #include "components/infobars/core/confirm_infobar_delegate.h" |
27 #include "components/infobars/core/infobar.h" | 30 #include "components/infobars/core/infobar.h" |
28 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
29 #include "content/public/browser/navigation_details.h" | 32 #include "content/public/browser/navigation_details.h" |
30 #include "content/public/browser/notification_registrar.h" | 33 #include "content/public/browser/notification_registrar.h" |
31 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
32 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
33 #include "content/public/test/mock_render_process_host.h" | 36 #include "content/public/test/mock_render_process_host.h" |
34 #include "content/public/test/test_renderer_host.h" | 37 #include "content/public/test/test_renderer_host.h" |
| 38 #include "content/public/test/test_utils.h" |
35 #include "content/public/test/web_contents_tester.h" | 39 #include "content/public/test/web_contents_tester.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
37 | 41 |
38 #if defined(OS_ANDROID) | 42 #if defined(OS_ANDROID) |
39 #include "base/prefs/pref_service.h" | 43 #include "base/prefs/pref_service.h" |
40 #include "chrome/browser/android/mock_google_location_settings_helper.h" | 44 #include "chrome/browser/android/mock_google_location_settings_helper.h" |
41 #include "chrome/common/pref_names.h" | 45 #include "chrome/common/pref_names.h" |
42 #endif | 46 #endif |
43 | 47 |
44 #if defined(ENABLE_EXTENSIONS) | 48 #if defined(ENABLE_EXTENSIONS) |
45 #include "extensions/browser/view_type_utils.h" | 49 #include "extensions/browser/view_type_utils.h" |
46 #endif | 50 #endif |
47 | 51 |
48 using content::MockRenderProcessHost; | 52 using content::MockRenderProcessHost; |
49 | 53 |
| 54 class MockPermissionBubbleView : public PermissionBubbleView { |
| 55 public: |
| 56 MockPermissionBubbleView() : shown_(false) {} |
| 57 virtual ~MockPermissionBubbleView() {} |
| 58 |
| 59 virtual void SetDelegate(Delegate* delegate) OVERRIDE { |
| 60 } |
| 61 |
| 62 virtual void Show( |
| 63 const std::vector<PermissionBubbleRequest*>& requests, |
| 64 const std::vector<bool>& accept_state, |
| 65 bool customization_mode) OVERRIDE { |
| 66 LOG(INFO) << "Showing view... " << requests[0]->GetMessageText(); |
| 67 shown_ = true; |
| 68 } |
| 69 |
| 70 virtual bool CanAcceptRequestUpdate() OVERRIDE { |
| 71 return true; |
| 72 } |
| 73 |
| 74 virtual void Hide() OVERRIDE { |
| 75 shown_ = false; |
| 76 } |
| 77 |
| 78 virtual bool IsVisible() OVERRIDE { |
| 79 return shown_; |
| 80 } |
| 81 |
| 82 private: |
| 83 bool shown_; |
| 84 }; |
50 | 85 |
51 // ClosedInfoBarTracker ------------------------------------------------------- | 86 // ClosedInfoBarTracker ------------------------------------------------------- |
52 | 87 |
53 // We need to track which infobars were closed. | 88 // We need to track which infobars were closed. |
54 class ClosedInfoBarTracker : public content::NotificationObserver { | 89 class ClosedInfoBarTracker : public content::NotificationObserver { |
55 public: | 90 public: |
56 ClosedInfoBarTracker(); | 91 ClosedInfoBarTracker(); |
57 virtual ~ClosedInfoBarTracker(); | 92 virtual ~ClosedInfoBarTracker(); |
58 | 93 |
59 // content::NotificationObserver: | 94 // content::NotificationObserver: |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 PermissionRequestID RequestIDForTab(int tab, int bridge_id); | 146 PermissionRequestID RequestIDForTab(int tab, int bridge_id); |
112 InfoBarService* infobar_service() { | 147 InfoBarService* infobar_service() { |
113 return InfoBarService::FromWebContents(web_contents()); | 148 return InfoBarService::FromWebContents(web_contents()); |
114 } | 149 } |
115 InfoBarService* infobar_service_for_tab(int tab) { | 150 InfoBarService* infobar_service_for_tab(int tab) { |
116 return InfoBarService::FromWebContents(extra_tabs_[tab]); | 151 return InfoBarService::FromWebContents(extra_tabs_[tab]); |
117 } | 152 } |
118 | 153 |
119 void RequestGeolocationPermission(content::WebContents* web_contents, | 154 void RequestGeolocationPermission(content::WebContents* web_contents, |
120 const PermissionRequestID& id, | 155 const PermissionRequestID& id, |
121 const GURL& requesting_frame); | 156 const GURL& requesting_frame, |
| 157 bool user_gesture); |
122 void RequestGeolocationPermission(content::WebContents* web_contents, | 158 void RequestGeolocationPermission(content::WebContents* web_contents, |
123 const PermissionRequestID& id, | 159 const PermissionRequestID& id, |
124 const GURL& requesting_frame, | 160 const GURL& requesting_frame, |
| 161 bool user_gesture, |
125 base::Closure* cancel_callback); | 162 base::Closure* cancel_callback); |
126 void PermissionResponse(const PermissionRequestID& id, | 163 void PermissionResponse(const PermissionRequestID& id, |
127 bool allowed); | 164 bool allowed); |
128 void CheckPermissionMessageSent(int bridge_id, bool allowed); | 165 void CheckPermissionMessageSent(int bridge_id, bool allowed); |
129 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); | 166 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); |
130 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, | 167 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, |
131 int bridge_id, | 168 int bridge_id, |
132 bool allowed); | 169 bool allowed); |
133 void AddNewTab(const GURL& url); | 170 void AddNewTab(const GURL& url); |
134 void CheckTabContentsState(const GURL& requesting_frame, | 171 void CheckTabContentsState(const GURL& requesting_frame, |
135 ContentSetting expected_content_setting); | 172 ContentSetting expected_content_setting); |
| 173 base::string16 GetFirstRequestText(PermissionBubbleManager* mgr); |
| 174 int GetBubblesQueueSize(PermissionBubbleManager* mgr); |
| 175 void AcceptBubble(PermissionBubbleManager* mgr); |
| 176 void DenyBubble(PermissionBubbleManager* mgr); |
| 177 void BubbleManagerDocumentLoadCompleted(); |
136 | 178 |
137 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; | 179 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; |
138 ClosedInfoBarTracker closed_infobar_tracker_; | 180 ClosedInfoBarTracker closed_infobar_tracker_; |
| 181 MockPermissionBubbleView bubble_view_; |
139 ScopedVector<content::WebContents> extra_tabs_; | 182 ScopedVector<content::WebContents> extra_tabs_; |
140 | 183 |
141 // A map between renderer child id and a pair represending the bridge id and | 184 // A map between renderer child id and a pair represending the bridge id and |
142 // whether the requested permission was allowed. | 185 // whether the requested permission was allowed. |
143 base::hash_map<int, std::pair<int, bool> > responses_; | 186 base::hash_map<int, std::pair<int, bool> > responses_; |
144 }; | 187 }; |
145 | 188 |
146 PermissionRequestID GeolocationPermissionContextTests::RequestID( | 189 PermissionRequestID GeolocationPermissionContextTests::RequestID( |
147 int bridge_id) { | 190 int bridge_id) { |
148 return PermissionRequestID( | 191 return PermissionRequestID( |
149 web_contents()->GetRenderProcessHost()->GetID(), | 192 web_contents()->GetRenderProcessHost()->GetID(), |
150 web_contents()->GetRenderViewHost()->GetRoutingID(), | 193 web_contents()->GetRenderViewHost()->GetRoutingID(), |
151 bridge_id, | 194 bridge_id, |
152 GURL()); | 195 GURL()); |
153 } | 196 } |
154 | 197 |
155 PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab( | 198 PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab( |
156 int tab, | 199 int tab, |
157 int bridge_id) { | 200 int bridge_id) { |
158 return PermissionRequestID( | 201 return PermissionRequestID( |
159 extra_tabs_[tab]->GetRenderProcessHost()->GetID(), | 202 extra_tabs_[tab]->GetRenderProcessHost()->GetID(), |
160 extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(), | 203 extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(), |
161 bridge_id, | 204 bridge_id, |
162 GURL()); | 205 GURL()); |
163 } | 206 } |
164 | 207 |
165 void GeolocationPermissionContextTests::RequestGeolocationPermission( | 208 void GeolocationPermissionContextTests::RequestGeolocationPermission( |
166 content::WebContents* web_contents, | 209 content::WebContents* web_contents, |
167 const PermissionRequestID& id, | 210 const PermissionRequestID& id, |
168 const GURL& requesting_frame) { | 211 const GURL& requesting_frame, |
169 RequestGeolocationPermission(web_contents, id, requesting_frame, NULL); | 212 bool user_gesture) { |
| 213 RequestGeolocationPermission(web_contents, id, requesting_frame, |
| 214 user_gesture, NULL); |
170 } | 215 } |
171 | 216 |
172 void GeolocationPermissionContextTests::RequestGeolocationPermission( | 217 void GeolocationPermissionContextTests::RequestGeolocationPermission( |
173 content::WebContents* web_contents, | 218 content::WebContents* web_contents, |
174 const PermissionRequestID& id, | 219 const PermissionRequestID& id, |
175 const GURL& requesting_frame, | 220 const GURL& requesting_frame, |
| 221 bool user_gesture, |
176 base::Closure* cancel_callback) { | 222 base::Closure* cancel_callback) { |
177 geolocation_permission_context_->RequestGeolocationPermission( | 223 geolocation_permission_context_->RequestGeolocationPermission( |
178 web_contents, id.bridge_id(), requesting_frame, false, | 224 web_contents, id.bridge_id(), requesting_frame, user_gesture, |
179 base::Bind(&GeolocationPermissionContextTests::PermissionResponse, | 225 base::Bind(&GeolocationPermissionContextTests::PermissionResponse, |
180 base::Unretained(this), id), | 226 base::Unretained(this), id), |
181 cancel_callback); | 227 cancel_callback); |
182 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 228 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
183 base::RunLoop().RunUntilIdle(); | 229 base::RunLoop().RunUntilIdle(); |
184 } | 230 } |
185 | 231 |
186 void GeolocationPermissionContextTests::PermissionResponse( | 232 void GeolocationPermissionContextTests::PermissionResponse( |
187 const PermissionRequestID& id, | 233 const PermissionRequestID& id, |
188 bool allowed) { | 234 bool allowed) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 extra_tabs_.push_back(new_tab); | 277 extra_tabs_.push_back(new_tab); |
232 } | 278 } |
233 | 279 |
234 void GeolocationPermissionContextTests::CheckTabContentsState( | 280 void GeolocationPermissionContextTests::CheckTabContentsState( |
235 const GURL& requesting_frame, | 281 const GURL& requesting_frame, |
236 ContentSetting expected_content_setting) { | 282 ContentSetting expected_content_setting) { |
237 TabSpecificContentSettings* content_settings = | 283 TabSpecificContentSettings* content_settings = |
238 TabSpecificContentSettings::FromWebContents(web_contents()); | 284 TabSpecificContentSettings::FromWebContents(web_contents()); |
239 const ContentSettingsUsagesState::StateMap& state_map = | 285 const ContentSettingsUsagesState::StateMap& state_map = |
240 content_settings->geolocation_usages_state().state_map(); | 286 content_settings->geolocation_usages_state().state_map(); |
241 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin())); | 287 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin())) |
242 EXPECT_EQ(0U, state_map.count(requesting_frame)); | 288 << " for " << requesting_frame.spec(); |
| 289 EXPECT_EQ(0U, state_map.count(requesting_frame)) |
| 290 << " for " << requesting_frame.spec(); |
243 ContentSettingsUsagesState::StateMap::const_iterator settings = | 291 ContentSettingsUsagesState::StateMap::const_iterator settings = |
244 state_map.find(requesting_frame.GetOrigin()); | 292 state_map.find(requesting_frame.GetOrigin()); |
245 ASSERT_FALSE(settings == state_map.end()) | 293 ASSERT_FALSE(settings == state_map.end()) |
246 << "geolocation state not found " << requesting_frame; | 294 << "geolocation state not found " << requesting_frame; |
247 EXPECT_EQ(expected_content_setting, settings->second); | 295 EXPECT_EQ(expected_content_setting, settings->second) |
| 296 << " for " << requesting_frame.spec(); |
248 } | 297 } |
249 | 298 |
250 void GeolocationPermissionContextTests::SetUp() { | 299 void GeolocationPermissionContextTests::SetUp() { |
251 ChromeRenderViewHostTestHarness::SetUp(); | 300 ChromeRenderViewHostTestHarness::SetUp(); |
252 | 301 |
253 // Set up required helpers, and make this be as "tabby" as the code requires. | 302 // Set up required helpers, and make this be as "tabby" as the code requires. |
254 #if defined(ENABLE_EXTENSIONS) | 303 #if defined(ENABLE_EXTENSIONS) |
255 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); | 304 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); |
256 #endif | 305 #endif |
257 InfoBarService::CreateForWebContents(web_contents()); | 306 InfoBarService::CreateForWebContents(web_contents()); |
258 TabSpecificContentSettings::CreateForWebContents(web_contents()); | 307 TabSpecificContentSettings::CreateForWebContents(web_contents()); |
259 #if defined(OS_ANDROID) | 308 #if defined(OS_ANDROID) |
260 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | 309 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); |
261 #endif | 310 #endif |
262 geolocation_permission_context_ = | 311 geolocation_permission_context_ = |
263 GeolocationPermissionContextFactory::GetForProfile(profile()); | 312 GeolocationPermissionContextFactory::GetForProfile(profile()); |
| 313 |
| 314 PermissionBubbleManager::CreateForWebContents(web_contents()); |
| 315 PermissionBubbleManager::FromWebContents(web_contents())->SetView( |
| 316 &bubble_view_); |
264 } | 317 } |
265 | 318 |
266 void GeolocationPermissionContextTests::TearDown() { | 319 void GeolocationPermissionContextTests::TearDown() { |
267 extra_tabs_.clear(); | 320 extra_tabs_.clear(); |
268 ChromeRenderViewHostTestHarness::TearDown(); | 321 ChromeRenderViewHostTestHarness::TearDown(); |
269 } | 322 } |
270 | 323 |
| 324 base::string16 GeolocationPermissionContextTests::GetFirstRequestText( |
| 325 PermissionBubbleManager* mgr) { |
| 326 return mgr->requests_.front()->GetMessageText(); |
| 327 } |
| 328 |
| 329 int GeolocationPermissionContextTests::GetBubblesQueueSize( |
| 330 PermissionBubbleManager* mgr) { |
| 331 return static_cast<int>(mgr->requests_.size()); |
| 332 } |
| 333 |
| 334 void GeolocationPermissionContextTests::AcceptBubble( |
| 335 PermissionBubbleManager* mgr) { |
| 336 mgr->Accept(); |
| 337 } |
| 338 |
| 339 void GeolocationPermissionContextTests::DenyBubble( |
| 340 PermissionBubbleManager* mgr) { |
| 341 mgr->Deny(); |
| 342 } |
| 343 |
| 344 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted() { |
| 345 PermissionBubbleManager::FromWebContents(web_contents())-> |
| 346 DocumentOnLoadCompletedInMainFrame(); |
| 347 } |
| 348 |
271 // Tests ---------------------------------------------------------------------- | 349 // Tests ---------------------------------------------------------------------- |
272 | 350 |
273 TEST_F(GeolocationPermissionContextTests, SinglePermission) { | 351 TEST_F(GeolocationPermissionContextTests, SinglePermissionInfobar) { |
| 352 if (PermissionBubbleManager::Enabled()) |
| 353 return; |
| 354 |
274 GURL requesting_frame("http://www.example.com/geolocation"); | 355 GURL requesting_frame("http://www.example.com/geolocation"); |
275 NavigateAndCommit(requesting_frame); | 356 NavigateAndCommit(requesting_frame); |
276 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 357 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
277 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 358 RequestGeolocationPermission( |
| 359 web_contents(), RequestID(0), requesting_frame, true); |
278 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 360 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
279 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 361 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
280 ConfirmInfoBarDelegate* infobar_delegate = | 362 ConfirmInfoBarDelegate* infobar_delegate = |
281 infobar->delegate()->AsConfirmInfoBarDelegate(); | 363 infobar->delegate()->AsConfirmInfoBarDelegate(); |
282 ASSERT_TRUE(infobar_delegate); | 364 ASSERT_TRUE(infobar_delegate); |
283 infobar_delegate->Cancel(); | 365 infobar_delegate->Cancel(); |
284 infobar_service()->RemoveInfoBar(infobar); | 366 infobar_service()->RemoveInfoBar(infobar); |
285 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 367 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
286 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 368 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
287 } | 369 } |
288 | 370 |
| 371 TEST_F(GeolocationPermissionContextTests, SinglePermissionBubble) { |
| 372 if (!PermissionBubbleManager::Enabled()) |
| 373 return; |
| 374 |
| 375 GURL requesting_frame("http://www.example.com/geolocation"); |
| 376 NavigateAndCommit(requesting_frame); |
| 377 BubbleManagerDocumentLoadCompleted(); |
| 378 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 379 RequestGeolocationPermission( |
| 380 web_contents(), RequestID(0), requesting_frame, true); |
| 381 PermissionBubbleManager* mgr = |
| 382 PermissionBubbleManager::FromWebContents(web_contents()); |
| 383 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
| 384 } |
| 385 |
289 #if defined(OS_ANDROID) | 386 #if defined(OS_ANDROID) |
290 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { | 387 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { |
291 GURL requesting_frame("http://www.example.com/geolocation"); | 388 GURL requesting_frame("http://www.example.com/geolocation"); |
292 NavigateAndCommit(requesting_frame); | 389 NavigateAndCommit(requesting_frame); |
293 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | 390 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); |
294 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 391 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
295 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 392 RequestGeolocationPermission( |
| 393 web_contents(), RequestID(0), requesting_frame, true); |
296 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 394 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
297 ConfirmInfoBarDelegate* infobar_delegate_0 = | 395 ConfirmInfoBarDelegate* infobar_delegate_0 = |
298 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 396 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
299 ASSERT_TRUE(infobar_delegate_0); | 397 ASSERT_TRUE(infobar_delegate_0); |
300 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( | 398 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( |
301 ConfirmInfoBarDelegate::BUTTON_OK); | 399 ConfirmInfoBarDelegate::BUTTON_OK); |
302 | 400 |
303 Reload(); | 401 Reload(); |
304 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); | 402 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); |
305 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 403 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
306 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 404 RequestGeolocationPermission( |
| 405 web_contents(), RequestID(0), requesting_frame, true); |
307 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 406 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
308 } | 407 } |
309 | 408 |
310 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { | 409 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { |
311 GURL requesting_frame("http://www.example.com/geolocation"); | 410 GURL requesting_frame("http://www.example.com/geolocation"); |
312 NavigateAndCommit(requesting_frame); | 411 NavigateAndCommit(requesting_frame); |
313 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | 412 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); |
314 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 413 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
315 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 414 RequestGeolocationPermission( |
| 415 web_contents(), RequestID(0), requesting_frame, true); |
316 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 416 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
317 ConfirmInfoBarDelegate* infobar_delegate = | 417 ConfirmInfoBarDelegate* infobar_delegate = |
318 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 418 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
319 ASSERT_TRUE(infobar_delegate); | 419 ASSERT_TRUE(infobar_delegate); |
320 infobar_delegate->Accept(); | 420 infobar_delegate->Accept(); |
321 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 421 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
322 CheckPermissionMessageSent(0, true); | 422 CheckPermissionMessageSent(0, true); |
323 } | 423 } |
324 | 424 |
325 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { | 425 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { |
326 GURL requesting_frame("http://www.example.com/geolocation"); | 426 GURL requesting_frame("http://www.example.com/geolocation"); |
327 NavigateAndCommit(requesting_frame); | 427 NavigateAndCommit(requesting_frame); |
328 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); | 428 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); |
329 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 429 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
330 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 430 RequestGeolocationPermission( |
| 431 web_contents(), RequestID(0), requesting_frame, true); |
331 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 432 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
332 } | 433 } |
333 #endif | 434 #endif |
334 | 435 |
335 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { | 436 TEST_F(GeolocationPermissionContextTests, QueuedPermissionInfobar) { |
| 437 if (PermissionBubbleManager::Enabled()) |
| 438 return; |
| 439 |
336 GURL requesting_frame_0("http://www.example.com/geolocation"); | 440 GURL requesting_frame_0("http://www.example.com/geolocation"); |
337 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 441 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
338 EXPECT_EQ(CONTENT_SETTING_ASK, | 442 EXPECT_EQ(CONTENT_SETTING_ASK, |
339 profile()->GetHostContentSettingsMap()->GetContentSetting( | 443 profile()->GetHostContentSettingsMap()->GetContentSetting( |
340 requesting_frame_0, requesting_frame_0, | 444 requesting_frame_0, requesting_frame_0, |
341 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 445 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
342 EXPECT_EQ(CONTENT_SETTING_ASK, | 446 EXPECT_EQ(CONTENT_SETTING_ASK, |
343 profile()->GetHostContentSettingsMap()->GetContentSetting( | 447 profile()->GetHostContentSettingsMap()->GetContentSetting( |
344 requesting_frame_1, requesting_frame_0, | 448 requesting_frame_1, requesting_frame_0, |
345 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 449 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
346 | 450 |
347 NavigateAndCommit(requesting_frame_0); | 451 NavigateAndCommit(requesting_frame_0); |
348 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 452 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
349 // Request permission for two frames. | 453 // Request permission for two frames. |
350 RequestGeolocationPermission( | 454 RequestGeolocationPermission( |
351 web_contents(), RequestID(0), requesting_frame_0); | 455 web_contents(), RequestID(0), requesting_frame_0, true); |
352 RequestGeolocationPermission( | 456 RequestGeolocationPermission( |
353 web_contents(), RequestID(1), requesting_frame_1); | 457 web_contents(), RequestID(1), requesting_frame_1, true); |
354 // Ensure only one infobar is created. | 458 // Ensure only one infobar is created. |
355 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 459 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
356 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 460 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); |
357 ConfirmInfoBarDelegate* infobar_delegate_0 = | 461 ConfirmInfoBarDelegate* infobar_delegate_0 = |
358 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 462 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
359 ASSERT_TRUE(infobar_delegate_0); | 463 ASSERT_TRUE(infobar_delegate_0); |
360 base::string16 text_0 = infobar_delegate_0->GetMessageText(); | 464 base::string16 text_0 = infobar_delegate_0->GetMessageText(); |
361 | 465 |
362 // Accept the first frame. | 466 // Accept the first frame. |
363 infobar_delegate_0->Accept(); | 467 infobar_delegate_0->Accept(); |
(...skipping 27 matching lines...) Expand all Loading... |
391 profile()->GetHostContentSettingsMap()->GetContentSetting( | 495 profile()->GetHostContentSettingsMap()->GetContentSetting( |
392 requesting_frame_0, requesting_frame_0, | 496 requesting_frame_0, requesting_frame_0, |
393 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 497 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
394 | 498 |
395 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 499 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
396 profile()->GetHostContentSettingsMap()->GetContentSetting( | 500 profile()->GetHostContentSettingsMap()->GetContentSetting( |
397 requesting_frame_1, requesting_frame_0, | 501 requesting_frame_1, requesting_frame_0, |
398 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 502 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
399 } | 503 } |
400 | 504 |
401 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { | 505 TEST_F(GeolocationPermissionContextTests, QueuedPermissionBubble) { |
| 506 if (!PermissionBubbleManager::Enabled()) |
| 507 return; |
| 508 |
| 509 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 510 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 511 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 512 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 513 requesting_frame_0, requesting_frame_0, |
| 514 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 515 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 516 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 517 requesting_frame_1, requesting_frame_0, |
| 518 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 519 |
| 520 NavigateAndCommit(requesting_frame_0); |
| 521 BubbleManagerDocumentLoadCompleted(); |
| 522 |
| 523 PermissionBubbleManager* mgr = |
| 524 PermissionBubbleManager::FromWebContents(web_contents()); |
| 525 ASSERT_EQ(0, GetBubblesQueueSize(mgr)); |
| 526 |
| 527 // Request permission for two frames. |
| 528 RequestGeolocationPermission( |
| 529 web_contents(), RequestID(0), requesting_frame_0, true); |
| 530 RequestGeolocationPermission( |
| 531 web_contents(), RequestID(1), requesting_frame_1, true); |
| 532 // Only main frame permission shown. |
| 533 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
| 534 base::string16 text_0 = GetFirstRequestText(mgr); |
| 535 |
| 536 // Accept the first frame. |
| 537 AcceptBubble(mgr); |
| 538 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
| 539 CheckPermissionMessageSent(0, true); |
| 540 |
| 541 // Now we should have a new bubble for the second frame. |
| 542 EXPECT_EQ(1, GetBubblesQueueSize(mgr)); |
| 543 |
| 544 base::string16 text_1 = GetFirstRequestText(mgr); |
| 545 EXPECT_NE(text_0, text_1); |
| 546 |
| 547 // Cancel (block) this frame. |
| 548 DenyBubble(mgr); |
| 549 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
| 550 CheckPermissionMessageSent(1, false); |
| 551 |
| 552 // Ensure the persisted permissions are ok. |
| 553 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 554 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 555 requesting_frame_0, requesting_frame_0, |
| 556 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 557 |
| 558 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 559 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 560 requesting_frame_1, requesting_frame_0, |
| 561 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 562 } |
| 563 |
| 564 TEST_F(GeolocationPermissionContextTests, UrlFragmentIsIgnoredInfobar) { |
| 565 if (PermissionBubbleManager::Enabled()) |
| 566 return; |
| 567 |
402 GURL url_a("http://www.example.com/geolocation#a"); | 568 GURL url_a("http://www.example.com/geolocation#a"); |
403 GURL url_b("http://www.example.com/geolocation#b"); | 569 GURL url_b("http://www.example.com/geolocation#b"); |
404 | 570 |
405 // Navigate to the first url and check permission is requested. | 571 // Navigate to the first url and check permission is requested. |
406 NavigateAndCommit(url_a); | 572 NavigateAndCommit(url_a); |
407 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 573 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
408 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); | 574 RequestGeolocationPermission(web_contents(), RequestID(0), url_a, true); |
409 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 575 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
410 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 576 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
411 ConfirmInfoBarDelegate* infobar_delegate = | 577 ConfirmInfoBarDelegate* infobar_delegate = |
412 infobar->delegate()->AsConfirmInfoBarDelegate(); | 578 infobar->delegate()->AsConfirmInfoBarDelegate(); |
413 ASSERT_TRUE(infobar_delegate); | 579 ASSERT_TRUE(infobar_delegate); |
414 | 580 |
415 // Change the hash, we'll still be on the same page. | 581 // Change the hash, we'll still be on the same page. |
416 NavigateAndCommit(url_b); | 582 NavigateAndCommit(url_b); |
417 | 583 |
418 // Accept. | 584 // Accept. |
419 infobar_delegate->Accept(); | 585 infobar_delegate->Accept(); |
420 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); | 586 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); |
421 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); | 587 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); |
422 CheckPermissionMessageSent(0, true); | 588 CheckPermissionMessageSent(0, true); |
423 | 589 |
424 // Cleanup. | 590 // Cleanup. |
425 infobar_service()->RemoveInfoBar(infobar); | 591 infobar_service()->RemoveInfoBar(infobar); |
426 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 592 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
427 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 593 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
428 } | 594 } |
429 | 595 |
430 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { | 596 TEST_F(GeolocationPermissionContextTests, UrlFragmentIsIgnoredBubble) { |
| 597 if (!PermissionBubbleManager::Enabled()) |
| 598 return; |
| 599 |
| 600 GURL url_a("http://www.example.com/geolocation#a"); |
| 601 GURL url_b("http://www.example.com/geolocation#b"); |
| 602 |
| 603 // Navigate to the first url and check permission is requested. |
| 604 NavigateAndCommit(url_a); |
| 605 BubbleManagerDocumentLoadCompleted(); |
| 606 |
| 607 PermissionBubbleManager* mgr = |
| 608 PermissionBubbleManager::FromWebContents(web_contents()); |
| 609 ASSERT_EQ(0, GetBubblesQueueSize(mgr)); |
| 610 |
| 611 RequestGeolocationPermission(web_contents(), RequestID(0), url_a, true); |
| 612 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
| 613 |
| 614 // Change the hash, we'll still be on the same page. |
| 615 NavigateAndCommit(url_b); |
| 616 BubbleManagerDocumentLoadCompleted(); |
| 617 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
| 618 |
| 619 // Accept. |
| 620 AcceptBubble(mgr); |
| 621 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); |
| 622 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); |
| 623 CheckPermissionMessageSent(0, true); |
| 624 } |
| 625 |
| 626 TEST_F(GeolocationPermissionContextTests, PermissionForFileSchemeInfobars) { |
| 627 if (PermissionBubbleManager::Enabled()) |
| 628 return; |
| 629 |
431 GURL requesting_frame("file://example/geolocation.html"); | 630 GURL requesting_frame("file://example/geolocation.html"); |
432 NavigateAndCommit(requesting_frame); | 631 NavigateAndCommit(requesting_frame); |
433 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 632 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
434 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 633 RequestGeolocationPermission( |
| 634 web_contents(), RequestID(0), requesting_frame, true); |
435 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 635 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
436 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 636 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
437 ConfirmInfoBarDelegate* infobar_delegate = | 637 ConfirmInfoBarDelegate* infobar_delegate = |
438 infobar->delegate()->AsConfirmInfoBarDelegate(); | 638 infobar->delegate()->AsConfirmInfoBarDelegate(); |
439 ASSERT_TRUE(infobar_delegate); | 639 ASSERT_TRUE(infobar_delegate); |
440 // Accept the frame. | 640 // Accept the frame. |
441 infobar_delegate->Accept(); | 641 infobar_delegate->Accept(); |
442 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 642 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
443 CheckPermissionMessageSent(0, true); | 643 CheckPermissionMessageSent(0, true); |
444 infobar_service()->RemoveInfoBar(infobar); | 644 infobar_service()->RemoveInfoBar(infobar); |
445 | 645 |
446 // Make sure the setting is not stored. | 646 // Make sure the setting is not stored. |
447 EXPECT_EQ(CONTENT_SETTING_ASK, | 647 EXPECT_EQ(CONTENT_SETTING_ASK, |
448 profile()->GetHostContentSettingsMap()->GetContentSetting( | 648 profile()->GetHostContentSettingsMap()->GetContentSetting( |
449 requesting_frame, | 649 requesting_frame, |
450 requesting_frame, | 650 requesting_frame, |
451 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 651 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
452 std::string())); | 652 std::string())); |
453 } | 653 } |
454 | 654 |
455 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { | 655 TEST_F(GeolocationPermissionContextTests, PermissionForFileSchemeBubbles) { |
| 656 if (!PermissionBubbleManager::Enabled()) |
| 657 return; |
| 658 |
| 659 GURL requesting_frame("file://example/geolocation.html"); |
| 660 NavigateAndCommit(requesting_frame); |
| 661 BubbleManagerDocumentLoadCompleted(); |
| 662 |
| 663 PermissionBubbleManager* mgr = |
| 664 PermissionBubbleManager::FromWebContents(web_contents()); |
| 665 ASSERT_EQ(0, GetBubblesQueueSize(mgr)); |
| 666 RequestGeolocationPermission( |
| 667 web_contents(), RequestID(0), requesting_frame, true); |
| 668 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
| 669 |
| 670 // Accept the frame. |
| 671 AcceptBubble(mgr); |
| 672 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
| 673 CheckPermissionMessageSent(0, true); |
| 674 |
| 675 // Make sure the setting is not stored. |
| 676 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 677 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 678 requesting_frame, |
| 679 requesting_frame, |
| 680 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 681 std::string())); |
| 682 } |
| 683 |
| 684 TEST_F(GeolocationPermissionContextTests, |
| 685 CancelGeolocationPermissionRequestInfobar) { |
| 686 if (PermissionBubbleManager::Enabled()) |
| 687 return; |
| 688 |
456 GURL requesting_frame_0("http://www.example.com/geolocation"); | 689 GURL requesting_frame_0("http://www.example.com/geolocation"); |
457 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 690 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
458 EXPECT_EQ(CONTENT_SETTING_ASK, | 691 EXPECT_EQ(CONTENT_SETTING_ASK, |
459 profile()->GetHostContentSettingsMap()->GetContentSetting( | 692 profile()->GetHostContentSettingsMap()->GetContentSetting( |
460 requesting_frame_0, requesting_frame_0, | 693 requesting_frame_0, requesting_frame_0, |
461 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 694 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
462 | 695 |
463 EXPECT_EQ(CONTENT_SETTING_ASK, | 696 EXPECT_EQ(CONTENT_SETTING_ASK, |
464 profile()->GetHostContentSettingsMap()->GetContentSetting( | 697 profile()->GetHostContentSettingsMap()->GetContentSetting( |
465 requesting_frame_1, requesting_frame_0, | 698 requesting_frame_1, requesting_frame_0, |
466 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 699 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
467 | 700 |
468 NavigateAndCommit(requesting_frame_0); | 701 NavigateAndCommit(requesting_frame_0); |
469 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 702 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
470 // Request permission for two frames. | 703 // Request permission for two frames. |
471 base::Closure cancel_callback; | 704 base::Closure cancel_callback; |
472 RequestGeolocationPermission( | 705 RequestGeolocationPermission( |
473 web_contents(), RequestID(0), requesting_frame_0, &cancel_callback); | 706 web_contents(), RequestID(0), requesting_frame_0, true, &cancel_callback); |
474 RequestGeolocationPermission( | 707 RequestGeolocationPermission( |
475 web_contents(), RequestID(1), requesting_frame_1); | 708 web_contents(), RequestID(1), requesting_frame_1, true); |
476 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 709 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
477 | 710 |
478 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 711 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); |
479 ConfirmInfoBarDelegate* infobar_delegate_0 = | 712 ConfirmInfoBarDelegate* infobar_delegate_0 = |
480 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 713 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
481 ASSERT_TRUE(infobar_delegate_0); | 714 ASSERT_TRUE(infobar_delegate_0); |
482 base::string16 text_0 = infobar_delegate_0->GetMessageText(); | 715 base::string16 text_0 = infobar_delegate_0->GetMessageText(); |
483 | 716 |
484 // Simulate the frame going away, ensure the infobar for this frame | 717 // Simulate the frame going away, ensure the infobar for this frame |
485 // is removed and the next pending infobar is created. | 718 // is removed and the next pending infobar is created. |
(...skipping 23 matching lines...) Expand all Loading... |
509 profile()->GetHostContentSettingsMap()->GetContentSetting( | 742 profile()->GetHostContentSettingsMap()->GetContentSetting( |
510 requesting_frame_0, requesting_frame_0, | 743 requesting_frame_0, requesting_frame_0, |
511 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 744 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
512 | 745 |
513 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 746 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
514 profile()->GetHostContentSettingsMap()->GetContentSetting( | 747 profile()->GetHostContentSettingsMap()->GetContentSetting( |
515 requesting_frame_1, requesting_frame_0, | 748 requesting_frame_1, requesting_frame_0, |
516 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 749 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
517 } | 750 } |
518 | 751 |
| 752 TEST_F(GeolocationPermissionContextTests, |
| 753 CancelGeolocationPermissionRequestBubbles) { |
| 754 if (!PermissionBubbleManager::Enabled()) |
| 755 return; |
| 756 |
| 757 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 758 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 759 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 760 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 761 requesting_frame_0, requesting_frame_0, |
| 762 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 763 |
| 764 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 765 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 766 requesting_frame_1, requesting_frame_0, |
| 767 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 768 |
| 769 NavigateAndCommit(requesting_frame_0); |
| 770 BubbleManagerDocumentLoadCompleted(); |
| 771 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 772 // Request permission for two frames. |
| 773 base::Closure cancel_callback; |
| 774 RequestGeolocationPermission( |
| 775 web_contents(), RequestID(0), requesting_frame_0, true, &cancel_callback); |
| 776 RequestGeolocationPermission( |
| 777 web_contents(), RequestID(1), requesting_frame_1, true); |
| 778 |
| 779 PermissionBubbleManager* mgr = |
| 780 PermissionBubbleManager::FromWebContents(web_contents()); |
| 781 ASSERT_TRUE(mgr != NULL); |
| 782 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
| 783 base::string16 text_0 = GetFirstRequestText(mgr); |
| 784 ASSERT_NE(base::string16(), text_0); |
| 785 |
| 786 // Cancel the request. This will still leave the bubble showing, since |
| 787 // the request is showing in the view. It will just be dummied. |
| 788 cancel_callback.Run(); |
| 789 AcceptBubble(mgr); // Dummy accept |
| 790 base::string16 text_1 = GetFirstRequestText(mgr); |
| 791 EXPECT_NE(text_0, text_1); |
| 792 |
| 793 // Allow this frame. |
| 794 AcceptBubble(mgr); |
| 795 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); |
| 796 CheckPermissionMessageSent(1, true); |
| 797 EXPECT_EQ(0, GetBubblesQueueSize(mgr)); |
| 798 |
| 799 // Ensure the persisted permissions are ok. |
| 800 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 801 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 802 requesting_frame_0, requesting_frame_0, |
| 803 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 804 |
| 805 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 806 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 807 requesting_frame_1, requesting_frame_0, |
| 808 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 809 } |
| 810 |
519 TEST_F(GeolocationPermissionContextTests, InvalidURL) { | 811 TEST_F(GeolocationPermissionContextTests, InvalidURL) { |
520 GURL invalid_embedder("about:blank"); | 812 GURL invalid_embedder("about:blank"); |
521 GURL requesting_frame; | 813 GURL requesting_frame; |
522 NavigateAndCommit(invalid_embedder); | 814 NavigateAndCommit(invalid_embedder); |
523 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 815 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
524 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 816 RequestGeolocationPermission( |
| 817 web_contents(), RequestID(0), requesting_frame, true); |
525 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 818 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
526 CheckPermissionMessageSent(0, false); | 819 CheckPermissionMessageSent(0, false); |
527 } | 820 } |
528 | 821 |
529 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { | 822 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabsInfobar) { |
| 823 if (PermissionBubbleManager::Enabled()) |
| 824 return; |
| 825 |
530 GURL url_a("http://www.example.com/geolocation"); | 826 GURL url_a("http://www.example.com/geolocation"); |
531 GURL url_b("http://www.example-2.com/geolocation"); | 827 GURL url_b("http://www.example-2.com/geolocation"); |
532 NavigateAndCommit(url_a); | 828 NavigateAndCommit(url_a); |
533 AddNewTab(url_b); | 829 AddNewTab(url_b); |
534 AddNewTab(url_a); | 830 AddNewTab(url_a); |
535 | 831 |
536 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 832 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
537 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); | 833 RequestGeolocationPermission(web_contents(), RequestID(0), url_a, true); |
538 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 834 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
539 | 835 |
540 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_b); | 836 RequestGeolocationPermission( |
| 837 extra_tabs_[0], RequestIDForTab(0, 0), url_b, true); |
541 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 838 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
542 | 839 |
543 RequestGeolocationPermission(extra_tabs_[1], RequestIDForTab(1, 0), url_a); | 840 RequestGeolocationPermission( |
| 841 extra_tabs_[1], RequestIDForTab(1, 0), url_a, true); |
544 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); | 842 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); |
545 | 843 |
546 infobars::InfoBar* removed_infobar = | 844 infobars::InfoBar* removed_infobar = |
547 infobar_service_for_tab(1)->infobar_at(0); | 845 infobar_service_for_tab(1)->infobar_at(0); |
548 | 846 |
549 // Accept the first tab. | 847 // Accept the first tab. |
550 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 848 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); |
551 ConfirmInfoBarDelegate* infobar_delegate_0 = | 849 ConfirmInfoBarDelegate* infobar_delegate_0 = |
552 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 850 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
553 ASSERT_TRUE(infobar_delegate_0); | 851 ASSERT_TRUE(infobar_delegate_0); |
(...skipping 13 matching lines...) Expand all Loading... |
567 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); | 865 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); |
568 ConfirmInfoBarDelegate* infobar_delegate_1 = | 866 ConfirmInfoBarDelegate* infobar_delegate_1 = |
569 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 867 infobar_1->delegate()->AsConfirmInfoBarDelegate(); |
570 ASSERT_TRUE(infobar_delegate_1); | 868 ASSERT_TRUE(infobar_delegate_1); |
571 infobar_delegate_1->Cancel(); | 869 infobar_delegate_1->Cancel(); |
572 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | 870 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); |
573 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 871 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
574 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 872 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); |
575 } | 873 } |
576 | 874 |
577 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { | 875 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabsInfobar) { |
| 876 if (PermissionBubbleManager::Enabled()) |
| 877 return; |
| 878 |
578 GURL url_a("http://www.example.com/geolocation"); | 879 GURL url_a("http://www.example.com/geolocation"); |
579 GURL url_b("http://www.example-2.com/geolocation"); | 880 GURL url_b("http://www.example-2.com/geolocation"); |
580 NavigateAndCommit(url_a); | 881 NavigateAndCommit(url_a); |
581 AddNewTab(url_a); | 882 AddNewTab(url_a); |
582 | 883 |
583 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 884 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
584 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); | 885 RequestGeolocationPermission(web_contents(), RequestID(0), url_a, true); |
585 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 886 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
586 | 887 |
587 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_a); | 888 RequestGeolocationPermission( |
| 889 extra_tabs_[0], RequestIDForTab(0, 0), url_a, true); |
588 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 890 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
589 | 891 |
590 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 1), url_b); | 892 RequestGeolocationPermission( |
| 893 extra_tabs_[0], RequestIDForTab(0, 1), url_b, true); |
591 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 894 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
592 | 895 |
593 infobars::InfoBar* removed_infobar = infobar_service()->infobar_at(0); | 896 infobars::InfoBar* removed_infobar = infobar_service()->infobar_at(0); |
594 | 897 |
595 // Accept the second tab. | 898 // Accept the second tab. |
596 infobars::InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0); | 899 infobars::InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0); |
597 ConfirmInfoBarDelegate* infobar_delegate_0 = | 900 ConfirmInfoBarDelegate* infobar_delegate_0 = |
598 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 901 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
599 ASSERT_TRUE(infobar_delegate_0); | 902 ASSERT_TRUE(infobar_delegate_0); |
600 infobar_delegate_0->Accept(); | 903 infobar_delegate_0->Accept(); |
(...skipping 15 matching lines...) Expand all Loading... |
616 ConfirmInfoBarDelegate* infobar_delegate_1 = | 919 ConfirmInfoBarDelegate* infobar_delegate_1 = |
617 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 920 infobar_1->delegate()->AsConfirmInfoBarDelegate(); |
618 ASSERT_TRUE(infobar_delegate_1); | 921 ASSERT_TRUE(infobar_delegate_1); |
619 infobar_delegate_1->Accept(); | 922 infobar_delegate_1->Accept(); |
620 CheckPermissionMessageSentForTab(0, 1, true); | 923 CheckPermissionMessageSentForTab(0, 1, true); |
621 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | 924 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); |
622 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 925 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
623 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 926 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); |
624 } | 927 } |
625 | 928 |
626 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { | 929 TEST_F(GeolocationPermissionContextTests, TabDestroyedInfobar) { |
| 930 if (PermissionBubbleManager::Enabled()) |
| 931 return; |
| 932 |
627 GURL requesting_frame_0("http://www.example.com/geolocation"); | 933 GURL requesting_frame_0("http://www.example.com/geolocation"); |
628 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 934 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
629 EXPECT_EQ(CONTENT_SETTING_ASK, | 935 EXPECT_EQ(CONTENT_SETTING_ASK, |
630 profile()->GetHostContentSettingsMap()->GetContentSetting( | 936 profile()->GetHostContentSettingsMap()->GetContentSetting( |
631 requesting_frame_0, requesting_frame_0, | 937 requesting_frame_0, requesting_frame_0, |
632 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 938 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
633 | 939 |
634 EXPECT_EQ(CONTENT_SETTING_ASK, | 940 EXPECT_EQ(CONTENT_SETTING_ASK, |
635 profile()->GetHostContentSettingsMap()->GetContentSetting( | 941 profile()->GetHostContentSettingsMap()->GetContentSetting( |
636 requesting_frame_1, requesting_frame_0, | 942 requesting_frame_1, requesting_frame_0, |
637 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 943 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
638 | 944 |
639 NavigateAndCommit(requesting_frame_0); | 945 NavigateAndCommit(requesting_frame_0); |
640 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 946 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
641 // Request permission for two frames. | 947 // Request permission for two frames. |
642 RequestGeolocationPermission( | 948 RequestGeolocationPermission( |
643 web_contents(), RequestID(0), requesting_frame_0); | 949 web_contents(), RequestID(0), requesting_frame_0, true); |
644 RequestGeolocationPermission( | 950 RequestGeolocationPermission( |
645 web_contents(), RequestID(1), requesting_frame_1); | 951 web_contents(), RequestID(1), requesting_frame_1, true); |
646 // Ensure only one infobar is created. | 952 // Ensure only one infobar is created. |
647 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 953 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
648 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 954 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
649 | 955 |
650 // Delete the tab contents. | 956 // Delete the tab contents. |
651 DeleteContents(); | 957 DeleteContents(); |
652 | 958 |
653 // During contents destruction, the infobar will have been closed, and the | 959 // During contents destruction, the infobar will have been closed, and the |
654 // pending request should have been cleared without an infobar being created. | 960 // pending request should have been cleared without an infobar being created. |
655 ASSERT_EQ(1U, closed_infobar_tracker_.size()); | 961 ASSERT_EQ(1U, closed_infobar_tracker_.size()); |
656 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 962 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
657 } | 963 } |
658 | 964 |
| 965 TEST_F(GeolocationPermissionContextTests, TabDestroyedBubbles) { |
| 966 if (!PermissionBubbleManager::Enabled()) |
| 967 return; |
| 968 |
| 969 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 970 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 971 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 972 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 973 requesting_frame_0, requesting_frame_0, |
| 974 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 975 |
| 976 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 977 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 978 requesting_frame_1, requesting_frame_0, |
| 979 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 980 |
| 981 NavigateAndCommit(requesting_frame_0); |
| 982 BubbleManagerDocumentLoadCompleted(); |
| 983 PermissionBubbleManager* mgr = |
| 984 PermissionBubbleManager::FromWebContents(web_contents()); |
| 985 ASSERT_TRUE(mgr != NULL); |
| 986 ASSERT_EQ(0, GetBubblesQueueSize(mgr)); |
| 987 |
| 988 // Request permission for two frames. |
| 989 RequestGeolocationPermission( |
| 990 web_contents(), RequestID(0), requesting_frame_0, true); |
| 991 RequestGeolocationPermission( |
| 992 web_contents(), RequestID(1), requesting_frame_1, true); |
| 993 // Ensure only one bubble request is shown. |
| 994 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
| 995 |
| 996 // Delete the tab contents. |
| 997 DeleteContents(); |
| 998 |
| 999 // During contents destruction, the bubble will have been closed, and the |
| 1000 // pending request should have been cleared without a bubble being shown. |
| 1001 } |
| 1002 |
659 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { | 1003 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { |
| 1004 if (PermissionBubbleManager::Enabled()) |
| 1005 return; |
| 1006 |
660 GURL requesting_frame_0("http://www.example.com/geolocation"); | 1007 GURL requesting_frame_0("http://www.example.com/geolocation"); |
661 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 1008 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
662 NavigateAndCommit(requesting_frame_0); | 1009 NavigateAndCommit(requesting_frame_0); |
663 NavigateAndCommit(requesting_frame_1); | 1010 NavigateAndCommit(requesting_frame_1); |
664 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 1011 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
665 // Go back: navigate to a pending entry before requesting geolocation | 1012 // Go back: navigate to a pending entry before requesting geolocation |
666 // permission. | 1013 // permission. |
667 web_contents()->GetController().GoBack(); | 1014 web_contents()->GetController().GoBack(); |
668 // Request permission for the committed frame (not the pending one). | 1015 // Request permission for the committed frame (not the pending one). |
669 RequestGeolocationPermission( | 1016 RequestGeolocationPermission( |
670 web_contents(), RequestID(0), requesting_frame_1); | 1017 web_contents(), RequestID(0), requesting_frame_1, true); |
671 // Ensure the infobar is created. | 1018 // Ensure the infobar is created. |
672 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 1019 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
673 infobars::InfoBarDelegate* infobar_delegate = | 1020 infobars::InfoBarDelegate* infobar_delegate = |
674 infobar_service()->infobar_at(0)->delegate(); | 1021 infobar_service()->infobar_at(0)->delegate(); |
675 ASSERT_TRUE(infobar_delegate); | 1022 ASSERT_TRUE(infobar_delegate); |
676 // Ensure the infobar wouldn't expire for a navigation to the committed entry. | 1023 // Ensure the infobar wouldn't expire for a navigation to the committed entry. |
677 content::LoadCommittedDetails details; | 1024 content::LoadCommittedDetails details; |
678 details.entry = web_contents()->GetController().GetLastCommittedEntry(); | 1025 details.entry = web_contents()->GetController().GetLastCommittedEntry(); |
679 EXPECT_FALSE(infobar_delegate->ShouldExpire( | 1026 EXPECT_FALSE(infobar_delegate->ShouldExpire( |
680 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details))); | 1027 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details))); |
(...skipping 17 matching lines...) Expand all Loading... |
698 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); | 1045 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); |
699 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); | 1046 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); |
700 | 1047 |
701 // The permission shouldn't have been used yet. | 1048 // The permission shouldn't have been used yet. |
702 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | 1049 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), |
703 requesting_frame.GetOrigin(), | 1050 requesting_frame.GetOrigin(), |
704 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1051 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
705 0); | 1052 0); |
706 | 1053 |
707 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 1054 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
708 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 1055 RequestGeolocationPermission( |
709 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 1056 web_contents(), RequestID(0), requesting_frame, true); |
710 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 1057 |
711 ConfirmInfoBarDelegate* infobar_delegate = | 1058 if (!PermissionBubbleManager::Enabled()) { |
712 infobar->delegate()->AsConfirmInfoBarDelegate(); | 1059 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
713 ASSERT_TRUE(infobar_delegate); | 1060 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
714 infobar_delegate->Accept(); | 1061 ConfirmInfoBarDelegate* infobar_delegate = |
| 1062 infobar->delegate()->AsConfirmInfoBarDelegate(); |
| 1063 ASSERT_TRUE(infobar_delegate); |
| 1064 infobar_delegate->Accept(); |
| 1065 } else { |
| 1066 PermissionBubbleManager* mgr = |
| 1067 PermissionBubbleManager::FromWebContents(web_contents()); |
| 1068 AcceptBubble(mgr); |
| 1069 } |
| 1070 |
715 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 1071 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
716 CheckPermissionMessageSent(0, true); | 1072 CheckPermissionMessageSent(0, true); |
717 | 1073 |
718 // Permission has been used at the starting time. | 1074 // Permission has been used at the starting time. |
719 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | 1075 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), |
720 requesting_frame.GetOrigin(), | 1076 requesting_frame.GetOrigin(), |
721 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1077 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
722 10); | 1078 10); |
723 | 1079 |
724 test_clock->Advance(base::TimeDelta::FromSeconds(3)); | 1080 test_clock->Advance(base::TimeDelta::FromSeconds(3)); |
725 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 1081 RequestGeolocationPermission( |
| 1082 web_contents(), RequestID(0), requesting_frame, true); |
726 | 1083 |
727 // Permission has been used three seconds later. | 1084 // Permission has been used three seconds later. |
728 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | 1085 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), |
729 requesting_frame.GetOrigin(), | 1086 requesting_frame.GetOrigin(), |
730 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1087 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
731 13); | 1088 13); |
732 } | 1089 } |
733 | 1090 |
734 TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) { | 1091 TEST_F(GeolocationPermissionContextTests, |
| 1092 LastUsageAuditedMultipleFramesInfobar) { |
| 1093 if (PermissionBubbleManager::Enabled()) |
| 1094 return; |
| 1095 |
735 base::SimpleTestClock* test_clock = new base::SimpleTestClock; | 1096 base::SimpleTestClock* test_clock = new base::SimpleTestClock; |
736 test_clock->SetNow(base::Time::UnixEpoch() + | 1097 test_clock->SetNow(base::Time::UnixEpoch() + |
737 base::TimeDelta::FromSeconds(10)); | 1098 base::TimeDelta::FromSeconds(10)); |
738 | 1099 |
739 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); | 1100 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); |
740 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); | 1101 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); |
741 | 1102 |
742 GURL requesting_frame_0("http://www.example.com/geolocation"); | 1103 GURL requesting_frame_0("http://www.example.com/geolocation"); |
743 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 1104 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
744 | 1105 |
745 // The permission shouldn't have been used yet. | 1106 // The permission shouldn't have been used yet. |
746 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 1107 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
747 requesting_frame_0.GetOrigin(), | 1108 requesting_frame_0.GetOrigin(), |
748 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1109 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
749 0); | 1110 0); |
750 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 1111 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
751 requesting_frame_0.GetOrigin(), | 1112 requesting_frame_0.GetOrigin(), |
752 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1113 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
753 0); | 1114 0); |
754 | 1115 |
755 NavigateAndCommit(requesting_frame_0); | 1116 NavigateAndCommit(requesting_frame_0); |
756 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 1117 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
757 | 1118 |
758 // Request permission for two frames. | 1119 // Request permission for two frames. |
759 RequestGeolocationPermission( | 1120 RequestGeolocationPermission( |
760 web_contents(), RequestID(0), requesting_frame_0); | 1121 web_contents(), RequestID(0), requesting_frame_0, true); |
761 RequestGeolocationPermission( | 1122 RequestGeolocationPermission( |
762 web_contents(), RequestID(1), requesting_frame_1); | 1123 web_contents(), RequestID(1), requesting_frame_1, true); |
763 | 1124 |
764 // Ensure only one infobar is created. | 1125 // Ensure only one infobar is created. |
765 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 1126 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
766 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 1127 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); |
767 ConfirmInfoBarDelegate* infobar_delegate_0 = | 1128 ConfirmInfoBarDelegate* infobar_delegate_0 = |
768 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 1129 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
769 | 1130 |
770 // Accept the first frame. | 1131 // Accept the first frame. |
771 infobar_delegate_0->Accept(); | 1132 infobar_delegate_0->Accept(); |
| 1133 |
772 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | 1134 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
773 CheckPermissionMessageSent(0, true); | 1135 CheckPermissionMessageSent(0, true); |
774 infobar_service()->RemoveInfoBar(infobar_0); | 1136 infobar_service()->RemoveInfoBar(infobar_0); |
775 | 1137 |
776 // Verify that accepting the first didn't accept because it's embedder | 1138 // Verify that accepting the first didn't accept because it's embedder |
777 // in the other. | 1139 // in the other. |
778 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 1140 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
779 requesting_frame_0.GetOrigin(), | 1141 requesting_frame_0.GetOrigin(), |
780 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1142 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
781 10); | 1143 10); |
(...skipping 20 matching lines...) Expand all Loading... |
802 requesting_frame_0.GetOrigin(), | 1164 requesting_frame_0.GetOrigin(), |
803 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1165 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
804 10); | 1166 10); |
805 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 1167 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
806 requesting_frame_0.GetOrigin(), | 1168 requesting_frame_0.GetOrigin(), |
807 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1169 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
808 11); | 1170 11); |
809 | 1171 |
810 test_clock->Advance(base::TimeDelta::FromSeconds(2)); | 1172 test_clock->Advance(base::TimeDelta::FromSeconds(2)); |
811 RequestGeolocationPermission( | 1173 RequestGeolocationPermission( |
812 web_contents(), RequestID(0), requesting_frame_0); | 1174 web_contents(), RequestID(0), requesting_frame_0, true); |
813 | 1175 |
814 // Verify that requesting permission in one frame doesn't update other where | 1176 // Verify that requesting permission in one frame doesn't update other where |
815 // it is the embedder. | 1177 // it is the embedder. |
| 1178 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
| 1179 requesting_frame_0.GetOrigin(), |
| 1180 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 1181 13); |
| 1182 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
| 1183 requesting_frame_0.GetOrigin(), |
| 1184 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 1185 11); |
| 1186 } |
| 1187 |
| 1188 TEST_F(GeolocationPermissionContextTests, |
| 1189 LastUsageAuditedMultipleFramesBubble) { |
| 1190 if (!PermissionBubbleManager::Enabled()) |
| 1191 return; |
| 1192 |
| 1193 base::SimpleTestClock* test_clock = new base::SimpleTestClock; |
| 1194 test_clock->SetNow(base::Time::UnixEpoch() + |
| 1195 base::TimeDelta::FromSeconds(10)); |
| 1196 |
| 1197 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); |
| 1198 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); |
| 1199 |
| 1200 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 1201 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 1202 |
| 1203 // The permission shouldn't have been used yet. |
| 1204 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
| 1205 requesting_frame_0.GetOrigin(), |
| 1206 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 1207 0); |
| 1208 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
| 1209 requesting_frame_0.GetOrigin(), |
| 1210 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 1211 0); |
| 1212 |
| 1213 NavigateAndCommit(requesting_frame_0); |
| 1214 BubbleManagerDocumentLoadCompleted(); |
| 1215 PermissionBubbleManager* mgr = |
| 1216 PermissionBubbleManager::FromWebContents(web_contents()); |
| 1217 EXPECT_EQ(0, GetBubblesQueueSize(mgr)); |
| 1218 |
| 1219 // Request permission for two frames. |
| 1220 RequestGeolocationPermission( |
| 1221 web_contents(), RequestID(0), requesting_frame_0, true); |
| 1222 RequestGeolocationPermission( |
| 1223 web_contents(), RequestID(1), requesting_frame_1, true); |
| 1224 EXPECT_EQ(1, GetBubblesQueueSize(mgr)); // 1 in request queue, 1 in pending |
| 1225 content::RunAllPendingInMessageLoop(); |
| 1226 |
| 1227 // Accept the first frame. |
| 1228 AcceptBubble(mgr); |
| 1229 |
| 1230 LOG(INFO) << "Checking state after accepting requesting_frame_0"; |
| 1231 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
| 1232 CheckPermissionMessageSent(0, true); |
| 1233 |
| 1234 // Verify that accepting the first didn't accept because it's embedder |
| 1235 // in the other. |
| 1236 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
| 1237 requesting_frame_0.GetOrigin(), |
| 1238 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 1239 10); |
| 1240 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
| 1241 requesting_frame_0.GetOrigin(), |
| 1242 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 1243 0); |
| 1244 |
| 1245 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 1246 AcceptBubble(mgr); |
| 1247 LOG(INFO) << "Checking state after accepting second bubble."; |
| 1248 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); |
| 1249 CheckPermissionMessageSent(1, true); |
| 1250 |
| 1251 // Verify that the times are different. |
| 1252 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
| 1253 requesting_frame_0.GetOrigin(), |
| 1254 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 1255 10); |
| 1256 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
| 1257 requesting_frame_0.GetOrigin(), |
| 1258 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 1259 11); |
| 1260 |
| 1261 test_clock->Advance(base::TimeDelta::FromSeconds(2)); |
| 1262 RequestGeolocationPermission( |
| 1263 web_contents(), RequestID(0), requesting_frame_0, true); |
| 1264 |
| 1265 // Verify that requesting permission in one frame doesn't update other where |
| 1266 // it is the embedder. |
816 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 1267 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
817 requesting_frame_0.GetOrigin(), | 1268 requesting_frame_0.GetOrigin(), |
818 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1269 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
819 13); | 1270 13); |
820 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 1271 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
821 requesting_frame_0.GetOrigin(), | 1272 requesting_frame_0.GetOrigin(), |
822 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1273 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
823 11); | 1274 11); |
824 } | 1275 } |
OLD | NEW |