Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Side by Side Diff: chrome/browser/geolocation/geolocation_browsertest.cc

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

Powered by Google App Engine
This is Rietveld 408576698