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