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/mock_permission_bubble_view.h" |
| 23 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
21 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
| 25 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.h" |
23 #include "chrome/test/base/ui_test_utils.h" | 27 #include "chrome/test/base/ui_test_utils.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" |
31 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
(...skipping 86 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(wait_for_prompt_ ? |
| 232 (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_->visible_) |
| 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 if (PermissionBubbleManager::Enabled()) { |
406 current_browser_->tab_strip_model()->GetActiveWebContents(); | 452 WebContents* web_contents = |
407 TabSpecificContentSettings* content_settings = | 453 current_browser_->tab_strip_model()->GetActiveWebContents(); |
408 TabSpecificContentSettings::FromWebContents(web_contents); | 454 TabSpecificContentSettings* content_settings = |
409 const ContentSettingsUsagesState& usages_state = | 455 TabSpecificContentSettings::FromWebContents(web_contents); |
410 content_settings->geolocation_usages_state(); | 456 const ContentSettingsUsagesState& usages_state = |
411 size_t state_map_size = usages_state.state_map().size(); | 457 content_settings->geolocation_usages_state(); |
412 ASSERT_TRUE(infobar_); | 458 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) | 459 if (allowed) |
419 infobar_->delegate()->AsConfirmInfoBarDelegate()->Accept(); | 460 mock_bubble_view_.Accept(); |
420 else | 461 else |
421 infobar_->delegate()->AsConfirmInfoBarDelegate()->Cancel(); | 462 mock_bubble_view_.Deny(); |
422 observer.Wait(); | 463 |
| 464 EXPECT_GT(usages_state.state_map().size(), state_map_size); |
| 465 GURL requesting_origin(requesting_url.GetOrigin()); |
| 466 EXPECT_EQ(1U, usages_state.state_map().count(requesting_origin)); |
| 467 ContentSetting expected_setting = |
| 468 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 469 EXPECT_EQ(expected_setting, |
| 470 usages_state.state_map().find(requesting_origin)->second); |
| 471 content::RunAllPendingInMessageLoop(); |
| 472 } else { |
| 473 WebContents* web_contents = |
| 474 current_browser_->tab_strip_model()->GetActiveWebContents(); |
| 475 TabSpecificContentSettings* content_settings = |
| 476 TabSpecificContentSettings::FromWebContents(web_contents); |
| 477 const ContentSettingsUsagesState& usages_state = |
| 478 content_settings->geolocation_usages_state(); |
| 479 size_t state_map_size = usages_state.state_map().size(); |
| 480 ASSERT_TRUE(infobar_); |
| 481 LOG(WARNING) << "will set infobar response"; |
| 482 { |
| 483 content::WindowedNotificationObserver observer( |
| 484 content::NOTIFICATION_LOAD_STOP, |
| 485 content::Source<NavigationController>( |
| 486 &web_contents->GetController())); |
| 487 if (allowed) |
| 488 infobar_->delegate()->AsConfirmInfoBarDelegate()->Accept(); |
| 489 else |
| 490 infobar_->delegate()->AsConfirmInfoBarDelegate()->Cancel(); |
| 491 observer.Wait(); |
| 492 } |
| 493 |
| 494 InfoBarService* infobar_service = |
| 495 InfoBarService::FromWebContents(web_contents); |
| 496 infobar_service->RemoveInfoBar(infobar_); |
| 497 LOG(WARNING) << "infobar response set"; |
| 498 infobar_ = nullptr; |
| 499 EXPECT_GT(usages_state.state_map().size(), state_map_size); |
| 500 GURL requesting_origin(requesting_url.GetOrigin()); |
| 501 EXPECT_EQ(1U, usages_state.state_map().count(requesting_origin)); |
| 502 ContentSetting expected_setting = |
| 503 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 504 EXPECT_EQ(expected_setting, |
| 505 usages_state.state_map().find(requesting_origin)->second); |
423 } | 506 } |
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 } | 507 } |
438 | 508 |
439 void GeolocationBrowserTest::CheckStringValueFromJavascriptForFrame( | 509 void GeolocationBrowserTest::CheckStringValueFromJavascriptForFrame( |
440 const std::string& expected, | 510 const std::string& expected, |
441 const std::string& function, | 511 const std::string& function, |
442 content::RenderFrameHost* render_frame_host) { | 512 content::RenderFrameHost* render_frame_host) { |
443 std::string script(base::StringPrintf( | 513 std::string script(base::StringPrintf( |
444 "window.domAutomationController.send(%s)", function.c_str())); | 514 "window.domAutomationController.send(%s)", function.c_str())); |
445 std::string result; | 515 std::string result; |
446 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 516 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
447 render_frame_host, script, &result)); | 517 render_frame_host, script, &result)); |
448 EXPECT_EQ(expected, result); | 518 EXPECT_EQ(expected, result); |
449 } | 519 } |
450 | 520 |
451 void GeolocationBrowserTest::CheckStringValueFromJavascript( | 521 void GeolocationBrowserTest::CheckStringValueFromJavascript( |
452 const std::string& expected, | 522 const std::string& expected, |
453 const std::string& function) { | 523 const std::string& function) { |
454 CheckStringValueFromJavascriptForFrame( | 524 CheckStringValueFromJavascriptForFrame( |
455 expected, function, render_frame_host_); | 525 expected, function, render_frame_host_); |
456 } | 526 } |
457 | 527 |
458 void GeolocationBrowserTest::NotifyGeoposition(double latitude, | 528 void GeolocationBrowserTest::NotifyGeoposition(double latitude, |
459 double longitude) { | 529 double longitude) { |
460 fake_latitude_ = latitude; | 530 fake_latitude_ = latitude; |
461 fake_longitude_ = longitude; | 531 fake_longitude_ = longitude; |
462 ui_test_utils::OverrideGeolocation(latitude, longitude); | 532 ui_test_utils::OverrideGeolocation(latitude, longitude); |
463 LOG(WARNING) << "MockLocationProvider listeners updated"; | 533 LOG(WARNING) << "MockLocationProvider listeners updated"; |
464 } | 534 } |
465 | 535 |
| 536 int GeolocationBrowserTest::GetBubblesQueueSize(PermissionBubbleManager* mgr) { |
| 537 return static_cast<int>(mgr->requests_.size()); |
| 538 } |
466 | 539 |
467 // Tests ---------------------------------------------------------------------- | 540 // Tests ---------------------------------------------------------------------- |
468 | 541 |
469 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DisplaysPermissionBar) { | 542 IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, DisplaysPrompt) { |
470 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 543 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
471 SetFrameHost(""); | 544 SetFrameHost(""); |
472 AddGeolocationWatch(true); | 545 AddGeolocationWatch(true); |
473 } | 546 } |
474 | 547 |
475 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, Geoposition) { | 548 IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, Geoposition) { |
476 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 549 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
477 SetFrameHost(""); | 550 SetFrameHost(""); |
478 AddGeolocationWatch(true); | 551 AddGeolocationWatch(true); |
479 SetInfoBarResponse(current_url(), true); | 552 SetPromptResponse(current_url(), true); |
480 CheckGeoposition(fake_latitude(), fake_longitude()); | 553 CheckGeoposition(fake_latitude(), fake_longitude()); |
481 } | 554 } |
482 | 555 |
483 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, | 556 IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, |
484 ErrorOnPermissionDenied) { | 557 ErrorOnPermissionDenied) { |
485 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 558 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
486 SetFrameHost(""); | 559 SetFrameHost(""); |
487 AddGeolocationWatch(true); | 560 AddGeolocationWatch(true); |
488 // Infobar was displayed, deny access and check for error code. | 561 // Prompt was displayed, deny access and check for error code. |
489 SetInfoBarResponse(current_url(), false); | 562 SetPromptResponse(current_url(), false); |
490 CheckStringValueFromJavascript("1", "geoGetLastError()"); | 563 CheckStringValueFromJavascript("1", "geoGetLastError()"); |
491 } | 564 } |
492 | 565 |
493 // See http://crbug.com/308358 | 566 // See http://crbug.com/308358 |
494 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DISABLED_NoInfobarForSecondTab) { | 567 IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, DISABLED_NoPromptForSecondTab) { |
495 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 568 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
496 SetFrameHost(""); | 569 SetFrameHost(""); |
497 AddGeolocationWatch(true); | 570 AddGeolocationWatch(true); |
498 SetInfoBarResponse(current_url(), true); | 571 SetPromptResponse(current_url(), true); |
499 // Disables further prompts from this tab. | 572 // Disables further prompts from this tab. |
500 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 573 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
501 | 574 |
502 // Checks infobar will not be created in a second tab. | 575 // Checks prompt will not be created in a second tab. |
503 ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB)); | 576 ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB)); |
504 SetFrameHost(""); | 577 SetFrameHost(""); |
505 AddGeolocationWatch(false); | 578 AddGeolocationWatch(false); |
506 CheckGeoposition(fake_latitude(), fake_longitude()); | 579 CheckGeoposition(fake_latitude(), fake_longitude()); |
507 } | 580 } |
508 | 581 |
509 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfobarForDeniedOrigin) { | 582 IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, NoPromptForDeniedOrigin) { |
510 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 583 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
511 current_browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 584 current_browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
512 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 585 ContentSettingsPattern::FromURLNoWildcard(current_url()), |
513 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 586 ContentSettingsPattern::FromURLNoWildcard(current_url()), |
514 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), CONTENT_SETTING_BLOCK); | 587 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), CONTENT_SETTING_BLOCK); |
515 SetFrameHost(""); | 588 SetFrameHost(""); |
516 AddGeolocationWatch(false); | 589 AddGeolocationWatch(false); |
517 // Checks we have an error for this denied origin. | 590 // Checks we have an error for this denied origin. |
518 CheckStringValueFromJavascript("1", "geoGetLastError()"); | 591 CheckStringValueFromJavascript("1", "geoGetLastError()"); |
519 // Checks infobar will not be created a second tab. | 592 // Checks prompt will not be created a second tab. |
520 ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB)); | 593 ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB)); |
521 SetFrameHost(""); | 594 SetFrameHost(""); |
522 AddGeolocationWatch(false); | 595 AddGeolocationWatch(false); |
523 CheckStringValueFromJavascript("1", "geoGetLastError()"); | 596 CheckStringValueFromJavascript("1", "geoGetLastError()"); |
524 } | 597 } |
525 | 598 |
526 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfobarForAllowedOrigin) { | 599 IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, NoPromptForAllowedOrigin) { |
527 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 600 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
528 current_browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 601 current_browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
529 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 602 ContentSettingsPattern::FromURLNoWildcard(current_url()), |
530 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 603 ContentSettingsPattern::FromURLNoWildcard(current_url()), |
531 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), CONTENT_SETTING_ALLOW); | 604 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), CONTENT_SETTING_ALLOW); |
532 // Checks no infobar will be created and there's no error callback. | 605 // Checks no prompt will be created and there's no error callback. |
533 SetFrameHost(""); | 606 SetFrameHost(""); |
534 AddGeolocationWatch(false); | 607 AddGeolocationWatch(false); |
535 CheckGeoposition(fake_latitude(), fake_longitude()); | 608 CheckGeoposition(fake_latitude(), fake_longitude()); |
536 } | 609 } |
537 | 610 |
538 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfobarForOffTheRecord) { | 611 IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, NoPromptForOffTheRecord) { |
539 // First, check infobar will be created for regular profile | 612 // First, check prompt will be created for regular profile |
540 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 613 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
541 SetFrameHost(""); | 614 SetFrameHost(""); |
542 AddGeolocationWatch(true); | 615 AddGeolocationWatch(true); |
543 // Response will be persisted. | 616 // Response will be persisted. |
544 SetInfoBarResponse(current_url(), true); | 617 SetPromptResponse(current_url(), true); |
545 CheckGeoposition(fake_latitude(), fake_longitude()); | 618 CheckGeoposition(fake_latitude(), fake_longitude()); |
546 // Disables further prompts from this tab. | 619 // Disables further prompts from this tab. |
547 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 620 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
548 // Go incognito, and checks no infobar will be created. | 621 // Go incognito, and checks no prompt will be created. |
549 ASSERT_TRUE(Initialize(INITIALIZATION_OFFTHERECORD)); | 622 ASSERT_TRUE(Initialize(INITIALIZATION_OFFTHERECORD)); |
550 SetFrameHost(""); | 623 SetFrameHost(""); |
551 AddGeolocationWatch(false); | 624 AddGeolocationWatch(false); |
552 CheckGeoposition(fake_latitude(), fake_longitude()); | 625 CheckGeoposition(fake_latitude(), fake_longitude()); |
553 } | 626 } |
554 | 627 |
555 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoLeakFromOffTheRecord) { | 628 IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, NoLeakFromOffTheRecord) { |
556 // First, check infobar will be created for incognito profile. | 629 // First, check prompt will be created for incognito profile. |
557 ASSERT_TRUE(Initialize(INITIALIZATION_OFFTHERECORD)); | 630 ASSERT_TRUE(Initialize(INITIALIZATION_OFFTHERECORD)); |
558 SetFrameHost(""); | 631 SetFrameHost(""); |
559 AddGeolocationWatch(true); | 632 AddGeolocationWatch(true); |
560 // Response won't be persisted. | 633 // Response won't be persisted. |
561 SetInfoBarResponse(current_url(), true); | 634 SetPromptResponse(current_url(), true); |
562 CheckGeoposition(fake_latitude(), fake_longitude()); | 635 CheckGeoposition(fake_latitude(), fake_longitude()); |
563 // Disables further prompts from this tab. | 636 // Disables further prompts from this tab. |
564 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 637 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
565 // Go to the regular profile, infobar will be created. | 638 // Go to the regular profile, prompt will be created. |
566 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 639 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
567 SetFrameHost(""); | 640 SetFrameHost(""); |
568 AddGeolocationWatch(true); | 641 AddGeolocationWatch(true); |
569 SetInfoBarResponse(current_url(), false); | 642 SetPromptResponse(current_url(), false); |
570 CheckStringValueFromJavascript("1", "geoGetLastError()"); | 643 CheckStringValueFromJavascript("1", "geoGetLastError()"); |
571 } | 644 } |
572 | 645 |
573 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, IFramesWithFreshPosition) { | 646 IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, IFramesWithFreshPosition) { |
574 set_html_for_tests("/geolocation/iframes_different_origin.html"); | 647 set_html_for_tests("/geolocation/iframes_different_origin.html"); |
575 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 648 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
576 LoadIFrames(2); | 649 LoadIFrames(2); |
577 LOG(WARNING) << "frames loaded"; | 650 LOG(WARNING) << "frames loaded"; |
578 | 651 |
579 SetFrameHost("iframe_0"); | 652 SetFrameHost("iframe_0"); |
580 AddGeolocationWatch(true); | 653 AddGeolocationWatch(true); |
581 SetInfoBarResponse(iframe_url(0), true); | 654 SetPromptResponse(iframe_url(0), true); |
582 CheckGeoposition(fake_latitude(), fake_longitude()); | 655 CheckGeoposition(fake_latitude(), fake_longitude()); |
583 // Disables further prompts from this iframe. | 656 // Disables further prompts from this iframe. |
584 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 657 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
585 | 658 |
586 // Test second iframe from a different origin with a cached geoposition will | 659 // Test second iframe from a different origin with a cached geoposition will |
587 // create the infobar. | 660 // create the prompt. |
588 SetFrameHost("iframe_1"); | 661 SetFrameHost("iframe_1"); |
589 AddGeolocationWatch(true); | 662 AddGeolocationWatch(true); |
590 | 663 |
591 // Back to the first frame, enable navigation and refresh geoposition. | 664 // Back to the first frame, enable navigation and refresh geoposition. |
592 SetFrameHost("iframe_0"); | 665 SetFrameHost("iframe_0"); |
593 CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); | 666 CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); |
594 double fresh_position_latitude = 3.17; | 667 double fresh_position_latitude = 3.17; |
595 double fresh_position_longitude = 4.23; | 668 double fresh_position_longitude = 4.23; |
596 content::WindowedNotificationObserver observer( | 669 content::WindowedNotificationObserver observer( |
597 content::NOTIFICATION_LOAD_STOP, | 670 content::NOTIFICATION_LOAD_STOP, |
598 content::Source<NavigationController>( | 671 content::Source<NavigationController>( |
599 ¤t_browser()->tab_strip_model()->GetActiveWebContents()-> | 672 ¤t_browser()->tab_strip_model()->GetActiveWebContents()-> |
600 GetController())); | 673 GetController())); |
601 NotifyGeoposition(fresh_position_latitude, fresh_position_longitude); | 674 NotifyGeoposition(fresh_position_latitude, fresh_position_longitude); |
602 observer.Wait(); | 675 observer.Wait(); |
603 CheckGeoposition(fresh_position_latitude, fresh_position_longitude); | 676 CheckGeoposition(fresh_position_latitude, fresh_position_longitude); |
604 | 677 |
605 // Disable navigation for this frame. | 678 // Disable navigation for this frame. |
606 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 679 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
607 | 680 |
608 // Now go ahead an authorize the second frame. | 681 // Now go ahead an authorize the second frame. |
609 SetFrameHost("iframe_1"); | 682 SetFrameHost("iframe_1"); |
610 // Infobar was displayed, allow access and check there's no error code. | 683 // Infobar was displayed, allow access and check there's no error code. |
611 SetInfoBarResponse(iframe_url(1), true); | 684 SetPromptResponse(iframe_url(1), true); |
612 LOG(WARNING) << "Checking position..."; | 685 LOG(WARNING) << "Checking position..."; |
613 CheckGeoposition(fresh_position_latitude, fresh_position_longitude); | 686 CheckGeoposition(fresh_position_latitude, fresh_position_longitude); |
614 LOG(WARNING) << "...done."; | 687 LOG(WARNING) << "...done."; |
615 } | 688 } |
616 | 689 |
617 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, | 690 IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, |
618 IFramesWithCachedPosition) { | 691 IFramesWithCachedPosition) { |
619 set_html_for_tests("/geolocation/iframes_different_origin.html"); | 692 set_html_for_tests("/geolocation/iframes_different_origin.html"); |
620 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 693 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
621 LoadIFrames(2); | 694 LoadIFrames(2); |
622 | 695 |
623 SetFrameHost("iframe_0"); | 696 SetFrameHost("iframe_0"); |
624 AddGeolocationWatch(true); | 697 AddGeolocationWatch(true); |
625 SetInfoBarResponse(iframe_url(0), true); | 698 SetPromptResponse(iframe_url(0), true); |
626 CheckGeoposition(fake_latitude(), fake_longitude()); | 699 CheckGeoposition(fake_latitude(), fake_longitude()); |
627 | 700 |
628 // Refresh geoposition, but let's not yet create the watch on the second frame | 701 // Refresh geoposition, but let's not yet create the watch on the second frame |
629 // so that it'll fetch from cache. | 702 // so that it'll fetch from cache. |
630 double cached_position_latitude = 5.67; | 703 double cached_position_latitude = 5.67; |
631 double cached_position_lognitude = 8.09; | 704 double cached_position_lognitude = 8.09; |
632 content::WindowedNotificationObserver observer( | 705 content::WindowedNotificationObserver observer( |
633 content::NOTIFICATION_LOAD_STOP, | 706 content::NOTIFICATION_LOAD_STOP, |
634 content::Source<NavigationController>( | 707 content::Source<NavigationController>( |
635 ¤t_browser()->tab_strip_model()->GetActiveWebContents()-> | 708 ¤t_browser()->tab_strip_model()->GetActiveWebContents()-> |
636 GetController())); | 709 GetController())); |
637 NotifyGeoposition(cached_position_latitude, cached_position_lognitude); | 710 NotifyGeoposition(cached_position_latitude, cached_position_lognitude); |
638 observer.Wait(); | 711 observer.Wait(); |
639 CheckGeoposition(cached_position_latitude, cached_position_lognitude); | 712 CheckGeoposition(cached_position_latitude, cached_position_lognitude); |
640 | 713 |
641 // Disable navigation for this frame. | 714 // Disable navigation for this frame. |
642 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 715 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
643 | 716 |
644 // Now go ahead and authorize the second frame. | 717 // Now go ahead and authorize the second frame. |
645 SetFrameHost("iframe_1"); | 718 SetFrameHost("iframe_1"); |
646 AddGeolocationWatch(true); | 719 AddGeolocationWatch(true); |
647 // WebKit will use its cache, but we also broadcast a position shortly | 720 // 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 | 721 // afterwards. We're only interested in the first navigation for the success |
649 // callback from the cached position. | 722 // callback from the cached position. |
650 CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); | 723 CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); |
651 SetInfoBarResponse(iframe_url(1), true); | 724 SetPromptResponse(iframe_url(1), true); |
652 CheckGeoposition(cached_position_latitude, cached_position_lognitude); | 725 CheckGeoposition(cached_position_latitude, cached_position_lognitude); |
653 } | 726 } |
654 | 727 |
655 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, CancelPermissionForFrame) { | 728 IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, CancelPermissionForFrame) { |
656 set_html_for_tests("/geolocation/iframes_different_origin.html"); | 729 set_html_for_tests("/geolocation/iframes_different_origin.html"); |
657 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 730 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
658 LoadIFrames(2); | 731 LoadIFrames(2); |
659 LOG(WARNING) << "frames loaded"; | 732 LOG(WARNING) << "frames loaded"; |
660 | 733 |
661 SetFrameHost("iframe_0"); | 734 SetFrameHost("iframe_0"); |
662 AddGeolocationWatch(true); | 735 AddGeolocationWatch(true); |
663 SetInfoBarResponse(iframe_url(0), true); | 736 SetPromptResponse(iframe_url(0), true); |
664 CheckGeoposition(fake_latitude(), fake_longitude()); | 737 CheckGeoposition(fake_latitude(), fake_longitude()); |
665 // Disables further prompts from this iframe. | 738 // Disables further prompts from this iframe. |
666 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 739 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
667 | 740 |
668 // Test second iframe from a different origin with a cached geoposition will | 741 // Test second iframe from a different origin with a cached geoposition will |
669 // create the infobar. | 742 // create the prompt. |
670 SetFrameHost("iframe_1"); | 743 SetFrameHost("iframe_1"); |
671 AddGeolocationWatch(true); | 744 AddGeolocationWatch(true); |
672 | 745 |
673 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 746 // Change the iframe, and ensure the prompt is gone. |
674 current_browser()->tab_strip_model()->GetActiveWebContents()); | 747 if (PermissionBubbleManager::Enabled()) { |
675 size_t num_infobars_before_cancel = infobar_service->infobar_count(); | 748 WebContents* web_contents = |
676 // Change the iframe, and ensure the infobar is gone. | 749 current_browser()->tab_strip_model()->GetActiveWebContents(); |
677 IFrameLoader change_iframe_1(current_browser(), 1, current_url()); | 750 int num_bubbles_before_cancel = GetBubblesQueueSize( |
678 size_t num_infobars_after_cancel = infobar_service->infobar_count(); | 751 PermissionBubbleManager::FromWebContents(web_contents)); |
679 EXPECT_EQ(num_infobars_before_cancel, num_infobars_after_cancel + 1); | 752 IFrameLoader change_iframe_1(current_browser(), 1, current_url()); |
| 753 int num_bubbles_after_cancel = GetBubblesQueueSize( |
| 754 PermissionBubbleManager::FromWebContents(web_contents)); |
| 755 EXPECT_EQ(num_bubbles_before_cancel, num_bubbles_after_cancel + 1); |
| 756 } else { |
| 757 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| 758 current_browser()->tab_strip_model()->GetActiveWebContents()); |
| 759 size_t num_infobars_before_cancel = infobar_service->infobar_count(); |
| 760 IFrameLoader change_iframe_1(current_browser(), 1, current_url()); |
| 761 size_t num_infobars_after_cancel = infobar_service->infobar_count(); |
| 762 EXPECT_EQ(num_infobars_before_cancel, num_infobars_after_cancel + 1); |
| 763 } |
680 } | 764 } |
681 | 765 |
682 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, InvalidUrlRequest) { | 766 IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, InvalidUrlRequest) { |
683 // Tests that an invalid URL (e.g. from a popup window) is rejected | 767 // 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 | 768 // correctly. Also acts as a regression test for http://crbug.com/40478 |
685 set_html_for_tests("/geolocation/invalid_request_url.html"); | 769 set_html_for_tests("/geolocation/invalid_request_url.html"); |
686 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 770 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
687 | 771 |
688 SetFrameHost(""); | 772 SetFrameHost(""); |
689 WebContents* original_tab = | 773 WebContents* original_tab = |
690 current_browser()->tab_strip_model()->GetActiveWebContents(); | 774 current_browser()->tab_strip_model()->GetActiveWebContents(); |
691 CheckStringValueFromJavascript("1", "requestGeolocationFromInvalidUrl()"); | 775 CheckStringValueFromJavascript("1", "requestGeolocationFromInvalidUrl()"); |
692 CheckStringValueFromJavascriptForFrame("1", "isAlive()", | 776 CheckStringValueFromJavascriptForFrame("1", "isAlive()", |
693 original_tab->GetMainFrame()); | 777 original_tab->GetMainFrame()); |
694 } | 778 } |
695 | 779 |
696 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfoBarBeforeStart) { | 780 IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, NoPromptBeforeStart) { |
697 // See http://crbug.com/42789 | 781 // See http://crbug.com/42789 |
698 set_html_for_tests("/geolocation/iframes_different_origin.html"); | 782 set_html_for_tests("/geolocation/iframes_different_origin.html"); |
699 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 783 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
700 LoadIFrames(2); | 784 LoadIFrames(2); |
701 LOG(WARNING) << "frames loaded"; | 785 LOG(WARNING) << "frames loaded"; |
702 | 786 |
703 // Access navigator.geolocation, but ensure it won't request permission. | 787 // Access navigator.geolocation, but ensure it won't request permission. |
704 SetFrameHost("iframe_1"); | 788 SetFrameHost("iframe_1"); |
705 CheckStringValueFromJavascript("object", "geoAccessNavigatorGeolocation()"); | 789 CheckStringValueFromJavascript("object", "geoAccessNavigatorGeolocation()"); |
706 | 790 |
707 SetFrameHost("iframe_0"); | 791 SetFrameHost("iframe_0"); |
708 AddGeolocationWatch(true); | 792 AddGeolocationWatch(true); |
709 SetInfoBarResponse(iframe_url(0), true); | 793 SetPromptResponse(iframe_url(0), true); |
710 CheckGeoposition(fake_latitude(), fake_longitude()); | 794 CheckGeoposition(fake_latitude(), fake_longitude()); |
711 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 795 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
712 | 796 |
713 // Permission should be requested after adding a watch. | 797 // Permission should be requested after adding a watch. |
714 SetFrameHost("iframe_1"); | 798 SetFrameHost("iframe_1"); |
715 AddGeolocationWatch(true); | 799 AddGeolocationWatch(true); |
716 SetInfoBarResponse(iframe_url(1), true); | 800 SetPromptResponse(iframe_url(1), true); |
717 CheckGeoposition(fake_latitude(), fake_longitude()); | 801 CheckGeoposition(fake_latitude(), fake_longitude()); |
718 } | 802 } |
719 | 803 |
720 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) { | 804 IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, TwoWatchesInOneFrame) { |
721 set_html_for_tests("/geolocation/two_watches.html"); | 805 set_html_for_tests("/geolocation/two_watches.html"); |
722 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 806 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
723 | 807 |
724 // First, set the JavaScript to navigate when it receives |final_position|. | 808 // First, set the JavaScript to navigate when it receives |final_position|. |
725 double final_position_latitude = 3.17; | 809 double final_position_latitude = 3.17; |
726 double final_position_longitude = 4.23; | 810 double final_position_longitude = 4.23; |
727 std::string script = base::StringPrintf( | 811 std::string script = base::StringPrintf( |
728 "window.domAutomationController.send(geoSetFinalPosition(%f, %f))", | 812 "window.domAutomationController.send(geoSetFinalPosition(%f, %f))", |
729 final_position_latitude, final_position_longitude); | 813 final_position_latitude, final_position_longitude); |
730 std::string js_result; | 814 std::string js_result; |
731 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 815 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
732 current_browser()->tab_strip_model()->GetActiveWebContents(), script, | 816 current_browser()->tab_strip_model()->GetActiveWebContents(), script, |
733 &js_result)); | 817 &js_result)); |
734 EXPECT_EQ(js_result, "ok"); | 818 EXPECT_EQ(js_result, "ok"); |
735 | 819 |
736 // Send a position which both geolocation watches will receive. | 820 // Send a position which both geolocation watches will receive. |
737 SetFrameHost(""); | 821 SetFrameHost(""); |
738 AddGeolocationWatch(true); | 822 AddGeolocationWatch(true); |
739 SetInfoBarResponse(current_url(), true); | 823 SetPromptResponse(current_url(), true); |
740 CheckGeoposition(fake_latitude(), fake_longitude()); | 824 CheckGeoposition(fake_latitude(), fake_longitude()); |
741 | 825 |
742 // The second watch will now have cancelled. Ensure an update still makes | 826 // The second watch will now have cancelled. Ensure an update still makes |
743 // its way through to the first watcher. | 827 // its way through to the first watcher. |
744 content::WindowedNotificationObserver observer( | 828 content::WindowedNotificationObserver observer( |
745 content::NOTIFICATION_LOAD_STOP, | 829 content::NOTIFICATION_LOAD_STOP, |
746 content::Source<NavigationController>( | 830 content::Source<NavigationController>( |
747 ¤t_browser()->tab_strip_model()->GetActiveWebContents()-> | 831 ¤t_browser()->tab_strip_model()->GetActiveWebContents()-> |
748 GetController())); | 832 GetController())); |
749 NotifyGeoposition(final_position_latitude, final_position_longitude); | 833 NotifyGeoposition(final_position_latitude, final_position_longitude); |
750 observer.Wait(); | 834 observer.Wait(); |
751 CheckGeoposition(final_position_latitude, final_position_longitude); | 835 CheckGeoposition(final_position_latitude, final_position_longitude); |
752 } | 836 } |
753 | 837 |
754 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TabDestroyed) { | 838 IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, TabDestroyed) { |
| 839 // This test triggers crbug.com/433877. |
| 840 // TODO(felt): Reenable this test for permission bubbles once that's fixed. |
| 841 if (PermissionBubbleManager::Enabled()) return; |
| 842 |
755 set_html_for_tests("/geolocation/tab_destroyed.html"); | 843 set_html_for_tests("/geolocation/tab_destroyed.html"); |
756 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 844 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
757 LoadIFrames(3); | 845 LoadIFrames(3); |
758 | 846 |
759 SetFrameHost("iframe_0"); | 847 SetFrameHost("iframe_0"); |
760 AddGeolocationWatch(true); | 848 AddGeolocationWatch(true); |
761 | 849 |
762 SetFrameHost("iframe_1"); | 850 SetFrameHost("iframe_1"); |
763 AddGeolocationWatch(false); | 851 AddGeolocationWatch(false); |
764 | 852 |
765 SetFrameHost("iframe_2"); | 853 SetFrameHost("iframe_2"); |
766 AddGeolocationWatch(false); | 854 AddGeolocationWatch(false); |
767 | 855 |
768 std::string script = | 856 std::string script = |
769 "window.domAutomationController.send(window.close());"; | 857 "window.domAutomationController.send(window.close());"; |
770 bool result = content::ExecuteScript( | 858 bool result = content::ExecuteScript( |
771 current_browser()->tab_strip_model()->GetActiveWebContents(), script); | 859 current_browser()->tab_strip_model()->GetActiveWebContents(), script); |
772 EXPECT_EQ(result, true); | 860 EXPECT_EQ(result, true); |
773 } | 861 } |
774 | 862 |
775 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, LastUsageUpdated) { | 863 IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, LastUsageUpdated) { |
776 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 864 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
777 base::SimpleTestClock* clock_ = new base::SimpleTestClock(); | 865 base::SimpleTestClock* clock_ = new base::SimpleTestClock(); |
778 current_browser() | 866 current_browser() |
779 ->profile() | 867 ->profile() |
780 ->GetHostContentSettingsMap() | 868 ->GetHostContentSettingsMap() |
781 ->SetPrefClockForTesting(scoped_ptr<base::Clock>(clock_)); | 869 ->SetPrefClockForTesting(scoped_ptr<base::Clock>(clock_)); |
782 clock_->SetNow(base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(10)); | 870 clock_->SetNow(base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(10)); |
783 | 871 |
784 // Setting the permission should trigger the last usage. | 872 // Setting the permission should trigger the last usage. |
785 current_browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 873 current_browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
(...skipping 23 matching lines...) Expand all Loading... |
809 // Last usage has been updated. | 897 // Last usage has been updated. |
810 EXPECT_EQ(current_browser() | 898 EXPECT_EQ(current_browser() |
811 ->profile() | 899 ->profile() |
812 ->GetHostContentSettingsMap() | 900 ->GetHostContentSettingsMap() |
813 ->GetLastUsage(current_url().GetOrigin(), | 901 ->GetLastUsage(current_url().GetOrigin(), |
814 current_url().GetOrigin(), | 902 current_url().GetOrigin(), |
815 CONTENT_SETTINGS_TYPE_GEOLOCATION) | 903 CONTENT_SETTINGS_TYPE_GEOLOCATION) |
816 .ToDoubleT(), | 904 .ToDoubleT(), |
817 13); | 905 13); |
818 } | 906 } |
| 907 |
| 908 INSTANTIATE_TEST_CASE_P(GeolocationBrowserTestWithParams, |
| 909 GeolocationBrowserTest, |
| 910 testing::Values(false, true)); |
OLD | NEW |