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

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

Issue 273523007: Dispatch geolocation IPCs on the UI thread. Aside from simplifying the code to avoid a lot of threa… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync Created 6 years, 7 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
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 InfoBarService* infobar_service() { 108 InfoBarService* infobar_service() {
109 return InfoBarService::FromWebContents(web_contents()); 109 return InfoBarService::FromWebContents(web_contents());
110 } 110 }
111 InfoBarService* infobar_service_for_tab(int tab) { 111 InfoBarService* infobar_service_for_tab(int tab) {
112 return InfoBarService::FromWebContents(extra_tabs_[tab]); 112 return InfoBarService::FromWebContents(extra_tabs_[tab]);
113 } 113 }
114 114
115 void RequestGeolocationPermission(const PermissionRequestID& id, 115 void RequestGeolocationPermission(content::WebContents* web_contents,
116 const PermissionRequestID& id,
116 const GURL& requesting_frame); 117 const GURL& requesting_frame);
117 void CancelGeolocationPermissionRequest(const PermissionRequestID& id, 118 void CancelGeolocationPermissionRequest(content::WebContents* web_contents,
119 const PermissionRequestID& id,
118 const GURL& requesting_frame); 120 const GURL& requesting_frame);
119 void PermissionResponse(const PermissionRequestID& id, 121 void PermissionResponse(const PermissionRequestID& id,
120 bool allowed); 122 bool allowed);
121 void CheckPermissionMessageSent(int bridge_id, bool allowed); 123 void CheckPermissionMessageSent(int bridge_id, bool allowed);
122 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); 124 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed);
123 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, 125 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process,
124 int bridge_id, 126 int bridge_id,
125 bool allowed); 127 bool allowed);
126 void AddNewTab(const GURL& url); 128 void AddNewTab(const GURL& url);
127 void CheckTabContentsState(const GURL& requesting_frame, 129 void CheckTabContentsState(const GURL& requesting_frame,
(...skipping 22 matching lines...) Expand all
150 int tab, 152 int tab,
151 int bridge_id) { 153 int bridge_id) {
152 return PermissionRequestID( 154 return PermissionRequestID(
153 extra_tabs_[tab]->GetRenderProcessHost()->GetID(), 155 extra_tabs_[tab]->GetRenderProcessHost()->GetID(),
154 extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(), 156 extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(),
155 bridge_id, 157 bridge_id,
156 0); 158 0);
157 } 159 }
158 160
159 void GeolocationPermissionContextTests::RequestGeolocationPermission( 161 void GeolocationPermissionContextTests::RequestGeolocationPermission(
162 content::WebContents* web_contents,
160 const PermissionRequestID& id, 163 const PermissionRequestID& id,
161 const GURL& requesting_frame) { 164 const GURL& requesting_frame) {
162 geolocation_permission_context_->RequestGeolocationPermission( 165 geolocation_permission_context_->RequestGeolocationPermission(
163 id.render_process_id(), id.render_view_id(), id.bridge_id(), 166 web_contents, id.bridge_id(), requesting_frame, false,
164 requesting_frame, false,
165 base::Bind(&GeolocationPermissionContextTests::PermissionResponse, 167 base::Bind(&GeolocationPermissionContextTests::PermissionResponse,
166 base::Unretained(this), id)); 168 base::Unretained(this), id));
167 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 169 content::BrowserThread::GetBlockingPool()->FlushForTesting();
168 base::RunLoop().RunUntilIdle(); 170 base::RunLoop().RunUntilIdle();
169 } 171 }
170 172
171 void GeolocationPermissionContextTests::CancelGeolocationPermissionRequest( 173 void GeolocationPermissionContextTests::CancelGeolocationPermissionRequest(
174 content::WebContents* web_contents,
172 const PermissionRequestID& id, 175 const PermissionRequestID& id,
173 const GURL& requesting_frame) { 176 const GURL& requesting_frame) {
174 geolocation_permission_context_->CancelGeolocationPermissionRequest( 177 geolocation_permission_context_->CancelGeolocationPermissionRequest(
175 id.render_process_id(), id.render_view_id(), id.bridge_id(), 178 web_contents, id.bridge_id(), requesting_frame);
176 requesting_frame);
177 } 179 }
178 180
179 void GeolocationPermissionContextTests::PermissionResponse( 181 void GeolocationPermissionContextTests::PermissionResponse(
180 const PermissionRequestID& id, 182 const PermissionRequestID& id,
181 bool allowed) { 183 bool allowed) {
182 responses_[id.render_process_id()] = std::make_pair(id.bridge_id(), allowed); 184 responses_[id.render_process_id()] = std::make_pair(id.bridge_id(), allowed);
183 } 185 }
184 186
185 void GeolocationPermissionContextTests::CheckPermissionMessageSent( 187 void GeolocationPermissionContextTests::CheckPermissionMessageSent(
186 int bridge_id, 188 int bridge_id,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 extra_tabs_.clear(); 258 extra_tabs_.clear();
257 ChromeRenderViewHostTestHarness::TearDown(); 259 ChromeRenderViewHostTestHarness::TearDown();
258 } 260 }
259 261
260 // Tests ---------------------------------------------------------------------- 262 // Tests ----------------------------------------------------------------------
261 263
262 TEST_F(GeolocationPermissionContextTests, SinglePermission) { 264 TEST_F(GeolocationPermissionContextTests, SinglePermission) {
263 GURL requesting_frame("http://www.example.com/geolocation"); 265 GURL requesting_frame("http://www.example.com/geolocation");
264 NavigateAndCommit(requesting_frame); 266 NavigateAndCommit(requesting_frame);
265 EXPECT_EQ(0U, infobar_service()->infobar_count()); 267 EXPECT_EQ(0U, infobar_service()->infobar_count());
266 RequestGeolocationPermission(RequestID(0), requesting_frame); 268 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
267 ASSERT_EQ(1U, infobar_service()->infobar_count()); 269 ASSERT_EQ(1U, infobar_service()->infobar_count());
268 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 270 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
269 ConfirmInfoBarDelegate* infobar_delegate = 271 ConfirmInfoBarDelegate* infobar_delegate =
270 infobar->delegate()->AsConfirmInfoBarDelegate(); 272 infobar->delegate()->AsConfirmInfoBarDelegate();
271 ASSERT_TRUE(infobar_delegate); 273 ASSERT_TRUE(infobar_delegate);
272 infobar_delegate->Cancel(); 274 infobar_delegate->Cancel();
273 infobar_service()->RemoveInfoBar(infobar); 275 infobar_service()->RemoveInfoBar(infobar);
274 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 276 EXPECT_EQ(1U, closed_infobar_tracker_.size());
275 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); 277 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
276 } 278 }
277 279
278 #if defined(OS_ANDROID) 280 #if defined(OS_ANDROID)
279 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { 281 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) {
280 GURL requesting_frame("http://www.example.com/geolocation"); 282 GURL requesting_frame("http://www.example.com/geolocation");
281 NavigateAndCommit(requesting_frame); 283 NavigateAndCommit(requesting_frame);
282 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); 284 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true);
283 EXPECT_EQ(0U, infobar_service()->infobar_count()); 285 EXPECT_EQ(0U, infobar_service()->infobar_count());
284 RequestGeolocationPermission(RequestID(0), requesting_frame); 286 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
285 EXPECT_EQ(1U, infobar_service()->infobar_count()); 287 EXPECT_EQ(1U, infobar_service()->infobar_count());
286 ConfirmInfoBarDelegate* infobar_delegate_0 = 288 ConfirmInfoBarDelegate* infobar_delegate_0 =
287 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 289 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
288 ASSERT_TRUE(infobar_delegate_0); 290 ASSERT_TRUE(infobar_delegate_0);
289 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( 291 base::string16 text_0 = infobar_delegate_0->GetButtonLabel(
290 ConfirmInfoBarDelegate::BUTTON_OK); 292 ConfirmInfoBarDelegate::BUTTON_OK);
291 293
292 NavigateAndCommit(requesting_frame); 294 NavigateAndCommit(requesting_frame);
293 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); 295 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false);
294 EXPECT_EQ(0U, infobar_service()->infobar_count()); 296 EXPECT_EQ(0U, infobar_service()->infobar_count());
295 RequestGeolocationPermission(RequestID(0), requesting_frame); 297 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
296 EXPECT_EQ(1U, infobar_service()->infobar_count()); 298 EXPECT_EQ(1U, infobar_service()->infobar_count());
297 ConfirmInfoBarDelegate* infobar_delegate_1 = 299 ConfirmInfoBarDelegate* infobar_delegate_1 =
298 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 300 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
299 ASSERT_TRUE(infobar_delegate_1); 301 ASSERT_TRUE(infobar_delegate_1);
300 base::string16 text_1 = infobar_delegate_1->GetButtonLabel( 302 base::string16 text_1 = infobar_delegate_1->GetButtonLabel(
301 ConfirmInfoBarDelegate::BUTTON_OK); 303 ConfirmInfoBarDelegate::BUTTON_OK);
302 EXPECT_NE(text_0, text_1); 304 EXPECT_NE(text_0, text_1);
303 305
304 NavigateAndCommit(requesting_frame); 306 NavigateAndCommit(requesting_frame);
305 MockGoogleLocationSettingsHelper::SetLocationStatus(false, false); 307 MockGoogleLocationSettingsHelper::SetLocationStatus(false, false);
306 EXPECT_EQ(0U, infobar_service()->infobar_count()); 308 EXPECT_EQ(0U, infobar_service()->infobar_count());
307 RequestGeolocationPermission(RequestID(0), requesting_frame); 309 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
308 EXPECT_EQ(0U, infobar_service()->infobar_count()); 310 EXPECT_EQ(0U, infobar_service()->infobar_count());
309 } 311 }
310 312
311 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { 313 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) {
312 GURL requesting_frame("http://www.example.com/geolocation"); 314 GURL requesting_frame("http://www.example.com/geolocation");
313 NavigateAndCommit(requesting_frame); 315 NavigateAndCommit(requesting_frame);
314 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); 316 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true);
315 EXPECT_EQ(0U, infobar_service()->infobar_count()); 317 EXPECT_EQ(0U, infobar_service()->infobar_count());
316 RequestGeolocationPermission(RequestID(0), requesting_frame); 318 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
317 EXPECT_EQ(1U, infobar_service()->infobar_count()); 319 EXPECT_EQ(1U, infobar_service()->infobar_count());
318 ConfirmInfoBarDelegate* infobar_delegate = 320 ConfirmInfoBarDelegate* infobar_delegate =
319 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 321 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
320 ASSERT_TRUE(infobar_delegate); 322 ASSERT_TRUE(infobar_delegate);
321 infobar_delegate->Accept(); 323 infobar_delegate->Accept();
322 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 324 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
323 CheckPermissionMessageSent(0, true); 325 CheckPermissionMessageSent(0, true);
324 } 326 }
325 327
326 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { 328 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) {
327 GURL requesting_frame("http://www.example.com/geolocation"); 329 GURL requesting_frame("http://www.example.com/geolocation");
328 NavigateAndCommit(requesting_frame); 330 NavigateAndCommit(requesting_frame);
329 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); 331 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false);
330 EXPECT_EQ(0U, infobar_service()->infobar_count()); 332 EXPECT_EQ(0U, infobar_service()->infobar_count());
331 RequestGeolocationPermission(RequestID(0), requesting_frame); 333 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
332 EXPECT_EQ(1U, infobar_service()->infobar_count()); 334 EXPECT_EQ(1U, infobar_service()->infobar_count());
333 ConfirmInfoBarDelegate* infobar_delegate = 335 ConfirmInfoBarDelegate* infobar_delegate =
334 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 336 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
335 ASSERT_TRUE(infobar_delegate); 337 ASSERT_TRUE(infobar_delegate);
336 infobar_delegate->Accept(); 338 infobar_delegate->Accept();
337 EXPECT_TRUE( 339 EXPECT_TRUE(
338 MockGoogleLocationSettingsHelper::WasGoogleLocationSettingsCalled()); 340 MockGoogleLocationSettingsHelper::WasGoogleLocationSettingsCalled());
339 } 341 }
340 #endif 342 #endif
341 343
342 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { 344 TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
343 GURL requesting_frame_0("http://www.example.com/geolocation"); 345 GURL requesting_frame_0("http://www.example.com/geolocation");
344 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 346 GURL requesting_frame_1("http://www.example-2.com/geolocation");
345 EXPECT_EQ(CONTENT_SETTING_ASK, 347 EXPECT_EQ(CONTENT_SETTING_ASK,
346 profile()->GetHostContentSettingsMap()->GetContentSetting( 348 profile()->GetHostContentSettingsMap()->GetContentSetting(
347 requesting_frame_0, requesting_frame_0, 349 requesting_frame_0, requesting_frame_0,
348 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 350 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
349 EXPECT_EQ(CONTENT_SETTING_ASK, 351 EXPECT_EQ(CONTENT_SETTING_ASK,
350 profile()->GetHostContentSettingsMap()->GetContentSetting( 352 profile()->GetHostContentSettingsMap()->GetContentSetting(
351 requesting_frame_1, requesting_frame_0, 353 requesting_frame_1, requesting_frame_0,
352 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 354 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
353 355
354 NavigateAndCommit(requesting_frame_0); 356 NavigateAndCommit(requesting_frame_0);
355 EXPECT_EQ(0U, infobar_service()->infobar_count()); 357 EXPECT_EQ(0U, infobar_service()->infobar_count());
356 // Request permission for two frames. 358 // Request permission for two frames.
357 RequestGeolocationPermission(RequestID(0), requesting_frame_0); 359 RequestGeolocationPermission(
358 RequestGeolocationPermission(RequestID(1), requesting_frame_1); 360 web_contents(), RequestID(0), requesting_frame_0);
361 RequestGeolocationPermission(
362 web_contents(), RequestID(1), requesting_frame_1);
359 // Ensure only one infobar is created. 363 // Ensure only one infobar is created.
360 ASSERT_EQ(1U, infobar_service()->infobar_count()); 364 ASSERT_EQ(1U, infobar_service()->infobar_count());
361 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); 365 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0);
362 ConfirmInfoBarDelegate* infobar_delegate_0 = 366 ConfirmInfoBarDelegate* infobar_delegate_0 =
363 infobar_0->delegate()->AsConfirmInfoBarDelegate(); 367 infobar_0->delegate()->AsConfirmInfoBarDelegate();
364 ASSERT_TRUE(infobar_delegate_0); 368 ASSERT_TRUE(infobar_delegate_0);
365 base::string16 text_0 = infobar_delegate_0->GetMessageText(); 369 base::string16 text_0 = infobar_delegate_0->GetMessageText();
366 370
367 // Accept the first frame. 371 // Accept the first frame.
368 infobar_delegate_0->Accept(); 372 infobar_delegate_0->Accept();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 407 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
404 } 408 }
405 409
406 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { 410 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) {
407 GURL url_a("http://www.example.com/geolocation#a"); 411 GURL url_a("http://www.example.com/geolocation#a");
408 GURL url_b("http://www.example.com/geolocation#b"); 412 GURL url_b("http://www.example.com/geolocation#b");
409 413
410 // Navigate to the first url and check permission is requested. 414 // Navigate to the first url and check permission is requested.
411 NavigateAndCommit(url_a); 415 NavigateAndCommit(url_a);
412 EXPECT_EQ(0U, infobar_service()->infobar_count()); 416 EXPECT_EQ(0U, infobar_service()->infobar_count());
413 RequestGeolocationPermission(RequestID(0), url_a); 417 RequestGeolocationPermission(web_contents(), RequestID(0), url_a);
414 ASSERT_EQ(1U, infobar_service()->infobar_count()); 418 ASSERT_EQ(1U, infobar_service()->infobar_count());
415 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 419 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
416 ConfirmInfoBarDelegate* infobar_delegate = 420 ConfirmInfoBarDelegate* infobar_delegate =
417 infobar->delegate()->AsConfirmInfoBarDelegate(); 421 infobar->delegate()->AsConfirmInfoBarDelegate();
418 ASSERT_TRUE(infobar_delegate); 422 ASSERT_TRUE(infobar_delegate);
419 423
420 // Change the hash, we'll still be on the same page. 424 // Change the hash, we'll still be on the same page.
421 NavigateAndCommit(url_b); 425 NavigateAndCommit(url_b);
422 426
423 // Accept. 427 // Accept.
424 infobar_delegate->Accept(); 428 infobar_delegate->Accept();
425 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); 429 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW);
426 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); 430 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW);
427 CheckPermissionMessageSent(0, true); 431 CheckPermissionMessageSent(0, true);
428 432
429 // Cleanup. 433 // Cleanup.
430 infobar_service()->RemoveInfoBar(infobar); 434 infobar_service()->RemoveInfoBar(infobar);
431 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 435 EXPECT_EQ(1U, closed_infobar_tracker_.size());
432 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); 436 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
433 } 437 }
434 438
435 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { 439 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) {
436 GURL requesting_frame("file://example/geolocation.html"); 440 GURL requesting_frame("file://example/geolocation.html");
437 NavigateAndCommit(requesting_frame); 441 NavigateAndCommit(requesting_frame);
438 EXPECT_EQ(0U, infobar_service()->infobar_count()); 442 EXPECT_EQ(0U, infobar_service()->infobar_count());
439 RequestGeolocationPermission(RequestID(0), requesting_frame); 443 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
440 EXPECT_EQ(1U, infobar_service()->infobar_count()); 444 EXPECT_EQ(1U, infobar_service()->infobar_count());
441 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 445 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
442 ConfirmInfoBarDelegate* infobar_delegate = 446 ConfirmInfoBarDelegate* infobar_delegate =
443 infobar->delegate()->AsConfirmInfoBarDelegate(); 447 infobar->delegate()->AsConfirmInfoBarDelegate();
444 ASSERT_TRUE(infobar_delegate); 448 ASSERT_TRUE(infobar_delegate);
445 // Accept the frame. 449 // Accept the frame.
446 infobar_delegate->Accept(); 450 infobar_delegate->Accept();
447 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 451 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
448 CheckPermissionMessageSent(0, true); 452 CheckPermissionMessageSent(0, true);
449 infobar_service()->RemoveInfoBar(infobar); 453 infobar_service()->RemoveInfoBar(infobar);
(...skipping 16 matching lines...) Expand all
466 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 470 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
467 471
468 EXPECT_EQ(CONTENT_SETTING_ASK, 472 EXPECT_EQ(CONTENT_SETTING_ASK,
469 profile()->GetHostContentSettingsMap()->GetContentSetting( 473 profile()->GetHostContentSettingsMap()->GetContentSetting(
470 requesting_frame_1, requesting_frame_0, 474 requesting_frame_1, requesting_frame_0,
471 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 475 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
472 476
473 NavigateAndCommit(requesting_frame_0); 477 NavigateAndCommit(requesting_frame_0);
474 EXPECT_EQ(0U, infobar_service()->infobar_count()); 478 EXPECT_EQ(0U, infobar_service()->infobar_count());
475 // Request permission for two frames. 479 // Request permission for two frames.
476 RequestGeolocationPermission(RequestID(0), requesting_frame_0); 480 RequestGeolocationPermission(
477 RequestGeolocationPermission(RequestID(1), requesting_frame_1); 481 web_contents(), RequestID(0), requesting_frame_0);
482 RequestGeolocationPermission(
483 web_contents(), RequestID(1), requesting_frame_1);
478 ASSERT_EQ(1U, infobar_service()->infobar_count()); 484 ASSERT_EQ(1U, infobar_service()->infobar_count());
479 485
480 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); 486 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0);
481 ConfirmInfoBarDelegate* infobar_delegate_0 = 487 ConfirmInfoBarDelegate* infobar_delegate_0 =
482 infobar_0->delegate()->AsConfirmInfoBarDelegate(); 488 infobar_0->delegate()->AsConfirmInfoBarDelegate();
483 ASSERT_TRUE(infobar_delegate_0); 489 ASSERT_TRUE(infobar_delegate_0);
484 base::string16 text_0 = infobar_delegate_0->GetMessageText(); 490 base::string16 text_0 = infobar_delegate_0->GetMessageText();
485 491
486 // Simulate the frame going away, ensure the infobar for this frame 492 // Simulate the frame going away, ensure the infobar for this frame
487 // is removed and the next pending infobar is created. 493 // is removed and the next pending infobar is created.
488 CancelGeolocationPermissionRequest(RequestID(0), requesting_frame_0); 494 CancelGeolocationPermissionRequest(
495 web_contents(), RequestID(0), requesting_frame_0);
489 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 496 EXPECT_EQ(1U, closed_infobar_tracker_.size());
490 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); 497 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
491 closed_infobar_tracker_.Clear(); 498 closed_infobar_tracker_.Clear();
492 ASSERT_EQ(1U, infobar_service()->infobar_count()); 499 ASSERT_EQ(1U, infobar_service()->infobar_count());
493 500
494 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); 501 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0);
495 ConfirmInfoBarDelegate* infobar_delegate_1 = 502 ConfirmInfoBarDelegate* infobar_delegate_1 =
496 infobar_1->delegate()->AsConfirmInfoBarDelegate(); 503 infobar_1->delegate()->AsConfirmInfoBarDelegate();
497 ASSERT_TRUE(infobar_delegate_1); 504 ASSERT_TRUE(infobar_delegate_1);
498 base::string16 text_1 = infobar_delegate_1->GetMessageText(); 505 base::string16 text_1 = infobar_delegate_1->GetMessageText();
(...skipping 17 matching lines...) Expand all
516 profile()->GetHostContentSettingsMap()->GetContentSetting( 523 profile()->GetHostContentSettingsMap()->GetContentSetting(
517 requesting_frame_1, requesting_frame_0, 524 requesting_frame_1, requesting_frame_0,
518 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 525 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
519 } 526 }
520 527
521 TEST_F(GeolocationPermissionContextTests, InvalidURL) { 528 TEST_F(GeolocationPermissionContextTests, InvalidURL) {
522 GURL invalid_embedder("about:blank"); 529 GURL invalid_embedder("about:blank");
523 GURL requesting_frame; 530 GURL requesting_frame;
524 NavigateAndCommit(invalid_embedder); 531 NavigateAndCommit(invalid_embedder);
525 EXPECT_EQ(0U, infobar_service()->infobar_count()); 532 EXPECT_EQ(0U, infobar_service()->infobar_count());
526 RequestGeolocationPermission(RequestID(0), requesting_frame); 533 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
527 EXPECT_EQ(0U, infobar_service()->infobar_count()); 534 EXPECT_EQ(0U, infobar_service()->infobar_count());
528 CheckPermissionMessageSent(0, false); 535 CheckPermissionMessageSent(0, false);
529 } 536 }
530 537
531 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { 538 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
532 GURL url_a("http://www.example.com/geolocation"); 539 GURL url_a("http://www.example.com/geolocation");
533 GURL url_b("http://www.example-2.com/geolocation"); 540 GURL url_b("http://www.example-2.com/geolocation");
534 NavigateAndCommit(url_a); 541 NavigateAndCommit(url_a);
535 AddNewTab(url_b); 542 AddNewTab(url_b);
536 AddNewTab(url_a); 543 AddNewTab(url_a);
537 544
538 EXPECT_EQ(0U, infobar_service()->infobar_count()); 545 EXPECT_EQ(0U, infobar_service()->infobar_count());
539 RequestGeolocationPermission(RequestID(0), url_a); 546 RequestGeolocationPermission(web_contents(), RequestID(0), url_a);
540 ASSERT_EQ(1U, infobar_service()->infobar_count()); 547 ASSERT_EQ(1U, infobar_service()->infobar_count());
541 548
542 RequestGeolocationPermission(RequestIDForTab(0, 0), url_b); 549 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_b);
543 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 550 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
544 551
545 RequestGeolocationPermission(RequestIDForTab(1, 0), url_a); 552 RequestGeolocationPermission(extra_tabs_[1], RequestIDForTab(1, 0), url_a);
546 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); 553 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count());
547 554
548 infobars::InfoBar* removed_infobar = 555 infobars::InfoBar* removed_infobar =
549 infobar_service_for_tab(1)->infobar_at(0); 556 infobar_service_for_tab(1)->infobar_at(0);
550 557
551 // Accept the first tab. 558 // Accept the first tab.
552 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); 559 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0);
553 ConfirmInfoBarDelegate* infobar_delegate_0 = 560 ConfirmInfoBarDelegate* infobar_delegate_0 =
554 infobar_0->delegate()->AsConfirmInfoBarDelegate(); 561 infobar_0->delegate()->AsConfirmInfoBarDelegate();
555 ASSERT_TRUE(infobar_delegate_0); 562 ASSERT_TRUE(infobar_delegate_0);
(...skipping 20 matching lines...) Expand all
576 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); 583 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
577 } 584 }
578 585
579 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { 586 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
580 GURL url_a("http://www.example.com/geolocation"); 587 GURL url_a("http://www.example.com/geolocation");
581 GURL url_b("http://www.example-2.com/geolocation"); 588 GURL url_b("http://www.example-2.com/geolocation");
582 NavigateAndCommit(url_a); 589 NavigateAndCommit(url_a);
583 AddNewTab(url_a); 590 AddNewTab(url_a);
584 591
585 EXPECT_EQ(0U, infobar_service()->infobar_count()); 592 EXPECT_EQ(0U, infobar_service()->infobar_count());
586 RequestGeolocationPermission(RequestID(0), url_a); 593 RequestGeolocationPermission(web_contents(), RequestID(0), url_a);
587 ASSERT_EQ(1U, infobar_service()->infobar_count()); 594 ASSERT_EQ(1U, infobar_service()->infobar_count());
588 595
589 RequestGeolocationPermission(RequestIDForTab(0, 0), url_a); 596 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_a);
590 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 597 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
591 598
592 RequestGeolocationPermission(RequestIDForTab(0, 1), url_b); 599 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 1), url_b);
593 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 600 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
594 601
595 infobars::InfoBar* removed_infobar = infobar_service()->infobar_at(0); 602 infobars::InfoBar* removed_infobar = infobar_service()->infobar_at(0);
596 603
597 // Accept the second tab. 604 // Accept the second tab.
598 infobars::InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0); 605 infobars::InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0);
599 ConfirmInfoBarDelegate* infobar_delegate_0 = 606 ConfirmInfoBarDelegate* infobar_delegate_0 =
600 infobar_0->delegate()->AsConfirmInfoBarDelegate(); 607 infobar_0->delegate()->AsConfirmInfoBarDelegate();
601 ASSERT_TRUE(infobar_delegate_0); 608 ASSERT_TRUE(infobar_delegate_0);
602 infobar_delegate_0->Accept(); 609 infobar_delegate_0->Accept();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 641 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
635 642
636 EXPECT_EQ(CONTENT_SETTING_ASK, 643 EXPECT_EQ(CONTENT_SETTING_ASK,
637 profile()->GetHostContentSettingsMap()->GetContentSetting( 644 profile()->GetHostContentSettingsMap()->GetContentSetting(
638 requesting_frame_1, requesting_frame_0, 645 requesting_frame_1, requesting_frame_0,
639 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 646 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
640 647
641 NavigateAndCommit(requesting_frame_0); 648 NavigateAndCommit(requesting_frame_0);
642 EXPECT_EQ(0U, infobar_service()->infobar_count()); 649 EXPECT_EQ(0U, infobar_service()->infobar_count());
643 // Request permission for two frames. 650 // Request permission for two frames.
644 RequestGeolocationPermission(RequestID(0), requesting_frame_0); 651 RequestGeolocationPermission(
645 RequestGeolocationPermission(RequestID(1), requesting_frame_1); 652 web_contents(), RequestID(0), requesting_frame_0);
653 RequestGeolocationPermission(
654 web_contents(), RequestID(1), requesting_frame_1);
646 // Ensure only one infobar is created. 655 // Ensure only one infobar is created.
647 ASSERT_EQ(1U, infobar_service()->infobar_count()); 656 ASSERT_EQ(1U, infobar_service()->infobar_count());
648 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 657 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
649 658
650 // Delete the tab contents. 659 // Delete the tab contents.
651 DeleteContents(); 660 DeleteContents();
652 661
653 // During contents destruction, the infobar will have been closed, and the 662 // During contents destruction, the infobar will have been closed, and the
654 // pending request should have been cleared without an infobar being created. 663 // pending request should have been cleared without an infobar being created.
655 ASSERT_EQ(1U, closed_infobar_tracker_.size()); 664 ASSERT_EQ(1U, closed_infobar_tracker_.size());
656 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); 665 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar));
657 } 666 }
658 667
659 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { 668 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) {
660 GURL requesting_frame_0("http://www.example.com/geolocation"); 669 GURL requesting_frame_0("http://www.example.com/geolocation");
661 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 670 GURL requesting_frame_1("http://www.example-2.com/geolocation");
662 NavigateAndCommit(requesting_frame_0); 671 NavigateAndCommit(requesting_frame_0);
663 NavigateAndCommit(requesting_frame_1); 672 NavigateAndCommit(requesting_frame_1);
664 EXPECT_EQ(0U, infobar_service()->infobar_count()); 673 EXPECT_EQ(0U, infobar_service()->infobar_count());
665 // Go back: navigate to a pending entry before requesting geolocation 674 // Go back: navigate to a pending entry before requesting geolocation
666 // permission. 675 // permission.
667 web_contents()->GetController().GoBack(); 676 web_contents()->GetController().GoBack();
668 // Request permission for the committed frame (not the pending one). 677 // Request permission for the committed frame (not the pending one).
669 RequestGeolocationPermission(RequestID(0), requesting_frame_1); 678 RequestGeolocationPermission(
679 web_contents(), RequestID(0), requesting_frame_1);
670 // Ensure the infobar is created. 680 // Ensure the infobar is created.
671 ASSERT_EQ(1U, infobar_service()->infobar_count()); 681 ASSERT_EQ(1U, infobar_service()->infobar_count());
672 infobars::InfoBarDelegate* infobar_delegate = 682 infobars::InfoBarDelegate* infobar_delegate =
673 infobar_service()->infobar_at(0)->delegate(); 683 infobar_service()->infobar_at(0)->delegate();
674 ASSERT_TRUE(infobar_delegate); 684 ASSERT_TRUE(infobar_delegate);
675 // Ensure the infobar wouldn't expire for a navigation to the committed entry. 685 // Ensure the infobar wouldn't expire for a navigation to the committed entry.
676 content::LoadCommittedDetails details; 686 content::LoadCommittedDetails details;
677 details.entry = web_contents()->GetController().GetLastCommittedEntry(); 687 details.entry = web_contents()->GetController().GetLastCommittedEntry();
678 EXPECT_FALSE(infobar_delegate->ShouldExpire( 688 EXPECT_FALSE(infobar_delegate->ShouldExpire(
679 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details))); 689 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details)));
680 // Ensure the infobar will expire when we commit the pending navigation. 690 // Ensure the infobar will expire when we commit the pending navigation.
681 details.entry = web_contents()->GetController().GetActiveEntry(); 691 details.entry = web_contents()->GetController().GetActiveEntry();
682 EXPECT_TRUE(infobar_delegate->ShouldExpire( 692 EXPECT_TRUE(infobar_delegate->ShouldExpire(
683 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details))); 693 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details)));
684 694
685 // Delete the tab contents. 695 // Delete the tab contents.
686 DeleteContents(); 696 DeleteContents();
687 } 697 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698