| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/test/simple_test_clock.h" | 14 #include "base/test/simple_test_clock.h" |
| 15 #include "base/time/clock.h" | 15 #include "base/time/clock.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
| 18 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 18 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 19 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 19 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 20 #include "chrome/browser/permissions/permission_request_manager.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_commands.h" | 23 #include "chrome/browser/ui/browser_commands.h" |
| 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 24 #include "chrome/browser/ui/website_settings/permission_bubble_manager.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 "components/content_settings/core/browser/content_settings_usages_state
.h" | 27 #include "components/content_settings/core/browser/content_settings_usages_state
.h" |
| 28 #include "components/content_settings/core/browser/host_content_settings_map.h" | 28 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 29 #include "content/public/browser/navigation_controller.h" | 29 #include "content/public/browser/navigation_controller.h" |
| 30 #include "content/public/browser/notification_details.h" | 30 #include "content/public/browser/notification_details.h" |
| 31 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
| 32 #include "content/public/browser/render_frame_host.h" | 32 #include "content/public/browser/render_frame_host.h" |
| 33 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 34 #include "content/public/common/geoposition.h" | 34 #include "content/public/common/geoposition.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 navigation_completed_ = true; | 120 navigation_completed_ = true; |
| 121 } else if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) { | 121 } else if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) { |
| 122 content::Details<std::string> dom_op_result(details); | 122 content::Details<std::string> dom_op_result(details); |
| 123 javascript_response_ = *dom_op_result.ptr(); | 123 javascript_response_ = *dom_op_result.ptr(); |
| 124 javascript_completed_ = true; | 124 javascript_completed_ = true; |
| 125 } | 125 } |
| 126 if (javascript_completed_ && navigation_completed_) | 126 if (javascript_completed_ && navigation_completed_) |
| 127 base::MessageLoopForUI::current()->QuitWhenIdle(); | 127 base::MessageLoopForUI::current()->QuitWhenIdle(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 // PermissionBubbleObserver --------------------------------------------------- | 130 // PermissionRequestObserver --------------------------------------------------- |
| 131 | 131 |
| 132 // Used to observe the creation of a single permission bubble without | 132 // Used to observe the creation of a single permission request without |
| 133 // responding. | 133 // responding. |
| 134 class PermissionBubbleObserver : public PermissionBubbleManager::Observer { | 134 class PermissionRequestObserver : public PermissionRequestManager::Observer { |
| 135 public: | 135 public: |
| 136 explicit PermissionBubbleObserver(content::WebContents* web_contents) | 136 explicit PermissionRequestObserver(content::WebContents* web_contents) |
| 137 : bubble_manager_(PermissionBubbleManager::FromWebContents(web_contents)), | 137 : request_manager_( |
| 138 PermissionRequestManager::FromWebContents(web_contents)), |
| 138 request_shown_(false), | 139 request_shown_(false), |
| 139 message_loop_runner_(new content::MessageLoopRunner) { | 140 message_loop_runner_(new content::MessageLoopRunner) { |
| 140 bubble_manager_->AddObserver(this); | 141 request_manager_->AddObserver(this); |
| 141 } | 142 } |
| 142 ~PermissionBubbleObserver() override { | 143 ~PermissionRequestObserver() override { |
| 143 // Safe to remove twice if it happens. | 144 // Safe to remove twice if it happens. |
| 144 bubble_manager_->RemoveObserver(this); | 145 request_manager_->RemoveObserver(this); |
| 145 } | 146 } |
| 146 | 147 |
| 147 void Wait() { message_loop_runner_->Run(); } | 148 void Wait() { message_loop_runner_->Run(); } |
| 148 | 149 |
| 149 bool request_shown() { return request_shown_; } | 150 bool request_shown() { return request_shown_; } |
| 150 | 151 |
| 151 private: | 152 private: |
| 152 // PermissionBubbleManager::Observer | 153 // PermissionRequestManager::Observer |
| 153 void OnBubbleAdded() override { | 154 void OnBubbleAdded() override { |
| 154 request_shown_ = true; | 155 request_shown_ = true; |
| 155 bubble_manager_->RemoveObserver(this); | 156 request_manager_->RemoveObserver(this); |
| 156 message_loop_runner_->Quit(); | 157 message_loop_runner_->Quit(); |
| 157 } | 158 } |
| 158 | 159 |
| 159 PermissionBubbleManager* bubble_manager_; | 160 PermissionRequestManager* request_manager_; |
| 160 bool request_shown_; | 161 bool request_shown_; |
| 161 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 162 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 162 | 163 |
| 163 DISALLOW_COPY_AND_ASSIGN(PermissionBubbleObserver); | 164 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver); |
| 164 }; | 165 }; |
| 165 | 166 |
| 166 } // namespace | 167 } // namespace |
| 167 | 168 |
| 168 | 169 |
| 169 // GeolocationBrowserTest ----------------------------------------------------- | 170 // GeolocationBrowserTest ----------------------------------------------------- |
| 170 | 171 |
| 171 // This is a browser test for Geolocation. | 172 // This is a browser test for Geolocation. |
| 172 // It exercises various integration points from javascript <-> browser: | 173 // It exercises various integration points from javascript <-> browser: |
| 173 // 1. The user is prompted when a position is requested from an unauthorized | 174 // 1. The user is prompted when a position is requested from an unauthorized |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 // http://localhost. | 215 // http://localhost. |
| 215 void LoadIFrames(); | 216 void LoadIFrames(); |
| 216 | 217 |
| 217 // Specifies which frame to use for executing JavaScript. | 218 // Specifies which frame to use for executing JavaScript. |
| 218 void SetFrameForScriptExecution(const std::string& frame_name); | 219 void SetFrameForScriptExecution(const std::string& frame_name); |
| 219 | 220 |
| 220 // Gets the HostContentSettingsMap for the current profile. | 221 // Gets the HostContentSettingsMap for the current profile. |
| 221 HostContentSettingsMap* GetHostContentSettingsMap(); | 222 HostContentSettingsMap* GetHostContentSettingsMap(); |
| 222 | 223 |
| 223 // Calls watchPosition in JavaScript and accepts or denies the resulting | 224 // Calls watchPosition in JavaScript and accepts or denies the resulting |
| 224 // permission bubble. Returns |true| if the expected behavior happened. | 225 // permission request. Returns |true| if the expected behavior happened. |
| 225 bool WatchPositionAndGrantPermission() WARN_UNUSED_RESULT; | 226 bool WatchPositionAndGrantPermission() WARN_UNUSED_RESULT; |
| 226 bool WatchPositionAndDenyPermission() WARN_UNUSED_RESULT; | 227 bool WatchPositionAndDenyPermission() WARN_UNUSED_RESULT; |
| 227 | 228 |
| 228 // Calls watchPosition in JavaScript and observes whether the permission | 229 // Calls watchPosition in JavaScript and observes whether the permission |
| 229 // bubble is shown without interacting with it. Callers should set | 230 // request is shown without interacting with it. Callers should set |
| 230 // |bubble_should_display| to |true| if they expect a bubble to display. | 231 // |request_should_display| to |true| if they expect a request to display. |
| 231 void WatchPositionAndObservePermissionBubble(bool bubble_should_display); | 232 void WatchPositionAndObservePermissionRequest(bool request_should_display); |
| 232 | 233 |
| 233 // Checks that no errors have been received in JavaScript, and checks that the | 234 // Checks that no errors have been received in JavaScript, and checks that the |
| 234 // position most recently received matches |latitude| and |longitude|. | 235 // position most recently received matches |latitude| and |longitude|. |
| 235 void ExpectPosition(double latitude, double longitude); | 236 void ExpectPosition(double latitude, double longitude); |
| 236 | 237 |
| 237 // Executes |function| in |render_frame_host| and checks that the return value | 238 // Executes |function| in |render_frame_host| and checks that the return value |
| 238 // matches |expected|. | 239 // matches |expected|. |
| 239 void ExpectValueFromScriptForFrame( | 240 void ExpectValueFromScriptForFrame( |
| 240 const std::string& expected, | 241 const std::string& expected, |
| 241 const std::string& function, | 242 const std::string& function, |
| 242 content::RenderFrameHost* render_frame_host); | 243 content::RenderFrameHost* render_frame_host); |
| 243 | 244 |
| 244 // Executes |function| and checks that the return value matches |expected|. | 245 // Executes |function| and checks that the return value matches |expected|. |
| 245 void ExpectValueFromScript(const std::string& expected, | 246 void ExpectValueFromScript(const std::string& expected, |
| 246 const std::string& function); | 247 const std::string& function); |
| 247 | 248 |
| 248 // Sets a new (second) position and runs all callbacks currently registered | 249 // Sets a new (second) position and runs all callbacks currently registered |
| 249 // with the Geolocation system. Returns |true| if the new position is updated | 250 // with the Geolocation system. Returns |true| if the new position is updated |
| 250 // successfully in JavaScript. | 251 // successfully in JavaScript. |
| 251 bool SetPositionAndWaitUntilUpdated(double latitude, double longitude); | 252 bool SetPositionAndWaitUntilUpdated(double latitude, double longitude); |
| 252 | 253 |
| 253 // Convenience method to look up the number of queued permission bubbles. | 254 // Convenience method to look up the number of queued permission requests. |
| 254 int GetBubbleQueueSize(PermissionBubbleManager* manager); | 255 int GetRequestQueueSize(PermissionRequestManager* manager); |
| 255 | 256 |
| 256 private: | 257 private: |
| 257 // Calls watchPosition() in JavaScript and accepts or denies the resulting | 258 // Calls watchPosition() in JavaScript and accepts or denies the resulting |
| 258 // permission bubble. Returns the JavaScript response. | 259 // permission request. Returns the JavaScript response. |
| 259 std::string WatchPositionAndRespondToPermissionBubble( | 260 std::string WatchPositionAndRespondToPermissionRequest( |
| 260 PermissionBubbleManager::AutoResponseType bubble_response); | 261 PermissionRequestManager::AutoResponseType request_response); |
| 261 | 262 |
| 262 // The current Browser as set in Initialize. May be for an incognito profile. | 263 // The current Browser as set in Initialize. May be for an incognito profile. |
| 263 Browser* current_browser_ = nullptr; | 264 Browser* current_browser_ = nullptr; |
| 264 | 265 |
| 265 // The path element of a URL referencing the html content for this test. | 266 // The path element of a URL referencing the html content for this test. |
| 266 std::string html_for_tests_ = "/geolocation/simple.html"; | 267 std::string html_for_tests_ = "/geolocation/simple.html"; |
| 267 | 268 |
| 268 // The frame where the JavaScript calls will run. | 269 // The frame where the JavaScript calls will run. |
| 269 content::RenderFrameHost* render_frame_host_ = nullptr; | 270 content::RenderFrameHost* render_frame_host_ = nullptr; |
| 270 | 271 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 } | 341 } |
| 341 DCHECK(render_frame_host_); | 342 DCHECK(render_frame_host_); |
| 342 } | 343 } |
| 343 | 344 |
| 344 HostContentSettingsMap* GeolocationBrowserTest::GetHostContentSettingsMap() { | 345 HostContentSettingsMap* GeolocationBrowserTest::GetHostContentSettingsMap() { |
| 345 return HostContentSettingsMapFactory::GetForProfile( | 346 return HostContentSettingsMapFactory::GetForProfile( |
| 346 current_browser()->profile()); | 347 current_browser()->profile()); |
| 347 } | 348 } |
| 348 | 349 |
| 349 bool GeolocationBrowserTest::WatchPositionAndGrantPermission() { | 350 bool GeolocationBrowserTest::WatchPositionAndGrantPermission() { |
| 350 std::string result = WatchPositionAndRespondToPermissionBubble( | 351 std::string result = WatchPositionAndRespondToPermissionRequest( |
| 351 PermissionBubbleManager::ACCEPT_ALL); | 352 PermissionRequestManager::ACCEPT_ALL); |
| 352 return "request-callback-success" == result; | 353 return "request-callback-success" == result; |
| 353 } | 354 } |
| 354 | 355 |
| 355 bool GeolocationBrowserTest::WatchPositionAndDenyPermission() { | 356 bool GeolocationBrowserTest::WatchPositionAndDenyPermission() { |
| 356 std::string result = WatchPositionAndRespondToPermissionBubble( | 357 std::string result = WatchPositionAndRespondToPermissionRequest( |
| 357 PermissionBubbleManager::DENY_ALL); | 358 PermissionRequestManager::DENY_ALL); |
| 358 return "request-callback-error" == result; | 359 return "request-callback-error" == result; |
| 359 } | 360 } |
| 360 | 361 |
| 361 std::string GeolocationBrowserTest::WatchPositionAndRespondToPermissionBubble( | 362 std::string GeolocationBrowserTest::WatchPositionAndRespondToPermissionRequest( |
| 362 PermissionBubbleManager::AutoResponseType bubble_response) { | 363 PermissionRequestManager::AutoResponseType request_response) { |
| 363 PermissionBubbleManager::FromWebContents( | 364 PermissionRequestManager::FromWebContents( |
| 364 current_browser_->tab_strip_model()->GetActiveWebContents()) | 365 current_browser_->tab_strip_model()->GetActiveWebContents()) |
| 365 ->set_auto_response_for_test(bubble_response); | 366 ->set_auto_response_for_test(request_response); |
| 366 return RunScript(render_frame_host_, "geoStartWithAsyncResponse()"); | 367 return RunScript(render_frame_host_, "geoStartWithAsyncResponse()"); |
| 367 } | 368 } |
| 368 | 369 |
| 369 void GeolocationBrowserTest::WatchPositionAndObservePermissionBubble( | 370 void GeolocationBrowserTest::WatchPositionAndObservePermissionRequest( |
| 370 bool bubble_should_display) { | 371 bool request_should_display) { |
| 371 PermissionBubbleObserver observer( | 372 PermissionRequestObserver observer( |
| 372 current_browser_->tab_strip_model()->GetActiveWebContents()); | 373 current_browser_->tab_strip_model()->GetActiveWebContents()); |
| 373 if (bubble_should_display) { | 374 if (request_should_display) { |
| 374 // Control will return as soon as the API call is made, and then the | 375 // Control will return as soon as the API call is made, and then the |
| 375 // observer will wait for the bubble to display. | 376 // observer will wait for the request to display. |
| 376 RunScript(render_frame_host_, "geoStartWithSyncResponse()"); | 377 RunScript(render_frame_host_, "geoStartWithSyncResponse()"); |
| 377 observer.Wait(); | 378 observer.Wait(); |
| 378 } else { | 379 } else { |
| 379 // Control will return once one of the callbacks fires. | 380 // Control will return once one of the callbacks fires. |
| 380 RunScript(render_frame_host_, "geoStartWithAsyncResponse()"); | 381 RunScript(render_frame_host_, "geoStartWithAsyncResponse()"); |
| 381 } | 382 } |
| 382 EXPECT_EQ(bubble_should_display, observer.request_shown()); | 383 EXPECT_EQ(request_should_display, observer.request_shown()); |
| 383 } | 384 } |
| 384 | 385 |
| 385 void GeolocationBrowserTest::ExpectPosition(double latitude, double longitude) { | 386 void GeolocationBrowserTest::ExpectPosition(double latitude, double longitude) { |
| 386 // Checks we have no error. | 387 // Checks we have no error. |
| 387 ExpectValueFromScript("0", "geoGetLastError()"); | 388 ExpectValueFromScript("0", "geoGetLastError()"); |
| 388 ExpectValueFromScript(base::DoubleToString(latitude), | 389 ExpectValueFromScript(base::DoubleToString(latitude), |
| 389 "geoGetLastPositionLatitude()"); | 390 "geoGetLastPositionLatitude()"); |
| 390 ExpectValueFromScript(base::DoubleToString(longitude), | 391 ExpectValueFromScript(base::DoubleToString(longitude), |
| 391 "geoGetLastPositionLongitude()"); | 392 "geoGetLastPositionLongitude()"); |
| 392 } | 393 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 416 // Control will return (a) if the update has already been received, or (b) | 417 // Control will return (a) if the update has already been received, or (b) |
| 417 // when the update is received. This will hang if the position is never | 418 // when the update is received. This will hang if the position is never |
| 418 // updated. Currently this expects the position to be updated once; if your | 419 // updated. Currently this expects the position to be updated once; if your |
| 419 // test updates it repeatedly, |position_updated| (JS) needs to change to an | 420 // test updates it repeatedly, |position_updated| (JS) needs to change to an |
| 420 // int to count how often it's been updated. | 421 // int to count how often it's been updated. |
| 421 std::string result = | 422 std::string result = |
| 422 RunScript(render_frame_host_, "checkIfGeopositionUpdated()"); | 423 RunScript(render_frame_host_, "checkIfGeopositionUpdated()"); |
| 423 return result == "geoposition-updated"; | 424 return result == "geoposition-updated"; |
| 424 } | 425 } |
| 425 | 426 |
| 426 int GeolocationBrowserTest::GetBubbleQueueSize( | 427 int GeolocationBrowserTest::GetRequestQueueSize( |
| 427 PermissionBubbleManager* manager) { | 428 PermissionRequestManager* manager) { |
| 428 return static_cast<int>(manager->requests_.size()); | 429 return static_cast<int>(manager->requests_.size()); |
| 429 } | 430 } |
| 430 | 431 |
| 431 // Tests ---------------------------------------------------------------------- | 432 // Tests ---------------------------------------------------------------------- |
| 432 | 433 |
| 433 #if defined(OS_LINUX) | 434 #if defined(OS_LINUX) |
| 434 // http://crbug.com/527437 | 435 // http://crbug.com/527437 |
| 435 #define MAYBE_DisplaysPrompt DISABLED_DisplaysPrompt | 436 #define MAYBE_DisplaysPrompt DISABLED_DisplaysPrompt |
| 436 #else | 437 #else |
| 437 #define MAYBE_DisplaysPrompt DisplaysPrompt | 438 #define MAYBE_DisplaysPrompt DisplaysPrompt |
| (...skipping 24 matching lines...) Expand all Loading... |
| 462 #if defined(OS_LINUX) | 463 #if defined(OS_LINUX) |
| 463 // http://crbug.com/527437 | 464 // http://crbug.com/527437 |
| 464 #define MAYBE_NoPromptForSecondTab DISABLED_NoPromptForSecondTab | 465 #define MAYBE_NoPromptForSecondTab DISABLED_NoPromptForSecondTab |
| 465 #else | 466 #else |
| 466 #define MAYBE_NoPromptForSecondTab NoPromptForSecondTab | 467 #define MAYBE_NoPromptForSecondTab NoPromptForSecondTab |
| 467 #endif | 468 #endif |
| 468 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoPromptForSecondTab) { | 469 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoPromptForSecondTab) { |
| 469 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 470 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 470 ASSERT_TRUE(WatchPositionAndGrantPermission()); | 471 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
| 471 | 472 |
| 472 // Checks bubble is not needed in a second tab. | 473 // Checks request is not needed in a second tab. |
| 473 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_NEWTAB)); | 474 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_NEWTAB)); |
| 474 WatchPositionAndObservePermissionBubble(false); | 475 WatchPositionAndObservePermissionRequest(false); |
| 475 ExpectPosition(fake_latitude(), fake_longitude()); | 476 ExpectPosition(fake_latitude(), fake_longitude()); |
| 476 } | 477 } |
| 477 | 478 |
| 478 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForDeniedOrigin) { | 479 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForDeniedOrigin) { |
| 479 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 480 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 480 GetHostContentSettingsMap()->SetContentSettingDefaultScope( | 481 GetHostContentSettingsMap()->SetContentSettingDefaultScope( |
| 481 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, | 482 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 482 std::string(), CONTENT_SETTING_BLOCK); | 483 std::string(), CONTENT_SETTING_BLOCK); |
| 483 | 484 |
| 484 // Check that the bubble wasn't shown but we get an error for this origin. | 485 // Check that the request wasn't shown but we get an error for this origin. |
| 485 WatchPositionAndObservePermissionBubble(false); | 486 WatchPositionAndObservePermissionRequest(false); |
| 486 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); | 487 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); |
| 487 | 488 |
| 488 // Checks prompt will not be created a second tab. | 489 // Checks prompt will not be created a second tab. |
| 489 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_NEWTAB)); | 490 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_NEWTAB)); |
| 490 WatchPositionAndObservePermissionBubble(false); | 491 WatchPositionAndObservePermissionRequest(false); |
| 491 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); | 492 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); |
| 492 } | 493 } |
| 493 | 494 |
| 494 #if defined(OS_LINUX) | 495 #if defined(OS_LINUX) |
| 495 // http://crbug.com/527437 | 496 // http://crbug.com/527437 |
| 496 #define MAYBE_NoPromptForAllowedOrigin DISABLED_NoPromptForAllowedOrigin | 497 #define MAYBE_NoPromptForAllowedOrigin DISABLED_NoPromptForAllowedOrigin |
| 497 #else | 498 #else |
| 498 #define MAYBE_NoPromptForAllowedOrigin NoPromptForAllowedOrigin | 499 #define MAYBE_NoPromptForAllowedOrigin NoPromptForAllowedOrigin |
| 499 #endif | 500 #endif |
| 500 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoPromptForAllowedOrigin) { | 501 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoPromptForAllowedOrigin) { |
| 501 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 502 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 502 GetHostContentSettingsMap()->SetContentSettingDefaultScope( | 503 GetHostContentSettingsMap()->SetContentSettingDefaultScope( |
| 503 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, | 504 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 504 std::string(), CONTENT_SETTING_ALLOW); | 505 std::string(), CONTENT_SETTING_ALLOW); |
| 505 // The bubble is not shown, there is no error, and the position gets to the | 506 // The request is not shown, there is no error, and the position gets to the |
| 506 // script. | 507 // script. |
| 507 WatchPositionAndObservePermissionBubble(false); | 508 WatchPositionAndObservePermissionRequest(false); |
| 508 ExpectPosition(fake_latitude(), fake_longitude()); | 509 ExpectPosition(fake_latitude(), fake_longitude()); |
| 509 } | 510 } |
| 510 | 511 |
| 511 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForOffTheRecord) { | 512 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForOffTheRecord) { |
| 512 // For a regular profile the user is prompted, and when granted the position | 513 // For a regular profile the user is prompted, and when granted the position |
| 513 // gets to the script. | 514 // gets to the script. |
| 514 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 515 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 515 ASSERT_TRUE(WatchPositionAndGrantPermission()); | 516 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
| 516 ExpectPosition(fake_latitude(), fake_longitude()); | 517 ExpectPosition(fake_latitude(), fake_longitude()); |
| 517 | 518 |
| 518 // The permission is persisted for the regular profile, and inherited by its | 519 // The permission is persisted for the regular profile, and inherited by its |
| 519 // incognito profile. Go incognito, and check that the user is not prompted | 520 // incognito profile. Go incognito, and check that the user is not prompted |
| 520 // again and the position gets to the script. | 521 // again and the position gets to the script. |
| 521 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_OFFTHERECORD)); | 522 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_OFFTHERECORD)); |
| 522 WatchPositionAndObservePermissionBubble(false); | 523 WatchPositionAndObservePermissionRequest(false); |
| 523 ExpectPosition(fake_latitude(), fake_longitude()); | 524 ExpectPosition(fake_latitude(), fake_longitude()); |
| 524 } | 525 } |
| 525 | 526 |
| 526 // http://crbug.com/523387 | 527 // http://crbug.com/523387 |
| 527 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, | 528 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, |
| 528 DISABLED_NoLeakFromOffTheRecord) { | 529 DISABLED_NoLeakFromOffTheRecord) { |
| 529 // The user is prompted in a fresh incognito profile, and when granted the | 530 // The user is prompted in a fresh incognito profile, and when granted the |
| 530 // position gets to the script. | 531 // position gets to the script. |
| 531 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_OFFTHERECORD)); | 532 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_OFFTHERECORD)); |
| 532 ASSERT_TRUE(WatchPositionAndGrantPermission()); | 533 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 551 LoadIFrames(); | 552 LoadIFrames(); |
| 552 | 553 |
| 553 // Grant permission in the first frame, the position gets to the script. | 554 // Grant permission in the first frame, the position gets to the script. |
| 554 SetFrameForScriptExecution("iframe_0"); | 555 SetFrameForScriptExecution("iframe_0"); |
| 555 ASSERT_TRUE(WatchPositionAndGrantPermission()); | 556 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
| 556 ExpectPosition(fake_latitude(), fake_longitude()); | 557 ExpectPosition(fake_latitude(), fake_longitude()); |
| 557 | 558 |
| 558 // In a second iframe from a different origin with a cached position the user | 559 // In a second iframe from a different origin with a cached position the user |
| 559 // is prompted. | 560 // is prompted. |
| 560 SetFrameForScriptExecution("iframe_1"); | 561 SetFrameForScriptExecution("iframe_1"); |
| 561 WatchPositionAndObservePermissionBubble(true); | 562 WatchPositionAndObservePermissionRequest(true); |
| 562 | 563 |
| 563 // Back to the first frame, enable navigation and refresh geoposition. | 564 // Back to the first frame, enable navigation and refresh geoposition. |
| 564 SetFrameForScriptExecution("iframe_0"); | 565 SetFrameForScriptExecution("iframe_0"); |
| 565 double fresh_position_latitude = 3.17; | 566 double fresh_position_latitude = 3.17; |
| 566 double fresh_position_longitude = 4.23; | 567 double fresh_position_longitude = 4.23; |
| 567 ASSERT_TRUE(SetPositionAndWaitUntilUpdated(fresh_position_latitude, | 568 ASSERT_TRUE(SetPositionAndWaitUntilUpdated(fresh_position_latitude, |
| 568 fresh_position_longitude)); | 569 fresh_position_longitude)); |
| 569 ExpectPosition(fresh_position_latitude, fresh_position_longitude); | 570 ExpectPosition(fresh_position_latitude, fresh_position_longitude); |
| 570 | 571 |
| 571 // When permission is granted to the second iframe the fresh position gets to | 572 // When permission is granted to the second iframe the fresh position gets to |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 614 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 614 LoadIFrames(); | 615 LoadIFrames(); |
| 615 | 616 |
| 616 SetFrameForScriptExecution("iframe_0"); | 617 SetFrameForScriptExecution("iframe_0"); |
| 617 ASSERT_TRUE(WatchPositionAndGrantPermission()); | 618 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
| 618 ExpectPosition(fake_latitude(), fake_longitude()); | 619 ExpectPosition(fake_latitude(), fake_longitude()); |
| 619 | 620 |
| 620 // Test second iframe from a different origin with a cached position will | 621 // Test second iframe from a different origin with a cached position will |
| 621 // create the prompt. | 622 // create the prompt. |
| 622 SetFrameForScriptExecution("iframe_1"); | 623 SetFrameForScriptExecution("iframe_1"); |
| 623 WatchPositionAndObservePermissionBubble(true); | 624 WatchPositionAndObservePermissionRequest(true); |
| 624 | 625 |
| 625 // Navigate the iframe, and ensure the prompt is gone. | 626 // Navigate the iframe, and ensure the prompt is gone. |
| 626 content::WebContents* web_contents = | 627 content::WebContents* web_contents = |
| 627 current_browser()->tab_strip_model()->GetActiveWebContents(); | 628 current_browser()->tab_strip_model()->GetActiveWebContents(); |
| 628 IFrameLoader change_iframe_1(current_browser(), 1, current_url()); | 629 IFrameLoader change_iframe_1(current_browser(), 1, current_url()); |
| 629 int num_bubbles_after_cancel = GetBubbleQueueSize( | 630 int num_requests_after_cancel = GetRequestQueueSize( |
| 630 PermissionBubbleManager::FromWebContents(web_contents)); | 631 PermissionRequestManager::FromWebContents(web_contents)); |
| 631 EXPECT_EQ(0, num_bubbles_after_cancel); | 632 EXPECT_EQ(0, num_requests_after_cancel); |
| 632 } | 633 } |
| 633 | 634 |
| 634 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, InvalidUrlRequest) { | 635 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, InvalidUrlRequest) { |
| 635 // Tests that an invalid URL (e.g. from a popup window) is rejected | 636 // Tests that an invalid URL (e.g. from a popup window) is rejected |
| 636 // correctly. Also acts as a regression test for http://crbug.com/40478 | 637 // correctly. Also acts as a regression test for http://crbug.com/40478 |
| 637 set_html_for_tests("/geolocation/invalid_request_url.html"); | 638 set_html_for_tests("/geolocation/invalid_request_url.html"); |
| 638 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 639 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 639 | 640 |
| 640 content::WebContents* original_tab = | 641 content::WebContents* original_tab = |
| 641 current_browser()->tab_strip_model()->GetActiveWebContents(); | 642 current_browser()->tab_strip_model()->GetActiveWebContents(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 ExpectPosition(final_position_latitude, final_position_longitude); | 704 ExpectPosition(final_position_latitude, final_position_longitude); |
| 704 } | 705 } |
| 705 | 706 |
| 706 // TODO(felt): Disabled because the second permission request hangs. | 707 // TODO(felt): Disabled because the second permission request hangs. |
| 707 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DISABLED_PendingChildFrames) { | 708 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DISABLED_PendingChildFrames) { |
| 708 set_html_for_tests("/geolocation/two_iframes.html"); | 709 set_html_for_tests("/geolocation/two_iframes.html"); |
| 709 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 710 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 710 LoadIFrames(); | 711 LoadIFrames(); |
| 711 | 712 |
| 712 SetFrameForScriptExecution("iframe_0"); | 713 SetFrameForScriptExecution("iframe_0"); |
| 713 WatchPositionAndObservePermissionBubble(true); | 714 WatchPositionAndObservePermissionRequest(true); |
| 714 | 715 |
| 715 SetFrameForScriptExecution("iframe_1"); | 716 SetFrameForScriptExecution("iframe_1"); |
| 716 WatchPositionAndObservePermissionBubble(true); | 717 WatchPositionAndObservePermissionRequest(true); |
| 717 } | 718 } |
| 718 | 719 |
| 719 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TabDestroyed) { | 720 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TabDestroyed) { |
| 720 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 721 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 721 WatchPositionAndObservePermissionBubble(true); | 722 WatchPositionAndObservePermissionRequest(true); |
| 722 | 723 |
| 723 // TODO(mvanouwerkerk): Can't close a window you did not open. Maybe this was | 724 // TODO(mvanouwerkerk): Can't close a window you did not open. Maybe this was |
| 724 // valid when the test was written, but now it just prints "Scripts may close | 725 // valid when the test was written, but now it just prints "Scripts may close |
| 725 // only the windows that were opened by it." | 726 // only the windows that were opened by it." |
| 726 std::string script = "window.domAutomationController.send(window.close())"; | 727 std::string script = "window.domAutomationController.send(window.close())"; |
| 727 ASSERT_TRUE(content::ExecuteScript( | 728 ASSERT_TRUE(content::ExecuteScript( |
| 728 current_browser()->tab_strip_model()->GetActiveWebContents(), script)); | 729 current_browser()->tab_strip_model()->GetActiveWebContents(), script)); |
| 729 } | 730 } |
| 730 | 731 |
| 731 #if defined(OS_LINUX) | 732 #if defined(OS_LINUX) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 748 | 749 |
| 749 // Permission has been used at the starting time. | 750 // Permission has been used at the starting time. |
| 750 EXPECT_EQ(GetHostContentSettingsMap()->GetLastUsage( | 751 EXPECT_EQ(GetHostContentSettingsMap()->GetLastUsage( |
| 751 current_url().GetOrigin(), | 752 current_url().GetOrigin(), |
| 752 current_url().GetOrigin(), | 753 current_url().GetOrigin(), |
| 753 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 10); | 754 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 10); |
| 754 | 755 |
| 755 clock_->Advance(base::TimeDelta::FromSeconds(3)); | 756 clock_->Advance(base::TimeDelta::FromSeconds(3)); |
| 756 | 757 |
| 757 // Calling watchPosition should trigger the last usage update. | 758 // Calling watchPosition should trigger the last usage update. |
| 758 WatchPositionAndObservePermissionBubble(false); | 759 WatchPositionAndObservePermissionRequest(false); |
| 759 ExpectPosition(fake_latitude(), fake_longitude()); | 760 ExpectPosition(fake_latitude(), fake_longitude()); |
| 760 | 761 |
| 761 // Last usage has been updated. | 762 // Last usage has been updated. |
| 762 EXPECT_EQ(GetHostContentSettingsMap()->GetLastUsage( | 763 EXPECT_EQ(GetHostContentSettingsMap()->GetLastUsage( |
| 763 current_url().GetOrigin(), | 764 current_url().GetOrigin(), |
| 764 current_url().GetOrigin(), | 765 current_url().GetOrigin(), |
| 765 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 13); | 766 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 13); |
| 766 } | 767 } |
| OLD | NEW |