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