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

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

Issue 1320005: Adds GeolocationContentSettings on TabContents. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/geolocation/geolocation_permission_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/string_util.h" 5 #include "base/string_util.h"
6 #include "base/waitable_event.h" 6 #include "base/waitable_event.h"
7 #include "chrome/browser/app_modal_dialog.h" 7 #include "chrome/browser/app_modal_dialog.h"
8 #include "chrome/browser/browser.h" 8 #include "chrome/browser/browser.h"
9 #include "chrome/browser/browser_list.h" 9 #include "chrome/browser/browser_list.h"
10 #include "chrome/browser/dom_operation_notification_details.h" 10 #include "chrome/browser/dom_operation_notification_details.h"
(...skipping 29 matching lines...) Expand all
40 Source<NavigationController>(controller)); 40 Source<NavigationController>(controller));
41 registrar_.Add(this, NotificationType::DOM_OPERATION_RESPONSE, 41 registrar_.Add(this, NotificationType::DOM_OPERATION_RESPONSE,
42 NotificationService::AllSources()); 42 NotificationService::AllSources());
43 std::string script = StringPrintf( 43 std::string script = StringPrintf(
44 "window.domAutomationController.setAutomationId(0);" 44 "window.domAutomationController.setAutomationId(0);"
45 "window.domAutomationController.send(addIFrame(%d));", 45 "window.domAutomationController.send(addIFrame(%d));",
46 iframe_id); 46 iframe_id);
47 browser->GetSelectedTabContents()->render_view_host()-> 47 browser->GetSelectedTabContents()->render_view_host()->
48 ExecuteJavascriptInWebFrame(L"", UTF8ToWide(script)); 48 ExecuteJavascriptInWebFrame(L"", UTF8ToWide(script));
49 ui_test_utils::RunMessageLoop(); 49 ui_test_utils::RunMessageLoop();
50
50 EXPECT_EQ(StringPrintf("\"%d\"", iframe_id), javascript_response_); 51 EXPECT_EQ(StringPrintf("\"%d\"", iframe_id), javascript_response_);
51 registrar_.RemoveAll(); 52 registrar_.RemoveAll();
53 // Now that we loaded the iframe, let's fetch its src.
54 script = StringPrintf(
55 "window.domAutomationController.send(getIFrameSrc(%d))", iframe_id);
56 std::string iframe_src;
57 ui_test_utils::ExecuteJavaScriptAndExtractString(
58 browser->GetSelectedTabContents()->render_view_host(),
59 L"", UTF8ToWide(script), &iframe_src);
60 iframe_url_ = GURL(iframe_src);
52 } 61 }
53 62
63 GURL iframe_url() const { return iframe_url_; }
64
54 virtual void Observe(NotificationType type, 65 virtual void Observe(NotificationType type,
55 const NotificationSource& source, 66 const NotificationSource& source,
56 const NotificationDetails& details) { 67 const NotificationDetails& details) {
57 if (type == NotificationType::LOAD_STOP) { 68 if (type == NotificationType::LOAD_STOP) {
58 navigation_completed_ = true; 69 navigation_completed_ = true;
59 } else if (type == NotificationType::DOM_OPERATION_RESPONSE) { 70 } else if (type == NotificationType::DOM_OPERATION_RESPONSE) {
60 Details<DomOperationNotificationDetails> dom_op_details(details); 71 Details<DomOperationNotificationDetails> dom_op_details(details);
61 javascript_response_ = dom_op_details->json(); 72 javascript_response_ = dom_op_details->json();
62 javascript_completed_ = true; 73 javascript_completed_ = true;
63 } 74 }
64 if (javascript_completed_ && navigation_completed_) 75 if (javascript_completed_ && navigation_completed_)
65 MessageLoopForUI::current()->Quit(); 76 MessageLoopForUI::current()->Quit();
66 } 77 }
67 78
68 private: 79 private:
69 NotificationRegistrar registrar_; 80 NotificationRegistrar registrar_;
70 81
71 // If true the navigation has completed. 82 // If true the navigation has completed.
72 bool navigation_completed_; 83 bool navigation_completed_;
73 84
74 // If true the javascript call has completed. 85 // If true the javascript call has completed.
75 bool javascript_completed_; 86 bool javascript_completed_;
76 87
77 std::string javascript_response_; 88 std::string javascript_response_;
78 89
90 // The URL for the iframe we just loaded.
91 GURL iframe_url_;
92
79 DISALLOW_COPY_AND_ASSIGN(IFrameLoader); 93 DISALLOW_COPY_AND_ASSIGN(IFrameLoader);
80 }; 94 };
81 95
82 class GeolocationNotificationObserver : public NotificationObserver { 96 class GeolocationNotificationObserver : public NotificationObserver {
83 public: 97 public:
84 GeolocationNotificationObserver() : infobar_(NULL) { 98 GeolocationNotificationObserver() : infobar_(NULL) {
85 } 99 }
86 100
87 void ObserveInfobarAddedNotification() { 101 void ObserveInfobarAddedNotification() {
88 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED, 102 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 INITIALIZATION_NEWTAB, 182 INITIALIZATION_NEWTAB,
169 INITIALIZATION_IFRAMES, 183 INITIALIZATION_IFRAMES,
170 }; 184 };
171 185
172 void Initialize(InitializationOptions options) { 186 void Initialize(InitializationOptions options) {
173 GeolocationArbitrator::SetProviderFactoryForTest( 187 GeolocationArbitrator::SetProviderFactoryForTest(
174 &NewAutoSuccessMockLocationProvider); 188 &NewAutoSuccessMockLocationProvider);
175 if (!server_.get()) 189 if (!server_.get())
176 server_ = StartHTTPServer(); 190 server_ = StartHTTPServer();
177 191
178 GURL url = server_->TestServerPage(html_for_tests_); 192 current_url_ = server_->TestServerPage(html_for_tests_);
179 LOG(WARNING) << "before navigate"; 193 LOG(WARNING) << "before navigate";
180 if (options == INITIALIZATION_OFFTHERECORD) { 194 if (options == INITIALIZATION_OFFTHERECORD) {
181 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), url); 195 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), current_url_);
182 current_browser_ = BrowserList::FindBrowserWithType( 196 current_browser_ = BrowserList::FindBrowserWithType(
183 browser()->profile()->GetOffTheRecordProfile(), Browser::TYPE_NORMAL); 197 browser()->profile()->GetOffTheRecordProfile(), Browser::TYPE_NORMAL);
184 } else if (options == INITIALIZATION_NEWTAB) { 198 } else if (options == INITIALIZATION_NEWTAB) {
185 current_browser_ = browser(); 199 current_browser_ = browser();
186 current_browser_->NewTab(); 200 current_browser_->NewTab();
187 ui_test_utils::NavigateToURL(current_browser_, url); 201 ui_test_utils::NavigateToURL(current_browser_, current_url_);
188 } else if (options == INITIALIZATION_IFRAMES) { 202 } else if (options == INITIALIZATION_IFRAMES) {
189 current_browser_ = browser(); 203 current_browser_ = browser();
190 ui_test_utils::NavigateToURL(current_browser_, url); 204 ui_test_utils::NavigateToURL(current_browser_, current_url_);
191 IFrameLoader(current_browser_, 0); 205 IFrameLoader iframe0(current_browser_, 0);
192 IFrameLoader(current_browser_, 1); 206 iframe0_url_ = iframe0.iframe_url();
207
208 IFrameLoader iframe1(current_browser_, 1);
209 iframe1_url_ = iframe1.iframe_url();
193 } else { 210 } else {
194 current_browser_ = browser(); 211 current_browser_ = browser();
195 ui_test_utils::NavigateToURL(current_browser_, url); 212 ui_test_utils::NavigateToURL(current_browser_, current_url_);
196 } 213 }
197 EXPECT_TRUE(current_browser_); 214 EXPECT_TRUE(current_browser_);
198 LOG(WARNING) << "after navigate"; 215 LOG(WARNING) << "after navigate";
199 } 216 }
200 217
201 void AddGeolocationWatch(bool wait_for_infobar) { 218 void AddGeolocationWatch(bool wait_for_infobar) {
202 GeolocationNotificationObserver notification_observer; 219 GeolocationNotificationObserver notification_observer;
203 if (wait_for_infobar) { 220 if (wait_for_infobar) {
204 // Observe infobar notification. 221 // Observe infobar notification.
205 notification_observer.ObserveInfobarAddedNotification(); 222 notification_observer.ObserveInfobarAddedNotification();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 254
238 void CheckGeoposition(const Geoposition& geoposition) { 255 void CheckGeoposition(const Geoposition& geoposition) {
239 // Checks we have no error. 256 // Checks we have no error.
240 CheckStringValueFromJavascript("0", "geoGetLastError()"); 257 CheckStringValueFromJavascript("0", "geoGetLastError()");
241 CheckStringValueFromJavascript( 258 CheckStringValueFromJavascript(
242 DoubleToString(geoposition.latitude), "geoGetLastPositionLatitude()"); 259 DoubleToString(geoposition.latitude), "geoGetLastPositionLatitude()");
243 CheckStringValueFromJavascript( 260 CheckStringValueFromJavascript(
244 DoubleToString(geoposition.longitude), "geoGetLastPositionLongitude()"); 261 DoubleToString(geoposition.longitude), "geoGetLastPositionLongitude()");
245 } 262 }
246 263
247 void SetInfobarResponse(bool allowed) { 264 void SetInfobarResponse(const GURL& requesting_url, bool allowed) {
265 TabContents* tab_contents = current_browser_->GetSelectedTabContents();
266 TabContents::GeolocationContentSettings content_settings =
267 tab_contents->geolocation_content_settings();
268 size_t settings_size = content_settings.size();
248 GeolocationNotificationObserver notification_observer; 269 GeolocationNotificationObserver notification_observer;
249 notification_observer.ObserveInfobarRemovedNotification(); 270 notification_observer.ObserveInfobarRemovedNotification();
250 ASSERT_TRUE(infobar_); 271 ASSERT_TRUE(infobar_);
251 LOG(WARNING) << "will set infobar response"; 272 LOG(WARNING) << "will set infobar response";
252 if (allowed) 273 if (allowed)
253 infobar_->AsConfirmInfoBarDelegate()->Accept(); 274 infobar_->AsConfirmInfoBarDelegate()->Accept();
254 else 275 else
255 infobar_->AsConfirmInfoBarDelegate()->Cancel(); 276 infobar_->AsConfirmInfoBarDelegate()->Cancel();
256 LOG(WARNING) << "infobar response set"; 277 LOG(WARNING) << "infobar response set";
257 EXPECT_FALSE(notification_observer.infobar_); 278 EXPECT_FALSE(notification_observer.infobar_);
258 infobar_ = NULL; 279 infobar_ = NULL;
259 WaitForJSPrompt(); 280 WaitForJSPrompt();
281 content_settings = tab_contents->geolocation_content_settings();
282 EXPECT_GT(content_settings.size(), settings_size);
283 EXPECT_EQ(1U, content_settings.count(requesting_url));
284 ContentSetting expected_setting =
285 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
286 EXPECT_EQ(expected_setting, content_settings[requesting_url]);
260 } 287 }
261 288
262 void WaitForJSPrompt() { 289 void WaitForJSPrompt() {
263 LOG(WARNING) << "will block for JS prompt"; 290 LOG(WARNING) << "will block for JS prompt";
264 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); 291 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
265 LOG(WARNING) << "JS prompt received"; 292 LOG(WARNING) << "JS prompt received";
266 ASSERT_TRUE(alert); 293 ASSERT_TRUE(alert);
267 LOG(WARNING) << "will close JS prompt"; 294 LOG(WARNING) << "will close JS prompt";
268 alert->CloseModalDialog(); 295 alert->CloseModalDialog();
269 LOG(WARNING) << "closed JS prompt"; 296 LOG(WARNING) << "closed JS prompt";
(...skipping 16 matching lines...) Expand all
286 } 313 }
287 314
288 scoped_refptr<HTTPTestServer> server_; 315 scoped_refptr<HTTPTestServer> server_;
289 InfoBarDelegate* infobar_; 316 InfoBarDelegate* infobar_;
290 Browser* current_browser_; 317 Browser* current_browser_;
291 // path element of a URL referencing the html content for this test. 318 // path element of a URL referencing the html content for this test.
292 std::string html_for_tests_; 319 std::string html_for_tests_;
293 // This member defines the iframe (or top-level page, if empty) where the 320 // This member defines the iframe (or top-level page, if empty) where the
294 // javascript calls will run. 321 // javascript calls will run.
295 std::wstring iframe_xpath_; 322 std::wstring iframe_xpath_;
323 // The current url for the top level page.
324 GURL current_url_;
325 // If not empty, the GURL for the first iframe.
326 GURL iframe0_url_;
327 // If not empty, the GURL for the second iframe.
328 GURL iframe1_url_;
296 }; 329 };
297 330
298 #if defined(OS_MACOSX) 331 #if defined(OS_MACOSX)
299 // TODO(bulach): investigate why this fails on mac. It may be related to: 332 // TODO(bulach): investigate why this fails on mac. It may be related to:
300 // http://crbug.com//29424 333 // http://crbug.com//29424
301 #define MAYBE_DisplaysPermissionBar DISABLED_DisplaysPermissionBar 334 #define MAYBE_DisplaysPermissionBar DISABLED_DisplaysPermissionBar
302 #else 335 #else
303 #define MAYBE_DisplaysPermissionBar DisplaysPermissionBar 336 #define MAYBE_DisplaysPermissionBar DisplaysPermissionBar
304 #endif 337 #endif
305 338
306 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_DisplaysPermissionBar) { 339 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_DisplaysPermissionBar) {
307 Initialize(INITIALIZATION_NONE); 340 Initialize(INITIALIZATION_NONE);
308 AddGeolocationWatch(true); 341 AddGeolocationWatch(true);
309 } 342 }
310 343
311 #if defined(OS_MACOSX) 344 #if defined(OS_MACOSX)
312 // TODO(bulach): investigate why this fails on mac. It may be related to: 345 // TODO(bulach): investigate why this fails on mac. It may be related to:
313 // http://crbug.com//29424 346 // http://crbug.com//29424
314 #define MAYBE_Geoposition DISABLED_Geoposition 347 #define MAYBE_Geoposition DISABLED_Geoposition
315 #else 348 #else
316 #define MAYBE_Geoposition Geoposition 349 #define MAYBE_Geoposition Geoposition
317 #endif 350 #endif
318 351
319 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_Geoposition) { 352 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_Geoposition) {
320 Initialize(INITIALIZATION_NONE); 353 Initialize(INITIALIZATION_NONE);
321 AddGeolocationWatch(true); 354 AddGeolocationWatch(true);
322 SetInfobarResponse(true); 355 SetInfobarResponse(current_url_, true);
323 CheckGeoposition(MockLocationProvider::instance_->position_); 356 CheckGeoposition(MockLocationProvider::instance_->position_);
324 } 357 }
325 358
326 #if defined(OS_MACOSX) 359 #if defined(OS_MACOSX)
327 // TODO(bulach): investigate why this fails on mac. It may be related to: 360 // TODO(bulach): investigate why this fails on mac. It may be related to:
328 // http://crbug.com//29424 361 // http://crbug.com//29424
329 #define MAYBE_ErrorOnPermissionDenied DISABLED_ErrorOnPermissionDenied 362 #define MAYBE_ErrorOnPermissionDenied DISABLED_ErrorOnPermissionDenied
330 #else 363 #else
331 #define MAYBE_ErrorOnPermissionDenied ErrorOnPermissionDenied 364 #define MAYBE_ErrorOnPermissionDenied ErrorOnPermissionDenied
332 #endif 365 #endif
333 366
334 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_ErrorOnPermissionDenied) { 367 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_ErrorOnPermissionDenied) {
335 Initialize(INITIALIZATION_NONE); 368 Initialize(INITIALIZATION_NONE);
336 AddGeolocationWatch(true); 369 AddGeolocationWatch(true);
337 // Infobar was displayed, deny access and check for error code. 370 // Infobar was displayed, deny access and check for error code.
338 SetInfobarResponse(false); 371 SetInfobarResponse(current_url_, false);
339 CheckStringValueFromJavascript("1", "geoGetLastError()"); 372 CheckStringValueFromJavascript("1", "geoGetLastError()");
340 } 373 }
341 374
342 #if defined(OS_MACOSX) 375 #if defined(OS_MACOSX)
343 // TODO(bulach): investigate why this fails on mac. It may be related to: 376 // TODO(bulach): investigate why this fails on mac. It may be related to:
344 // http://crbug.com//29424 377 // http://crbug.com//29424
345 #define MAYBE_NoInfobarForSecondTab DISABLED_NoInfobarForSecondTab 378 #define MAYBE_NoInfobarForSecondTab DISABLED_NoInfobarForSecondTab
346 #else 379 #else
347 #define MAYBE_NoInfobarForSecondTab NoInfobarForSecondTab 380 #define MAYBE_NoInfobarForSecondTab NoInfobarForSecondTab
348 #endif 381 #endif
349 382
350 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForSecondTab) { 383 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoInfobarForSecondTab) {
351 #if 0 384 #if 0
352 // TODO(bulach): enable this test once we use HostContentSettingsMap instead 385 // TODO(bulach): enable this test once we use HostContentSettingsMap instead
353 // of files. 386 // of files.
354 Initialize(INITIALIZATION_NONE); 387 Initialize(INITIALIZATION_NONE);
355 SendGeoposition(true, GeopositionFromLatLong(0, 0)); 388 SendGeoposition(true, GeopositionFromLatLong(0, 0));
356 SetInfobarResponse(true); 389 SetInfobarResponse(current_url_, true);
357 // Checks infobar will not be created a second tab. 390 // Checks infobar will not be created a second tab.
358 Initialize(INITIALIZATION_NEWTAB); 391 Initialize(INITIALIZATION_NEWTAB);
359 SendGeoposition(false, GeopositionFromLatLong(0, 0)); 392 SendGeoposition(false, GeopositionFromLatLong(0, 0));
360 CheckStringValueFromJavascript("0", "geoGetLastError()"); 393 CheckStringValueFromJavascript("0", "geoGetLastError()");
361 #endif 394 #endif
362 } 395 }
363 396
364 #if defined(OS_MACOSX) 397 #if defined(OS_MACOSX)
365 // TODO(bulach): investigate why this fails on mac. It may be related to: 398 // TODO(bulach): investigate why this fails on mac. It may be related to:
366 // http://crbug.com//29424 399 // http://crbug.com//29424
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 // http://crbug.com//29424 444 // http://crbug.com//29424
412 #define MAYBE_InfobarForOffTheRecord DISABLED_InfobarForOffTheRecord 445 #define MAYBE_InfobarForOffTheRecord DISABLED_InfobarForOffTheRecord
413 #else 446 #else
414 #define MAYBE_InfobarForOffTheRecord InfobarForOffTheRecord 447 #define MAYBE_InfobarForOffTheRecord InfobarForOffTheRecord
415 #endif 448 #endif
416 449
417 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_InfobarForOffTheRecord) { 450 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_InfobarForOffTheRecord) {
418 // Checks infobar will be created for regular profile. 451 // Checks infobar will be created for regular profile.
419 Initialize(INITIALIZATION_NONE); 452 Initialize(INITIALIZATION_NONE);
420 AddGeolocationWatch(true); 453 AddGeolocationWatch(true);
421 SetInfobarResponse(true); 454 SetInfobarResponse(current_url_, true);
422 CheckGeoposition(MockLocationProvider::instance_->position_); 455 CheckGeoposition(MockLocationProvider::instance_->position_);
423 // Disables further prompts from this tab. 456 // Disables further prompts from this tab.
424 CheckStringValueFromJavascript("false", "geoEnableAlerts(false)"); 457 CheckStringValueFromJavascript("false", "geoEnableAlerts(false)");
425 // Go off the record, and checks infobar will be created and an error callback 458 // Go off the record, and checks infobar will be created and an error callback
426 // is triggered. 459 // is triggered.
427 Initialize(INITIALIZATION_OFFTHERECORD); 460 Initialize(INITIALIZATION_OFFTHERECORD);
428 AddGeolocationWatch(true); 461 AddGeolocationWatch(true);
429 SetInfobarResponse(false); 462 SetInfobarResponse(current_url_, false);
430 CheckStringValueFromJavascript("1", "geoGetLastError()"); 463 CheckStringValueFromJavascript("1", "geoGetLastError()");
431 } 464 }
432 465
433 #if defined(OS_MACOSX) 466 #if defined(OS_MACOSX)
434 // TODO(bulach): investigate why this fails on mac. It may be related to: 467 // TODO(bulach): investigate why this fails on mac. It may be related to:
435 // http://crbug.com//29424 468 // http://crbug.com//29424
436 #define MAYBE_IFramesWithFreshPosition DISABLED_IFramesWithFreshPosition 469 #define MAYBE_IFramesWithFreshPosition DISABLED_IFramesWithFreshPosition
437 #else 470 #else
438 // TODO(bulach): investigate this failure. 471 // TODO(bulach): investigate this failure.
439 // http://build.chromium.org/buildbot/waterfall/builders/XP%20Tests/builds/18549 /steps/browser_tests/logs/stdio 472 // http://build.chromium.org/buildbot/waterfall/builders/XP%20Tests/builds/18549 /steps/browser_tests/logs/stdio
440 #define MAYBE_IFramesWithFreshPosition FLAKY_IFramesWithFreshPosition 473 #define MAYBE_IFramesWithFreshPosition FLAKY_IFramesWithFreshPosition
441 #endif 474 #endif
442 475
443 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, 476 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest,
444 MAYBE_IFramesWithFreshPosition) { 477 MAYBE_IFramesWithFreshPosition) {
445 html_for_tests_ = "files/geolocation/iframes_different_origin.html"; 478 html_for_tests_ = "files/geolocation/iframes_different_origin.html";
446 Initialize(INITIALIZATION_IFRAMES); 479 Initialize(INITIALIZATION_IFRAMES);
447 LOG(WARNING) << "frames loaded"; 480 LOG(WARNING) << "frames loaded";
448 481
449 iframe_xpath_ = L"//iframe[@id='iframe_0']"; 482 iframe_xpath_ = L"//iframe[@id='iframe_0']";
450 AddGeolocationWatch(true); 483 AddGeolocationWatch(true);
451 SetInfobarResponse(true); 484 SetInfobarResponse(iframe0_url_, true);
452 CheckGeoposition(MockLocationProvider::instance_->position_); 485 CheckGeoposition(MockLocationProvider::instance_->position_);
453 // Disables further prompts from this iframe. 486 // Disables further prompts from this iframe.
454 CheckStringValueFromJavascript("false", "geoEnableAlerts(false)"); 487 CheckStringValueFromJavascript("false", "geoEnableAlerts(false)");
455 488
456 // Test second iframe from a different origin with a cached geoposition will 489 // Test second iframe from a different origin with a cached geoposition will
457 // create the infobar. 490 // create the infobar.
458 iframe_xpath_ = L"//iframe[@id='iframe_1']"; 491 iframe_xpath_ = L"//iframe[@id='iframe_1']";
459 AddGeolocationWatch(true); 492 AddGeolocationWatch(true);
460 493
461 // Back to the first frame, enable alert and refresh geoposition. 494 // Back to the first frame, enable alert and refresh geoposition.
462 iframe_xpath_ = L"//iframe[@id='iframe_0']"; 495 iframe_xpath_ = L"//iframe[@id='iframe_0']";
463 CheckStringValueFromJavascript("true", "geoEnableAlerts(true)"); 496 CheckStringValueFromJavascript("true", "geoEnableAlerts(true)");
464 // MockLocationProvider must have been created. 497 // MockLocationProvider must have been created.
465 ASSERT_TRUE(MockLocationProvider::instance_); 498 ASSERT_TRUE(MockLocationProvider::instance_);
466 Geoposition fresh_position = GeopositionFromLatLong(3.17, 4.23); 499 Geoposition fresh_position = GeopositionFromLatLong(3.17, 4.23);
467 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, NewRunnableFunction( 500 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, NewRunnableFunction(
468 &NotifyGeopositionOnIOThread, fresh_position)); 501 &NotifyGeopositionOnIOThread, fresh_position));
469 WaitForJSPrompt(); 502 WaitForJSPrompt();
470 CheckGeoposition(fresh_position); 503 CheckGeoposition(fresh_position);
471 504
472 // Disable alert for this frame. 505 // Disable alert for this frame.
473 CheckStringValueFromJavascript("false", "geoEnableAlerts(false)"); 506 CheckStringValueFromJavascript("false", "geoEnableAlerts(false)");
474 507
475 // Now go ahead an authorize the second frame. 508 // Now go ahead an authorize the second frame.
476 iframe_xpath_ = L"//iframe[@id='iframe_1']"; 509 iframe_xpath_ = L"//iframe[@id='iframe_1']";
477 // Infobar was displayed, allow access and check there's no error code. 510 // Infobar was displayed, allow access and check there's no error code.
478 SetInfobarResponse(true); 511 SetInfobarResponse(iframe1_url_, true);
479 CheckGeoposition(fresh_position); 512 CheckGeoposition(fresh_position);
480 } 513 }
481 514
482 515
483 #if defined(OS_MACOSX) 516 #if defined(OS_MACOSX)
484 // TODO(bulach): investigate why this fails on mac. It may be related to: 517 // TODO(bulach): investigate why this fails on mac. It may be related to:
485 // http://crbug.com//29424 518 // http://crbug.com//29424
486 #define MAYBE_IFramesWithCachedPosition DISABLED_IFramesWithCachedPosition 519 #define MAYBE_IFramesWithCachedPosition DISABLED_IFramesWithCachedPosition
487 #else 520 #else
488 // TODO(bulach): enable this test when we roll to 521 // TODO(bulach): enable this test when we roll to
489 // https://bugs.webkit.org/show_bug.cgi?id=36315 522 // https://bugs.webkit.org/show_bug.cgi?id=36315
490 #define MAYBE_IFramesWithCachedPosition DISABLED_IFramesWithCachedPosition 523 #define MAYBE_IFramesWithCachedPosition DISABLED_IFramesWithCachedPosition
491 #endif 524 #endif
492 525
493 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, 526 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest,
494 MAYBE_IFramesWithCachedPosition) { 527 MAYBE_IFramesWithCachedPosition) {
495 html_for_tests_ = "files/geolocation/iframes_different_origin.html"; 528 html_for_tests_ = "files/geolocation/iframes_different_origin.html";
496 Initialize(INITIALIZATION_IFRAMES); 529 Initialize(INITIALIZATION_IFRAMES);
497 530
498 iframe_xpath_ = L"//iframe[@id='iframe_0']"; 531 iframe_xpath_ = L"//iframe[@id='iframe_0']";
499 AddGeolocationWatch(true); 532 AddGeolocationWatch(true);
500 SetInfobarResponse(true); 533 SetInfobarResponse(iframe0_url_, true);
501 CheckGeoposition(MockLocationProvider::instance_->position_); 534 CheckGeoposition(MockLocationProvider::instance_->position_);
502 535
503 // Refresh geoposition, but let's not yet create the watch on the second frame 536 // Refresh geoposition, but let's not yet create the watch on the second frame
504 // so that it'll fetch from cache. 537 // so that it'll fetch from cache.
505 // MockLocationProvider must have been created. 538 // MockLocationProvider must have been created.
506 ASSERT_TRUE(MockLocationProvider::instance_); 539 ASSERT_TRUE(MockLocationProvider::instance_);
507 Geoposition cached_position = GeopositionFromLatLong(3.17, 4.23); 540 Geoposition cached_position = GeopositionFromLatLong(3.17, 4.23);
508 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, NewRunnableFunction( 541 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, NewRunnableFunction(
509 &NotifyGeopositionOnIOThread, cached_position)); 542 &NotifyGeopositionOnIOThread, cached_position));
510 WaitForJSPrompt(); 543 WaitForJSPrompt();
511 CheckGeoposition(cached_position); 544 CheckGeoposition(cached_position);
512 545
513 // Disables further prompts from this iframe. 546 // Disable alert for this frame.
514 CheckStringValueFromJavascript("false", "geoEnableAlerts(false)"); 547 CheckStringValueFromJavascript("false", "geoEnableAlerts(false)");
515 548
516 // Test second iframe from a different origin with a cached geoposition. 549 // Now go ahead an authorize the second frame.
517 iframe_xpath_ = L"//iframe[@id='iframe_1']"; 550 iframe_xpath_ = L"//iframe[@id='iframe_1']";
518 AddGeolocationWatch(true); 551 AddGeolocationWatch(true);
519 // Infobar was displayed, allow access and check there's no error code. 552 SetInfobarResponse(iframe1_url_, true);
520 SetInfobarResponse(true);
521 CheckGeoposition(cached_position); 553 CheckGeoposition(cached_position);
522 } 554 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/geolocation/geolocation_permission_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698