OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "content/browser/geolocation/location_arbitrator.h" | 28 #include "content/browser/geolocation/location_arbitrator.h" |
29 #include "content/browser/geolocation/mock_location_provider.h" | 29 #include "content/browser/geolocation/mock_location_provider.h" |
30 #include "content/browser/renderer_host/render_view_host.h" | 30 #include "content/browser/renderer_host/render_view_host.h" |
31 #include "content/public/browser/navigation_controller.h" | 31 #include "content/public/browser/navigation_controller.h" |
32 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
33 #include "content/public/browser/notification_details.h" | 33 #include "content/public/browser/notification_details.h" |
34 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
35 #include "net/base/net_util.h" | 35 #include "net/base/net_util.h" |
36 #include "net/test/test_server.h" | 36 #include "net/test/test_server.h" |
37 | 37 |
| 38 using content::NavigationController; |
38 using content::WebContents; | 39 using content::WebContents; |
39 | 40 |
40 namespace { | 41 namespace { |
41 | 42 |
42 // Used to block until an iframe is loaded via a javascript call. | 43 // Used to block until an iframe is loaded via a javascript call. |
43 // Note: NavigateToURLBlockUntilNavigationsComplete doesn't seem to work for | 44 // Note: NavigateToURLBlockUntilNavigationsComplete doesn't seem to work for |
44 // multiple embedded iframes, as notifications seem to be 'batched'. Instead, we | 45 // multiple embedded iframes, as notifications seem to be 'batched'. Instead, we |
45 // load and wait one single frame here by calling a javascript function. | 46 // load and wait one single frame here by calling a javascript function. |
46 class IFrameLoader : public content::NotificationObserver { | 47 class IFrameLoader : public content::NotificationObserver { |
47 public: | 48 public: |
48 IFrameLoader(Browser* browser, int iframe_id, const GURL& url) | 49 IFrameLoader(Browser* browser, int iframe_id, const GURL& url) |
49 : navigation_completed_(false), | 50 : navigation_completed_(false), |
50 javascript_completed_(false) { | 51 javascript_completed_(false) { |
51 content::NavigationController* controller = | 52 NavigationController* controller = |
52 &browser->GetSelectedWebContents()->GetController(); | 53 &browser->GetSelectedWebContents()->GetController(); |
53 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | 54 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
54 content::Source<content::NavigationController>(controller)); | 55 content::Source<NavigationController>(controller)); |
55 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, | 56 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, |
56 content::NotificationService::AllSources()); | 57 content::NotificationService::AllSources()); |
57 std::string script = base::StringPrintf( | 58 std::string script = base::StringPrintf( |
58 "window.domAutomationController.setAutomationId(0);" | 59 "window.domAutomationController.setAutomationId(0);" |
59 "window.domAutomationController.send(addIFrame(%d, \"%s\"));", | 60 "window.domAutomationController.send(addIFrame(%d, \"%s\"));", |
60 iframe_id, | 61 iframe_id, |
61 url.spec().c_str()); | 62 url.spec().c_str()); |
62 browser->GetSelectedWebContents()->GetRenderViewHost()-> | 63 browser->GetSelectedWebContents()->GetRenderViewHost()-> |
63 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(script)); | 64 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(script)); |
64 ui_test_utils::RunMessageLoop(); | 65 ui_test_utils::RunMessageLoop(); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 TabSpecificContentSettings* content_settings = | 320 TabSpecificContentSettings* content_settings = |
320 tab_contents_wrapper->content_settings(); | 321 tab_contents_wrapper->content_settings(); |
321 const GeolocationSettingsState& settings_state = | 322 const GeolocationSettingsState& settings_state = |
322 content_settings->geolocation_settings_state(); | 323 content_settings->geolocation_settings_state(); |
323 size_t state_map_size = settings_state.state_map().size(); | 324 size_t state_map_size = settings_state.state_map().size(); |
324 ASSERT_TRUE(infobar_); | 325 ASSERT_TRUE(infobar_); |
325 LOG(WARNING) << "will set infobar response"; | 326 LOG(WARNING) << "will set infobar response"; |
326 { | 327 { |
327 ui_test_utils::WindowedNotificationObserver observer( | 328 ui_test_utils::WindowedNotificationObserver observer( |
328 content::NOTIFICATION_LOAD_STOP, | 329 content::NOTIFICATION_LOAD_STOP, |
329 content::Source<content::NavigationController>( | 330 content::Source<NavigationController>( |
330 &tab_contents_wrapper->web_contents()->GetController())); | 331 &tab_contents_wrapper->web_contents()->GetController())); |
331 if (allowed) | 332 if (allowed) |
332 infobar_->AsConfirmInfoBarDelegate()->Accept(); | 333 infobar_->AsConfirmInfoBarDelegate()->Accept(); |
333 else | 334 else |
334 infobar_->AsConfirmInfoBarDelegate()->Cancel(); | 335 infobar_->AsConfirmInfoBarDelegate()->Cancel(); |
335 observer.Wait(); | 336 observer.Wait(); |
336 } | 337 } |
337 | 338 |
338 tab_contents_wrapper->infobar_tab_helper()->RemoveInfoBar(infobar_); | 339 tab_contents_wrapper->infobar_tab_helper()->RemoveInfoBar(infobar_); |
339 LOG(WARNING) << "infobar response set"; | 340 LOG(WARNING) << "infobar response set"; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 AddGeolocationWatch(true); | 503 AddGeolocationWatch(true); |
503 | 504 |
504 // Back to the first frame, enable navigation and refresh geoposition. | 505 // Back to the first frame, enable navigation and refresh geoposition. |
505 iframe_xpath_ = L"//iframe[@id='iframe_0']"; | 506 iframe_xpath_ = L"//iframe[@id='iframe_0']"; |
506 CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); | 507 CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); |
507 // MockLocationProvider must have been created. | 508 // MockLocationProvider must have been created. |
508 ASSERT_TRUE(MockLocationProvider::instance_); | 509 ASSERT_TRUE(MockLocationProvider::instance_); |
509 Geoposition fresh_position = GeopositionFromLatLong(3.17, 4.23); | 510 Geoposition fresh_position = GeopositionFromLatLong(3.17, 4.23); |
510 ui_test_utils::WindowedNotificationObserver observer( | 511 ui_test_utils::WindowedNotificationObserver observer( |
511 content::NOTIFICATION_LOAD_STOP, | 512 content::NOTIFICATION_LOAD_STOP, |
512 content::Source<content::NavigationController>( | 513 content::Source<NavigationController>( |
513 ¤t_browser_->GetSelectedWebContents()->GetController())); | 514 ¤t_browser_->GetSelectedWebContents()->GetController())); |
514 NotifyGeoposition(fresh_position); | 515 NotifyGeoposition(fresh_position); |
515 observer.Wait(); | 516 observer.Wait(); |
516 CheckGeoposition(fresh_position); | 517 CheckGeoposition(fresh_position); |
517 | 518 |
518 // Disable navigation for this frame. | 519 // Disable navigation for this frame. |
519 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 520 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
520 | 521 |
521 // Now go ahead an authorize the second frame. | 522 // Now go ahead an authorize the second frame. |
522 iframe_xpath_ = L"//iframe[@id='iframe_1']"; | 523 iframe_xpath_ = L"//iframe[@id='iframe_1']"; |
(...skipping 16 matching lines...) Expand all Loading... |
539 SetInfobarResponse(iframe_urls_[0], true); | 540 SetInfobarResponse(iframe_urls_[0], true); |
540 CheckGeoposition(MockLocationProvider::instance_->position_); | 541 CheckGeoposition(MockLocationProvider::instance_->position_); |
541 | 542 |
542 // Refresh geoposition, but let's not yet create the watch on the second frame | 543 // Refresh geoposition, but let's not yet create the watch on the second frame |
543 // so that it'll fetch from cache. | 544 // so that it'll fetch from cache. |
544 // MockLocationProvider must have been created. | 545 // MockLocationProvider must have been created. |
545 ASSERT_TRUE(MockLocationProvider::instance_); | 546 ASSERT_TRUE(MockLocationProvider::instance_); |
546 Geoposition cached_position = GeopositionFromLatLong(5.67, 8.09); | 547 Geoposition cached_position = GeopositionFromLatLong(5.67, 8.09); |
547 ui_test_utils::WindowedNotificationObserver observer( | 548 ui_test_utils::WindowedNotificationObserver observer( |
548 content::NOTIFICATION_LOAD_STOP, | 549 content::NOTIFICATION_LOAD_STOP, |
549 content::Source<content::NavigationController>( | 550 content::Source<NavigationController>( |
550 ¤t_browser_->GetSelectedWebContents()->GetController())); | 551 ¤t_browser_->GetSelectedWebContents()->GetController())); |
551 NotifyGeoposition(cached_position); | 552 NotifyGeoposition(cached_position); |
552 observer.Wait(); | 553 observer.Wait(); |
553 CheckGeoposition(cached_position); | 554 CheckGeoposition(cached_position); |
554 | 555 |
555 // Disable navigation for this frame. | 556 // Disable navigation for this frame. |
556 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 557 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
557 | 558 |
558 // Now go ahead an authorize the second frame. | 559 // Now go ahead an authorize the second frame. |
559 iframe_xpath_ = L"//iframe[@id='iframe_1']"; | 560 iframe_xpath_ = L"//iframe[@id='iframe_1']"; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 | 648 |
648 // Send a position which both geolocation watches will receive. | 649 // Send a position which both geolocation watches will receive. |
649 AddGeolocationWatch(true); | 650 AddGeolocationWatch(true); |
650 SetInfobarResponse(current_url_, true); | 651 SetInfobarResponse(current_url_, true); |
651 CheckGeoposition(MockLocationProvider::instance_->position_); | 652 CheckGeoposition(MockLocationProvider::instance_->position_); |
652 | 653 |
653 // The second watch will now have cancelled. Ensure an update still makes | 654 // The second watch will now have cancelled. Ensure an update still makes |
654 // its way through to the first watcher. | 655 // its way through to the first watcher. |
655 ui_test_utils::WindowedNotificationObserver observer( | 656 ui_test_utils::WindowedNotificationObserver observer( |
656 content::NOTIFICATION_LOAD_STOP, | 657 content::NOTIFICATION_LOAD_STOP, |
657 content::Source<content::NavigationController>( | 658 content::Source<NavigationController>( |
658 ¤t_browser_->GetSelectedWebContents()->GetController())); | 659 ¤t_browser_->GetSelectedWebContents()->GetController())); |
659 NotifyGeoposition(final_position); | 660 NotifyGeoposition(final_position); |
660 observer.Wait(); | 661 observer.Wait(); |
661 CheckGeoposition(final_position); | 662 CheckGeoposition(final_position); |
662 } | 663 } |
663 | 664 |
664 // Hangs flakily, http://crbug.com/70588. | 665 // Hangs flakily, http://crbug.com/70588. |
665 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DISABLED_TabDestroyed) { | 666 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DISABLED_TabDestroyed) { |
666 html_for_tests_ = "files/geolocation/tab_destroyed.html"; | 667 html_for_tests_ = "files/geolocation/tab_destroyed.html"; |
667 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 668 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
(...skipping 12 matching lines...) Expand all Loading... |
680 "window.domAutomationController.setAutomationId(0);" | 681 "window.domAutomationController.setAutomationId(0);" |
681 "window.domAutomationController.send(window.close());"; | 682 "window.domAutomationController.send(window.close());"; |
682 bool result = | 683 bool result = |
683 ui_test_utils::ExecuteJavaScript( | 684 ui_test_utils::ExecuteJavaScript( |
684 current_browser_->GetSelectedWebContents()->GetRenderViewHost(), | 685 current_browser_->GetSelectedWebContents()->GetRenderViewHost(), |
685 L"", UTF8ToWide(script)); | 686 L"", UTF8ToWide(script)); |
686 EXPECT_EQ(result, true); | 687 EXPECT_EQ(result, true); |
687 } | 688 } |
688 | 689 |
689 } // namespace | 690 } // namespace |
OLD | NEW |