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

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

Issue 1459793002: Android: Allow compiling browser without Java UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years 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
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/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/command_line.h" 12 #include "base/command_line.h"
13 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/id_map.h" 15 #include "base/id_map.h"
16 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
17 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
18 #include "base/test/simple_test_clock.h" 18 #include "base/test/simple_test_clock.h"
19 #include "base/time/clock.h" 19 #include "base/time/clock.h"
20 #include "chrome/browser/chrome_notification_types.h" 20 #include "chrome/browser/chrome_notification_types.h"
21 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 21 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
22 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 22 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
23 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" 23 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
24 #include "chrome/browser/infobars/infobar_service.h" 24 #include "chrome/browser/infobars/infobar_service.h"
25 #include "chrome/browser/permissions/permission_request_id.h" 25 #include "chrome/browser/permissions/permission_request_id.h"
26 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" 26 #include "chrome/browser/ui/website_settings/permission_bubble_request.h"
27 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/features.h"
28 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 29 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
29 #include "chrome/test/base/testing_profile.h" 30 #include "chrome/test/base/testing_profile.h"
30 #include "components/content_settings/core/browser/host_content_settings_map.h" 31 #include "components/content_settings/core/browser/host_content_settings_map.h"
31 #include "components/infobars/core/confirm_infobar_delegate.h" 32 #include "components/infobars/core/confirm_infobar_delegate.h"
32 #include "components/infobars/core/infobar.h" 33 #include "components/infobars/core/infobar.h"
33 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
34 #include "content/public/browser/navigation_details.h" 35 #include "content/public/browser/navigation_details.h"
35 #include "content/public/browser/navigation_entry.h" 36 #include "content/public/browser/navigation_entry.h"
36 #include "content/public/browser/notification_observer.h" 37 #include "content/public/browser/notification_observer.h"
37 #include "content/public/browser/notification_registrar.h" 38 #include "content/public/browser/notification_registrar.h"
38 #include "content/public/browser/notification_service.h" 39 #include "content/public/browser/notification_service.h"
39 #include "content/public/browser/render_frame_host.h" 40 #include "content/public/browser/render_frame_host.h"
40 #include "content/public/browser/web_contents.h" 41 #include "content/public/browser/web_contents.h"
41 #include "content/public/test/mock_render_process_host.h" 42 #include "content/public/test/mock_render_process_host.h"
42 #include "content/public/test/test_renderer_host.h" 43 #include "content/public/test/test_renderer_host.h"
43 #include "content/public/test/test_utils.h" 44 #include "content/public/test/test_utils.h"
44 #include "content/public/test/web_contents_tester.h" 45 #include "content/public/test/web_contents_tester.h"
45 #include "testing/gtest/include/gtest/gtest.h" 46 #include "testing/gtest/include/gtest/gtest.h"
46 47
47 #if defined(OS_ANDROID) 48 #if BUILDFLAG(ANDROID_JAVA_UI)
48 #include "base/prefs/pref_service.h" 49 #include "base/prefs/pref_service.h"
49 #include "chrome/browser/android/mock_location_settings.h" 50 #include "chrome/browser/android/mock_location_settings.h"
50 #include "chrome/browser/geolocation/geolocation_permission_context_android.h" 51 #include "chrome/browser/geolocation/geolocation_permission_context_android.h"
51 #else 52 #else
52 #include "chrome/browser/ui/website_settings/mock_permission_bubble_view.h" 53 #include "chrome/browser/ui/website_settings/mock_permission_bubble_view.h"
53 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 54 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
54 #endif 55 #endif
55 56
56 #if defined(ENABLE_EXTENSIONS) 57 #if defined(ENABLE_EXTENSIONS)
57 #include "extensions/browser/view_type_utils.h" 58 #include "extensions/browser/view_type_utils.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 void PermissionResponse(const PermissionRequestID& id, 137 void PermissionResponse(const PermissionRequestID& id,
137 ContentSetting content_setting); 138 ContentSetting content_setting);
138 void CheckPermissionMessageSent(int request_id, bool allowed); 139 void CheckPermissionMessageSent(int request_id, bool allowed);
139 void CheckPermissionMessageSentForTab(int tab, int request_id, bool allowed); 140 void CheckPermissionMessageSentForTab(int tab, int request_id, bool allowed);
140 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, 141 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process,
141 int request_id, 142 int request_id,
142 bool allowed); 143 bool allowed);
143 void AddNewTab(const GURL& url); 144 void AddNewTab(const GURL& url);
144 void CheckTabContentsState(const GURL& requesting_frame, 145 void CheckTabContentsState(const GURL& requesting_frame,
145 ContentSetting expected_content_setting); 146 ContentSetting expected_content_setting);
146 #if !defined(OS_ANDROID) 147 #if !BUILDFLAG(ANDROID_JAVA_UI)
147 size_t GetBubblesQueueSize(PermissionBubbleManager* manager); 148 size_t GetBubblesQueueSize(PermissionBubbleManager* manager);
148 void AcceptBubble(PermissionBubbleManager* manager); 149 void AcceptBubble(PermissionBubbleManager* manager);
149 void DenyBubble(PermissionBubbleManager* manager); 150 void DenyBubble(PermissionBubbleManager* manager);
150 void CloseBubble(PermissionBubbleManager* manager); 151 void CloseBubble(PermissionBubbleManager* manager);
151 #endif 152 #endif
152 void BubbleManagerDocumentLoadCompleted(); 153 void BubbleManagerDocumentLoadCompleted();
153 void BubbleManagerDocumentLoadCompleted(content::WebContents* web_contents); 154 void BubbleManagerDocumentLoadCompleted(content::WebContents* web_contents);
154 ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1); 155 ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1);
155 size_t GetNumberOfPrompts(); 156 size_t GetNumberOfPrompts();
156 void AcceptPrompt(); 157 void AcceptPrompt();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 new_tab->GetController().LoadURL( 233 new_tab->GetController().LoadURL(
233 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 234 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
234 content::NavigationEntry* entry = new_tab->GetController().GetPendingEntry(); 235 content::NavigationEntry* entry = new_tab->GetController().GetPendingEntry();
235 content::RenderFrameHostTester::For(new_tab->GetMainFrame()) 236 content::RenderFrameHostTester::For(new_tab->GetMainFrame())
236 ->SendNavigate(extra_tabs_.size() + 1, entry->GetUniqueID(), true, url); 237 ->SendNavigate(extra_tabs_.size() + 1, entry->GetUniqueID(), true, url);
237 238
238 // Set up required helpers, and make this be as "tabby" as the code requires. 239 // Set up required helpers, and make this be as "tabby" as the code requires.
239 #if defined(ENABLE_EXTENSIONS) 240 #if defined(ENABLE_EXTENSIONS)
240 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS); 241 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS);
241 #endif 242 #endif
242 #if defined(OS_ANDROID) 243 #if BUILDFLAG(ANDROID_JAVA_UI)
243 InfoBarService::CreateForWebContents(new_tab); 244 InfoBarService::CreateForWebContents(new_tab);
244 #else 245 #else
245 PermissionBubbleManager::CreateForWebContents(new_tab); 246 PermissionBubbleManager::CreateForWebContents(new_tab);
246 PermissionBubbleManager* permission_bubble_manager = 247 PermissionBubbleManager* permission_bubble_manager =
247 PermissionBubbleManager::FromWebContents(new_tab); 248 PermissionBubbleManager::FromWebContents(new_tab);
248 MockPermissionBubbleView::SetFactory(permission_bubble_manager, false); 249 MockPermissionBubbleView::SetFactory(permission_bubble_manager, false);
249 permission_bubble_manager->DisplayPendingRequests(); 250 permission_bubble_manager->DisplayPendingRequests();
250 #endif 251 #endif
251 252
252 extra_tabs_.push_back(new_tab); 253 extra_tabs_.push_back(new_tab);
(...skipping 19 matching lines...) Expand all
272 ChromeRenderViewHostTestHarness::SetUp(); 273 ChromeRenderViewHostTestHarness::SetUp();
273 274
274 // Set up required helpers, and make this be as "tabby" as the code requires. 275 // Set up required helpers, and make this be as "tabby" as the code requires.
275 #if defined(ENABLE_EXTENSIONS) 276 #if defined(ENABLE_EXTENSIONS)
276 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); 277 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS);
277 #endif 278 #endif
278 InfoBarService::CreateForWebContents(web_contents()); 279 InfoBarService::CreateForWebContents(web_contents());
279 TabSpecificContentSettings::CreateForWebContents(web_contents()); 280 TabSpecificContentSettings::CreateForWebContents(web_contents());
280 geolocation_permission_context_ = 281 geolocation_permission_context_ =
281 GeolocationPermissionContextFactory::GetForProfile(profile()); 282 GeolocationPermissionContextFactory::GetForProfile(profile());
282 #if defined(OS_ANDROID) 283 #if BUILDFLAG(ANDROID_JAVA_UI)
283 static_cast<GeolocationPermissionContextAndroid*>( 284 static_cast<GeolocationPermissionContextAndroid*>(
284 geolocation_permission_context_) 285 geolocation_permission_context_)
285 ->SetLocationSettingsForTesting( 286 ->SetLocationSettingsForTesting(
286 scoped_ptr<LocationSettings>(new MockLocationSettings())); 287 scoped_ptr<LocationSettings>(new MockLocationSettings()));
287 MockLocationSettings::SetLocationStatus(true, true); 288 MockLocationSettings::SetLocationStatus(true, true);
288 #else 289 #else
289 PermissionBubbleManager::CreateForWebContents(web_contents()); 290 PermissionBubbleManager::CreateForWebContents(web_contents());
290 PermissionBubbleManager* permission_bubble_manager = 291 PermissionBubbleManager* permission_bubble_manager =
291 PermissionBubbleManager::FromWebContents(web_contents()); 292 PermissionBubbleManager::FromWebContents(web_contents());
292 MockPermissionBubbleView::SetFactory(permission_bubble_manager, false); 293 MockPermissionBubbleView::SetFactory(permission_bubble_manager, false);
293 permission_bubble_manager->DisplayPendingRequests(); 294 permission_bubble_manager->DisplayPendingRequests();
294 #endif 295 #endif
295 } 296 }
296 297
297 void GeolocationPermissionContextTests::TearDown() { 298 void GeolocationPermissionContextTests::TearDown() {
298 extra_tabs_.clear(); 299 extra_tabs_.clear();
299 ChromeRenderViewHostTestHarness::TearDown(); 300 ChromeRenderViewHostTestHarness::TearDown();
300 } 301 }
301 302
302 #if !defined(OS_ANDROID) 303 #if !BUILDFLAG(ANDROID_JAVA_UI)
303 size_t GeolocationPermissionContextTests::GetBubblesQueueSize( 304 size_t GeolocationPermissionContextTests::GetBubblesQueueSize(
304 PermissionBubbleManager* manager) { 305 PermissionBubbleManager* manager) {
305 return manager->requests_.size(); 306 return manager->requests_.size();
306 } 307 }
307 308
308 void GeolocationPermissionContextTests::AcceptBubble( 309 void GeolocationPermissionContextTests::AcceptBubble(
309 PermissionBubbleManager* manager) { 310 PermissionBubbleManager* manager) {
310 manager->Accept(); 311 manager->Accept();
311 } 312 }
312 313
313 void GeolocationPermissionContextTests::DenyBubble( 314 void GeolocationPermissionContextTests::DenyBubble(
314 PermissionBubbleManager* manager) { 315 PermissionBubbleManager* manager) {
315 manager->Deny(); 316 manager->Deny();
316 } 317 }
317 318
318 void GeolocationPermissionContextTests::CloseBubble( 319 void GeolocationPermissionContextTests::CloseBubble(
319 PermissionBubbleManager* manager) { 320 PermissionBubbleManager* manager) {
320 manager->Closing(); 321 manager->Closing();
321 } 322 }
322 #endif 323 #endif
323 324
324 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted() { 325 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted() {
325 GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted( 326 GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted(
326 web_contents()); 327 web_contents());
327 } 328 }
328 329
329 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted( 330 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted(
330 content::WebContents* web_contents) { 331 content::WebContents* web_contents) {
331 #if !defined(OS_ANDROID) 332 #if !BUILDFLAG(ANDROID_JAVA_UI)
332 PermissionBubbleManager::FromWebContents(web_contents)-> 333 PermissionBubbleManager::FromWebContents(web_contents)->
333 DocumentOnLoadCompletedInMainFrame(); 334 DocumentOnLoadCompletedInMainFrame();
334 #endif 335 #endif
335 } 336 }
336 337
337 ContentSetting GeolocationPermissionContextTests::GetGeolocationContentSetting( 338 ContentSetting GeolocationPermissionContextTests::GetGeolocationContentSetting(
338 GURL frame_0, GURL frame_1) { 339 GURL frame_0, GURL frame_1) {
339 return HostContentSettingsMapFactory::GetForProfile(profile()) 340 return HostContentSettingsMapFactory::GetForProfile(profile())
340 ->GetContentSetting(frame_0, 341 ->GetContentSetting(frame_0,
341 frame_1, 342 frame_1,
342 CONTENT_SETTINGS_TYPE_GEOLOCATION, 343 CONTENT_SETTINGS_TYPE_GEOLOCATION,
343 std::string()); 344 std::string());
344 } 345 }
345 346
346 size_t GeolocationPermissionContextTests::GetNumberOfPrompts() { 347 size_t GeolocationPermissionContextTests::GetNumberOfPrompts() {
347 #if !defined(OS_ANDROID) 348 #if !BUILDFLAG(ANDROID_JAVA_UI)
348 PermissionBubbleManager* manager = 349 PermissionBubbleManager* manager =
349 PermissionBubbleManager::FromWebContents(web_contents()); 350 PermissionBubbleManager::FromWebContents(web_contents());
350 return GetBubblesQueueSize(manager); 351 return GetBubblesQueueSize(manager);
351 #else 352 #else
352 return infobar_service()->infobar_count(); 353 return infobar_service()->infobar_count();
353 #endif 354 #endif
354 } 355 }
355 356
356 void GeolocationPermissionContextTests::AcceptPrompt() { 357 void GeolocationPermissionContextTests::AcceptPrompt() {
357 #if !defined(OS_ANDROID) 358 #if !BUILDFLAG(ANDROID_JAVA_UI)
358 PermissionBubbleManager* manager = 359 PermissionBubbleManager* manager =
359 PermissionBubbleManager::FromWebContents(web_contents()); 360 PermissionBubbleManager::FromWebContents(web_contents());
360 AcceptBubble(manager); 361 AcceptBubble(manager);
361 #else 362 #else
362 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 363 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
363 ConfirmInfoBarDelegate* infobar_delegate = 364 ConfirmInfoBarDelegate* infobar_delegate =
364 infobar->delegate()->AsConfirmInfoBarDelegate(); 365 infobar->delegate()->AsConfirmInfoBarDelegate();
365 infobar_delegate->Accept(); 366 infobar_delegate->Accept();
366 #endif 367 #endif
367 } 368 }
368 369
369 base::string16 GeolocationPermissionContextTests::GetPromptText() { 370 base::string16 GeolocationPermissionContextTests::GetPromptText() {
370 #if !defined(OS_ANDROID) 371 #if !BUILDFLAG(ANDROID_JAVA_UI)
371 PermissionBubbleManager* manager = 372 PermissionBubbleManager* manager =
372 PermissionBubbleManager::FromWebContents(web_contents()); 373 PermissionBubbleManager::FromWebContents(web_contents());
373 return manager->requests_.front()->GetMessageText(); 374 return manager->requests_.front()->GetMessageText();
374 #else 375 #else
375 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 376 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
376 ConfirmInfoBarDelegate* infobar_delegate = 377 ConfirmInfoBarDelegate* infobar_delegate =
377 infobar->delegate()->AsConfirmInfoBarDelegate(); 378 infobar->delegate()->AsConfirmInfoBarDelegate();
378 return infobar_delegate->GetMessageText(); 379 return infobar_delegate->GetMessageText();
379 #endif 380 #endif
380 } 381 }
381 382
382 // Tests ---------------------------------------------------------------------- 383 // Tests ----------------------------------------------------------------------
383 384
384 TEST_F(GeolocationPermissionContextTests, SinglePermissionBubble) { 385 TEST_F(GeolocationPermissionContextTests, SinglePermissionBubble) {
385 GURL requesting_frame("http://www.example.com/geolocation"); 386 GURL requesting_frame("http://www.example.com/geolocation");
386 NavigateAndCommit(requesting_frame); 387 NavigateAndCommit(requesting_frame);
387 BubbleManagerDocumentLoadCompleted(); 388 BubbleManagerDocumentLoadCompleted();
388 389
389 EXPECT_EQ(0U, GetNumberOfPrompts()); 390 EXPECT_EQ(0U, GetNumberOfPrompts());
390 RequestGeolocationPermission( 391 RequestGeolocationPermission(
391 web_contents(), RequestID(0), requesting_frame, true); 392 web_contents(), RequestID(0), requesting_frame, true);
392 ASSERT_EQ(1U, GetNumberOfPrompts()); 393 ASSERT_EQ(1U, GetNumberOfPrompts());
393 } 394 }
394 395
395 #if defined(OS_ANDROID) 396 #if BUILDFLAG(ANDROID_JAVA_UI)
396 TEST_F(GeolocationPermissionContextTests, SinglePermissionInfobar) { 397 TEST_F(GeolocationPermissionContextTests, SinglePermissionInfobar) {
397 GURL requesting_frame("http://www.example.com/geolocation"); 398 GURL requesting_frame("http://www.example.com/geolocation");
398 NavigateAndCommit(requesting_frame); 399 NavigateAndCommit(requesting_frame);
399 EXPECT_EQ(0U, infobar_service()->infobar_count()); 400 EXPECT_EQ(0U, infobar_service()->infobar_count());
400 RequestGeolocationPermission( 401 RequestGeolocationPermission(
401 web_contents(), RequestID(0), requesting_frame, true); 402 web_contents(), RequestID(0), requesting_frame, true);
402 ASSERT_EQ(1U, infobar_service()->infobar_count()); 403 ASSERT_EQ(1U, infobar_service()->infobar_count());
403 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 404 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
404 ConfirmInfoBarDelegate* infobar_delegate = 405 ConfirmInfoBarDelegate* infobar_delegate =
405 infobar->delegate()->AsConfirmInfoBarDelegate(); 406 infobar->delegate()->AsConfirmInfoBarDelegate();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 web_contents(), RequestID(1), requesting_frame_1, true); 484 web_contents(), RequestID(1), requesting_frame_1, true);
484 // Ensure only one infobar is created. 485 // Ensure only one infobar is created.
485 ASSERT_EQ(1U, GetNumberOfPrompts()); 486 ASSERT_EQ(1U, GetNumberOfPrompts());
486 base::string16 text_0 = GetPromptText(); 487 base::string16 text_0 = GetPromptText();
487 488
488 // Accept the first frame. 489 // Accept the first frame.
489 AcceptPrompt(); 490 AcceptPrompt();
490 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); 491 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
491 CheckPermissionMessageSent(0, true); 492 CheckPermissionMessageSent(0, true);
492 493
493 #if defined(OS_ANDROID) 494 #if BUILDFLAG(ANDROID_JAVA_UI)
494 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); 495 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0);
495 infobar_service()->RemoveInfoBar(infobar_0); 496 infobar_service()->RemoveInfoBar(infobar_0);
496 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 497 EXPECT_EQ(1U, closed_infobar_tracker_.size());
497 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); 498 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
498 closed_infobar_tracker_.Clear(); 499 closed_infobar_tracker_.Clear();
499 #endif 500 #endif
500 501
501 // Now we should have a new infobar for the second frame. 502 // Now we should have a new infobar for the second frame.
502 ASSERT_EQ(1U, GetNumberOfPrompts()); 503 ASSERT_EQ(1U, GetNumberOfPrompts());
503 base::string16 text_1 = GetPromptText(); 504 base::string16 text_1 = GetPromptText();
504 505
505 // Check that the messages differ. 506 // Check that the messages differ.
506 EXPECT_NE(text_0, text_1); 507 EXPECT_NE(text_0, text_1);
507 508
508 // Cancel (block) this frame. 509 // Cancel (block) this frame.
509 #if !defined(OS_ANDROID) 510 #if !BUILDFLAG(ANDROID_JAVA_UI)
510 PermissionBubbleManager* manager = 511 PermissionBubbleManager* manager =
511 PermissionBubbleManager::FromWebContents(web_contents()); 512 PermissionBubbleManager::FromWebContents(web_contents());
512 DenyBubble(manager); 513 DenyBubble(manager);
513 #else 514 #else
514 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); 515 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0);
515 infobar_1->delegate()->AsConfirmInfoBarDelegate()->Cancel(); 516 infobar_1->delegate()->AsConfirmInfoBarDelegate()->Cancel();
516 #endif 517 #endif
517 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); 518 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK);
518 CheckPermissionMessageSent(1, false); 519 CheckPermissionMessageSent(1, false);
519 520
520 // Ensure the persisted permissions are ok. 521 // Ensure the persisted permissions are ok.
521 EXPECT_EQ( 522 EXPECT_EQ(
522 CONTENT_SETTING_ALLOW, 523 CONTENT_SETTING_ALLOW,
523 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); 524 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0));
524 EXPECT_EQ( 525 EXPECT_EQ(
525 CONTENT_SETTING_BLOCK, 526 CONTENT_SETTING_BLOCK,
526 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); 527 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0));
527 } 528 }
528 529
529 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { 530 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) {
530 GURL url_a("http://www.example.com/geolocation#a"); 531 GURL url_a("http://www.example.com/geolocation#a");
531 GURL url_b("http://www.example.com/geolocation#b"); 532 GURL url_b("http://www.example.com/geolocation#b");
532 533
533 // Navigate to the first url. 534 // Navigate to the first url.
534 NavigateAndCommit(url_a); 535 NavigateAndCommit(url_a);
535 BubbleManagerDocumentLoadCompleted(); 536 BubbleManagerDocumentLoadCompleted();
536 537
537 // Check permission is requested. 538 // Check permission is requested.
538 ASSERT_EQ(0U, GetNumberOfPrompts()); 539 ASSERT_EQ(0U, GetNumberOfPrompts());
539 #if defined(OS_ANDROID) 540 #if BUILDFLAG(ANDROID_JAVA_UI)
540 const bool user_gesture = false; 541 const bool user_gesture = false;
541 #else 542 #else
542 const bool user_gesture = true; 543 const bool user_gesture = true;
543 #endif 544 #endif
544 RequestGeolocationPermission(web_contents(), RequestID(0), url_a, 545 RequestGeolocationPermission(web_contents(), RequestID(0), url_a,
545 user_gesture); 546 user_gesture);
546 ASSERT_EQ(1U, GetNumberOfPrompts()); 547 ASSERT_EQ(1U, GetNumberOfPrompts());
547 548
548 // Change the hash, we'll still be on the same page. 549 // Change the hash, we'll still be on the same page.
549 NavigateAndCommit(url_b); 550 NavigateAndCommit(url_b);
550 BubbleManagerDocumentLoadCompleted(); 551 BubbleManagerDocumentLoadCompleted();
551 552
552 // Accept. 553 // Accept.
553 AcceptPrompt(); 554 AcceptPrompt();
554 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); 555 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW);
555 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); 556 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW);
556 CheckPermissionMessageSent(0, true); 557 CheckPermissionMessageSent(0, true);
557 558
558 // Cleanup. 559 // Cleanup.
559 #if defined(OS_ANDROID) 560 #if BUILDFLAG(ANDROID_JAVA_UI)
560 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 561 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
561 infobar_service()->RemoveInfoBar(infobar); 562 infobar_service()->RemoveInfoBar(infobar);
562 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 563 EXPECT_EQ(1U, closed_infobar_tracker_.size());
563 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); 564 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
564 #endif 565 #endif
565 } 566 }
566 567
567 // TODO(felt): The bubble is rejecting file:// permission requests. 568 // TODO(felt): The bubble is rejecting file:// permission requests.
568 // Fix and enable this test. crbug.com/444047 569 // Fix and enable this test. crbug.com/444047
569 #if defined(OS_ANDROID) 570 #if BUILDFLAG(ANDROID_JAVA_UI)
570 #define MAYBE_PermissionForFileScheme PermissionForFileScheme 571 #define MAYBE_PermissionForFileScheme PermissionForFileScheme
571 #else 572 #else
572 #define MAYBE_PermissionForFileScheme DISABLED_PermissionForFileScheme 573 #define MAYBE_PermissionForFileScheme DISABLED_PermissionForFileScheme
573 #endif 574 #endif
574 TEST_F(GeolocationPermissionContextTests, MAYBE_PermissionForFileScheme) { 575 TEST_F(GeolocationPermissionContextTests, MAYBE_PermissionForFileScheme) {
575 GURL requesting_frame("file://example/geolocation.html"); 576 GURL requesting_frame("file://example/geolocation.html");
576 NavigateAndCommit(requesting_frame); 577 NavigateAndCommit(requesting_frame);
577 BubbleManagerDocumentLoadCompleted(); 578 BubbleManagerDocumentLoadCompleted();
578 579
579 // Check permission is requested. 580 // Check permission is requested.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 web_contents(), RequestID(0), frame_0, true); 612 web_contents(), RequestID(0), frame_0, true);
612 RequestGeolocationPermission( 613 RequestGeolocationPermission(
613 web_contents(), RequestID(1), frame_1, true); 614 web_contents(), RequestID(1), frame_1, true);
614 615
615 // Get the first permission request text. 616 // Get the first permission request text.
616 ASSERT_EQ(1U, GetNumberOfPrompts()); 617 ASSERT_EQ(1U, GetNumberOfPrompts());
617 base::string16 text_0 = GetPromptText(); 618 base::string16 text_0 = GetPromptText();
618 ASSERT_FALSE(text_0.empty()); 619 ASSERT_FALSE(text_0.empty());
619 620
620 // Simulate the frame going away; the request should be removed. 621 // Simulate the frame going away; the request should be removed.
621 #if !defined(OS_ANDROID) 622 #if !BUILDFLAG(ANDROID_JAVA_UI)
622 PermissionBubbleManager* manager = 623 PermissionBubbleManager* manager =
623 PermissionBubbleManager::FromWebContents(web_contents()); 624 PermissionBubbleManager::FromWebContents(web_contents());
624 CloseBubble(manager); 625 CloseBubble(manager);
625 #else 626 #else
626 geolocation_permission_context_->CancelPermissionRequest(web_contents(), 627 geolocation_permission_context_->CancelPermissionRequest(web_contents(),
627 RequestID(0)); 628 RequestID(0));
628 #endif 629 #endif
629 630
630 // Check that the next pending request is created correctly. 631 // Check that the next pending request is created correctly.
631 base::string16 text_1 = GetPromptText(); 632 base::string16 text_1 = GetPromptText();
(...skipping 28 matching lines...) Expand all
660 661
661 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { 662 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
662 GURL url_a("http://www.example.com/geolocation"); 663 GURL url_a("http://www.example.com/geolocation");
663 GURL url_b("http://www.example-2.com/geolocation"); 664 GURL url_b("http://www.example-2.com/geolocation");
664 NavigateAndCommit(url_a); // Tab A0 665 NavigateAndCommit(url_a); // Tab A0
665 AddNewTab(url_b); // Tab B (extra_tabs_[0]) 666 AddNewTab(url_b); // Tab B (extra_tabs_[0])
666 AddNewTab(url_a); // Tab A1 (extra_tabs_[1]) 667 AddNewTab(url_a); // Tab A1 (extra_tabs_[1])
667 BubbleManagerDocumentLoadCompleted(); 668 BubbleManagerDocumentLoadCompleted();
668 BubbleManagerDocumentLoadCompleted(extra_tabs_[0]); 669 BubbleManagerDocumentLoadCompleted(extra_tabs_[0]);
669 BubbleManagerDocumentLoadCompleted(extra_tabs_[1]); 670 BubbleManagerDocumentLoadCompleted(extra_tabs_[1]);
670 #if !defined(OS_ANDROID) 671 #if !BUILDFLAG(ANDROID_JAVA_UI)
671 PermissionBubbleManager* manager_a0 = 672 PermissionBubbleManager* manager_a0 =
672 PermissionBubbleManager::FromWebContents(web_contents()); 673 PermissionBubbleManager::FromWebContents(web_contents());
673 PermissionBubbleManager* manager_b = 674 PermissionBubbleManager* manager_b =
674 PermissionBubbleManager::FromWebContents(extra_tabs_[0]); 675 PermissionBubbleManager::FromWebContents(extra_tabs_[0]);
675 PermissionBubbleManager* manager_a1 = 676 PermissionBubbleManager* manager_a1 =
676 PermissionBubbleManager::FromWebContents(extra_tabs_[1]); 677 PermissionBubbleManager::FromWebContents(extra_tabs_[1]);
677 #endif 678 #endif
678 679
679 // Request permission in all three tabs. 680 // Request permission in all three tabs.
680 RequestGeolocationPermission( 681 RequestGeolocationPermission(
681 web_contents(), RequestID(0), url_a, true); 682 web_contents(), RequestID(0), url_a, true);
682 RequestGeolocationPermission( 683 RequestGeolocationPermission(
683 extra_tabs_[0], RequestIDForTab(0, 0), url_b, true); 684 extra_tabs_[0], RequestIDForTab(0, 0), url_b, true);
684 RequestGeolocationPermission( 685 RequestGeolocationPermission(
685 extra_tabs_[1], RequestIDForTab(1, 0), url_a, true); 686 extra_tabs_[1], RequestIDForTab(1, 0), url_a, true);
686 ASSERT_EQ(1U, GetNumberOfPrompts()); // For A0. 687 ASSERT_EQ(1U, GetNumberOfPrompts()); // For A0.
687 #if !defined(OS_ANDROID) 688 #if !BUILDFLAG(ANDROID_JAVA_UI)
688 ASSERT_EQ(1U, GetBubblesQueueSize(manager_b)); 689 ASSERT_EQ(1U, GetBubblesQueueSize(manager_b));
689 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); 690 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1));
690 #else 691 #else
691 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 692 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
692 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); 693 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count());
693 #endif 694 #endif
694 695
695 // Accept the permission in tab A0. 696 // Accept the permission in tab A0.
696 #if !defined(OS_ANDROID) 697 #if !BUILDFLAG(ANDROID_JAVA_UI)
697 AcceptBubble(manager_a0); 698 AcceptBubble(manager_a0);
698 #else 699 #else
699 infobars::InfoBar* infobar_a0 = infobar_service()->infobar_at(0); 700 infobars::InfoBar* infobar_a0 = infobar_service()->infobar_at(0);
700 ConfirmInfoBarDelegate* infobar_delegate_a0 = 701 ConfirmInfoBarDelegate* infobar_delegate_a0 =
701 infobar_a0->delegate()->AsConfirmInfoBarDelegate(); 702 infobar_a0->delegate()->AsConfirmInfoBarDelegate();
702 ASSERT_TRUE(infobar_delegate_a0); 703 ASSERT_TRUE(infobar_delegate_a0);
703 infobar_delegate_a0->Accept(); 704 infobar_delegate_a0->Accept();
704 infobar_service()->RemoveInfoBar(infobar_a0); 705 infobar_service()->RemoveInfoBar(infobar_a0);
705 EXPECT_EQ(2U, closed_infobar_tracker_.size()); 706 EXPECT_EQ(2U, closed_infobar_tracker_.size());
706 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a0)); 707 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a0));
707 #endif 708 #endif
708 CheckPermissionMessageSent(0, true); 709 CheckPermissionMessageSent(0, true);
709 // Because they're the same origin, this will cause tab A1's infobar to 710 // Because they're the same origin, this will cause tab A1's infobar to
710 // disappear. It does not cause the bubble to disappear: crbug.com/443013. 711 // disappear. It does not cause the bubble to disappear: crbug.com/443013.
711 // TODO(felt): Update this test when the bubble's behavior is changed. 712 // TODO(felt): Update this test when the bubble's behavior is changed.
712 // Either way, tab B should still have a pending permission request. 713 // Either way, tab B should still have a pending permission request.
713 #if !defined(OS_ANDROID) 714 #if !BUILDFLAG(ANDROID_JAVA_UI)
714 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); 715 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1));
715 ASSERT_EQ(1U, GetBubblesQueueSize(manager_b)); 716 ASSERT_EQ(1U, GetBubblesQueueSize(manager_b));
716 #else 717 #else
717 CheckPermissionMessageSentForTab(1, 0, true); 718 CheckPermissionMessageSentForTab(1, 0, true);
718 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 719 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
719 #endif 720 #endif
720 } 721 }
721 722
722 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { 723 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
723 GURL url_a("http://www.example.com/geolocation"); 724 GURL url_a("http://www.example.com/geolocation");
724 GURL url_b("http://www.example-2.com/geolocation"); 725 GURL url_b("http://www.example-2.com/geolocation");
725 NavigateAndCommit(url_a); // Tab A0. 726 NavigateAndCommit(url_a); // Tab A0.
726 AddNewTab(url_a); // Tab A1. 727 AddNewTab(url_a); // Tab A1.
727 #if !defined(OS_ANDROID) 728 #if !BUILDFLAG(ANDROID_JAVA_UI)
728 BubbleManagerDocumentLoadCompleted(); 729 BubbleManagerDocumentLoadCompleted();
729 BubbleManagerDocumentLoadCompleted(extra_tabs_[0]); 730 BubbleManagerDocumentLoadCompleted(extra_tabs_[0]);
730 PermissionBubbleManager* manager_a0 = 731 PermissionBubbleManager* manager_a0 =
731 PermissionBubbleManager::FromWebContents(web_contents()); 732 PermissionBubbleManager::FromWebContents(web_contents());
732 PermissionBubbleManager* manager_a1 = 733 PermissionBubbleManager* manager_a1 =
733 PermissionBubbleManager::FromWebContents(extra_tabs_[0]); 734 PermissionBubbleManager::FromWebContents(extra_tabs_[0]);
734 #endif 735 #endif
735 736
736 // Request permission in both tabs; the extra tab will have two permission 737 // Request permission in both tabs; the extra tab will have two permission
737 // requests from two origins. 738 // requests from two origins.
738 RequestGeolocationPermission( 739 RequestGeolocationPermission(
739 web_contents(), RequestID(0), url_a, true); 740 web_contents(), RequestID(0), url_a, true);
740 RequestGeolocationPermission( 741 RequestGeolocationPermission(
741 extra_tabs_[0], RequestIDForTab(0, 0), url_a, true); 742 extra_tabs_[0], RequestIDForTab(0, 0), url_a, true);
742 RequestGeolocationPermission( 743 RequestGeolocationPermission(
743 extra_tabs_[0], RequestIDForTab(0, 1), url_b, true); 744 extra_tabs_[0], RequestIDForTab(0, 1), url_b, true);
744 #if !defined(OS_ANDROID) 745 #if !BUILDFLAG(ANDROID_JAVA_UI)
745 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a0)); 746 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a0));
746 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); 747 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1));
747 #else 748 #else
748 ASSERT_EQ(1U, infobar_service()->infobar_count()); 749 ASSERT_EQ(1U, infobar_service()->infobar_count());
749 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 750 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
750 #endif 751 #endif
751 752
752 // Accept the first request in tab A1. 753 // Accept the first request in tab A1.
753 #if !defined(OS_ANDROID) 754 #if !BUILDFLAG(ANDROID_JAVA_UI)
754 AcceptBubble(manager_a1); 755 AcceptBubble(manager_a1);
755 #else 756 #else
756 infobars::InfoBar* infobar_a1 = infobar_service_for_tab(0)->infobar_at(0); 757 infobars::InfoBar* infobar_a1 = infobar_service_for_tab(0)->infobar_at(0);
757 ConfirmInfoBarDelegate* infobar_delegate_a1 = 758 ConfirmInfoBarDelegate* infobar_delegate_a1 =
758 infobar_a1->delegate()->AsConfirmInfoBarDelegate(); 759 infobar_a1->delegate()->AsConfirmInfoBarDelegate();
759 ASSERT_TRUE(infobar_delegate_a1); 760 ASSERT_TRUE(infobar_delegate_a1);
760 infobar_delegate_a1->Accept(); 761 infobar_delegate_a1->Accept();
761 infobar_service_for_tab(0)->RemoveInfoBar(infobar_a1); 762 infobar_service_for_tab(0)->RemoveInfoBar(infobar_a1);
762 EXPECT_EQ(2U, closed_infobar_tracker_.size()); 763 EXPECT_EQ(2U, closed_infobar_tracker_.size());
763 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a1)); 764 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a1));
764 #endif 765 #endif
765 CheckPermissionMessageSentForTab(0, 0, true); 766 CheckPermissionMessageSentForTab(0, 0, true);
766 767
767 // Because they're the same origin, this will cause tab A0's infobar to 768 // Because they're the same origin, this will cause tab A0's infobar to
768 // disappear. It does not cause the bubble to disappear: crbug.com/443013. 769 // disappear. It does not cause the bubble to disappear: crbug.com/443013.
769 // TODO(felt): Update this test when the bubble's behavior is changed. 770 // TODO(felt): Update this test when the bubble's behavior is changed.
770 #if !defined(OS_ANDROID) 771 #if !BUILDFLAG(ANDROID_JAVA_UI)
771 EXPECT_EQ(1U, GetBubblesQueueSize(manager_a0)); 772 EXPECT_EQ(1U, GetBubblesQueueSize(manager_a0));
772 #else 773 #else
773 EXPECT_EQ(0U, infobar_service()->infobar_count()); 774 EXPECT_EQ(0U, infobar_service()->infobar_count());
774 CheckPermissionMessageSent(0, true); 775 CheckPermissionMessageSent(0, true);
775 #endif 776 #endif
776 777
777 // The second request should now be visible in tab A1. 778 // The second request should now be visible in tab A1.
778 #if !defined(OS_ANDROID) 779 #if !BUILDFLAG(ANDROID_JAVA_UI)
779 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); 780 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1));
780 #else 781 #else
781 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 782 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
782 #endif 783 #endif
783 784
784 // Accept the second request and check that it's gone. 785 // Accept the second request and check that it's gone.
785 #if !defined(OS_ANDROID) 786 #if !BUILDFLAG(ANDROID_JAVA_UI)
786 AcceptBubble(manager_a1); 787 AcceptBubble(manager_a1);
787 EXPECT_EQ(0U, GetBubblesQueueSize(manager_a1)); 788 EXPECT_EQ(0U, GetBubblesQueueSize(manager_a1));
788 #else 789 #else
789 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); 790 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0);
790 ConfirmInfoBarDelegate* infobar_delegate_1 = 791 ConfirmInfoBarDelegate* infobar_delegate_1 =
791 infobar_1->delegate()->AsConfirmInfoBarDelegate(); 792 infobar_1->delegate()->AsConfirmInfoBarDelegate();
792 ASSERT_TRUE(infobar_delegate_1); 793 ASSERT_TRUE(infobar_delegate_1);
793 infobar_delegate_1->Accept(); 794 infobar_delegate_1->Accept();
794 #endif 795 #endif
795 } 796 }
(...skipping 14 matching lines...) Expand all
810 // Request permission for two frames. 811 // Request permission for two frames.
811 RequestGeolocationPermission( 812 RequestGeolocationPermission(
812 web_contents(), RequestID(0), requesting_frame_0, false); 813 web_contents(), RequestID(0), requesting_frame_0, false);
813 RequestGeolocationPermission( 814 RequestGeolocationPermission(
814 web_contents(), RequestID(1), requesting_frame_1, false); 815 web_contents(), RequestID(1), requesting_frame_1, false);
815 816
816 // Ensure only one prompt is created. 817 // Ensure only one prompt is created.
817 ASSERT_EQ(1U, GetNumberOfPrompts()); 818 ASSERT_EQ(1U, GetNumberOfPrompts());
818 819
819 // Delete the tab contents. 820 // Delete the tab contents.
820 #if defined(OS_ANDROID) 821 #if BUILDFLAG(ANDROID_JAVA_UI)
821 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 822 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
822 DeleteContents(); 823 DeleteContents();
823 ASSERT_EQ(1U, closed_infobar_tracker_.size()); 824 ASSERT_EQ(1U, closed_infobar_tracker_.size());
824 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); 825 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar));
825 #endif 826 #endif
826 827
827 // The content settings should not have changed. 828 // The content settings should not have changed.
828 EXPECT_EQ( 829 EXPECT_EQ(
829 CONTENT_SETTING_ASK, 830 CONTENT_SETTING_ASK,
830 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); 831 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 RequestGeolocationPermission( 909 RequestGeolocationPermission(
909 web_contents(), RequestID(0), requesting_frame_0, false); 910 web_contents(), RequestID(0), requesting_frame_0, false);
910 RequestGeolocationPermission( 911 RequestGeolocationPermission(
911 web_contents(), RequestID(1), requesting_frame_1, false); 912 web_contents(), RequestID(1), requesting_frame_1, false);
912 913
913 // Ensure only one infobar is created. 914 // Ensure only one infobar is created.
914 ASSERT_EQ(1U, GetNumberOfPrompts()); 915 ASSERT_EQ(1U, GetNumberOfPrompts());
915 916
916 // Accept the first frame. 917 // Accept the first frame.
917 AcceptPrompt(); 918 AcceptPrompt();
918 #if defined(OS_ANDROID) 919 #if BUILDFLAG(ANDROID_JAVA_UI)
919 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); 920 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0));
920 #endif 921 #endif
921 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); 922 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
922 CheckPermissionMessageSent(0, true); 923 CheckPermissionMessageSent(0, true);
923 924
924 // Verify that accepting the first didn't accept because it's embedded 925 // Verify that accepting the first didn't accept because it's embedded
925 // in the other. 926 // in the other.
926 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), 927 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
927 requesting_frame_0.GetOrigin(), 928 requesting_frame_0.GetOrigin(),
928 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 929 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
929 10); 930 10);
930 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), 931 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
931 requesting_frame_0.GetOrigin(), 932 requesting_frame_0.GetOrigin(),
932 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 933 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
933 0); 934 0);
934 935
935 ASSERT_EQ(1U, GetNumberOfPrompts()); 936 ASSERT_EQ(1U, GetNumberOfPrompts());
936 937
937 test_clock->Advance(base::TimeDelta::FromSeconds(1)); 938 test_clock->Advance(base::TimeDelta::FromSeconds(1));
938 939
939 // Allow the second frame. 940 // Allow the second frame.
940 AcceptPrompt(); 941 AcceptPrompt();
941 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); 942 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW);
942 CheckPermissionMessageSent(1, true); 943 CheckPermissionMessageSent(1, true);
943 #if defined(OS_ANDROID) 944 #if BUILDFLAG(ANDROID_JAVA_UI)
944 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); 945 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0));
945 #endif 946 #endif
946 947
947 // Verify that the times are different. 948 // Verify that the times are different.
948 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), 949 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
949 requesting_frame_0.GetOrigin(), 950 requesting_frame_0.GetOrigin(),
950 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 951 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
951 10); 952 10);
952 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), 953 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
953 requesting_frame_0.GetOrigin(), 954 requesting_frame_0.GetOrigin(),
954 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 955 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
955 11); 956 11);
956 957
957 test_clock->Advance(base::TimeDelta::FromSeconds(2)); 958 test_clock->Advance(base::TimeDelta::FromSeconds(2));
958 RequestGeolocationPermission( 959 RequestGeolocationPermission(
959 web_contents(), RequestID(0), requesting_frame_0, false); 960 web_contents(), RequestID(0), requesting_frame_0, false);
960 961
961 // Verify that requesting permission in one frame doesn't update other where 962 // Verify that requesting permission in one frame doesn't update other where
962 // it is the embedder. 963 // it is the embedder.
963 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), 964 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
964 requesting_frame_0.GetOrigin(), 965 requesting_frame_0.GetOrigin(),
965 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 966 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
966 13); 967 13);
967 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), 968 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
968 requesting_frame_0.GetOrigin(), 969 requesting_frame_0.GetOrigin(),
969 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 970 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
970 11); 971 11);
971 } 972 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698