| 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" |
| 11 #include "base/test/simple_test_clock.h" | 11 #include "base/test/simple_test_clock.h" |
| 12 #include "base/time/clock.h" | 12 #include "base/time/clock.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/content_settings/content_settings_usages_state.h" | 14 #include "chrome/browser/content_settings/content_settings_usages_state.h" |
| 15 #include "chrome/browser/content_settings/host_content_settings_map.h" | 15 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 17 #include "chrome/browser/infobars/infobar_service.h" | 17 #include "chrome/browser/infobars/infobar_service.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_commands.h" | 20 #include "chrome/browser/ui/browser_commands.h" |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 22 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 22 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 23 #include "chrome/common/content_settings_pattern.h" | 24 #include "chrome/common/content_settings_pattern.h" |
| 24 #include "chrome/test/base/in_process_browser_test.h" | 25 #include "chrome/test/base/in_process_browser_test.h" |
| 25 #include "chrome/test/base/ui_test_utils.h" | 26 #include "chrome/test/base/ui_test_utils.h" |
| 26 #include "components/infobars/core/confirm_infobar_delegate.h" | 27 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 27 #include "components/infobars/core/infobar.h" | 28 #include "components/infobars/core/infobar.h" |
| 28 #include "content/public/browser/dom_operation_notification_details.h" | 29 #include "content/public/browser/dom_operation_notification_details.h" |
| 29 #include "content/public/browser/navigation_controller.h" | 30 #include "content/public/browser/navigation_controller.h" |
| 30 #include "content/public/browser/notification_details.h" | 31 #include "content/public/browser/notification_details.h" |
| 31 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 navigation_completed_ = true; | 115 navigation_completed_ = true; |
| 115 } else if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) { | 116 } else if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) { |
| 116 content::Details<DomOperationNotificationDetails> dom_op_details(details); | 117 content::Details<DomOperationNotificationDetails> dom_op_details(details); |
| 117 javascript_response_ = dom_op_details->json; | 118 javascript_response_ = dom_op_details->json; |
| 118 javascript_completed_ = true; | 119 javascript_completed_ = true; |
| 119 } | 120 } |
| 120 if (javascript_completed_ && navigation_completed_) | 121 if (javascript_completed_ && navigation_completed_) |
| 121 base::MessageLoopForUI::current()->Quit(); | 122 base::MessageLoopForUI::current()->Quit(); |
| 122 } | 123 } |
| 123 | 124 |
| 125 class MockView : public PermissionBubbleView { |
| 126 public: |
| 127 MockView() : shown_(false), can_accept_updates_(true), delegate_(NULL) {} |
| 128 virtual ~MockView() {} |
| 129 |
| 130 void Clear() { |
| 131 shown_ = false; |
| 132 can_accept_updates_ = true; |
| 133 delegate_ = NULL; |
| 134 permission_requests_.clear(); |
| 135 permission_states_.clear(); |
| 136 } |
| 137 |
| 138 // PermissionBubbleView: |
| 139 virtual void SetDelegate(Delegate* delegate) OVERRIDE { |
| 140 delegate_ = delegate; |
| 141 } |
| 142 |
| 143 virtual void Show( |
| 144 const std::vector<PermissionBubbleRequest*>& requests, |
| 145 const std::vector<bool>& accept_state, |
| 146 bool customization_state_) OVERRIDE { |
| 147 LOG(INFO) << "Mock view shown"; |
| 148 shown_ = true; |
| 149 permission_requests_ = requests; |
| 150 permission_states_ = accept_state; |
| 151 base::MessageLoopForUI::current()->Quit(); |
| 152 } |
| 153 |
| 154 virtual void Hide() OVERRIDE { |
| 155 shown_ = false; |
| 156 } |
| 157 |
| 158 virtual bool IsVisible() OVERRIDE { |
| 159 return shown_; |
| 160 } |
| 161 |
| 162 virtual bool CanAcceptRequestUpdate() OVERRIDE { |
| 163 return can_accept_updates_; |
| 164 } |
| 165 |
| 166 void Accept() { |
| 167 delegate_->Accept(); |
| 168 } |
| 169 |
| 170 void Deny() { |
| 171 delegate_->Deny(); |
| 172 } |
| 173 |
| 174 void Close() { |
| 175 delegate_->Closing(); |
| 176 } |
| 177 |
| 178 bool shown_; |
| 179 bool can_accept_updates_; |
| 180 Delegate* delegate_; |
| 181 std::vector<PermissionBubbleRequest*> permission_requests_; |
| 182 std::vector<bool> permission_states_; |
| 183 }; |
| 184 |
| 124 // GeolocationNotificationObserver -------------------------------------------- | 185 // GeolocationNotificationObserver -------------------------------------------- |
| 125 | 186 |
| 126 class GeolocationNotificationObserver : public content::NotificationObserver { | 187 class GeolocationNotificationObserver : public content::NotificationObserver { |
| 127 public: | 188 public: |
| 128 // If |wait_for_infobar| is true, AddWatchAndWaitForNotification will block | 189 // If |wait_for_prompt| is true, AddWatchAndWaitForNotification will block |
| 129 // until the infobar has been displayed; otherwise it will block until the | 190 // until the prompt has been displayed; otherwise it will block until the |
| 130 // navigation is completed. | 191 // navigation is completed. |
| 131 explicit GeolocationNotificationObserver(bool wait_for_infobar); | 192 explicit GeolocationNotificationObserver(bool wait_for_prompt, |
| 193 MockView* view); |
| 132 virtual ~GeolocationNotificationObserver(); | 194 virtual ~GeolocationNotificationObserver(); |
| 133 | 195 |
| 134 // content::NotificationObserver: | 196 // content::NotificationObserver: |
| 135 virtual void Observe(int type, | 197 virtual void Observe(int type, |
| 136 const content::NotificationSource& source, | 198 const content::NotificationSource& source, |
| 137 const content::NotificationDetails& details) OVERRIDE; | 199 const content::NotificationDetails& details) OVERRIDE; |
| 138 | 200 |
| 201 // Note: also runs the 'geoStart' method in the test JS script. |
| 139 void AddWatchAndWaitForNotification( | 202 void AddWatchAndWaitForNotification( |
| 140 content::RenderFrameHost* render_frame_host); | 203 content::RenderFrameHost* render_frame_host); |
| 141 | 204 |
| 142 bool has_infobar() const { return !!infobar_; } | 205 bool has_infobar() const { return !!infobar_; } |
| 143 infobars::InfoBar* infobar() { return infobar_; } | 206 infobars::InfoBar* infobar() { return infobar_; } |
| 144 | 207 |
| 145 private: | 208 private: |
| 146 content::NotificationRegistrar registrar_; | 209 content::NotificationRegistrar registrar_; |
| 147 bool wait_for_infobar_; | 210 bool wait_for_prompt_; |
| 148 infobars::InfoBar* infobar_; | 211 infobars::InfoBar* infobar_; |
| 149 bool navigation_started_; | 212 bool navigation_started_; |
| 150 bool navigation_completed_; | 213 bool navigation_completed_; |
| 151 std::string javascript_response_; | 214 std::string javascript_response_; |
| 215 MockView* mock_view_; |
| 152 | 216 |
| 153 DISALLOW_COPY_AND_ASSIGN(GeolocationNotificationObserver); | 217 DISALLOW_COPY_AND_ASSIGN(GeolocationNotificationObserver); |
| 154 }; | 218 }; |
| 155 | 219 |
| 156 GeolocationNotificationObserver::GeolocationNotificationObserver( | 220 GeolocationNotificationObserver::GeolocationNotificationObserver( |
| 157 bool wait_for_infobar) | 221 bool wait_for_prompt, |
| 158 : wait_for_infobar_(wait_for_infobar), | 222 MockView* view) |
| 223 : wait_for_prompt_(wait_for_prompt), |
| 159 infobar_(NULL), | 224 infobar_(NULL), |
| 160 navigation_started_(false), | 225 navigation_started_(false), |
| 161 navigation_completed_(false) { | 226 navigation_completed_(false), |
| 227 mock_view_(view) { |
| 162 registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE, | 228 registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE, |
| 163 content::NotificationService::AllSources()); | 229 content::NotificationService::AllSources()); |
| 164 if (wait_for_infobar) { | 230 if (wait_for_prompt) { |
| 165 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 231 if (!PermissionBubbleManager::Enabled()) { |
| 166 content::NotificationService::AllSources()); | 232 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
| 233 content::NotificationService::AllSources()); |
| 234 } |
| 167 } else { | 235 } else { |
| 168 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 236 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 169 content::NotificationService::AllSources()); | 237 content::NotificationService::AllSources()); |
| 170 registrar_.Add(this, content::NOTIFICATION_LOAD_START, | 238 registrar_.Add(this, content::NOTIFICATION_LOAD_START, |
| 171 content::NotificationService::AllSources()); | 239 content::NotificationService::AllSources()); |
| 172 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | 240 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
| 173 content::NotificationService::AllSources()); | 241 content::NotificationService::AllSources()); |
| 174 } | 242 } |
| 175 } | 243 } |
| 176 | 244 |
| 177 GeolocationNotificationObserver::~GeolocationNotificationObserver() { | 245 GeolocationNotificationObserver::~GeolocationNotificationObserver() { |
| 178 } | 246 } |
| 179 | 247 |
| 180 void GeolocationNotificationObserver::Observe( | 248 void GeolocationNotificationObserver::Observe( |
| 181 int type, | 249 int type, |
| 182 const content::NotificationSource& source, | 250 const content::NotificationSource& source, |
| 183 const content::NotificationDetails& details) { | 251 const content::NotificationDetails& details) { |
| 184 if (type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED) { | 252 if (type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED) { |
| 185 infobar_ = content::Details<infobars::InfoBar::AddedDetails>(details).ptr(); | 253 infobar_ = content::Details<infobars::InfoBar::AddedDetails>(details).ptr(); |
| 186 ASSERT_FALSE(infobar_->delegate()->GetIcon().IsEmpty()); | 254 ASSERT_FALSE(infobar_->delegate()->GetIcon().IsEmpty()); |
| 187 ASSERT_TRUE(infobar_->delegate()->AsConfirmInfoBarDelegate()); | 255 ASSERT_TRUE(infobar_->delegate()->AsConfirmInfoBarDelegate()); |
| 188 } else if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) { | 256 } else if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) { |
| 189 content::Details<DomOperationNotificationDetails> dom_op_details(details); | 257 content::Details<DomOperationNotificationDetails> dom_op_details(details); |
| 190 javascript_response_ = dom_op_details->json; | 258 javascript_response_ = dom_op_details->json; |
| 191 LOG(WARNING) << "javascript_response " << javascript_response_; | 259 LOG(WARNING) << "javascript_response " << javascript_response_; |
| 260 if (wait_for_prompt_ && PermissionBubbleManager::Enabled()) |
| 261 base::MessageLoopForUI::current()->Quit(); |
| 192 } else if ((type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) || | 262 } else if ((type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) || |
| 193 (type == content::NOTIFICATION_LOAD_START)) { | 263 (type == content::NOTIFICATION_LOAD_START)) { |
| 194 navigation_started_ = true; | 264 navigation_started_ = true; |
| 195 } else if ((type == content::NOTIFICATION_LOAD_STOP) && navigation_started_) { | 265 } else if ((type == content::NOTIFICATION_LOAD_STOP) && navigation_started_) { |
| 196 navigation_started_ = false; | 266 navigation_started_ = false; |
| 197 navigation_completed_ = true; | 267 navigation_completed_ = true; |
| 198 } | 268 } |
| 199 | 269 |
| 200 // We're either waiting for just the infobar, or for both a javascript | 270 // We're either waiting for just the infobar, or for both a javascript |
| 201 // prompt and response. | 271 // prompt and response. |
| 202 if ((wait_for_infobar_ && infobar_) || | 272 if ((wait_for_prompt_ && infobar_ && !PermissionBubbleManager::Enabled()) || |
| 203 (navigation_completed_ && !javascript_response_.empty())) | 273 (navigation_completed_ && !javascript_response_.empty())) { |
| 204 base::MessageLoopForUI::current()->Quit(); | 274 base::MessageLoopForUI::current()->Quit(); |
| 275 } |
| 205 } | 276 } |
| 206 | 277 |
| 207 void GeolocationNotificationObserver::AddWatchAndWaitForNotification( | 278 void GeolocationNotificationObserver::AddWatchAndWaitForNotification( |
| 208 content::RenderFrameHost* render_frame_host) { | 279 content::RenderFrameHost* render_frame_host) { |
| 209 LOG(WARNING) << "will add geolocation watch"; | 280 if (!PermissionBubbleManager::Enabled()) { |
| 210 std::string script( | 281 LOG(WARNING) << "will add geolocation watch"; |
| 211 "window.domAutomationController.setAutomationId(0);" | 282 std::string script( |
| 212 "window.domAutomationController.send(geoStart());"); | 283 "window.domAutomationController.setAutomationId(0);" |
| 213 render_frame_host->ExecuteJavaScript(base::UTF8ToUTF16(script)); | 284 "window.domAutomationController.send(geoStart());"); |
| 214 content::RunMessageLoop(); | 285 render_frame_host->ExecuteJavaScript(base::UTF8ToUTF16(script)); |
| 215 registrar_.RemoveAll(); | 286 content::RunMessageLoop(); |
| 216 LOG(WARNING) << "got geolocation watch" << javascript_response_; | 287 registrar_.RemoveAll(); |
| 217 EXPECT_NE("\"0\"", javascript_response_); | 288 LOG(WARNING) << "got geolocation watch" << javascript_response_; |
| 218 EXPECT_TRUE(wait_for_infobar_ ? (infobar_ != NULL) : navigation_completed_); | 289 EXPECT_NE("\"0\"", javascript_response_); |
| 290 EXPECT_TRUE(wait_for_prompt_ ? (infobar_ != NULL) : navigation_completed_); |
| 291 } else { |
| 292 LOG(WARNING) << "will add geolocation watch for bubble"; |
| 293 std::string script( |
| 294 "window.domAutomationController.setAutomationId(0);" |
| 295 "window.domAutomationController.send(geoStart());"); |
| 296 render_frame_host->ExecuteJavaScript(base::UTF8ToUTF16(script)); |
| 297 LOG(INFO) << "run..."; |
| 298 (new content::MessageLoopRunner())->Run(); |
| 299 while (wait_for_prompt_ && !mock_view_->shown_) { |
| 300 (new content::MessageLoopRunner())->Run(); |
| 301 } |
| 302 LOG(INFO) << "Watch done"; |
| 303 } |
| 219 } | 304 } |
| 220 | 305 |
| 221 } // namespace | 306 } // namespace |
| 222 | 307 |
| 223 | 308 |
| 224 // GeolocationBrowserTest ----------------------------------------------------- | 309 // GeolocationBrowserTest ----------------------------------------------------- |
| 225 | 310 |
| 226 // This is a browser test for Geolocation. | 311 // This is a browser test for Geolocation. |
| 227 // It exercises various integration points from javascript <-> browser: | 312 // It exercises various integration points from javascript <-> browser: |
| 228 // 1. Infobar is displayed when a geolocation is requested from an unauthorized | 313 // 1. Prompt is displayed when a geolocation is requested from an unauthorized |
| 229 // origin. | 314 // origin. |
| 230 // 2. Denying the infobar triggers the correct error callback. | 315 // 2. Denying the request triggers the correct error callback. |
| 231 // 3. Allowing the infobar does not trigger an error, and allow a geoposition to | 316 // 3. Allowing the request does not trigger an error, and allow a geoposition to |
| 232 // be passed to javascript. | 317 // be passed to javascript. |
| 233 // 4. Permissions persisted in disk are respected. | 318 // 4. Permissions persisted in disk are respected. |
| 234 // 5. Incognito profiles don't use saved permissions. | 319 // 5. Incognito profiles don't use saved permissions. |
| 235 class GeolocationBrowserTest : public InProcessBrowserTest { | 320 class GeolocationBrowserTest : public InProcessBrowserTest { |
| 236 public: | 321 public: |
| 237 enum InitializationOptions { | 322 enum InitializationOptions { |
| 238 INITIALIZATION_NONE, | 323 INITIALIZATION_NONE, |
| 239 INITIALIZATION_OFFTHERECORD, | 324 INITIALIZATION_OFFTHERECORD, |
| 240 INITIALIZATION_NEWTAB, | 325 INITIALIZATION_NEWTAB, |
| 241 INITIALIZATION_IFRAMES, | 326 INITIALIZATION_IFRAMES, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 260 | 345 |
| 261 // Initializes the test server and navigates to the initial url. | 346 // Initializes the test server and navigates to the initial url. |
| 262 bool Initialize(InitializationOptions options) WARN_UNUSED_RESULT; | 347 bool Initialize(InitializationOptions options) WARN_UNUSED_RESULT; |
| 263 | 348 |
| 264 // Loads the specified number of iframes. | 349 // Loads the specified number of iframes. |
| 265 void LoadIFrames(int number_iframes); | 350 void LoadIFrames(int number_iframes); |
| 266 | 351 |
| 267 // Specifies which frame is to be used for JavaScript calls. | 352 // Specifies which frame is to be used for JavaScript calls. |
| 268 void SetFrameHost(const std::string& frame_name); | 353 void SetFrameHost(const std::string& frame_name); |
| 269 | 354 |
| 270 // Start watching for geolocation notifications. If |wait_for_infobar| is | 355 // Start watching for geolocation notifications. If |wait_for_prompt| is |
| 271 // true, wait for the infobar to be displayed. Otherwise wait for a javascript | 356 // true, wait for the prompt (infobar or bubble) to be displayed. |
| 272 // response. | 357 // Otherwise wait for a javascript response. |
| 273 void AddGeolocationWatch(bool wait_for_infobar); | 358 void AddGeolocationWatch(bool wait_for_prompt); |
| 274 | 359 |
| 275 // Checks that no errors have been received in javascript, and checks that the | 360 // Checks that no errors have been received in javascript, and checks that the |
| 276 // position most recently received in javascript matches |latitude| and | 361 // position most recently received in javascript matches |latitude| and |
| 277 // |longitude|. | 362 // |longitude|. |
| 278 void CheckGeoposition(double latitude, double longitude); | 363 void CheckGeoposition(double latitude, double longitude); |
| 279 | 364 |
| 280 // For |requesting_url| if |allowed| is true accept the infobar. Otherwise | 365 // For |requesting_url| if |allowed| is true accept the geolocation request. |
| 281 // cancel it. | 366 // Otherwise cancel it. |
| 282 void SetInfoBarResponse(const GURL& requesting_url, bool allowed); | 367 void SetPromptResponse(const GURL& requesting_url, bool allowed); |
| 283 | 368 |
| 284 // Executes |function| in |render_frame_host| and checks that the return value | 369 // Executes |function| in |render_frame_host| and checks that the return value |
| 285 // matches |expected|. | 370 // matches |expected|. |
| 286 void CheckStringValueFromJavascriptForFrame( | 371 void CheckStringValueFromJavascriptForFrame( |
| 287 const std::string& expected, | 372 const std::string& expected, |
| 288 const std::string& function, | 373 const std::string& function, |
| 289 content::RenderFrameHost* render_frame_host); | 374 content::RenderFrameHost* render_frame_host); |
| 290 | 375 |
| 291 // Executes |function| and checks that the return value matches |expected|. | 376 // Executes |function| and checks that the return value matches |expected|. |
| 292 void CheckStringValueFromJavascript(const std::string& expected, | 377 void CheckStringValueFromJavascript(const std::string& expected, |
| 293 const std::string& function); | 378 const std::string& function); |
| 294 | 379 |
| 295 // Sets a new position and sends a notification with the new position. | 380 // Sets a new position and sends a notification with the new position. |
| 296 void NotifyGeoposition(double latitude, double longitude); | 381 void NotifyGeoposition(double latitude, double longitude); |
| 297 | 382 |
| 298 private: | 383 private: |
| 299 infobars::InfoBar* infobar_; | 384 infobars::InfoBar* infobar_; |
| 300 Browser* current_browser_; | 385 Browser* current_browser_; |
| 301 // path element of a URL referencing the html content for this test. | 386 // path element of a URL referencing the html content for this test. |
| 302 std::string html_for_tests_; | 387 std::string html_for_tests_; |
| 303 // This member defines the frame where the JavaScript calls will run. | 388 // This member defines the frame where the JavaScript calls will run. |
| 304 content::RenderFrameHost* render_frame_host_; | 389 content::RenderFrameHost* render_frame_host_; |
| 305 // The current url for the top level page. | 390 // The current url for the top level page. |
| 306 GURL current_url_; | 391 GURL current_url_; |
| 307 // If not empty, the GURLs for the iframes loaded by LoadIFrames(). | 392 // If not empty, the GURLs for the iframes loaded by LoadIFrames(). |
| 308 std::vector<GURL> iframe_urls_; | 393 std::vector<GURL> iframe_urls_; |
| 309 double fake_latitude_; | 394 double fake_latitude_; |
| 310 double fake_longitude_; | 395 double fake_longitude_; |
| 311 | 396 |
| 397 MockView mock_bubble_view_; |
| 398 |
| 312 DISALLOW_COPY_AND_ASSIGN(GeolocationBrowserTest); | 399 DISALLOW_COPY_AND_ASSIGN(GeolocationBrowserTest); |
| 313 }; | 400 }; |
| 314 | 401 |
| 315 GeolocationBrowserTest::GeolocationBrowserTest() | 402 GeolocationBrowserTest::GeolocationBrowserTest() |
| 316 : infobar_(NULL), | 403 : infobar_(NULL), |
| 317 current_browser_(NULL), | 404 current_browser_(NULL), |
| 318 html_for_tests_("/geolocation/simple.html"), | 405 html_for_tests_("/geolocation/simple.html"), |
| 319 render_frame_host_(NULL), | 406 render_frame_host_(NULL), |
| 320 fake_latitude_(1.23), | 407 fake_latitude_(1.23), |
| 321 fake_longitude_(4.56) { | 408 fake_longitude_(4.56) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 337 !embedded_test_server()->InitializeAndWaitUntilReady()) { | 424 !embedded_test_server()->InitializeAndWaitUntilReady()) { |
| 338 ADD_FAILURE() << "Test server failed to start."; | 425 ADD_FAILURE() << "Test server failed to start."; |
| 339 return false; | 426 return false; |
| 340 } | 427 } |
| 341 | 428 |
| 342 current_url_ = embedded_test_server()->GetURL(html_for_tests_); | 429 current_url_ = embedded_test_server()->GetURL(html_for_tests_); |
| 343 LOG(WARNING) << "before navigate"; | 430 LOG(WARNING) << "before navigate"; |
| 344 if (options == INITIALIZATION_OFFTHERECORD) { | 431 if (options == INITIALIZATION_OFFTHERECORD) { |
| 345 current_browser_ = ui_test_utils::OpenURLOffTheRecord( | 432 current_browser_ = ui_test_utils::OpenURLOffTheRecord( |
| 346 browser()->profile(), current_url_); | 433 browser()->profile(), current_url_); |
| 434 WebContents* web_contents = |
| 435 current_browser_->tab_strip_model()->GetActiveWebContents(); |
| 436 PermissionBubbleManager::FromWebContents(web_contents)->SetView( |
| 437 &mock_bubble_view_); |
| 347 } else { | 438 } else { |
| 348 current_browser_ = browser(); | 439 current_browser_ = browser(); |
| 349 if (options == INITIALIZATION_NEWTAB) | 440 if (options == INITIALIZATION_NEWTAB) |
| 350 chrome::NewTab(current_browser_); | 441 chrome::NewTab(current_browser_); |
| 442 WebContents* web_contents = |
| 443 current_browser_->tab_strip_model()->GetActiveWebContents(); |
| 444 PermissionBubbleManager::FromWebContents(web_contents)->SetView( |
| 445 &mock_bubble_view_); |
| 351 ui_test_utils::NavigateToURL(current_browser_, current_url_); | 446 ui_test_utils::NavigateToURL(current_browser_, current_url_); |
| 352 } | 447 } |
| 353 LOG(WARNING) << "after navigate"; | 448 LOG(WARNING) << "after navigate"; |
| 354 | 449 |
| 355 EXPECT_TRUE(current_browser_); | 450 EXPECT_TRUE(current_browser_); |
| 356 return !!current_browser_; | 451 return !!current_browser_; |
| 357 } | 452 } |
| 358 | 453 |
| 359 void GeolocationBrowserTest::LoadIFrames(int number_iframes) { | 454 void GeolocationBrowserTest::LoadIFrames(int number_iframes) { |
| 360 // Limit to 3 iframes. | 455 // Limit to 3 iframes. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 374 | 469 |
| 375 if (frame_name.empty()) { | 470 if (frame_name.empty()) { |
| 376 render_frame_host_ = web_contents->GetMainFrame(); | 471 render_frame_host_ = web_contents->GetMainFrame(); |
| 377 } else { | 472 } else { |
| 378 render_frame_host_ = content::FrameMatchingPredicate( | 473 render_frame_host_ = content::FrameMatchingPredicate( |
| 379 web_contents, base::Bind(&content::FrameMatchesName, frame_name)); | 474 web_contents, base::Bind(&content::FrameMatchesName, frame_name)); |
| 380 } | 475 } |
| 381 DCHECK(render_frame_host_); | 476 DCHECK(render_frame_host_); |
| 382 } | 477 } |
| 383 | 478 |
| 384 void GeolocationBrowserTest::AddGeolocationWatch(bool wait_for_infobar) { | 479 void GeolocationBrowserTest::AddGeolocationWatch(bool wait_for_prompt) { |
| 385 GeolocationNotificationObserver notification_observer(wait_for_infobar); | 480 LOG(INFO) << "Adding geo watch"; |
| 481 GeolocationNotificationObserver notification_observer( |
| 482 wait_for_prompt, &mock_bubble_view_); |
| 386 notification_observer.AddWatchAndWaitForNotification(render_frame_host_); | 483 notification_observer.AddWatchAndWaitForNotification(render_frame_host_); |
| 387 if (wait_for_infobar) { | 484 if (wait_for_prompt && !PermissionBubbleManager::Enabled()) { |
| 388 EXPECT_TRUE(notification_observer.has_infobar()); | 485 EXPECT_TRUE(notification_observer.has_infobar()); |
| 389 infobar_ = notification_observer.infobar(); | 486 infobar_ = notification_observer.infobar(); |
| 487 } else if (wait_for_prompt && PermissionBubbleManager::Enabled()) { |
| 488 // TODO(gbillock): something. |
| 390 } | 489 } |
| 391 } | 490 } |
| 392 | 491 |
| 393 void GeolocationBrowserTest::CheckGeoposition(double latitude, | 492 void GeolocationBrowserTest::CheckGeoposition(double latitude, |
| 394 double longitude) { | 493 double longitude) { |
| 395 // Checks we have no error. | 494 // Checks we have no error. |
| 396 CheckStringValueFromJavascript("0", "geoGetLastError()"); | 495 CheckStringValueFromJavascript("0", "geoGetLastError()"); |
| 397 CheckStringValueFromJavascript(base::DoubleToString(latitude), | 496 CheckStringValueFromJavascript(base::DoubleToString(latitude), |
| 398 "geoGetLastPositionLatitude()"); | 497 "geoGetLastPositionLatitude()"); |
| 399 CheckStringValueFromJavascript(base::DoubleToString(longitude), | 498 CheckStringValueFromJavascript(base::DoubleToString(longitude), |
| 400 "geoGetLastPositionLongitude()"); | 499 "geoGetLastPositionLongitude()"); |
| 401 } | 500 } |
| 402 | 501 |
| 403 void GeolocationBrowserTest::SetInfoBarResponse(const GURL& requesting_url, | 502 void GeolocationBrowserTest::SetPromptResponse(const GURL& requesting_url, |
| 404 bool allowed) { | 503 bool allowed) { |
| 405 WebContents* web_contents = | 504 if (!PermissionBubbleManager::Enabled()) { |
| 406 current_browser_->tab_strip_model()->GetActiveWebContents(); | 505 WebContents* web_contents = |
| 407 TabSpecificContentSettings* content_settings = | 506 current_browser_->tab_strip_model()->GetActiveWebContents(); |
| 408 TabSpecificContentSettings::FromWebContents(web_contents); | 507 TabSpecificContentSettings* content_settings = |
| 409 const ContentSettingsUsagesState& usages_state = | 508 TabSpecificContentSettings::FromWebContents(web_contents); |
| 410 content_settings->geolocation_usages_state(); | 509 const ContentSettingsUsagesState& usages_state = |
| 411 size_t state_map_size = usages_state.state_map().size(); | 510 content_settings->geolocation_usages_state(); |
| 412 ASSERT_TRUE(infobar_); | 511 size_t state_map_size = usages_state.state_map().size(); |
| 413 LOG(WARNING) << "will set infobar response"; | 512 ASSERT_TRUE(infobar_); |
| 414 { | 513 LOG(WARNING) << "will set infobar response"; |
| 415 content::WindowedNotificationObserver observer( | 514 { |
| 416 content::NOTIFICATION_LOAD_STOP, | 515 content::WindowedNotificationObserver observer( |
| 417 content::Source<NavigationController>(&web_contents->GetController())); | 516 content::NOTIFICATION_LOAD_STOP, |
| 517 content::Source<NavigationController>( |
| 518 &web_contents->GetController())); |
| 519 if (allowed) |
| 520 infobar_->delegate()->AsConfirmInfoBarDelegate()->Accept(); |
| 521 else |
| 522 infobar_->delegate()->AsConfirmInfoBarDelegate()->Cancel(); |
| 523 observer.Wait(); |
| 524 } |
| 525 |
| 526 InfoBarService* infobar_service = |
| 527 InfoBarService::FromWebContents(web_contents); |
| 528 infobar_service->RemoveInfoBar(infobar_); |
| 529 LOG(WARNING) << "infobar response set"; |
| 530 infobar_ = NULL; |
| 531 EXPECT_GT(usages_state.state_map().size(), state_map_size); |
| 532 GURL requesting_origin(requesting_url.GetOrigin()); |
| 533 EXPECT_EQ(1U, usages_state.state_map().count(requesting_origin)); |
| 534 ContentSetting expected_setting = |
| 535 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 536 EXPECT_EQ(expected_setting, |
| 537 usages_state.state_map().find(requesting_origin)->second); |
| 538 } else { |
| 539 LOG(INFO) << "Set allow " << allowed; |
| 540 WebContents* web_contents = |
| 541 current_browser_->tab_strip_model()->GetActiveWebContents(); |
| 542 TabSpecificContentSettings* content_settings = |
| 543 TabSpecificContentSettings::FromWebContents(web_contents); |
| 544 const ContentSettingsUsagesState& usages_state = |
| 545 content_settings->geolocation_usages_state(); |
| 546 size_t state_map_size = usages_state.state_map().size(); |
| 547 |
| 418 if (allowed) | 548 if (allowed) |
| 419 infobar_->delegate()->AsConfirmInfoBarDelegate()->Accept(); | 549 mock_bubble_view_.Accept(); |
| 420 else | 550 else |
| 421 infobar_->delegate()->AsConfirmInfoBarDelegate()->Cancel(); | 551 mock_bubble_view_.Deny(); |
| 422 observer.Wait(); | 552 |
| 553 EXPECT_GT(usages_state.state_map().size(), state_map_size); |
| 554 GURL requesting_origin(requesting_url.GetOrigin()); |
| 555 EXPECT_EQ(1U, usages_state.state_map().count(requesting_origin)); |
| 556 ContentSetting expected_setting = |
| 557 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 558 EXPECT_EQ(expected_setting, |
| 559 usages_state.state_map().find(requesting_origin)->second); |
| 423 } | 560 } |
| 424 | |
| 425 InfoBarService* infobar_service = | |
| 426 InfoBarService::FromWebContents(web_contents); | |
| 427 infobar_service->RemoveInfoBar(infobar_); | |
| 428 LOG(WARNING) << "infobar response set"; | |
| 429 infobar_ = NULL; | |
| 430 EXPECT_GT(usages_state.state_map().size(), state_map_size); | |
| 431 GURL requesting_origin(requesting_url.GetOrigin()); | |
| 432 EXPECT_EQ(1U, usages_state.state_map().count(requesting_origin)); | |
| 433 ContentSetting expected_setting = | |
| 434 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | |
| 435 EXPECT_EQ(expected_setting, | |
| 436 usages_state.state_map().find(requesting_origin)->second); | |
| 437 } | 561 } |
| 438 | 562 |
| 439 void GeolocationBrowserTest::CheckStringValueFromJavascriptForFrame( | 563 void GeolocationBrowserTest::CheckStringValueFromJavascriptForFrame( |
| 440 const std::string& expected, | 564 const std::string& expected, |
| 441 const std::string& function, | 565 const std::string& function, |
| 442 content::RenderFrameHost* render_frame_host) { | 566 content::RenderFrameHost* render_frame_host) { |
| 443 std::string script(base::StringPrintf( | 567 std::string script(base::StringPrintf( |
| 444 "window.domAutomationController.send(%s)", function.c_str())); | 568 "window.domAutomationController.send(%s)", function.c_str())); |
| 445 std::string result; | 569 std::string result; |
| 446 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 570 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 447 render_frame_host, script, &result)); | 571 render_frame_host, script, &result)); |
| 572 LOG(INFO) << "GOT JS RESULT " << result; |
| 448 EXPECT_EQ(expected, result); | 573 EXPECT_EQ(expected, result); |
| 449 } | 574 } |
| 450 | 575 |
| 451 void GeolocationBrowserTest::CheckStringValueFromJavascript( | 576 void GeolocationBrowserTest::CheckStringValueFromJavascript( |
| 452 const std::string& expected, | 577 const std::string& expected, |
| 453 const std::string& function) { | 578 const std::string& function) { |
| 454 CheckStringValueFromJavascriptForFrame( | 579 CheckStringValueFromJavascriptForFrame( |
| 455 expected, function, render_frame_host_); | 580 expected, function, render_frame_host_); |
| 456 } | 581 } |
| 457 | 582 |
| 458 void GeolocationBrowserTest::NotifyGeoposition(double latitude, | 583 void GeolocationBrowserTest::NotifyGeoposition(double latitude, |
| 459 double longitude) { | 584 double longitude) { |
| 460 fake_latitude_ = latitude; | 585 fake_latitude_ = latitude; |
| 461 fake_longitude_ = longitude; | 586 fake_longitude_ = longitude; |
| 462 ui_test_utils::OverrideGeolocation(latitude, longitude); | 587 ui_test_utils::OverrideGeolocation(latitude, longitude); |
| 463 LOG(WARNING) << "MockLocationProvider listeners updated"; | 588 LOG(WARNING) << "MockLocationProvider listeners updated"; |
| 464 } | 589 } |
| 465 | 590 |
| 466 | 591 |
| 467 // Tests ---------------------------------------------------------------------- | 592 // Tests ---------------------------------------------------------------------- |
| 468 | 593 |
| 469 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DisplaysPermissionBar) { | 594 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DisplaysPrompt) { |
| 470 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 595 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| 471 SetFrameHost(""); | 596 SetFrameHost(""); |
| 472 AddGeolocationWatch(true); | 597 AddGeolocationWatch(true); |
| 473 } | 598 } |
| 474 | 599 |
| 475 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, Geoposition) { | 600 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, Geoposition) { |
| 476 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 601 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| 477 SetFrameHost(""); | 602 SetFrameHost(""); |
| 478 AddGeolocationWatch(true); | 603 AddGeolocationWatch(true); |
| 479 SetInfoBarResponse(current_url(), true); | 604 SetPromptResponse(current_url(), true); |
| 480 CheckGeoposition(fake_latitude(), fake_longitude()); | 605 CheckGeoposition(fake_latitude(), fake_longitude()); |
| 481 } | 606 } |
| 482 | 607 |
| 483 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, | 608 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, |
| 484 ErrorOnPermissionDenied) { | 609 ErrorOnPermissionDenied) { |
| 485 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 610 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| 486 SetFrameHost(""); | 611 SetFrameHost(""); |
| 487 AddGeolocationWatch(true); | 612 AddGeolocationWatch(true); |
| 488 // Infobar was displayed, deny access and check for error code. | 613 // Prompt was displayed, deny access and check for error code. |
| 489 SetInfoBarResponse(current_url(), false); | 614 SetPromptResponse(current_url(), false); |
| 615 if (PermissionBubbleManager::Enabled()) |
| 616 content::RunAllPendingInMessageLoop(); |
| 490 CheckStringValueFromJavascript("1", "geoGetLastError()"); | 617 CheckStringValueFromJavascript("1", "geoGetLastError()"); |
| 491 } | 618 } |
| 492 | 619 |
| 493 // See http://crbug.com/308358 | 620 // See http://crbug.com/308358 |
| 494 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DISABLED_NoInfobarForSecondTab) { | 621 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DISABLED_NoPromptForSecondTab) { |
| 495 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 622 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| 496 SetFrameHost(""); | 623 SetFrameHost(""); |
| 497 AddGeolocationWatch(true); | 624 AddGeolocationWatch(true); |
| 498 SetInfoBarResponse(current_url(), true); | 625 SetPromptResponse(current_url(), true); |
| 499 // Disables further prompts from this tab. | 626 // Disables further prompts from this tab. |
| 500 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 627 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| 501 | 628 |
| 502 // Checks infobar will not be created in a second tab. | 629 // Checks prompt will not be created in a second tab. |
| 503 ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB)); | 630 ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB)); |
| 504 SetFrameHost(""); | 631 SetFrameHost(""); |
| 505 AddGeolocationWatch(false); | 632 AddGeolocationWatch(false); |
| 506 CheckGeoposition(fake_latitude(), fake_longitude()); | 633 CheckGeoposition(fake_latitude(), fake_longitude()); |
| 507 } | 634 } |
| 508 | 635 |
| 509 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfobarForDeniedOrigin) { | 636 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForDeniedOrigin) { |
| 510 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 637 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| 511 current_browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 638 current_browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
| 512 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 639 ContentSettingsPattern::FromURLNoWildcard(current_url()), |
| 513 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 640 ContentSettingsPattern::FromURLNoWildcard(current_url()), |
| 514 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), CONTENT_SETTING_BLOCK); | 641 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), CONTENT_SETTING_BLOCK); |
| 515 SetFrameHost(""); | 642 SetFrameHost(""); |
| 516 AddGeolocationWatch(false); | 643 AddGeolocationWatch(false); |
| 517 // Checks we have an error for this denied origin. | 644 // Checks we have an error for this denied origin. |
| 518 CheckStringValueFromJavascript("1", "geoGetLastError()"); | 645 CheckStringValueFromJavascript("1", "geoGetLastError()"); |
| 519 // Checks infobar will not be created a second tab. | 646 // Checks prompt will not be created a second tab. |
| 520 ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB)); | 647 ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB)); |
| 521 SetFrameHost(""); | 648 SetFrameHost(""); |
| 522 AddGeolocationWatch(false); | 649 AddGeolocationWatch(false); |
| 523 CheckStringValueFromJavascript("1", "geoGetLastError()"); | 650 CheckStringValueFromJavascript("1", "geoGetLastError()"); |
| 524 } | 651 } |
| 525 | 652 |
| 526 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfobarForAllowedOrigin) { | 653 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForAllowedOrigin) { |
| 527 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 654 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| 528 current_browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 655 current_browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
| 529 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 656 ContentSettingsPattern::FromURLNoWildcard(current_url()), |
| 530 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 657 ContentSettingsPattern::FromURLNoWildcard(current_url()), |
| 531 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), CONTENT_SETTING_ALLOW); | 658 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), CONTENT_SETTING_ALLOW); |
| 532 // Checks no infobar will be created and there's no error callback. | 659 // Checks no prompt will be created and there's no error callback. |
| 533 SetFrameHost(""); | 660 SetFrameHost(""); |
| 534 AddGeolocationWatch(false); | 661 AddGeolocationWatch(false); |
| 535 CheckGeoposition(fake_latitude(), fake_longitude()); | 662 CheckGeoposition(fake_latitude(), fake_longitude()); |
| 536 } | 663 } |
| 537 | 664 |
| 538 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfobarForOffTheRecord) { | 665 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForOffTheRecord) { |
| 539 // First, check infobar will be created for regular profile | 666 // First, check prompt will be created for regular profile |
| 540 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 667 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| 541 SetFrameHost(""); | 668 SetFrameHost(""); |
| 542 AddGeolocationWatch(true); | 669 AddGeolocationWatch(true); |
| 543 // Response will be persisted. | 670 // Response will be persisted. |
| 544 SetInfoBarResponse(current_url(), true); | 671 SetPromptResponse(current_url(), true); |
| 545 CheckGeoposition(fake_latitude(), fake_longitude()); | 672 CheckGeoposition(fake_latitude(), fake_longitude()); |
| 546 // Disables further prompts from this tab. | 673 // Disables further prompts from this tab. |
| 547 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 674 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| 548 // Go incognito, and checks no infobar will be created. | 675 // Go incognito, and checks no prompt will be created. |
| 549 ASSERT_TRUE(Initialize(INITIALIZATION_OFFTHERECORD)); | 676 ASSERT_TRUE(Initialize(INITIALIZATION_OFFTHERECORD)); |
| 550 SetFrameHost(""); | 677 SetFrameHost(""); |
| 551 AddGeolocationWatch(false); | 678 AddGeolocationWatch(false); |
| 552 CheckGeoposition(fake_latitude(), fake_longitude()); | 679 CheckGeoposition(fake_latitude(), fake_longitude()); |
| 553 } | 680 } |
| 554 | 681 |
| 555 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoLeakFromOffTheRecord) { | 682 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoLeakFromOffTheRecord) { |
| 556 // First, check infobar will be created for incognito profile. | 683 // First, check prompt will be created for incognito profile. |
| 557 ASSERT_TRUE(Initialize(INITIALIZATION_OFFTHERECORD)); | 684 ASSERT_TRUE(Initialize(INITIALIZATION_OFFTHERECORD)); |
| 558 SetFrameHost(""); | 685 SetFrameHost(""); |
| 559 AddGeolocationWatch(true); | 686 AddGeolocationWatch(true); |
| 560 // Response won't be persisted. | 687 // Response won't be persisted. |
| 561 SetInfoBarResponse(current_url(), true); | 688 SetPromptResponse(current_url(), true); |
| 562 CheckGeoposition(fake_latitude(), fake_longitude()); | 689 CheckGeoposition(fake_latitude(), fake_longitude()); |
| 563 // Disables further prompts from this tab. | 690 // Disables further prompts from this tab. |
| 564 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 691 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| 565 // Go to the regular profile, infobar will be created. | 692 // Go to the regular profile, prompt will be created. |
| 566 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 693 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| 567 SetFrameHost(""); | 694 SetFrameHost(""); |
| 568 AddGeolocationWatch(true); | 695 AddGeolocationWatch(true); |
| 569 SetInfoBarResponse(current_url(), false); | 696 LOG(INFO) << "---- Setting respons to false"; |
| 697 SetPromptResponse(current_url(), false); |
| 698 if (PermissionBubbleManager::Enabled()) |
| 699 content::RunAllPendingInMessageLoop(); |
| 570 CheckStringValueFromJavascript("1", "geoGetLastError()"); | 700 CheckStringValueFromJavascript("1", "geoGetLastError()"); |
| 571 } | 701 } |
| 572 | 702 |
| 573 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, IFramesWithFreshPosition) { | 703 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, IFramesWithFreshPosition) { |
| 574 set_html_for_tests("/geolocation/iframes_different_origin.html"); | 704 set_html_for_tests("/geolocation/iframes_different_origin.html"); |
| 575 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 705 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
| 576 LoadIFrames(2); | 706 LoadIFrames(2); |
| 577 LOG(WARNING) << "frames loaded"; | 707 LOG(WARNING) << "frames loaded"; |
| 578 | 708 |
| 579 SetFrameHost("iframe_0"); | 709 SetFrameHost("iframe_0"); |
| 580 AddGeolocationWatch(true); | 710 AddGeolocationWatch(true); |
| 581 SetInfoBarResponse(iframe_url(0), true); | 711 SetPromptResponse(iframe_url(0), true); |
| 582 CheckGeoposition(fake_latitude(), fake_longitude()); | 712 CheckGeoposition(fake_latitude(), fake_longitude()); |
| 583 // Disables further prompts from this iframe. | 713 // Disables further prompts from this iframe. |
| 584 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 714 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| 585 | 715 |
| 586 // Test second iframe from a different origin with a cached geoposition will | 716 // Test second iframe from a different origin with a cached geoposition will |
| 587 // create the infobar. | 717 // create the prompt. |
| 588 SetFrameHost("iframe_1"); | 718 SetFrameHost("iframe_1"); |
| 589 AddGeolocationWatch(true); | 719 AddGeolocationWatch(true); |
| 590 | 720 |
| 591 // Back to the first frame, enable navigation and refresh geoposition. | 721 // Back to the first frame, enable navigation and refresh geoposition. |
| 592 SetFrameHost("iframe_0"); | 722 SetFrameHost("iframe_0"); |
| 593 CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); | 723 CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); |
| 594 double fresh_position_latitude = 3.17; | 724 double fresh_position_latitude = 3.17; |
| 595 double fresh_position_longitude = 4.23; | 725 double fresh_position_longitude = 4.23; |
| 596 content::WindowedNotificationObserver observer( | 726 content::WindowedNotificationObserver observer( |
| 597 content::NOTIFICATION_LOAD_STOP, | 727 content::NOTIFICATION_LOAD_STOP, |
| 598 content::Source<NavigationController>( | 728 content::Source<NavigationController>( |
| 599 ¤t_browser()->tab_strip_model()->GetActiveWebContents()-> | 729 ¤t_browser()->tab_strip_model()->GetActiveWebContents()-> |
| 600 GetController())); | 730 GetController())); |
| 601 NotifyGeoposition(fresh_position_latitude, fresh_position_longitude); | 731 NotifyGeoposition(fresh_position_latitude, fresh_position_longitude); |
| 602 observer.Wait(); | 732 observer.Wait(); |
| 603 CheckGeoposition(fresh_position_latitude, fresh_position_longitude); | 733 CheckGeoposition(fresh_position_latitude, fresh_position_longitude); |
| 604 | 734 |
| 605 // Disable navigation for this frame. | 735 // Disable navigation for this frame. |
| 606 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 736 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| 607 | 737 |
| 608 // Now go ahead an authorize the second frame. | 738 // Now go ahead an authorize the second frame. |
| 609 SetFrameHost("iframe_1"); | 739 SetFrameHost("iframe_1"); |
| 610 // Infobar was displayed, allow access and check there's no error code. | 740 // Prompt was displayed, allow access and check there's no error code. |
| 611 SetInfoBarResponse(iframe_url(1), true); | 741 SetPromptResponse(iframe_url(1), true); |
| 612 LOG(WARNING) << "Checking position..."; | 742 LOG(WARNING) << "Checking position..."; |
| 613 CheckGeoposition(fresh_position_latitude, fresh_position_longitude); | 743 CheckGeoposition(fresh_position_latitude, fresh_position_longitude); |
| 614 LOG(WARNING) << "...done."; | 744 LOG(WARNING) << "...done."; |
| 615 } | 745 } |
| 616 | 746 |
| 617 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, | 747 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, |
| 618 IFramesWithCachedPosition) { | 748 IFramesWithCachedPosition) { |
| 619 set_html_for_tests("/geolocation/iframes_different_origin.html"); | 749 set_html_for_tests("/geolocation/iframes_different_origin.html"); |
| 620 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 750 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
| 621 LoadIFrames(2); | 751 LoadIFrames(2); |
| 622 | 752 |
| 623 SetFrameHost("iframe_0"); | 753 SetFrameHost("iframe_0"); |
| 624 AddGeolocationWatch(true); | 754 AddGeolocationWatch(true); |
| 625 SetInfoBarResponse(iframe_url(0), true); | 755 SetPromptResponse(iframe_url(0), true); |
| 626 CheckGeoposition(fake_latitude(), fake_longitude()); | 756 CheckGeoposition(fake_latitude(), fake_longitude()); |
| 627 | 757 |
| 628 // Refresh geoposition, but let's not yet create the watch on the second frame | 758 // Refresh geoposition, but let's not yet create the watch on the second frame |
| 629 // so that it'll fetch from cache. | 759 // so that it'll fetch from cache. |
| 630 double cached_position_latitude = 5.67; | 760 double cached_position_latitude = 5.67; |
| 631 double cached_position_lognitude = 8.09; | 761 double cached_position_lognitude = 8.09; |
| 632 content::WindowedNotificationObserver observer( | 762 content::WindowedNotificationObserver observer( |
| 633 content::NOTIFICATION_LOAD_STOP, | 763 content::NOTIFICATION_LOAD_STOP, |
| 634 content::Source<NavigationController>( | 764 content::Source<NavigationController>( |
| 635 ¤t_browser()->tab_strip_model()->GetActiveWebContents()-> | 765 ¤t_browser()->tab_strip_model()->GetActiveWebContents()-> |
| 636 GetController())); | 766 GetController())); |
| 637 NotifyGeoposition(cached_position_latitude, cached_position_lognitude); | 767 NotifyGeoposition(cached_position_latitude, cached_position_lognitude); |
| 638 observer.Wait(); | 768 observer.Wait(); |
| 639 CheckGeoposition(cached_position_latitude, cached_position_lognitude); | 769 CheckGeoposition(cached_position_latitude, cached_position_lognitude); |
| 640 | 770 |
| 641 // Disable navigation for this frame. | 771 // Disable navigation for this frame. |
| 642 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 772 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| 643 | 773 |
| 644 // Now go ahead and authorize the second frame. | 774 // Now go ahead and authorize the second frame. |
| 645 SetFrameHost("iframe_1"); | 775 SetFrameHost("iframe_1"); |
| 646 AddGeolocationWatch(true); | 776 AddGeolocationWatch(true); |
| 647 // WebKit will use its cache, but we also broadcast a position shortly | 777 // WebKit will use its cache, but we also broadcast a position shortly |
| 648 // afterwards. We're only interested in the first navigation for the success | 778 // afterwards. We're only interested in the first navigation for the success |
| 649 // callback from the cached position. | 779 // callback from the cached position. |
| 650 CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); | 780 CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); |
| 651 SetInfoBarResponse(iframe_url(1), true); | 781 SetPromptResponse(iframe_url(1), true); |
| 652 CheckGeoposition(cached_position_latitude, cached_position_lognitude); | 782 CheckGeoposition(cached_position_latitude, cached_position_lognitude); |
| 653 } | 783 } |
| 654 | 784 |
| 655 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, CancelPermissionForFrame) { | 785 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, CancelPermissionForFrame) { |
| 656 set_html_for_tests("/geolocation/iframes_different_origin.html"); | 786 set_html_for_tests("/geolocation/iframes_different_origin.html"); |
| 657 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 787 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
| 658 LoadIFrames(2); | 788 LoadIFrames(2); |
| 659 LOG(WARNING) << "frames loaded"; | 789 LOG(WARNING) << "frames loaded"; |
| 660 | 790 |
| 661 SetFrameHost("iframe_0"); | 791 SetFrameHost("iframe_0"); |
| 662 AddGeolocationWatch(true); | 792 AddGeolocationWatch(true); |
| 663 SetInfoBarResponse(iframe_url(0), true); | 793 SetPromptResponse(iframe_url(0), true); |
| 664 CheckGeoposition(fake_latitude(), fake_longitude()); | 794 CheckGeoposition(fake_latitude(), fake_longitude()); |
| 665 // Disables further prompts from this iframe. | 795 // Disables further prompts from this iframe. |
| 666 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 796 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| 667 | 797 |
| 668 // Test second iframe from a different origin with a cached geoposition will | 798 // Test second iframe from a different origin with a cached geoposition will |
| 669 // create the infobar. | 799 // create the prompt. |
| 670 SetFrameHost("iframe_1"); | 800 SetFrameHost("iframe_1"); |
| 671 AddGeolocationWatch(true); | 801 AddGeolocationWatch(true); |
| 672 | 802 |
| 673 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 803 if (!PermissionBubbleManager::Enabled()) { |
| 674 current_browser()->tab_strip_model()->GetActiveWebContents()); | 804 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| 675 size_t num_infobars_before_cancel = infobar_service->infobar_count(); | 805 current_browser()->tab_strip_model()->GetActiveWebContents()); |
| 676 // Change the iframe, and ensure the infobar is gone. | 806 size_t num_infobars_before_cancel = infobar_service->infobar_count(); |
| 677 IFrameLoader change_iframe_1(current_browser(), 1, current_url()); | 807 // Change the iframe, and ensure the infobar is gone. |
| 678 size_t num_infobars_after_cancel = infobar_service->infobar_count(); | 808 IFrameLoader change_iframe_1(current_browser(), 1, current_url()); |
| 679 EXPECT_EQ(num_infobars_before_cancel, num_infobars_after_cancel + 1); | 809 size_t num_infobars_after_cancel = infobar_service->infobar_count(); |
| 810 EXPECT_EQ(num_infobars_before_cancel, num_infobars_after_cancel + 1); |
| 811 } else { |
| 812 // TODO(gbillock): something with the queue size? |
| 813 } |
| 680 } | 814 } |
| 681 | 815 |
| 682 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, InvalidUrlRequest) { | 816 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, InvalidUrlRequest) { |
| 683 // Tests that an invalid URL (e.g. from a popup window) is rejected | 817 // Tests that an invalid URL (e.g. from a popup window) is rejected |
| 684 // correctly. Also acts as a regression test for http://crbug.com/40478 | 818 // correctly. Also acts as a regression test for http://crbug.com/40478 |
| 685 set_html_for_tests("/geolocation/invalid_request_url.html"); | 819 set_html_for_tests("/geolocation/invalid_request_url.html"); |
| 686 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 820 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| 687 | 821 |
| 688 SetFrameHost(""); | 822 SetFrameHost(""); |
| 689 WebContents* original_tab = | 823 WebContents* original_tab = |
| 690 current_browser()->tab_strip_model()->GetActiveWebContents(); | 824 current_browser()->tab_strip_model()->GetActiveWebContents(); |
| 691 CheckStringValueFromJavascript("1", "requestGeolocationFromInvalidUrl()"); | 825 CheckStringValueFromJavascript("1", "requestGeolocationFromInvalidUrl()"); |
| 692 CheckStringValueFromJavascriptForFrame("1", "isAlive()", | 826 CheckStringValueFromJavascriptForFrame("1", "isAlive()", |
| 693 original_tab->GetMainFrame()); | 827 original_tab->GetMainFrame()); |
| 694 } | 828 } |
| 695 | 829 |
| 696 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfoBarBeforeStart) { | 830 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptBeforeStart) { |
| 697 // See http://crbug.com/42789 | 831 // See http://crbug.com/42789 |
| 698 set_html_for_tests("/geolocation/iframes_different_origin.html"); | 832 set_html_for_tests("/geolocation/iframes_different_origin.html"); |
| 699 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 833 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
| 700 LoadIFrames(2); | 834 LoadIFrames(2); |
| 701 LOG(WARNING) << "frames loaded"; | 835 LOG(WARNING) << "frames loaded"; |
| 702 | 836 |
| 703 // Access navigator.geolocation, but ensure it won't request permission. | 837 // Access navigator.geolocation, but ensure it won't request permission. |
| 704 SetFrameHost("iframe_1"); | 838 SetFrameHost("iframe_1"); |
| 705 CheckStringValueFromJavascript("object", "geoAccessNavigatorGeolocation()"); | 839 CheckStringValueFromJavascript("object", "geoAccessNavigatorGeolocation()"); |
| 706 | 840 |
| 707 SetFrameHost("iframe_0"); | 841 SetFrameHost("iframe_0"); |
| 708 AddGeolocationWatch(true); | 842 AddGeolocationWatch(true); |
| 709 SetInfoBarResponse(iframe_url(0), true); | 843 SetPromptResponse(iframe_url(0), true); |
| 710 CheckGeoposition(fake_latitude(), fake_longitude()); | 844 CheckGeoposition(fake_latitude(), fake_longitude()); |
| 711 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 845 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| 712 | 846 |
| 713 // Permission should be requested after adding a watch. | 847 // Permission should be requested after adding a watch. |
| 714 SetFrameHost("iframe_1"); | 848 SetFrameHost("iframe_1"); |
| 715 AddGeolocationWatch(true); | 849 AddGeolocationWatch(true); |
| 716 SetInfoBarResponse(iframe_url(1), true); | 850 SetPromptResponse(iframe_url(1), true); |
| 717 CheckGeoposition(fake_latitude(), fake_longitude()); | 851 CheckGeoposition(fake_latitude(), fake_longitude()); |
| 718 } | 852 } |
| 719 | 853 |
| 720 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) { | 854 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) { |
| 721 set_html_for_tests("/geolocation/two_watches.html"); | 855 set_html_for_tests("/geolocation/two_watches.html"); |
| 722 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 856 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| 723 | 857 |
| 724 // First, set the JavaScript to navigate when it receives |final_position|. | 858 // First, set the JavaScript to navigate when it receives |final_position|. |
| 725 double final_position_latitude = 3.17; | 859 double final_position_latitude = 3.17; |
| 726 double final_position_longitude = 4.23; | 860 double final_position_longitude = 4.23; |
| 727 std::string script = base::StringPrintf( | 861 std::string script = base::StringPrintf( |
| 728 "window.domAutomationController.send(geoSetFinalPosition(%f, %f))", | 862 "window.domAutomationController.send(geoSetFinalPosition(%f, %f))", |
| 729 final_position_latitude, final_position_longitude); | 863 final_position_latitude, final_position_longitude); |
| 730 std::string js_result; | 864 std::string js_result; |
| 731 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 865 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 732 current_browser()->tab_strip_model()->GetActiveWebContents(), script, | 866 current_browser()->tab_strip_model()->GetActiveWebContents(), script, |
| 733 &js_result)); | 867 &js_result)); |
| 734 EXPECT_EQ(js_result, "ok"); | 868 EXPECT_EQ(js_result, "ok"); |
| 735 | 869 |
| 736 // Send a position which both geolocation watches will receive. | 870 // Send a position which both geolocation watches will receive. |
| 737 SetFrameHost(""); | 871 SetFrameHost(""); |
| 738 AddGeolocationWatch(true); | 872 AddGeolocationWatch(true); |
| 739 SetInfoBarResponse(current_url(), true); | 873 SetPromptResponse(current_url(), true); |
| 740 CheckGeoposition(fake_latitude(), fake_longitude()); | 874 CheckGeoposition(fake_latitude(), fake_longitude()); |
| 741 | 875 |
| 742 // The second watch will now have cancelled. Ensure an update still makes | 876 // The second watch will now have cancelled. Ensure an update still makes |
| 743 // its way through to the first watcher. | 877 // its way through to the first watcher. |
| 744 content::WindowedNotificationObserver observer( | 878 content::WindowedNotificationObserver observer( |
| 745 content::NOTIFICATION_LOAD_STOP, | 879 content::NOTIFICATION_LOAD_STOP, |
| 746 content::Source<NavigationController>( | 880 content::Source<NavigationController>( |
| 747 ¤t_browser()->tab_strip_model()->GetActiveWebContents()-> | 881 ¤t_browser()->tab_strip_model()->GetActiveWebContents()-> |
| 748 GetController())); | 882 GetController())); |
| 749 NotifyGeoposition(final_position_latitude, final_position_longitude); | 883 NotifyGeoposition(final_position_latitude, final_position_longitude); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 // Last usage has been updated. | 943 // Last usage has been updated. |
| 810 EXPECT_EQ(current_browser() | 944 EXPECT_EQ(current_browser() |
| 811 ->profile() | 945 ->profile() |
| 812 ->GetHostContentSettingsMap() | 946 ->GetHostContentSettingsMap() |
| 813 ->GetLastUsage(current_url().GetOrigin(), | 947 ->GetLastUsage(current_url().GetOrigin(), |
| 814 current_url().GetOrigin(), | 948 current_url().GetOrigin(), |
| 815 CONTENT_SETTINGS_TYPE_GEOLOCATION) | 949 CONTENT_SETTINGS_TYPE_GEOLOCATION) |
| 816 .ToDoubleT(), | 950 .ToDoubleT(), |
| 817 13); | 951 13); |
| 818 } | 952 } |
| OLD | NEW |