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