| 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 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 24 #include "chrome/common/content_settings_pattern.h" | 24 #include "chrome/common/content_settings_pattern.h" |
| 25 #include "chrome/test/base/in_process_browser_test.h" | 25 #include "chrome/test/base/in_process_browser_test.h" |
| 26 #include "chrome/test/base/ui_test_utils.h" | 26 #include "chrome/test/base/ui_test_utils.h" |
| 27 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h
" | 27 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h
" |
| 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/browser/tab_contents/tab_contents.h" | 31 #include "content/browser/tab_contents/tab_contents.h" |
| 32 #include "content/common/geoposition.h" | 32 #include "content/common/geoposition.h" |
| 33 #include "content/common/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
| 34 #include "content/public/browser/notification_details.h" | 34 #include "content/public/browser/notification_details.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 namespace { | 38 namespace { |
| 39 | 39 |
| 40 // Used to block until an iframe is loaded via a javascript call. | 40 // Used to block until an iframe is loaded via a javascript call. |
| 41 // Note: NavigateToURLBlockUntilNavigationsComplete doesn't seem to work for | 41 // Note: NavigateToURLBlockUntilNavigationsComplete doesn't seem to work for |
| 42 // multiple embedded iframes, as notifications seem to be 'batched'. Instead, we | 42 // multiple embedded iframes, as notifications seem to be 'batched'. Instead, we |
| 43 // load and wait one single frame here by calling a javascript function. | 43 // load and wait one single frame here by calling a javascript function. |
| 44 class IFrameLoader : public content::NotificationObserver { | 44 class IFrameLoader : public content::NotificationObserver { |
| 45 public: | 45 public: |
| 46 IFrameLoader(Browser* browser, int iframe_id, const GURL& url) | 46 IFrameLoader(Browser* browser, int iframe_id, const GURL& url) |
| 47 : navigation_completed_(false), | 47 : navigation_completed_(false), |
| 48 javascript_completed_(false) { | 48 javascript_completed_(false) { |
| 49 NavigationController* controller = | 49 NavigationController* controller = |
| 50 &browser->GetSelectedTabContents()->controller(); | 50 &browser->GetSelectedTabContents()->controller(); |
| 51 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | 51 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
| 52 content::Source<NavigationController>(controller)); | 52 content::Source<NavigationController>(controller)); |
| 53 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, | 53 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, |
| 54 NotificationService::AllSources()); | 54 content::NotificationService::AllSources()); |
| 55 std::string script = base::StringPrintf( | 55 std::string script = base::StringPrintf( |
| 56 "window.domAutomationController.setAutomationId(0);" | 56 "window.domAutomationController.setAutomationId(0);" |
| 57 "window.domAutomationController.send(addIFrame(%d, \"%s\"));", | 57 "window.domAutomationController.send(addIFrame(%d, \"%s\"));", |
| 58 iframe_id, | 58 iframe_id, |
| 59 url.spec().c_str()); | 59 url.spec().c_str()); |
| 60 browser->GetSelectedTabContents()->render_view_host()-> | 60 browser->GetSelectedTabContents()->render_view_host()-> |
| 61 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(script)); | 61 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(script)); |
| 62 ui_test_utils::RunMessageLoop(); | 62 ui_test_utils::RunMessageLoop(); |
| 63 | 63 |
| 64 EXPECT_EQ(base::StringPrintf("\"%d\"", iframe_id), javascript_response_); | 64 EXPECT_EQ(base::StringPrintf("\"%d\"", iframe_id), javascript_response_); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 public: | 110 public: |
| 111 // If |wait_for_infobar| is true, AddWatchAndWaitForNotification will block | 111 // If |wait_for_infobar| is true, AddWatchAndWaitForNotification will block |
| 112 // until the infobar has been displayed; otherwise it will block until the | 112 // until the infobar has been displayed; otherwise it will block until the |
| 113 // navigation is completed. | 113 // navigation is completed. |
| 114 explicit GeolocationNotificationObserver(bool wait_for_infobar) | 114 explicit GeolocationNotificationObserver(bool wait_for_infobar) |
| 115 : wait_for_infobar_(wait_for_infobar), | 115 : wait_for_infobar_(wait_for_infobar), |
| 116 infobar_(NULL), | 116 infobar_(NULL), |
| 117 navigation_started_(false), | 117 navigation_started_(false), |
| 118 navigation_completed_(false) { | 118 navigation_completed_(false) { |
| 119 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, | 119 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, |
| 120 NotificationService::AllSources()); | 120 content::NotificationService::AllSources()); |
| 121 if (wait_for_infobar) { | 121 if (wait_for_infobar) { |
| 122 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 122 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
| 123 NotificationService::AllSources()); | 123 content::NotificationService::AllSources()); |
| 124 } else { | 124 } else { |
| 125 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 125 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 126 NotificationService::AllSources()); | 126 content::NotificationService::AllSources()); |
| 127 registrar_.Add(this, content::NOTIFICATION_LOAD_START, | 127 registrar_.Add(this, content::NOTIFICATION_LOAD_START, |
| 128 NotificationService::AllSources()); | 128 content::NotificationService::AllSources()); |
| 129 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | 129 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
| 130 NotificationService::AllSources()); | 130 content::NotificationService::AllSources()); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 void AddWatchAndWaitForNotification(RenderViewHost* render_view_host, | 134 void AddWatchAndWaitForNotification(RenderViewHost* render_view_host, |
| 135 const std::wstring& iframe_xpath) { | 135 const std::wstring& iframe_xpath) { |
| 136 LOG(WARNING) << "will add geolocation watch"; | 136 LOG(WARNING) << "will add geolocation watch"; |
| 137 std::string script = | 137 std::string script = |
| 138 "window.domAutomationController.setAutomationId(0);" | 138 "window.domAutomationController.setAutomationId(0);" |
| 139 "window.domAutomationController.send(geoStart());"; | 139 "window.domAutomationController.send(geoStart());"; |
| 140 render_view_host->ExecuteJavascriptInWebFrame(WideToUTF16Hack(iframe_xpath), | 140 render_view_host->ExecuteJavascriptInWebFrame(WideToUTF16Hack(iframe_xpath), |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 "window.domAutomationController.setAutomationId(0);" | 678 "window.domAutomationController.setAutomationId(0);" |
| 679 "window.domAutomationController.send(window.close());"; | 679 "window.domAutomationController.send(window.close());"; |
| 680 bool result = | 680 bool result = |
| 681 ui_test_utils::ExecuteJavaScript( | 681 ui_test_utils::ExecuteJavaScript( |
| 682 current_browser_->GetSelectedTabContents()->render_view_host(), | 682 current_browser_->GetSelectedTabContents()->render_view_host(), |
| 683 L"", UTF8ToWide(script)); | 683 L"", UTF8ToWide(script)); |
| 684 EXPECT_EQ(result, true); | 684 EXPECT_EQ(result, true); |
| 685 } | 685 } |
| 686 | 686 |
| 687 } // namespace | 687 } // namespace |
| OLD | NEW |