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