OLD | NEW |
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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "chrome/test/base/in_process_browser_test.h" | 24 #include "chrome/test/base/in_process_browser_test.h" |
25 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
26 #include "content/public/browser/dom_operation_notification_details.h" | 26 #include "content/public/browser/dom_operation_notification_details.h" |
27 #include "content/public/browser/navigation_controller.h" | 27 #include "content/public/browser/navigation_controller.h" |
28 #include "content/public/browser/notification_details.h" | 28 #include "content/public/browser/notification_details.h" |
29 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
30 #include "content/public/browser/render_view_host.h" | 30 #include "content/public/browser/render_view_host.h" |
31 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
32 #include "content/public/test/browser_test_utils.h" | 32 #include "content/public/test/browser_test_utils.h" |
33 #include "net/base/net_util.h" | 33 #include "net/base/net_util.h" |
34 #include "net/test/spawned_test_server/spawned_test_server.h" | 34 #include "net/test/embedded_test_server/embedded_test_server.h" |
35 | 35 |
36 using content::DomOperationNotificationDetails; | 36 using content::DomOperationNotificationDetails; |
37 using content::NavigationController; | 37 using content::NavigationController; |
38 using content::WebContents; | 38 using content::WebContents; |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 | 42 |
43 // IFrameLoader --------------------------------------------------------------- | 43 // IFrameLoader --------------------------------------------------------------- |
44 | 44 |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 // This member defines the iframe (or top-level page, if empty) where the | 267 // This member defines the iframe (or top-level page, if empty) where the |
268 // javascript calls will run. | 268 // javascript calls will run. |
269 std::string iframe_xpath_; | 269 std::string iframe_xpath_; |
270 // The current url for the top level page. | 270 // The current url for the top level page. |
271 GURL current_url_; | 271 GURL current_url_; |
272 // If not empty, the GURLs for the iframes loaded by LoadIFrames(). | 272 // If not empty, the GURLs for the iframes loaded by LoadIFrames(). |
273 std::vector<GURL> iframe_urls_; | 273 std::vector<GURL> iframe_urls_; |
274 double fake_latitude_; | 274 double fake_latitude_; |
275 double fake_longitude_; | 275 double fake_longitude_; |
276 | 276 |
277 // TODO(phajdan.jr): Remove after we can ask TestServer whether it is started. | |
278 bool started_test_server_; | |
279 | |
280 private: | 277 private: |
281 DISALLOW_COPY_AND_ASSIGN(GeolocationBrowserTest); | 278 DISALLOW_COPY_AND_ASSIGN(GeolocationBrowserTest); |
282 }; | 279 }; |
283 | 280 |
284 GeolocationBrowserTest::GeolocationBrowserTest() | 281 GeolocationBrowserTest::GeolocationBrowserTest() |
285 : infobar_(NULL), | 282 : infobar_(NULL), |
286 current_browser_(NULL), | 283 current_browser_(NULL), |
287 html_for_tests_("files/geolocation/simple.html"), | 284 html_for_tests_("/geolocation/simple.html"), |
288 fake_latitude_(1.23), | 285 fake_latitude_(1.23), |
289 fake_longitude_(4.56), | 286 fake_longitude_(4.56) { |
290 started_test_server_(false) {} | 287 } |
291 | 288 |
292 void GeolocationBrowserTest::SetUpOnMainThread() { | 289 void GeolocationBrowserTest::SetUpOnMainThread() { |
293 ui_test_utils::OverrideGeolocation(fake_latitude_, fake_longitude_); | 290 ui_test_utils::OverrideGeolocation(fake_latitude_, fake_longitude_); |
294 } | 291 } |
295 | 292 |
296 void GeolocationBrowserTest::TearDownInProcessBrowserTestFixture() { | 293 void GeolocationBrowserTest::TearDownInProcessBrowserTestFixture() { |
297 LOG(WARNING) << "TearDownInProcessBrowserTestFixture. Test Finished."; | 294 LOG(WARNING) << "TearDownInProcessBrowserTestFixture. Test Finished."; |
298 } | 295 } |
299 | 296 |
300 bool GeolocationBrowserTest::Initialize(InitializationOptions options) { | 297 bool GeolocationBrowserTest::Initialize(InitializationOptions options) { |
301 if (!started_test_server_) | 298 if (!embedded_test_server()->Started() && |
302 started_test_server_ = test_server()->Start(); | 299 !embedded_test_server()->InitializeAndWaitUntilReady()) { |
303 EXPECT_TRUE(started_test_server_); | 300 ADD_FAILURE() << "Test server failed to start."; |
304 if (!started_test_server_) | |
305 return false; | 301 return false; |
| 302 } |
306 | 303 |
307 current_url_ = test_server()->GetURL(html_for_tests_); | 304 current_url_ = embedded_test_server()->GetURL(html_for_tests_); |
308 LOG(WARNING) << "before navigate"; | 305 LOG(WARNING) << "before navigate"; |
309 if (options == INITIALIZATION_OFFTHERECORD) { | 306 if (options == INITIALIZATION_OFFTHERECORD) { |
310 current_browser_ = ui_test_utils::OpenURLOffTheRecord( | 307 current_browser_ = ui_test_utils::OpenURLOffTheRecord( |
311 browser()->profile(), current_url_); | 308 browser()->profile(), current_url_); |
312 } else if (options == INITIALIZATION_NEWTAB) { | 309 } else if (options == INITIALIZATION_NEWTAB) { |
313 current_browser_ = browser(); | 310 current_browser_ = browser(); |
314 chrome::NewTab(current_browser_); | 311 chrome::NewTab(current_browser_); |
315 ui_test_utils::NavigateToURL(current_browser_, current_url_); | 312 ui_test_utils::NavigateToURL(current_browser_, current_url_); |
316 } else if (options == INITIALIZATION_IFRAMES) { | 313 } else if (options == INITIALIZATION_IFRAMES) { |
317 current_browser_ = browser(); | 314 current_browser_ = browser(); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 // Go to the regular profile, infobar will be created. | 530 // Go to the regular profile, infobar will be created. |
534 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 531 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
535 AddGeolocationWatch(true); | 532 AddGeolocationWatch(true); |
536 SetInfobarResponse(current_url_, false); | 533 SetInfobarResponse(current_url_, false); |
537 CheckStringValueFromJavascript("1", "geoGetLastError()"); | 534 CheckStringValueFromJavascript("1", "geoGetLastError()"); |
538 } | 535 } |
539 | 536 |
540 // crbug.com/176291 | 537 // crbug.com/176291 |
541 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, | 538 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, |
542 DISABLED_IFramesWithFreshPosition) { | 539 DISABLED_IFramesWithFreshPosition) { |
543 html_for_tests_ = "files/geolocation/iframes_different_origin.html"; | 540 html_for_tests_ = "/geolocation/iframes_different_origin.html"; |
544 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 541 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
545 LoadIFrames(2); | 542 LoadIFrames(2); |
546 LOG(WARNING) << "frames loaded"; | 543 LOG(WARNING) << "frames loaded"; |
547 | 544 |
548 iframe_xpath_ = "//iframe[@id='iframe_0']"; | 545 iframe_xpath_ = "//iframe[@id='iframe_0']"; |
549 AddGeolocationWatch(true); | 546 AddGeolocationWatch(true); |
550 SetInfobarResponse(iframe_urls_[0], true); | 547 SetInfobarResponse(iframe_urls_[0], true); |
551 CheckGeoposition(fake_latitude_, fake_longitude_); | 548 CheckGeoposition(fake_latitude_, fake_longitude_); |
552 // Disables further prompts from this iframe. | 549 // Disables further prompts from this iframe. |
553 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 550 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
(...skipping 24 matching lines...) Expand all Loading... |
578 iframe_xpath_ = "//iframe[@id='iframe_1']"; | 575 iframe_xpath_ = "//iframe[@id='iframe_1']"; |
579 // Infobar was displayed, allow access and check there's no error code. | 576 // Infobar was displayed, allow access and check there's no error code. |
580 SetInfobarResponse(iframe_urls_[1], true); | 577 SetInfobarResponse(iframe_urls_[1], true); |
581 LOG(WARNING) << "Checking position..."; | 578 LOG(WARNING) << "Checking position..."; |
582 CheckGeoposition(fresh_position_latitude, fresh_position_longitude); | 579 CheckGeoposition(fresh_position_latitude, fresh_position_longitude); |
583 LOG(WARNING) << "...done."; | 580 LOG(WARNING) << "...done."; |
584 } | 581 } |
585 | 582 |
586 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, | 583 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, |
587 IFramesWithCachedPosition) { | 584 IFramesWithCachedPosition) { |
588 html_for_tests_ = "files/geolocation/iframes_different_origin.html"; | 585 html_for_tests_ = "/geolocation/iframes_different_origin.html"; |
589 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 586 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
590 LoadIFrames(2); | 587 LoadIFrames(2); |
591 | 588 |
592 iframe_xpath_ = "//iframe[@id='iframe_0']"; | 589 iframe_xpath_ = "//iframe[@id='iframe_0']"; |
593 AddGeolocationWatch(true); | 590 AddGeolocationWatch(true); |
594 SetInfobarResponse(iframe_urls_[0], true); | 591 SetInfobarResponse(iframe_urls_[0], true); |
595 CheckGeoposition(fake_latitude_, fake_longitude_); | 592 CheckGeoposition(fake_latitude_, fake_longitude_); |
596 | 593 |
597 // Refresh geoposition, but let's not yet create the watch on the second frame | 594 // Refresh geoposition, but let's not yet create the watch on the second frame |
598 // so that it'll fetch from cache. | 595 // so that it'll fetch from cache. |
(...skipping 18 matching lines...) Expand all Loading... |
617 // afterwards. We're only interested in the first navigation for the success | 614 // afterwards. We're only interested in the first navigation for the success |
618 // callback from the cached position. | 615 // callback from the cached position. |
619 CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); | 616 CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); |
620 SetInfobarResponse(iframe_urls_[1], true); | 617 SetInfobarResponse(iframe_urls_[1], true); |
621 CheckGeoposition(cached_position_latitude, cached_position_lognitude); | 618 CheckGeoposition(cached_position_latitude, cached_position_lognitude); |
622 } | 619 } |
623 | 620 |
624 // crbug.com/176291 | 621 // crbug.com/176291 |
625 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, | 622 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, |
626 DISABLED_CancelPermissionForFrame) { | 623 DISABLED_CancelPermissionForFrame) { |
627 html_for_tests_ = "files/geolocation/iframes_different_origin.html"; | 624 html_for_tests_ = "/geolocation/iframes_different_origin.html"; |
628 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 625 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
629 LoadIFrames(2); | 626 LoadIFrames(2); |
630 LOG(WARNING) << "frames loaded"; | 627 LOG(WARNING) << "frames loaded"; |
631 | 628 |
632 iframe_xpath_ = "//iframe[@id='iframe_0']"; | 629 iframe_xpath_ = "//iframe[@id='iframe_0']"; |
633 AddGeolocationWatch(true); | 630 AddGeolocationWatch(true); |
634 SetInfobarResponse(iframe_urls_[0], true); | 631 SetInfobarResponse(iframe_urls_[0], true); |
635 CheckGeoposition(fake_latitude_, fake_longitude_); | 632 CheckGeoposition(fake_latitude_, fake_longitude_); |
636 // Disables further prompts from this iframe. | 633 // Disables further prompts from this iframe. |
637 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 634 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
638 | 635 |
639 // Test second iframe from a different origin with a cached geoposition will | 636 // Test second iframe from a different origin with a cached geoposition will |
640 // create the infobar. | 637 // create the infobar. |
641 iframe_xpath_ = "//iframe[@id='iframe_1']"; | 638 iframe_xpath_ = "//iframe[@id='iframe_1']"; |
642 AddGeolocationWatch(true); | 639 AddGeolocationWatch(true); |
643 | 640 |
644 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 641 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
645 current_browser_->tab_strip_model()->GetActiveWebContents()); | 642 current_browser_->tab_strip_model()->GetActiveWebContents()); |
646 size_t num_infobars_before_cancel = infobar_service->infobar_count(); | 643 size_t num_infobars_before_cancel = infobar_service->infobar_count(); |
647 // Change the iframe, and ensure the infobar is gone. | 644 // Change the iframe, and ensure the infobar is gone. |
648 IFrameLoader change_iframe_1(current_browser_, 1, current_url_); | 645 IFrameLoader change_iframe_1(current_browser_, 1, current_url_); |
649 size_t num_infobars_after_cancel = infobar_service->infobar_count(); | 646 size_t num_infobars_after_cancel = infobar_service->infobar_count(); |
650 EXPECT_EQ(num_infobars_before_cancel, num_infobars_after_cancel + 1); | 647 EXPECT_EQ(num_infobars_before_cancel, num_infobars_after_cancel + 1); |
651 } | 648 } |
652 | 649 |
653 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, InvalidUrlRequest) { | 650 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, InvalidUrlRequest) { |
654 // Tests that an invalid URL (e.g. from a popup window) is rejected | 651 // Tests that an invalid URL (e.g. from a popup window) is rejected |
655 // correctly. Also acts as a regression test for http://crbug.com/40478 | 652 // correctly. Also acts as a regression test for http://crbug.com/40478 |
656 html_for_tests_ = "files/geolocation/invalid_request_url.html"; | 653 html_for_tests_ = "/geolocation/invalid_request_url.html"; |
657 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 654 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
658 WebContents* original_tab = | 655 WebContents* original_tab = |
659 current_browser_->tab_strip_model()->GetActiveWebContents(); | 656 current_browser_->tab_strip_model()->GetActiveWebContents(); |
660 CheckStringValueFromJavascript("1", "requestGeolocationFromInvalidUrl()"); | 657 CheckStringValueFromJavascript("1", "requestGeolocationFromInvalidUrl()"); |
661 CheckStringValueFromJavascriptForTab("1", "isAlive()", original_tab); | 658 CheckStringValueFromJavascriptForTab("1", "isAlive()", original_tab); |
662 } | 659 } |
663 | 660 |
664 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfoBarBeforeStart) { | 661 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfoBarBeforeStart) { |
665 // See http://crbug.com/42789 | 662 // See http://crbug.com/42789 |
666 html_for_tests_ = "files/geolocation/iframes_different_origin.html"; | 663 html_for_tests_ = "/geolocation/iframes_different_origin.html"; |
667 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 664 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
668 LoadIFrames(2); | 665 LoadIFrames(2); |
669 LOG(WARNING) << "frames loaded"; | 666 LOG(WARNING) << "frames loaded"; |
670 | 667 |
671 // Access navigator.geolocation, but ensure it won't request permission. | 668 // Access navigator.geolocation, but ensure it won't request permission. |
672 iframe_xpath_ = "//iframe[@id='iframe_1']"; | 669 iframe_xpath_ = "//iframe[@id='iframe_1']"; |
673 CheckStringValueFromJavascript("object", "geoAccessNavigatorGeolocation()"); | 670 CheckStringValueFromJavascript("object", "geoAccessNavigatorGeolocation()"); |
674 | 671 |
675 iframe_xpath_ = "//iframe[@id='iframe_0']"; | 672 iframe_xpath_ = "//iframe[@id='iframe_0']"; |
676 AddGeolocationWatch(true); | 673 AddGeolocationWatch(true); |
677 SetInfobarResponse(iframe_urls_[0], true); | 674 SetInfobarResponse(iframe_urls_[0], true); |
678 CheckGeoposition(fake_latitude_, fake_longitude_); | 675 CheckGeoposition(fake_latitude_, fake_longitude_); |
679 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 676 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
680 | 677 |
681 // Permission should be requested after adding a watch. | 678 // Permission should be requested after adding a watch. |
682 iframe_xpath_ = "//iframe[@id='iframe_1']"; | 679 iframe_xpath_ = "//iframe[@id='iframe_1']"; |
683 AddGeolocationWatch(true); | 680 AddGeolocationWatch(true); |
684 SetInfobarResponse(iframe_urls_[1], true); | 681 SetInfobarResponse(iframe_urls_[1], true); |
685 CheckGeoposition(fake_latitude_, fake_longitude_); | 682 CheckGeoposition(fake_latitude_, fake_longitude_); |
686 } | 683 } |
687 | 684 |
688 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) { | 685 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) { |
689 html_for_tests_ = "files/geolocation/two_watches.html"; | 686 html_for_tests_ = "/geolocation/two_watches.html"; |
690 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 687 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
691 // First, set the JavaScript to navigate when it receives |final_position|. | 688 // First, set the JavaScript to navigate when it receives |final_position|. |
692 double final_position_latitude = 3.17; | 689 double final_position_latitude = 3.17; |
693 double final_position_longitude = 4.23; | 690 double final_position_longitude = 4.23; |
694 std::string script = base::StringPrintf( | 691 std::string script = base::StringPrintf( |
695 "window.domAutomationController.send(geoSetFinalPosition(%f, %f))", | 692 "window.domAutomationController.send(geoSetFinalPosition(%f, %f))", |
696 final_position_latitude, final_position_longitude); | 693 final_position_latitude, final_position_longitude); |
697 std::string js_result; | 694 std::string js_result; |
698 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 695 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
699 current_browser_->tab_strip_model()->GetActiveWebContents(), | 696 current_browser_->tab_strip_model()->GetActiveWebContents(), |
(...skipping 13 matching lines...) Expand all Loading... |
713 content::Source<NavigationController>( | 710 content::Source<NavigationController>( |
714 ¤t_browser_->tab_strip_model()->GetActiveWebContents()-> | 711 ¤t_browser_->tab_strip_model()->GetActiveWebContents()-> |
715 GetController())); | 712 GetController())); |
716 NotifyGeoposition(final_position_latitude, final_position_longitude); | 713 NotifyGeoposition(final_position_latitude, final_position_longitude); |
717 observer.Wait(); | 714 observer.Wait(); |
718 CheckGeoposition(final_position_latitude, final_position_longitude); | 715 CheckGeoposition(final_position_latitude, final_position_longitude); |
719 } | 716 } |
720 | 717 |
721 // crbug.com/176291 | 718 // crbug.com/176291 |
722 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DISABLED_TabDestroyed) { | 719 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DISABLED_TabDestroyed) { |
723 html_for_tests_ = "files/geolocation/tab_destroyed.html"; | 720 html_for_tests_ = "/geolocation/tab_destroyed.html"; |
724 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 721 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
725 LoadIFrames(3); | 722 LoadIFrames(3); |
726 | 723 |
727 iframe_xpath_ = "//iframe[@id='iframe_0']"; | 724 iframe_xpath_ = "//iframe[@id='iframe_0']"; |
728 AddGeolocationWatch(true); | 725 AddGeolocationWatch(true); |
729 | 726 |
730 iframe_xpath_ = "//iframe[@id='iframe_1']"; | 727 iframe_xpath_ = "//iframe[@id='iframe_1']"; |
731 AddGeolocationWatch(false); | 728 AddGeolocationWatch(false); |
732 | 729 |
733 iframe_xpath_ = "//iframe[@id='iframe_2']"; | 730 iframe_xpath_ = "//iframe[@id='iframe_2']"; |
734 AddGeolocationWatch(false); | 731 AddGeolocationWatch(false); |
735 | 732 |
736 std::string script = | 733 std::string script = |
737 "window.domAutomationController.send(window.close());"; | 734 "window.domAutomationController.send(window.close());"; |
738 bool result = | 735 bool result = |
739 content::ExecuteScript( | 736 content::ExecuteScript( |
740 current_browser_->tab_strip_model()->GetActiveWebContents(), | 737 current_browser_->tab_strip_model()->GetActiveWebContents(), |
741 script); | 738 script); |
742 EXPECT_EQ(result, true); | 739 EXPECT_EQ(result, true); |
743 } | 740 } |
OLD | NEW |