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