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