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

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

Issue 228293004: InfoBarService inherits from InfoBarManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: format Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/chrome_geolocation_permission_context.h" 5 #include "chrome/browser/geolocation/chrome_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 "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/content_settings/host_content_settings_map.h" 17 #include "chrome/browser/content_settings/host_content_settings_map.h"
18 #include "chrome/browser/content_settings/permission_request_id.h" 18 #include "chrome/browser/content_settings/permission_request_id.h"
19 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 19 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
20 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_facto ry.h" 20 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_facto ry.h"
21 #include "chrome/browser/infobars/confirm_infobar_delegate.h" 21 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
22 #include "chrome/browser/infobars/infobar.h" 22 #include "chrome/browser/infobars/infobar.h"
23 #include "chrome/browser/infobars/infobar_manager.h" 23 #include "chrome/browser/infobars/infobar_service.h"
24 #include "chrome/browser/infobars/infobar_service.h" 24 #include "chrome/browser/infobars/infobar_service.h"
25 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 25 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
26 #include "chrome/test/base/testing_profile.h" 26 #include "chrome/test/base/testing_profile.h"
27 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/navigation_details.h" 28 #include "content/public/browser/navigation_details.h"
29 #include "content/public/browser/notification_registrar.h" 29 #include "content/public/browser/notification_registrar.h"
30 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
31 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
32 #include "content/public/test/mock_render_process_host.h" 32 #include "content/public/test/mock_render_process_host.h"
33 #include "content/public/test/test_renderer_host.h" 33 #include "content/public/test/test_renderer_host.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 class GeolocationPermissionContextTests 99 class GeolocationPermissionContextTests
100 : public ChromeRenderViewHostTestHarness { 100 : public ChromeRenderViewHostTestHarness {
101 protected: 101 protected:
102 // ChromeRenderViewHostTestHarness: 102 // ChromeRenderViewHostTestHarness:
103 virtual void SetUp() OVERRIDE; 103 virtual void SetUp() OVERRIDE;
104 virtual void TearDown() OVERRIDE; 104 virtual void TearDown() OVERRIDE;
105 105
106 PermissionRequestID RequestID(int bridge_id); 106 PermissionRequestID RequestID(int bridge_id);
107 PermissionRequestID RequestIDForTab(int tab, int bridge_id); 107 PermissionRequestID RequestIDForTab(int tab, int bridge_id);
108 InfoBarManager* infobar_manager() { 108 InfoBarService* infobar_service() {
109 return InfoBarService::FromWebContents(web_contents())->infobar_manager(); 109 return InfoBarService::FromWebContents(web_contents());
110 } 110 }
111 InfoBarManager* infobar_manager_for_tab(int tab) { 111 InfoBarService* infobar_service_for_tab(int tab) {
112 return InfoBarService::FromWebContents(extra_tabs_[tab])->infobar_manager(); 112 return InfoBarService::FromWebContents(extra_tabs_[tab]);
113 } 113 }
114 114
115 void RequestGeolocationPermission(const PermissionRequestID& id, 115 void RequestGeolocationPermission(const PermissionRequestID& id,
116 const GURL& requesting_frame); 116 const GURL& requesting_frame);
117 void CancelGeolocationPermissionRequest(const PermissionRequestID& id, 117 void CancelGeolocationPermissionRequest(const PermissionRequestID& id,
118 const GURL& requesting_frame); 118 const GURL& requesting_frame);
119 void PermissionResponse(const PermissionRequestID& id, 119 void PermissionResponse(const PermissionRequestID& id,
120 bool allowed); 120 bool allowed);
121 void CheckPermissionMessageSent(int bridge_id, bool allowed); 121 void CheckPermissionMessageSent(int bridge_id, bool allowed);
122 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); 122 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 void GeolocationPermissionContextTests::TearDown() { 255 void GeolocationPermissionContextTests::TearDown() {
256 extra_tabs_.clear(); 256 extra_tabs_.clear();
257 ChromeRenderViewHostTestHarness::TearDown(); 257 ChromeRenderViewHostTestHarness::TearDown();
258 } 258 }
259 259
260 // Tests ---------------------------------------------------------------------- 260 // Tests ----------------------------------------------------------------------
261 261
262 TEST_F(GeolocationPermissionContextTests, SinglePermission) { 262 TEST_F(GeolocationPermissionContextTests, SinglePermission) {
263 GURL requesting_frame("http://www.example.com/geolocation"); 263 GURL requesting_frame("http://www.example.com/geolocation");
264 NavigateAndCommit(requesting_frame); 264 NavigateAndCommit(requesting_frame);
265 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 265 EXPECT_EQ(0U, infobar_service()->infobar_count());
266 RequestGeolocationPermission(RequestID(0), requesting_frame); 266 RequestGeolocationPermission(RequestID(0), requesting_frame);
267 ASSERT_EQ(1U, infobar_manager()->infobar_count()); 267 ASSERT_EQ(1U, infobar_service()->infobar_count());
268 InfoBar* infobar = infobar_manager()->infobar_at(0); 268 InfoBar* infobar = infobar_service()->infobar_at(0);
269 ConfirmInfoBarDelegate* infobar_delegate = 269 ConfirmInfoBarDelegate* infobar_delegate =
270 infobar->delegate()->AsConfirmInfoBarDelegate(); 270 infobar->delegate()->AsConfirmInfoBarDelegate();
271 ASSERT_TRUE(infobar_delegate); 271 ASSERT_TRUE(infobar_delegate);
272 infobar_delegate->Cancel(); 272 infobar_delegate->Cancel();
273 infobar_manager()->RemoveInfoBar(infobar); 273 infobar_service()->RemoveInfoBar(infobar);
274 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 274 EXPECT_EQ(1U, closed_infobar_tracker_.size());
275 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); 275 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
276 } 276 }
277 277
278 #if defined(OS_ANDROID) 278 #if defined(OS_ANDROID)
279 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { 279 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) {
280 GURL requesting_frame("http://www.example.com/geolocation"); 280 GURL requesting_frame("http://www.example.com/geolocation");
281 NavigateAndCommit(requesting_frame); 281 NavigateAndCommit(requesting_frame);
282 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); 282 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true);
283 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 283 EXPECT_EQ(0U, infobar_service()->infobar_count());
284 RequestGeolocationPermission(RequestID(0), requesting_frame); 284 RequestGeolocationPermission(RequestID(0), requesting_frame);
285 EXPECT_EQ(1U, infobar_manager()->infobar_count()); 285 EXPECT_EQ(1U, infobar_service()->infobar_count());
286 ConfirmInfoBarDelegate* infobar_delegate_0 = 286 ConfirmInfoBarDelegate* infobar_delegate_0 =
287 infobar_manager()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 287 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
288 ASSERT_TRUE(infobar_delegate_0); 288 ASSERT_TRUE(infobar_delegate_0);
289 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( 289 base::string16 text_0 = infobar_delegate_0->GetButtonLabel(
290 ConfirmInfoBarDelegate::BUTTON_OK); 290 ConfirmInfoBarDelegate::BUTTON_OK);
291 291
292 NavigateAndCommit(requesting_frame); 292 NavigateAndCommit(requesting_frame);
293 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); 293 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false);
294 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 294 EXPECT_EQ(0U, infobar_service()->infobar_count());
295 RequestGeolocationPermission(RequestID(0), requesting_frame); 295 RequestGeolocationPermission(RequestID(0), requesting_frame);
296 EXPECT_EQ(1U, infobar_manager()->infobar_count()); 296 EXPECT_EQ(1U, infobar_service()->infobar_count());
297 ConfirmInfoBarDelegate* infobar_delegate_1 = 297 ConfirmInfoBarDelegate* infobar_delegate_1 =
298 infobar_manager()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 298 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
299 ASSERT_TRUE(infobar_delegate_1); 299 ASSERT_TRUE(infobar_delegate_1);
300 base::string16 text_1 = infobar_delegate_1->GetButtonLabel( 300 base::string16 text_1 = infobar_delegate_1->GetButtonLabel(
301 ConfirmInfoBarDelegate::BUTTON_OK); 301 ConfirmInfoBarDelegate::BUTTON_OK);
302 EXPECT_NE(text_0, text_1); 302 EXPECT_NE(text_0, text_1);
303 303
304 NavigateAndCommit(requesting_frame); 304 NavigateAndCommit(requesting_frame);
305 MockGoogleLocationSettingsHelper::SetLocationStatus(false, false); 305 MockGoogleLocationSettingsHelper::SetLocationStatus(false, false);
306 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 306 EXPECT_EQ(0U, infobar_service()->infobar_count());
307 RequestGeolocationPermission(RequestID(0), requesting_frame); 307 RequestGeolocationPermission(RequestID(0), requesting_frame);
308 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 308 EXPECT_EQ(0U, infobar_service()->infobar_count());
309 } 309 }
310 310
311 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { 311 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) {
312 GURL requesting_frame("http://www.example.com/geolocation"); 312 GURL requesting_frame("http://www.example.com/geolocation");
313 NavigateAndCommit(requesting_frame); 313 NavigateAndCommit(requesting_frame);
314 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); 314 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true);
315 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 315 EXPECT_EQ(0U, infobar_service()->infobar_count());
316 RequestGeolocationPermission(RequestID(0), requesting_frame); 316 RequestGeolocationPermission(RequestID(0), requesting_frame);
317 EXPECT_EQ(1U, infobar_manager()->infobar_count()); 317 EXPECT_EQ(1U, infobar_service()->infobar_count());
318 ConfirmInfoBarDelegate* infobar_delegate = 318 ConfirmInfoBarDelegate* infobar_delegate =
319 infobar_manager()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 319 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
320 ASSERT_TRUE(infobar_delegate); 320 ASSERT_TRUE(infobar_delegate);
321 infobar_delegate->Accept(); 321 infobar_delegate->Accept();
322 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 322 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
323 CheckPermissionMessageSent(0, true); 323 CheckPermissionMessageSent(0, true);
324 } 324 }
325 325
326 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { 326 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) {
327 GURL requesting_frame("http://www.example.com/geolocation"); 327 GURL requesting_frame("http://www.example.com/geolocation");
328 NavigateAndCommit(requesting_frame); 328 NavigateAndCommit(requesting_frame);
329 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); 329 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false);
330 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 330 EXPECT_EQ(0U, infobar_service()->infobar_count());
331 RequestGeolocationPermission(RequestID(0), requesting_frame); 331 RequestGeolocationPermission(RequestID(0), requesting_frame);
332 EXPECT_EQ(1U, infobar_manager()->infobar_count()); 332 EXPECT_EQ(1U, infobar_service()->infobar_count());
333 ConfirmInfoBarDelegate* infobar_delegate = 333 ConfirmInfoBarDelegate* infobar_delegate =
334 infobar_manager()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 334 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
335 ASSERT_TRUE(infobar_delegate); 335 ASSERT_TRUE(infobar_delegate);
336 infobar_delegate->Accept(); 336 infobar_delegate->Accept();
337 EXPECT_TRUE( 337 EXPECT_TRUE(
338 MockGoogleLocationSettingsHelper::WasGoogleLocationSettingsCalled()); 338 MockGoogleLocationSettingsHelper::WasGoogleLocationSettingsCalled());
339 } 339 }
340 #endif 340 #endif
341 341
342 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { 342 TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
343 GURL requesting_frame_0("http://www.example.com/geolocation"); 343 GURL requesting_frame_0("http://www.example.com/geolocation");
344 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 344 GURL requesting_frame_1("http://www.example-2.com/geolocation");
345 EXPECT_EQ(CONTENT_SETTING_ASK, 345 EXPECT_EQ(CONTENT_SETTING_ASK,
346 profile()->GetHostContentSettingsMap()->GetContentSetting( 346 profile()->GetHostContentSettingsMap()->GetContentSetting(
347 requesting_frame_0, requesting_frame_0, 347 requesting_frame_0, requesting_frame_0,
348 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 348 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
349 EXPECT_EQ(CONTENT_SETTING_ASK, 349 EXPECT_EQ(CONTENT_SETTING_ASK,
350 profile()->GetHostContentSettingsMap()->GetContentSetting( 350 profile()->GetHostContentSettingsMap()->GetContentSetting(
351 requesting_frame_1, requesting_frame_0, 351 requesting_frame_1, requesting_frame_0,
352 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 352 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
353 353
354 NavigateAndCommit(requesting_frame_0); 354 NavigateAndCommit(requesting_frame_0);
355 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 355 EXPECT_EQ(0U, infobar_service()->infobar_count());
356 // Request permission for two frames. 356 // Request permission for two frames.
357 RequestGeolocationPermission(RequestID(0), requesting_frame_0); 357 RequestGeolocationPermission(RequestID(0), requesting_frame_0);
358 RequestGeolocationPermission(RequestID(1), requesting_frame_1); 358 RequestGeolocationPermission(RequestID(1), requesting_frame_1);
359 // Ensure only one infobar is created. 359 // Ensure only one infobar is created.
360 ASSERT_EQ(1U, infobar_manager()->infobar_count()); 360 ASSERT_EQ(1U, infobar_service()->infobar_count());
361 InfoBar* infobar_0 = infobar_manager()->infobar_at(0); 361 InfoBar* infobar_0 = infobar_service()->infobar_at(0);
362 ConfirmInfoBarDelegate* infobar_delegate_0 = 362 ConfirmInfoBarDelegate* infobar_delegate_0 =
363 infobar_0->delegate()->AsConfirmInfoBarDelegate(); 363 infobar_0->delegate()->AsConfirmInfoBarDelegate();
364 ASSERT_TRUE(infobar_delegate_0); 364 ASSERT_TRUE(infobar_delegate_0);
365 base::string16 text_0 = infobar_delegate_0->GetMessageText(); 365 base::string16 text_0 = infobar_delegate_0->GetMessageText();
366 366
367 // Accept the first frame. 367 // Accept the first frame.
368 infobar_delegate_0->Accept(); 368 infobar_delegate_0->Accept();
369 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); 369 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
370 CheckPermissionMessageSent(0, true); 370 CheckPermissionMessageSent(0, true);
371 371
372 infobar_manager()->RemoveInfoBar(infobar_0); 372 infobar_service()->RemoveInfoBar(infobar_0);
373 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 373 EXPECT_EQ(1U, closed_infobar_tracker_.size());
374 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); 374 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
375 closed_infobar_tracker_.Clear(); 375 closed_infobar_tracker_.Clear();
376 // Now we should have a new infobar for the second frame. 376 // Now we should have a new infobar for the second frame.
377 ASSERT_EQ(1U, infobar_manager()->infobar_count()); 377 ASSERT_EQ(1U, infobar_service()->infobar_count());
378 378
379 InfoBar* infobar_1 = infobar_manager()->infobar_at(0); 379 InfoBar* infobar_1 = infobar_service()->infobar_at(0);
380 ConfirmInfoBarDelegate* infobar_delegate_1 = 380 ConfirmInfoBarDelegate* infobar_delegate_1 =
381 infobar_1->delegate()->AsConfirmInfoBarDelegate(); 381 infobar_1->delegate()->AsConfirmInfoBarDelegate();
382 ASSERT_TRUE(infobar_delegate_1); 382 ASSERT_TRUE(infobar_delegate_1);
383 base::string16 text_1 = infobar_delegate_1->GetMessageText(); 383 base::string16 text_1 = infobar_delegate_1->GetMessageText();
384 EXPECT_NE(text_0, text_1); 384 EXPECT_NE(text_0, text_1);
385 385
386 // Cancel (block) this frame. 386 // Cancel (block) this frame.
387 infobar_delegate_1->Cancel(); 387 infobar_delegate_1->Cancel();
388 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); 388 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK);
389 CheckPermissionMessageSent(1, false); 389 CheckPermissionMessageSent(1, false);
390 infobar_manager()->RemoveInfoBar(infobar_1); 390 infobar_service()->RemoveInfoBar(infobar_1);
391 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 391 EXPECT_EQ(1U, closed_infobar_tracker_.size());
392 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); 392 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
393 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 393 EXPECT_EQ(0U, infobar_service()->infobar_count());
394 // Ensure the persisted permissions are ok. 394 // Ensure the persisted permissions are ok.
395 EXPECT_EQ(CONTENT_SETTING_ALLOW, 395 EXPECT_EQ(CONTENT_SETTING_ALLOW,
396 profile()->GetHostContentSettingsMap()->GetContentSetting( 396 profile()->GetHostContentSettingsMap()->GetContentSetting(
397 requesting_frame_0, requesting_frame_0, 397 requesting_frame_0, requesting_frame_0,
398 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 398 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
399 399
400 EXPECT_EQ(CONTENT_SETTING_BLOCK, 400 EXPECT_EQ(CONTENT_SETTING_BLOCK,
401 profile()->GetHostContentSettingsMap()->GetContentSetting( 401 profile()->GetHostContentSettingsMap()->GetContentSetting(
402 requesting_frame_1, requesting_frame_0, 402 requesting_frame_1, requesting_frame_0,
403 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 403 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
404 } 404 }
405 405
406 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { 406 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) {
407 GURL url_a("http://www.example.com/geolocation#a"); 407 GURL url_a("http://www.example.com/geolocation#a");
408 GURL url_b("http://www.example.com/geolocation#b"); 408 GURL url_b("http://www.example.com/geolocation#b");
409 409
410 // Navigate to the first url and check permission is requested. 410 // Navigate to the first url and check permission is requested.
411 NavigateAndCommit(url_a); 411 NavigateAndCommit(url_a);
412 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 412 EXPECT_EQ(0U, infobar_service()->infobar_count());
413 RequestGeolocationPermission(RequestID(0), url_a); 413 RequestGeolocationPermission(RequestID(0), url_a);
414 ASSERT_EQ(1U, infobar_manager()->infobar_count()); 414 ASSERT_EQ(1U, infobar_service()->infobar_count());
415 InfoBar* infobar = infobar_manager()->infobar_at(0); 415 InfoBar* infobar = infobar_service()->infobar_at(0);
416 ConfirmInfoBarDelegate* infobar_delegate = 416 ConfirmInfoBarDelegate* infobar_delegate =
417 infobar->delegate()->AsConfirmInfoBarDelegate(); 417 infobar->delegate()->AsConfirmInfoBarDelegate();
418 ASSERT_TRUE(infobar_delegate); 418 ASSERT_TRUE(infobar_delegate);
419 419
420 // Change the hash, we'll still be on the same page. 420 // Change the hash, we'll still be on the same page.
421 NavigateAndCommit(url_b); 421 NavigateAndCommit(url_b);
422 422
423 // Accept. 423 // Accept.
424 infobar_delegate->Accept(); 424 infobar_delegate->Accept();
425 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); 425 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW);
426 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); 426 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW);
427 CheckPermissionMessageSent(0, true); 427 CheckPermissionMessageSent(0, true);
428 428
429 // Cleanup. 429 // Cleanup.
430 infobar_manager()->RemoveInfoBar(infobar); 430 infobar_service()->RemoveInfoBar(infobar);
431 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 431 EXPECT_EQ(1U, closed_infobar_tracker_.size());
432 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); 432 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
433 } 433 }
434 434
435 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { 435 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) {
436 GURL requesting_frame("file://example/geolocation.html"); 436 GURL requesting_frame("file://example/geolocation.html");
437 NavigateAndCommit(requesting_frame); 437 NavigateAndCommit(requesting_frame);
438 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 438 EXPECT_EQ(0U, infobar_service()->infobar_count());
439 RequestGeolocationPermission(RequestID(0), requesting_frame); 439 RequestGeolocationPermission(RequestID(0), requesting_frame);
440 EXPECT_EQ(1U, infobar_manager()->infobar_count()); 440 EXPECT_EQ(1U, infobar_service()->infobar_count());
441 InfoBar* infobar = infobar_manager()->infobar_at(0); 441 InfoBar* infobar = infobar_service()->infobar_at(0);
442 ConfirmInfoBarDelegate* infobar_delegate = 442 ConfirmInfoBarDelegate* infobar_delegate =
443 infobar->delegate()->AsConfirmInfoBarDelegate(); 443 infobar->delegate()->AsConfirmInfoBarDelegate();
444 ASSERT_TRUE(infobar_delegate); 444 ASSERT_TRUE(infobar_delegate);
445 // Accept the frame. 445 // Accept the frame.
446 infobar_delegate->Accept(); 446 infobar_delegate->Accept();
447 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 447 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
448 CheckPermissionMessageSent(0, true); 448 CheckPermissionMessageSent(0, true);
449 infobar_manager()->RemoveInfoBar(infobar); 449 infobar_service()->RemoveInfoBar(infobar);
450 450
451 // Make sure the setting is not stored. 451 // Make sure the setting is not stored.
452 EXPECT_EQ(CONTENT_SETTING_ASK, 452 EXPECT_EQ(CONTENT_SETTING_ASK,
453 profile()->GetHostContentSettingsMap()->GetContentSetting( 453 profile()->GetHostContentSettingsMap()->GetContentSetting(
454 requesting_frame, 454 requesting_frame,
455 requesting_frame, 455 requesting_frame,
456 CONTENT_SETTINGS_TYPE_GEOLOCATION, 456 CONTENT_SETTINGS_TYPE_GEOLOCATION,
457 std::string())); 457 std::string()));
458 } 458 }
459 459
460 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { 460 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
461 GURL requesting_frame_0("http://www.example.com/geolocation"); 461 GURL requesting_frame_0("http://www.example.com/geolocation");
462 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 462 GURL requesting_frame_1("http://www.example-2.com/geolocation");
463 EXPECT_EQ(CONTENT_SETTING_ASK, 463 EXPECT_EQ(CONTENT_SETTING_ASK,
464 profile()->GetHostContentSettingsMap()->GetContentSetting( 464 profile()->GetHostContentSettingsMap()->GetContentSetting(
465 requesting_frame_0, requesting_frame_0, 465 requesting_frame_0, requesting_frame_0,
466 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 466 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
467 467
468 EXPECT_EQ(CONTENT_SETTING_ASK, 468 EXPECT_EQ(CONTENT_SETTING_ASK,
469 profile()->GetHostContentSettingsMap()->GetContentSetting( 469 profile()->GetHostContentSettingsMap()->GetContentSetting(
470 requesting_frame_1, requesting_frame_0, 470 requesting_frame_1, requesting_frame_0,
471 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 471 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
472 472
473 NavigateAndCommit(requesting_frame_0); 473 NavigateAndCommit(requesting_frame_0);
474 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 474 EXPECT_EQ(0U, infobar_service()->infobar_count());
475 // Request permission for two frames. 475 // Request permission for two frames.
476 RequestGeolocationPermission(RequestID(0), requesting_frame_0); 476 RequestGeolocationPermission(RequestID(0), requesting_frame_0);
477 RequestGeolocationPermission(RequestID(1), requesting_frame_1); 477 RequestGeolocationPermission(RequestID(1), requesting_frame_1);
478 ASSERT_EQ(1U, infobar_manager()->infobar_count()); 478 ASSERT_EQ(1U, infobar_service()->infobar_count());
479 479
480 InfoBar* infobar_0 = infobar_manager()->infobar_at(0); 480 InfoBar* infobar_0 = infobar_service()->infobar_at(0);
481 ConfirmInfoBarDelegate* infobar_delegate_0 = 481 ConfirmInfoBarDelegate* infobar_delegate_0 =
482 infobar_0->delegate()->AsConfirmInfoBarDelegate(); 482 infobar_0->delegate()->AsConfirmInfoBarDelegate();
483 ASSERT_TRUE(infobar_delegate_0); 483 ASSERT_TRUE(infobar_delegate_0);
484 base::string16 text_0 = infobar_delegate_0->GetMessageText(); 484 base::string16 text_0 = infobar_delegate_0->GetMessageText();
485 485
486 // Simulate the frame going away, ensure the infobar for this frame 486 // Simulate the frame going away, ensure the infobar for this frame
487 // is removed and the next pending infobar is created. 487 // is removed and the next pending infobar is created.
488 CancelGeolocationPermissionRequest(RequestID(0), requesting_frame_0); 488 CancelGeolocationPermissionRequest(RequestID(0), requesting_frame_0);
489 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 489 EXPECT_EQ(1U, closed_infobar_tracker_.size());
490 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); 490 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
491 closed_infobar_tracker_.Clear(); 491 closed_infobar_tracker_.Clear();
492 ASSERT_EQ(1U, infobar_manager()->infobar_count()); 492 ASSERT_EQ(1U, infobar_service()->infobar_count());
493 493
494 InfoBar* infobar_1 = infobar_manager()->infobar_at(0); 494 InfoBar* infobar_1 = infobar_service()->infobar_at(0);
495 ConfirmInfoBarDelegate* infobar_delegate_1 = 495 ConfirmInfoBarDelegate* infobar_delegate_1 =
496 infobar_1->delegate()->AsConfirmInfoBarDelegate(); 496 infobar_1->delegate()->AsConfirmInfoBarDelegate();
497 ASSERT_TRUE(infobar_delegate_1); 497 ASSERT_TRUE(infobar_delegate_1);
498 base::string16 text_1 = infobar_delegate_1->GetMessageText(); 498 base::string16 text_1 = infobar_delegate_1->GetMessageText();
499 EXPECT_NE(text_0, text_1); 499 EXPECT_NE(text_0, text_1);
500 500
501 // Allow this frame. 501 // Allow this frame.
502 infobar_delegate_1->Accept(); 502 infobar_delegate_1->Accept();
503 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); 503 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW);
504 CheckPermissionMessageSent(1, true); 504 CheckPermissionMessageSent(1, true);
505 infobar_manager()->RemoveInfoBar(infobar_1); 505 infobar_service()->RemoveInfoBar(infobar_1);
506 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 506 EXPECT_EQ(1U, closed_infobar_tracker_.size());
507 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); 507 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
508 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 508 EXPECT_EQ(0U, infobar_service()->infobar_count());
509 // Ensure the persisted permissions are ok. 509 // Ensure the persisted permissions are ok.
510 EXPECT_EQ(CONTENT_SETTING_ASK, 510 EXPECT_EQ(CONTENT_SETTING_ASK,
511 profile()->GetHostContentSettingsMap()->GetContentSetting( 511 profile()->GetHostContentSettingsMap()->GetContentSetting(
512 requesting_frame_0, requesting_frame_0, 512 requesting_frame_0, requesting_frame_0,
513 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 513 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
514 514
515 EXPECT_EQ(CONTENT_SETTING_ALLOW, 515 EXPECT_EQ(CONTENT_SETTING_ALLOW,
516 profile()->GetHostContentSettingsMap()->GetContentSetting( 516 profile()->GetHostContentSettingsMap()->GetContentSetting(
517 requesting_frame_1, requesting_frame_0, 517 requesting_frame_1, requesting_frame_0,
518 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 518 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
519 } 519 }
520 520
521 TEST_F(GeolocationPermissionContextTests, InvalidURL) { 521 TEST_F(GeolocationPermissionContextTests, InvalidURL) {
522 GURL invalid_embedder("about:blank"); 522 GURL invalid_embedder("about:blank");
523 GURL requesting_frame; 523 GURL requesting_frame;
524 NavigateAndCommit(invalid_embedder); 524 NavigateAndCommit(invalid_embedder);
525 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 525 EXPECT_EQ(0U, infobar_service()->infobar_count());
526 RequestGeolocationPermission(RequestID(0), requesting_frame); 526 RequestGeolocationPermission(RequestID(0), requesting_frame);
527 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 527 EXPECT_EQ(0U, infobar_service()->infobar_count());
528 CheckPermissionMessageSent(0, false); 528 CheckPermissionMessageSent(0, false);
529 } 529 }
530 530
531 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { 531 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
532 GURL url_a("http://www.example.com/geolocation"); 532 GURL url_a("http://www.example.com/geolocation");
533 GURL url_b("http://www.example-2.com/geolocation"); 533 GURL url_b("http://www.example-2.com/geolocation");
534 NavigateAndCommit(url_a); 534 NavigateAndCommit(url_a);
535 AddNewTab(url_b); 535 AddNewTab(url_b);
536 AddNewTab(url_a); 536 AddNewTab(url_a);
537 537
538 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 538 EXPECT_EQ(0U, infobar_service()->infobar_count());
539 RequestGeolocationPermission(RequestID(0), url_a); 539 RequestGeolocationPermission(RequestID(0), url_a);
540 ASSERT_EQ(1U, infobar_manager()->infobar_count()); 540 ASSERT_EQ(1U, infobar_service()->infobar_count());
541 541
542 RequestGeolocationPermission(RequestIDForTab(0, 0), url_b); 542 RequestGeolocationPermission(RequestIDForTab(0, 0), url_b);
543 EXPECT_EQ(1U, infobar_manager_for_tab(0)->infobar_count()); 543 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
544 544
545 RequestGeolocationPermission(RequestIDForTab(1, 0), url_a); 545 RequestGeolocationPermission(RequestIDForTab(1, 0), url_a);
546 ASSERT_EQ(1U, infobar_manager_for_tab(1)->infobar_count()); 546 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count());
547 547
548 InfoBar* removed_infobar = infobar_manager_for_tab(1)->infobar_at(0); 548 InfoBar* removed_infobar = infobar_service_for_tab(1)->infobar_at(0);
549 549
550 // Accept the first tab. 550 // Accept the first tab.
551 InfoBar* infobar_0 = infobar_manager()->infobar_at(0); 551 InfoBar* infobar_0 = infobar_service()->infobar_at(0);
552 ConfirmInfoBarDelegate* infobar_delegate_0 = 552 ConfirmInfoBarDelegate* infobar_delegate_0 =
553 infobar_0->delegate()->AsConfirmInfoBarDelegate(); 553 infobar_0->delegate()->AsConfirmInfoBarDelegate();
554 ASSERT_TRUE(infobar_delegate_0); 554 ASSERT_TRUE(infobar_delegate_0);
555 infobar_delegate_0->Accept(); 555 infobar_delegate_0->Accept();
556 CheckPermissionMessageSent(0, true); 556 CheckPermissionMessageSent(0, true);
557 infobar_manager()->RemoveInfoBar(infobar_0); 557 infobar_service()->RemoveInfoBar(infobar_0);
558 EXPECT_EQ(2U, closed_infobar_tracker_.size()); 558 EXPECT_EQ(2U, closed_infobar_tracker_.size());
559 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); 559 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
560 // Now the infobar for the tab with the same origin should have gone. 560 // Now the infobar for the tab with the same origin should have gone.
561 EXPECT_EQ(0U, infobar_manager_for_tab(1)->infobar_count()); 561 EXPECT_EQ(0U, infobar_service_for_tab(1)->infobar_count());
562 CheckPermissionMessageSentForTab(1, 0, true); 562 CheckPermissionMessageSentForTab(1, 0, true);
563 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); 563 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar));
564 closed_infobar_tracker_.Clear(); 564 closed_infobar_tracker_.Clear();
565 565
566 // But the other tab should still have the info bar... 566 // But the other tab should still have the info bar...
567 ASSERT_EQ(1U, infobar_manager_for_tab(0)->infobar_count()); 567 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
568 InfoBar* infobar_1 = infobar_manager_for_tab(0)->infobar_at(0); 568 InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0);
569 ConfirmInfoBarDelegate* infobar_delegate_1 = 569 ConfirmInfoBarDelegate* infobar_delegate_1 =
570 infobar_1->delegate()->AsConfirmInfoBarDelegate(); 570 infobar_1->delegate()->AsConfirmInfoBarDelegate();
571 ASSERT_TRUE(infobar_delegate_1); 571 ASSERT_TRUE(infobar_delegate_1);
572 infobar_delegate_1->Cancel(); 572 infobar_delegate_1->Cancel();
573 infobar_manager_for_tab(0)->RemoveInfoBar(infobar_1); 573 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1);
574 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 574 EXPECT_EQ(1U, closed_infobar_tracker_.size());
575 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); 575 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
576 } 576 }
577 577
578 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { 578 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
579 GURL url_a("http://www.example.com/geolocation"); 579 GURL url_a("http://www.example.com/geolocation");
580 GURL url_b("http://www.example-2.com/geolocation"); 580 GURL url_b("http://www.example-2.com/geolocation");
581 NavigateAndCommit(url_a); 581 NavigateAndCommit(url_a);
582 AddNewTab(url_a); 582 AddNewTab(url_a);
583 583
584 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 584 EXPECT_EQ(0U, infobar_service()->infobar_count());
585 RequestGeolocationPermission(RequestID(0), url_a); 585 RequestGeolocationPermission(RequestID(0), url_a);
586 ASSERT_EQ(1U, infobar_manager()->infobar_count()); 586 ASSERT_EQ(1U, infobar_service()->infobar_count());
587 587
588 RequestGeolocationPermission(RequestIDForTab(0, 0), url_a); 588 RequestGeolocationPermission(RequestIDForTab(0, 0), url_a);
589 EXPECT_EQ(1U, infobar_manager_for_tab(0)->infobar_count()); 589 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
590 590
591 RequestGeolocationPermission(RequestIDForTab(0, 1), url_b); 591 RequestGeolocationPermission(RequestIDForTab(0, 1), url_b);
592 ASSERT_EQ(1U, infobar_manager_for_tab(0)->infobar_count()); 592 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
593 593
594 InfoBar* removed_infobar = infobar_manager()->infobar_at(0); 594 InfoBar* removed_infobar = infobar_service()->infobar_at(0);
595 595
596 // Accept the second tab. 596 // Accept the second tab.
597 InfoBar* infobar_0 = infobar_manager_for_tab(0)->infobar_at(0); 597 InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0);
598 ConfirmInfoBarDelegate* infobar_delegate_0 = 598 ConfirmInfoBarDelegate* infobar_delegate_0 =
599 infobar_0->delegate()->AsConfirmInfoBarDelegate(); 599 infobar_0->delegate()->AsConfirmInfoBarDelegate();
600 ASSERT_TRUE(infobar_delegate_0); 600 ASSERT_TRUE(infobar_delegate_0);
601 infobar_delegate_0->Accept(); 601 infobar_delegate_0->Accept();
602 CheckPermissionMessageSentForTab(0, 0, true); 602 CheckPermissionMessageSentForTab(0, 0, true);
603 infobar_manager_for_tab(0)->RemoveInfoBar(infobar_0); 603 infobar_service_for_tab(0)->RemoveInfoBar(infobar_0);
604 EXPECT_EQ(2U, closed_infobar_tracker_.size()); 604 EXPECT_EQ(2U, closed_infobar_tracker_.size());
605 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); 605 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
606 // Now the infobar for the tab with the same origin should have gone. 606 // Now the infobar for the tab with the same origin should have gone.
607 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 607 EXPECT_EQ(0U, infobar_service()->infobar_count());
608 CheckPermissionMessageSent(0, true); 608 CheckPermissionMessageSent(0, true);
609 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); 609 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar));
610 closed_infobar_tracker_.Clear(); 610 closed_infobar_tracker_.Clear();
611 611
612 // And we should have the queued infobar displayed now. 612 // And we should have the queued infobar displayed now.
613 ASSERT_EQ(1U, infobar_manager_for_tab(0)->infobar_count()); 613 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
614 614
615 // Accept the second infobar. 615 // Accept the second infobar.
616 InfoBar* infobar_1 = infobar_manager_for_tab(0)->infobar_at(0); 616 InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0);
617 ConfirmInfoBarDelegate* infobar_delegate_1 = 617 ConfirmInfoBarDelegate* infobar_delegate_1 =
618 infobar_1->delegate()->AsConfirmInfoBarDelegate(); 618 infobar_1->delegate()->AsConfirmInfoBarDelegate();
619 ASSERT_TRUE(infobar_delegate_1); 619 ASSERT_TRUE(infobar_delegate_1);
620 infobar_delegate_1->Accept(); 620 infobar_delegate_1->Accept();
621 CheckPermissionMessageSentForTab(0, 1, true); 621 CheckPermissionMessageSentForTab(0, 1, true);
622 infobar_manager_for_tab(0)->RemoveInfoBar(infobar_1); 622 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1);
623 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 623 EXPECT_EQ(1U, closed_infobar_tracker_.size());
624 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); 624 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
625 } 625 }
626 626
627 #if defined(THREAD_SANITIZER) 627 #if defined(THREAD_SANITIZER)
628 // This test crashes under ThreadSanitizer v2, which builds with libc++. 628 // This test crashes under ThreadSanitizer v2, which builds with libc++.
629 // See http://crbug.com/358707. 629 // See http://crbug.com/358707.
630 #define MAYBE_TabDestroyed DISABLED_TabDestroyed 630 #define MAYBE_TabDestroyed DISABLED_TabDestroyed
631 #else 631 #else
632 #define MAYBE_TabDestroyed TabDestroyed 632 #define MAYBE_TabDestroyed TabDestroyed
633 #endif 633 #endif
634 TEST_F(GeolocationPermissionContextTests, MAYBE_TabDestroyed) { 634 TEST_F(GeolocationPermissionContextTests, MAYBE_TabDestroyed) {
635 GURL requesting_frame_0("http://www.example.com/geolocation"); 635 GURL requesting_frame_0("http://www.example.com/geolocation");
636 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 636 GURL requesting_frame_1("http://www.example-2.com/geolocation");
637 EXPECT_EQ(CONTENT_SETTING_ASK, 637 EXPECT_EQ(CONTENT_SETTING_ASK,
638 profile()->GetHostContentSettingsMap()->GetContentSetting( 638 profile()->GetHostContentSettingsMap()->GetContentSetting(
639 requesting_frame_0, requesting_frame_0, 639 requesting_frame_0, requesting_frame_0,
640 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 640 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
641 641
642 EXPECT_EQ(CONTENT_SETTING_ASK, 642 EXPECT_EQ(CONTENT_SETTING_ASK,
643 profile()->GetHostContentSettingsMap()->GetContentSetting( 643 profile()->GetHostContentSettingsMap()->GetContentSetting(
644 requesting_frame_1, requesting_frame_0, 644 requesting_frame_1, requesting_frame_0,
645 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 645 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
646 646
647 NavigateAndCommit(requesting_frame_0); 647 NavigateAndCommit(requesting_frame_0);
648 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 648 EXPECT_EQ(0U, infobar_service()->infobar_count());
649 // Request permission for two frames. 649 // Request permission for two frames.
650 RequestGeolocationPermission(RequestID(0), requesting_frame_0); 650 RequestGeolocationPermission(RequestID(0), requesting_frame_0);
651 RequestGeolocationPermission(RequestID(1), requesting_frame_1); 651 RequestGeolocationPermission(RequestID(1), requesting_frame_1);
652 // Ensure only one infobar is created. 652 // Ensure only one infobar is created.
653 ASSERT_EQ(1U, infobar_manager()->infobar_count()); 653 ASSERT_EQ(1U, infobar_service()->infobar_count());
654 InfoBar* infobar = infobar_manager()->infobar_at(0); 654 InfoBar* infobar = infobar_service()->infobar_at(0);
655 655
656 // Delete the tab contents. 656 // Delete the tab contents.
657 DeleteContents(); 657 DeleteContents();
658 658
659 // During contents destruction, the infobar will have been closed, and the 659 // During contents destruction, the infobar will have been closed, and the
660 // pending request should have been cleared without an infobar being created. 660 // pending request should have been cleared without an infobar being created.
661 ASSERT_EQ(1U, closed_infobar_tracker_.size()); 661 ASSERT_EQ(1U, closed_infobar_tracker_.size());
662 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); 662 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar));
663 } 663 }
664 664
665 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { 665 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) {
666 GURL requesting_frame_0("http://www.example.com/geolocation"); 666 GURL requesting_frame_0("http://www.example.com/geolocation");
667 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 667 GURL requesting_frame_1("http://www.example-2.com/geolocation");
668 NavigateAndCommit(requesting_frame_0); 668 NavigateAndCommit(requesting_frame_0);
669 NavigateAndCommit(requesting_frame_1); 669 NavigateAndCommit(requesting_frame_1);
670 EXPECT_EQ(0U, infobar_manager()->infobar_count()); 670 EXPECT_EQ(0U, infobar_service()->infobar_count());
671 // Go back: navigate to a pending entry before requesting geolocation 671 // Go back: navigate to a pending entry before requesting geolocation
672 // permission. 672 // permission.
673 web_contents()->GetController().GoBack(); 673 web_contents()->GetController().GoBack();
674 // Request permission for the committed frame (not the pending one). 674 // Request permission for the committed frame (not the pending one).
675 RequestGeolocationPermission(RequestID(0), requesting_frame_1); 675 RequestGeolocationPermission(RequestID(0), requesting_frame_1);
676 // Ensure the infobar is created. 676 // Ensure the infobar is created.
677 ASSERT_EQ(1U, infobar_manager()->infobar_count()); 677 ASSERT_EQ(1U, infobar_service()->infobar_count());
678 InfoBarDelegate* infobar_delegate = 678 InfoBarDelegate* infobar_delegate =
679 infobar_manager()->infobar_at(0)->delegate(); 679 infobar_service()->infobar_at(0)->delegate();
680 ASSERT_TRUE(infobar_delegate); 680 ASSERT_TRUE(infobar_delegate);
681 // Ensure the infobar wouldn't expire for a navigation to the committed entry. 681 // Ensure the infobar wouldn't expire for a navigation to the committed entry.
682 content::LoadCommittedDetails details; 682 content::LoadCommittedDetails details;
683 details.entry = web_contents()->GetController().GetLastCommittedEntry(); 683 details.entry = web_contents()->GetController().GetLastCommittedEntry();
684 EXPECT_FALSE(infobar_delegate->ShouldExpire( 684 EXPECT_FALSE(infobar_delegate->ShouldExpire(
685 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details))); 685 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details)));
686 // Ensure the infobar will expire when we commit the pending navigation. 686 // Ensure the infobar will expire when we commit the pending navigation.
687 details.entry = web_contents()->GetController().GetActiveEntry(); 687 details.entry = web_contents()->GetController().GetActiveEntry();
688 EXPECT_TRUE(infobar_delegate->ShouldExpire( 688 EXPECT_TRUE(infobar_delegate->ShouldExpire(
689 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details))); 689 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details)));
690 690
691 // Delete the tab contents. 691 // Delete the tab contents.
692 DeleteContents(); 692 DeleteContents();
693 } 693 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698