OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/string_util.h" | 5 #include "base/string_util.h" |
6 #include "base/waitable_event.h" | 6 #include "base/waitable_event.h" |
7 #include "chrome/browser/app_modal_dialog.h" | 7 #include "chrome/browser/app_modal_dialog.h" |
8 #include "chrome/browser/browser.h" | 8 #include "chrome/browser/browser.h" |
9 #include "chrome/browser/browser_list.h" | 9 #include "chrome/browser/browser_list.h" |
10 #include "chrome/browser/dom_operation_notification_details.h" | 10 #include "chrome/browser/dom_operation_notification_details.h" |
11 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | |
12 #include "chrome/browser/geolocation/location_arbitrator.h" | 11 #include "chrome/browser/geolocation/location_arbitrator.h" |
13 #include "chrome/browser/geolocation/location_provider.h" | 12 #include "chrome/browser/geolocation/location_provider.h" |
14 #include "chrome/browser/geolocation/mock_location_provider.h" | 13 #include "chrome/browser/geolocation/mock_location_provider.h" |
15 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
16 #include "chrome/browser/renderer_host/render_view_host.h" | 15 #include "chrome/browser/renderer_host/render_view_host.h" |
17 #include "chrome/browser/tab_contents/tab_contents.h" | 16 #include "chrome/browser/tab_contents/tab_contents.h" |
18 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
19 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/geoposition.h" | 19 #include "chrome/common/geoposition.h" |
21 #include "chrome/common/notification_details.h" | 20 #include "chrome/common/notification_details.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 // 1. Infobar is displayed when a geolocation is requested from an unauthorized | 164 // 1. Infobar is displayed when a geolocation is requested from an unauthorized |
166 // origin. | 165 // origin. |
167 // 2. Denying the infobar triggers the correct error callback. | 166 // 2. Denying the infobar triggers the correct error callback. |
168 // 3. Allowing the infobar does not trigger an error, and allow a geoposition to | 167 // 3. Allowing the infobar does not trigger an error, and allow a geoposition to |
169 // be passed to javascript. | 168 // be passed to javascript. |
170 // 4. Permissions persisted in disk are respected. | 169 // 4. Permissions persisted in disk are respected. |
171 // 5. Off the record profiles don't use saved permissions. | 170 // 5. Off the record profiles don't use saved permissions. |
172 class GeolocationBrowserTest : public InProcessBrowserTest { | 171 class GeolocationBrowserTest : public InProcessBrowserTest { |
173 public: | 172 public: |
174 GeolocationBrowserTest() | 173 GeolocationBrowserTest() |
175 : infobar_(NULL), | 174 : infobar_(NULL), current_browser_(NULL), |
176 current_browser_(NULL), | |
177 html_for_tests_("files/geolocation/simple.html") { | 175 html_for_tests_("files/geolocation/simple.html") { |
178 EnableDOMAutomation(); | 176 EnableDOMAutomation(); |
179 } | 177 } |
180 | 178 |
181 enum InitializationOptions { | 179 enum InitializationOptions { |
182 INITIALIZATION_NONE, | 180 INITIALIZATION_NONE, |
183 INITIALIZATION_OFFTHERECORD, | 181 INITIALIZATION_OFFTHERECORD, |
184 INITIALIZATION_NEWTAB, | 182 INITIALIZATION_NEWTAB, |
185 INITIALIZATION_IFRAMES, | 183 INITIALIZATION_IFRAMES, |
186 }; | 184 }; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 LOG(WARNING) << "got geolocation watch"; | 229 LOG(WARNING) << "got geolocation watch"; |
232 | 230 |
233 if (wait_for_infobar) { | 231 if (wait_for_infobar) { |
234 if (!notification_observer.infobar_) { | 232 if (!notification_observer.infobar_) { |
235 LOG(WARNING) << "will block for infobar"; | 233 LOG(WARNING) << "will block for infobar"; |
236 ui_test_utils::RunMessageLoop(); | 234 ui_test_utils::RunMessageLoop(); |
237 LOG(WARNING) << "infobar created"; | 235 LOG(WARNING) << "infobar created"; |
238 } | 236 } |
239 EXPECT_TRUE(notification_observer.infobar_); | 237 EXPECT_TRUE(notification_observer.infobar_); |
240 infobar_ = notification_observer.infobar_; | 238 infobar_ = notification_observer.infobar_; |
241 } else { | |
242 // Infobar wasn't displayed, so we need to wait for the JS prompt instead. | |
243 WaitForJSPrompt(); | |
244 } | 239 } |
245 } | 240 } |
246 | 241 |
247 Geoposition GeopositionFromLatLong(double latitude, double longitude) { | 242 Geoposition GeopositionFromLatLong(double latitude, double longitude) { |
248 Geoposition geoposition; | 243 Geoposition geoposition; |
249 geoposition.latitude = latitude; | 244 geoposition.latitude = latitude; |
250 geoposition.longitude = longitude; | 245 geoposition.longitude = longitude; |
251 geoposition.accuracy = 0; | 246 geoposition.accuracy = 0; |
252 geoposition.error_code = Geoposition::ERROR_CODE_NONE; | 247 geoposition.error_code = Geoposition::ERROR_CODE_NONE; |
253 // Webkit compares the timestamp to wall clock time, so we need | 248 // Webkit compares the timestamp to wall clock time, so we need |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 | 374 |
380 #if defined(OS_MACOSX) | 375 #if defined(OS_MACOSX) |
381 // TODO(bulach): investigate why this fails on mac. It may be related to: | 376 // TODO(bulach): investigate why this fails on mac. It may be related to: |
382 // http://crbug.com//29424 | 377 // http://crbug.com//29424 |
383 #define MAYBE_NoInfobarForSecondTab DISABLED_NoInfobarForSecondTab | 378 #define MAYBE_NoInfobarForSecondTab DISABLED_NoInfobarForSecondTab |
384 #else | 379 #else |
385 #define MAYBE_NoInfobarForSecondTab NoInfobarForSecondTab | 380 #define MAYBE_NoInfobarForSecondTab NoInfobarForSecondTab |
386 #endif | 381 #endif |
387 | 382 |
388 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForSecondTab) { | 383 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForSecondTab) { |
| 384 #if 0 |
| 385 // TODO(bulach): enable this test once we use HostContentSettingsMap instead |
| 386 // of files. |
389 Initialize(INITIALIZATION_NONE); | 387 Initialize(INITIALIZATION_NONE); |
390 AddGeolocationWatch(true); | 388 SendGeoposition(true, GeopositionFromLatLong(0, 0)); |
391 SetInfobarResponse(current_url_, true); | 389 SetInfobarResponse(current_url_, true); |
392 // Checks infobar will not be created a second tab. | 390 // Checks infobar will not be created a second tab. |
393 Initialize(INITIALIZATION_NEWTAB); | 391 Initialize(INITIALIZATION_NEWTAB); |
394 AddGeolocationWatch(false); | 392 SendGeoposition(false, GeopositionFromLatLong(0, 0)); |
395 CheckGeoposition(MockLocationProvider::instance_->position_); | 393 CheckStringValueFromJavascript("0", "geoGetLastError()"); |
| 394 #endif |
396 } | 395 } |
397 | 396 |
398 #if defined(OS_MACOSX) | 397 #if defined(OS_MACOSX) |
399 // TODO(bulach): investigate why this fails on mac. It may be related to: | 398 // TODO(bulach): investigate why this fails on mac. It may be related to: |
400 // http://crbug.com//29424 | 399 // http://crbug.com//29424 |
401 #define MAYBE_NoInfobarForDeniedOrigin DISABLED_NoInfobarForDeniedOrigin | 400 #define MAYBE_NoInfobarForDeniedOrigin DISABLED_NoInfobarForDeniedOrigin |
402 #else | 401 #else |
403 #define MAYBE_NoInfobarForDeniedOrigin NoInfobarForDeniedOrigin | 402 #define MAYBE_NoInfobarForDeniedOrigin NoInfobarForDeniedOrigin |
404 #endif | 403 #endif |
405 | 404 |
406 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForDeniedOrigin) { | 405 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForDeniedOrigin) { |
| 406 #if 0 |
| 407 // TODO(bulach): enable this test once we use HostContentSettingsMap instead |
| 408 // of files. |
| 409 WritePermissionFile("{\"allowed\":false}"); |
| 410 // Checks no infobar will be created. |
407 Initialize(INITIALIZATION_NONE); | 411 Initialize(INITIALIZATION_NONE); |
408 current_browser_->profile()->GetGeolocationContentSettingsMap()-> | 412 SendGeoposition(false, GeopositionFromLatLong(0, 0)); |
409 SetContentSetting(current_url_, current_url_, CONTENT_SETTING_BLOCK); | |
410 AddGeolocationWatch(false); | |
411 // Checks we have an error for this denied origin. | |
412 CheckStringValueFromJavascript("1", "geoGetLastError()"); | 413 CheckStringValueFromJavascript("1", "geoGetLastError()"); |
413 // Checks infobar will not be created a second tab. | 414 // Checks infobar will not be created a second tab. |
414 Initialize(INITIALIZATION_NEWTAB); | 415 Initialize(INITIALIZATION_NEWTAB); |
415 AddGeolocationWatch(false); | 416 SendGeoposition(false, GeopositionFromLatLong(0, 0)); |
416 CheckStringValueFromJavascript("1", "geoGetLastError()"); | 417 CheckStringValueFromJavascript("1", "geoGetLastError()"); |
| 418 #endif |
417 } | 419 } |
418 | 420 |
419 #if defined(OS_MACOSX) | 421 #if defined(OS_MACOSX) |
420 // TODO(bulach): investigate why this fails on mac. It may be related to: | 422 // TODO(bulach): investigate why this fails on mac. It may be related to: |
421 // http://crbug.com//29424 | 423 // http://crbug.com//29424 |
422 #define MAYBE_NoInfobarForAllowedOrigin DISABLED_NoInfobarForAllowedOrigin | 424 #define MAYBE_NoInfobarForAllowedOrigin DISABLED_NoInfobarForAllowedOrigin |
423 #else | 425 #else |
424 #define MAYBE_NoInfobarForAllowedOrigin NoInfobarForAllowedOrigin | 426 #define MAYBE_NoInfobarForAllowedOrigin NoInfobarForAllowedOrigin |
425 #endif | 427 #endif |
426 | 428 |
427 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, | 429 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, |
428 MAYBE_NoInfobarForAllowedOrigin) { | 430 MAYBE_NoInfobarForAllowedOrigin) { |
429 Initialize(INITIALIZATION_NONE); | 431 #if 0 |
430 current_browser_->profile()->GetGeolocationContentSettingsMap()-> | 432 // TODO(bulach): enable this test once we use HostContentSettingsMap instead |
431 SetContentSetting(current_url_, current_url_, CONTENT_SETTING_ALLOW); | 433 // of files. |
| 434 WritePermissionFile("{\"allowed\":true}"); |
432 // Checks no infobar will be created and there's no error callback. | 435 // Checks no infobar will be created and there's no error callback. |
433 Initialize(INITIALIZATION_NONE); | 436 Initialize(INITIALIZATION_NONE); |
434 AddGeolocationWatch(false); | 437 SendGeoposition(false, GeopositionFromLatLong(0, 0)); |
435 CheckGeoposition(MockLocationProvider::instance_->position_); | 438 CheckStringValueFromJavascript("0", "geoGetLastError()"); |
| 439 #endif |
436 } | 440 } |
437 | 441 |
438 #if defined(OS_MACOSX) | 442 #if defined(OS_MACOSX) |
439 // TODO(bulach): investigate why this fails on mac. It may be related to: | 443 // TODO(bulach): investigate why this fails on mac. It may be related to: |
440 // http://crbug.com//29424 | 444 // http://crbug.com//29424 |
441 #define MAYBE_InfobarForOffTheRecord DISABLED_InfobarForOffTheRecord | 445 #define MAYBE_InfobarForOffTheRecord DISABLED_InfobarForOffTheRecord |
442 #else | 446 #else |
443 #define MAYBE_InfobarForOffTheRecord InfobarForOffTheRecord | 447 #define MAYBE_InfobarForOffTheRecord InfobarForOffTheRecord |
444 #endif | 448 #endif |
445 | 449 |
446 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForOffTheRecord) { | 450 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_InfobarForOffTheRecord) { |
447 // First, check infobar will be created for regular profile | 451 // Checks infobar will be created for regular profile. |
448 Initialize(INITIALIZATION_NONE); | 452 Initialize(INITIALIZATION_NONE); |
449 AddGeolocationWatch(true); | 453 AddGeolocationWatch(true); |
450 // Response will be persisted | |
451 SetInfobarResponse(current_url_, true); | 454 SetInfobarResponse(current_url_, true); |
452 CheckGeoposition(MockLocationProvider::instance_->position_); | 455 CheckGeoposition(MockLocationProvider::instance_->position_); |
453 // Disables further prompts from this tab. | 456 // Disables further prompts from this tab. |
454 CheckStringValueFromJavascript("false", "geoEnableAlerts(false)"); | 457 CheckStringValueFromJavascript("false", "geoEnableAlerts(false)"); |
455 // Go off the record, and checks no infobar will be created. | 458 // Go off the record, and checks infobar will be created and an error callback |
| 459 // is triggered. |
456 Initialize(INITIALIZATION_OFFTHERECORD); | 460 Initialize(INITIALIZATION_OFFTHERECORD); |
457 AddGeolocationWatch(false); | 461 AddGeolocationWatch(true); |
458 CheckGeoposition(MockLocationProvider::instance_->position_); | 462 SetInfobarResponse(current_url_, false); |
| 463 CheckStringValueFromJavascript("1", "geoGetLastError()"); |
459 } | 464 } |
460 | 465 |
461 #if defined(OS_MACOSX) | 466 #if defined(OS_MACOSX) |
462 // TODO(bulach): investigate why this fails on mac. It may be related to: | 467 // TODO(bulach): investigate why this fails on mac. It may be related to: |
463 // http://crbug.com//29424 | 468 // http://crbug.com//29424 |
464 #define MAYBE_IFramesWithFreshPosition DISABLED_IFramesWithFreshPosition | 469 #define MAYBE_IFramesWithFreshPosition DISABLED_IFramesWithFreshPosition |
465 #else | 470 #else |
466 // TODO(bulach): investigate this failure. | 471 // TODO(bulach): investigate this failure. |
467 // http://build.chromium.org/buildbot/waterfall/builders/XP%20Tests/builds/18549
/steps/browser_tests/logs/stdio | 472 // http://build.chromium.org/buildbot/waterfall/builders/XP%20Tests/builds/18549
/steps/browser_tests/logs/stdio |
468 #define MAYBE_IFramesWithFreshPosition FLAKY_IFramesWithFreshPosition | 473 #define MAYBE_IFramesWithFreshPosition FLAKY_IFramesWithFreshPosition |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 | 545 |
541 // Disable alert for this frame. | 546 // Disable alert for this frame. |
542 CheckStringValueFromJavascript("false", "geoEnableAlerts(false)"); | 547 CheckStringValueFromJavascript("false", "geoEnableAlerts(false)"); |
543 | 548 |
544 // Now go ahead an authorize the second frame. | 549 // Now go ahead an authorize the second frame. |
545 iframe_xpath_ = L"//iframe[@id='iframe_1']"; | 550 iframe_xpath_ = L"//iframe[@id='iframe_1']"; |
546 AddGeolocationWatch(true); | 551 AddGeolocationWatch(true); |
547 SetInfobarResponse(iframe1_url_, true); | 552 SetInfobarResponse(iframe1_url_, true); |
548 CheckGeoposition(cached_position); | 553 CheckGeoposition(cached_position); |
549 } | 554 } |
OLD | NEW |