| 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 content::RunMessageLoop(); | 64 content::RunMessageLoop(); |
| 65 | 65 |
| 66 EXPECT_EQ(base::StringPrintf("\"%d\"", iframe_id), javascript_response_); | 66 EXPECT_EQ(base::StringPrintf("\"%d\"", iframe_id), javascript_response_); |
| 67 registrar_.RemoveAll(); | 67 registrar_.RemoveAll(); |
| 68 // Now that we loaded the iframe, let's fetch its src. | 68 // Now that we loaded the iframe, let's fetch its src. |
| 69 script = base::StringPrintf( | 69 script = base::StringPrintf( |
| 70 "window.domAutomationController.send(getIFrameSrc(%d))", iframe_id); | 70 "window.domAutomationController.send(getIFrameSrc(%d))", iframe_id); |
| 71 std::string iframe_src; | 71 std::string iframe_src; |
| 72 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractString( | 72 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractString( |
| 73 chrome::GetActiveWebContents(browser)->GetRenderViewHost(), | 73 chrome::GetActiveWebContents(browser)->GetRenderViewHost(), |
| 74 "", | 74 L"", UTF8ToWide(script), &iframe_src)); |
| 75 script, | |
| 76 &iframe_src)); | |
| 77 iframe_url_ = GURL(iframe_src); | 75 iframe_url_ = GURL(iframe_src); |
| 78 } | 76 } |
| 79 | 77 |
| 80 GURL iframe_url() const { return iframe_url_; } | 78 GURL iframe_url() const { return iframe_url_; } |
| 81 | 79 |
| 82 virtual void Observe(int type, | 80 virtual void Observe(int type, |
| 83 const content::NotificationSource& source, | 81 const content::NotificationSource& source, |
| 84 const content::NotificationDetails& details) { | 82 const content::NotificationDetails& details) { |
| 85 if (type == content::NOTIFICATION_LOAD_STOP) { | 83 if (type == content::NOTIFICATION_LOAD_STOP) { |
| 86 navigation_completed_ = true; | 84 navigation_completed_ = true; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 127 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 130 content::NotificationService::AllSources()); | 128 content::NotificationService::AllSources()); |
| 131 registrar_.Add(this, content::NOTIFICATION_LOAD_START, | 129 registrar_.Add(this, content::NOTIFICATION_LOAD_START, |
| 132 content::NotificationService::AllSources()); | 130 content::NotificationService::AllSources()); |
| 133 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | 131 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
| 134 content::NotificationService::AllSources()); | 132 content::NotificationService::AllSources()); |
| 135 } | 133 } |
| 136 } | 134 } |
| 137 | 135 |
| 138 void AddWatchAndWaitForNotification(content::RenderViewHost* render_view_host, | 136 void AddWatchAndWaitForNotification(content::RenderViewHost* render_view_host, |
| 139 const std::string& iframe_xpath) { | 137 const std::wstring& iframe_xpath) { |
| 140 LOG(WARNING) << "will add geolocation watch"; | 138 LOG(WARNING) << "will add geolocation watch"; |
| 141 std::string script = | 139 std::string script = |
| 142 "window.domAutomationController.setAutomationId(0);" | 140 "window.domAutomationController.setAutomationId(0);" |
| 143 "window.domAutomationController.send(geoStart());"; | 141 "window.domAutomationController.send(geoStart());"; |
| 144 render_view_host->ExecuteJavascriptInWebFrame(UTF8ToUTF16(iframe_xpath), | 142 render_view_host->ExecuteJavascriptInWebFrame(WideToUTF16Hack(iframe_xpath), |
| 145 UTF8ToUTF16(script)); | 143 UTF8ToUTF16(script)); |
| 146 content::RunMessageLoop(); | 144 content::RunMessageLoop(); |
| 147 registrar_.RemoveAll(); | 145 registrar_.RemoveAll(); |
| 148 LOG(WARNING) << "got geolocation watch" << javascript_response_; | 146 LOG(WARNING) << "got geolocation watch" << javascript_response_; |
| 149 EXPECT_NE("\"0\"", javascript_response_); | 147 EXPECT_NE("\"0\"", javascript_response_); |
| 150 if (wait_for_infobar_) { | 148 if (wait_for_infobar_) { |
| 151 EXPECT_TRUE(infobar_); | 149 EXPECT_TRUE(infobar_); |
| 152 } else { | 150 } else { |
| 153 EXPECT_TRUE(navigation_completed_); | 151 EXPECT_TRUE(navigation_completed_); |
| 154 } | 152 } |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 } | 322 } |
| 325 | 323 |
| 326 void CheckStringValueFromJavascriptForTab( | 324 void CheckStringValueFromJavascriptForTab( |
| 327 const std::string& expected, const std::string& function, | 325 const std::string& expected, const std::string& function, |
| 328 WebContents* web_contents) { | 326 WebContents* web_contents) { |
| 329 std::string script = base::StringPrintf( | 327 std::string script = base::StringPrintf( |
| 330 "window.domAutomationController.send(%s)", function.c_str()); | 328 "window.domAutomationController.send(%s)", function.c_str()); |
| 331 std::string result; | 329 std::string result; |
| 332 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | 330 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
| 333 web_contents->GetRenderViewHost(), | 331 web_contents->GetRenderViewHost(), |
| 334 iframe_xpath_, | 332 iframe_xpath_, UTF8ToWide(script), &result)); |
| 335 script, | |
| 336 &result)); | |
| 337 EXPECT_EQ(expected, result); | 333 EXPECT_EQ(expected, result); |
| 338 } | 334 } |
| 339 | 335 |
| 340 void CheckStringValueFromJavascript( | 336 void CheckStringValueFromJavascript( |
| 341 const std::string& expected, const std::string& function) { | 337 const std::string& expected, const std::string& function) { |
| 342 CheckStringValueFromJavascriptForTab( | 338 CheckStringValueFromJavascriptForTab( |
| 343 expected, function, chrome::GetActiveWebContents(current_browser_)); | 339 expected, function, chrome::GetActiveWebContents(current_browser_)); |
| 344 } | 340 } |
| 345 | 341 |
| 346 void NotifyGeoposition(double latitude, double longitude) { | 342 void NotifyGeoposition(double latitude, double longitude) { |
| 347 fake_latitude_ = latitude; | 343 fake_latitude_ = latitude; |
| 348 fake_longitude_ = longitude; | 344 fake_longitude_ = longitude; |
| 349 ui_test_utils::OverrideGeolocation(latitude, longitude); | 345 ui_test_utils::OverrideGeolocation(latitude, longitude); |
| 350 LOG(WARNING) << "MockLocationProvider listeners updated"; | 346 LOG(WARNING) << "MockLocationProvider listeners updated"; |
| 351 } | 347 } |
| 352 | 348 |
| 353 InfoBarDelegate* infobar_; | 349 InfoBarDelegate* infobar_; |
| 354 Browser* current_browser_; | 350 Browser* current_browser_; |
| 355 // path element of a URL referencing the html content for this test. | 351 // path element of a URL referencing the html content for this test. |
| 356 std::string html_for_tests_; | 352 std::string html_for_tests_; |
| 357 // This member defines the iframe (or top-level page, if empty) where the | 353 // This member defines the iframe (or top-level page, if empty) where the |
| 358 // javascript calls will run. | 354 // javascript calls will run. |
| 359 std::string iframe_xpath_; | 355 std::wstring iframe_xpath_; |
| 360 // The current url for the top level page. | 356 // The current url for the top level page. |
| 361 GURL current_url_; | 357 GURL current_url_; |
| 362 // If not empty, the GURLs for the iframes loaded by LoadIFrames(). | 358 // If not empty, the GURLs for the iframes loaded by LoadIFrames(). |
| 363 std::vector<GURL> iframe_urls_; | 359 std::vector<GURL> iframe_urls_; |
| 364 double fake_latitude_; | 360 double fake_latitude_; |
| 365 double fake_longitude_; | 361 double fake_longitude_; |
| 366 | 362 |
| 367 // TODO(phajdan.jr): Remove after we can ask TestServer whether it is started. | 363 // TODO(phajdan.jr): Remove after we can ask TestServer whether it is started. |
| 368 bool started_test_server_; | 364 bool started_test_server_; |
| 369 }; | 365 }; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 CheckGeoposition(fake_latitude_, fake_longitude_); | 455 CheckGeoposition(fake_latitude_, fake_longitude_); |
| 460 } | 456 } |
| 461 | 457 |
| 462 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, | 458 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, |
| 463 IFramesWithFreshPosition) { | 459 IFramesWithFreshPosition) { |
| 464 html_for_tests_ = "files/geolocation/iframes_different_origin.html"; | 460 html_for_tests_ = "files/geolocation/iframes_different_origin.html"; |
| 465 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 461 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
| 466 LoadIFrames(2); | 462 LoadIFrames(2); |
| 467 LOG(WARNING) << "frames loaded"; | 463 LOG(WARNING) << "frames loaded"; |
| 468 | 464 |
| 469 iframe_xpath_ = "//iframe[@id='iframe_0']"; | 465 iframe_xpath_ = L"//iframe[@id='iframe_0']"; |
| 470 AddGeolocationWatch(true); | 466 AddGeolocationWatch(true); |
| 471 SetInfobarResponse(iframe_urls_[0], true); | 467 SetInfobarResponse(iframe_urls_[0], true); |
| 472 CheckGeoposition(fake_latitude_, fake_longitude_); | 468 CheckGeoposition(fake_latitude_, fake_longitude_); |
| 473 // Disables further prompts from this iframe. | 469 // Disables further prompts from this iframe. |
| 474 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 470 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| 475 | 471 |
| 476 // Test second iframe from a different origin with a cached geoposition will | 472 // Test second iframe from a different origin with a cached geoposition will |
| 477 // create the infobar. | 473 // create the infobar. |
| 478 iframe_xpath_ = "//iframe[@id='iframe_1']"; | 474 iframe_xpath_ = L"//iframe[@id='iframe_1']"; |
| 479 AddGeolocationWatch(true); | 475 AddGeolocationWatch(true); |
| 480 | 476 |
| 481 // Back to the first frame, enable navigation and refresh geoposition. | 477 // Back to the first frame, enable navigation and refresh geoposition. |
| 482 iframe_xpath_ = "//iframe[@id='iframe_0']"; | 478 iframe_xpath_ = L"//iframe[@id='iframe_0']"; |
| 483 CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); | 479 CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); |
| 484 double fresh_position_latitude = 3.17; | 480 double fresh_position_latitude = 3.17; |
| 485 double fresh_position_longitude = 4.23; | 481 double fresh_position_longitude = 4.23; |
| 486 content::WindowedNotificationObserver observer( | 482 content::WindowedNotificationObserver observer( |
| 487 content::NOTIFICATION_LOAD_STOP, | 483 content::NOTIFICATION_LOAD_STOP, |
| 488 content::Source<NavigationController>( | 484 content::Source<NavigationController>( |
| 489 &chrome::GetActiveWebContents(current_browser_)->GetController())); | 485 &chrome::GetActiveWebContents(current_browser_)->GetController())); |
| 490 NotifyGeoposition(fresh_position_latitude, fresh_position_longitude); | 486 NotifyGeoposition(fresh_position_latitude, fresh_position_longitude); |
| 491 observer.Wait(); | 487 observer.Wait(); |
| 492 CheckGeoposition(fresh_position_latitude, fresh_position_longitude); | 488 CheckGeoposition(fresh_position_latitude, fresh_position_longitude); |
| 493 | 489 |
| 494 // Disable navigation for this frame. | 490 // Disable navigation for this frame. |
| 495 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 491 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| 496 | 492 |
| 497 // Now go ahead an authorize the second frame. | 493 // Now go ahead an authorize the second frame. |
| 498 iframe_xpath_ = "//iframe[@id='iframe_1']"; | 494 iframe_xpath_ = L"//iframe[@id='iframe_1']"; |
| 499 // Infobar was displayed, allow access and check there's no error code. | 495 // Infobar was displayed, allow access and check there's no error code. |
| 500 SetInfobarResponse(iframe_urls_[1], true); | 496 SetInfobarResponse(iframe_urls_[1], true); |
| 501 LOG(WARNING) << "Checking position..."; | 497 LOG(WARNING) << "Checking position..."; |
| 502 CheckGeoposition(fresh_position_latitude, fresh_position_longitude); | 498 CheckGeoposition(fresh_position_latitude, fresh_position_longitude); |
| 503 LOG(WARNING) << "...done."; | 499 LOG(WARNING) << "...done."; |
| 504 } | 500 } |
| 505 | 501 |
| 506 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, | 502 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, |
| 507 IFramesWithCachedPosition) { | 503 IFramesWithCachedPosition) { |
| 508 html_for_tests_ = "files/geolocation/iframes_different_origin.html"; | 504 html_for_tests_ = "files/geolocation/iframes_different_origin.html"; |
| 509 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 505 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
| 510 LoadIFrames(2); | 506 LoadIFrames(2); |
| 511 | 507 |
| 512 iframe_xpath_ = "//iframe[@id='iframe_0']"; | 508 iframe_xpath_ = L"//iframe[@id='iframe_0']"; |
| 513 AddGeolocationWatch(true); | 509 AddGeolocationWatch(true); |
| 514 SetInfobarResponse(iframe_urls_[0], true); | 510 SetInfobarResponse(iframe_urls_[0], true); |
| 515 CheckGeoposition(fake_latitude_, fake_longitude_); | 511 CheckGeoposition(fake_latitude_, fake_longitude_); |
| 516 | 512 |
| 517 // Refresh geoposition, but let's not yet create the watch on the second frame | 513 // Refresh geoposition, but let's not yet create the watch on the second frame |
| 518 // so that it'll fetch from cache. | 514 // so that it'll fetch from cache. |
| 519 double cached_position_latitude = 5.67; | 515 double cached_position_latitude = 5.67; |
| 520 double cached_position_lognitude = 8.09; | 516 double cached_position_lognitude = 8.09; |
| 521 content::WindowedNotificationObserver observer( | 517 content::WindowedNotificationObserver observer( |
| 522 content::NOTIFICATION_LOAD_STOP, | 518 content::NOTIFICATION_LOAD_STOP, |
| 523 content::Source<NavigationController>( | 519 content::Source<NavigationController>( |
| 524 &chrome::GetActiveWebContents(current_browser_)->GetController())); | 520 &chrome::GetActiveWebContents(current_browser_)->GetController())); |
| 525 NotifyGeoposition(cached_position_latitude, cached_position_lognitude); | 521 NotifyGeoposition(cached_position_latitude, cached_position_lognitude); |
| 526 observer.Wait(); | 522 observer.Wait(); |
| 527 CheckGeoposition(cached_position_latitude, cached_position_lognitude); | 523 CheckGeoposition(cached_position_latitude, cached_position_lognitude); |
| 528 | 524 |
| 529 // Disable navigation for this frame. | 525 // Disable navigation for this frame. |
| 530 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 526 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| 531 | 527 |
| 532 // Now go ahead an authorize the second frame. | 528 // Now go ahead an authorize the second frame. |
| 533 iframe_xpath_ = "//iframe[@id='iframe_1']"; | 529 iframe_xpath_ = L"//iframe[@id='iframe_1']"; |
| 534 AddGeolocationWatch(true); | 530 AddGeolocationWatch(true); |
| 535 // WebKit will use its cache, but we also broadcast a position shortly | 531 // WebKit will use its cache, but we also broadcast a position shortly |
| 536 // afterwards. We're only interested in the first navigation for the success | 532 // afterwards. We're only interested in the first navigation for the success |
| 537 // callback from the cached position. | 533 // callback from the cached position. |
| 538 CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); | 534 CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); |
| 539 SetInfobarResponse(iframe_urls_[1], true); | 535 SetInfobarResponse(iframe_urls_[1], true); |
| 540 CheckGeoposition(cached_position_latitude, cached_position_lognitude); | 536 CheckGeoposition(cached_position_latitude, cached_position_lognitude); |
| 541 } | 537 } |
| 542 | 538 |
| 543 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, CancelPermissionForFrame) { | 539 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, CancelPermissionForFrame) { |
| 544 html_for_tests_ = "files/geolocation/iframes_different_origin.html"; | 540 html_for_tests_ = "files/geolocation/iframes_different_origin.html"; |
| 545 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 541 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
| 546 LoadIFrames(2); | 542 LoadIFrames(2); |
| 547 LOG(WARNING) << "frames loaded"; | 543 LOG(WARNING) << "frames loaded"; |
| 548 | 544 |
| 549 iframe_xpath_ = "//iframe[@id='iframe_0']"; | 545 iframe_xpath_ = L"//iframe[@id='iframe_0']"; |
| 550 AddGeolocationWatch(true); | 546 AddGeolocationWatch(true); |
| 551 SetInfobarResponse(iframe_urls_[0], true); | 547 SetInfobarResponse(iframe_urls_[0], true); |
| 552 CheckGeoposition(fake_latitude_, fake_longitude_); | 548 CheckGeoposition(fake_latitude_, fake_longitude_); |
| 553 // Disables further prompts from this iframe. | 549 // Disables further prompts from this iframe. |
| 554 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 550 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| 555 | 551 |
| 556 // Test second iframe from a different origin with a cached geoposition will | 552 // Test second iframe from a different origin with a cached geoposition will |
| 557 // create the infobar. | 553 // create the infobar. |
| 558 iframe_xpath_ = "//iframe[@id='iframe_1']"; | 554 iframe_xpath_ = L"//iframe[@id='iframe_1']"; |
| 559 AddGeolocationWatch(true); | 555 AddGeolocationWatch(true); |
| 560 | 556 |
| 561 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 557 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| 562 chrome::GetActiveWebContents(current_browser_)); | 558 chrome::GetActiveWebContents(current_browser_)); |
| 563 size_t num_infobars_before_cancel = infobar_service->GetInfoBarCount(); | 559 size_t num_infobars_before_cancel = infobar_service->GetInfoBarCount(); |
| 564 // Change the iframe, and ensure the infobar is gone. | 560 // Change the iframe, and ensure the infobar is gone. |
| 565 IFrameLoader change_iframe_1(current_browser_, 1, current_url_); | 561 IFrameLoader change_iframe_1(current_browser_, 1, current_url_); |
| 566 size_t num_infobars_after_cancel = infobar_service->GetInfoBarCount(); | 562 size_t num_infobars_after_cancel = infobar_service->GetInfoBarCount(); |
| 567 EXPECT_EQ(num_infobars_before_cancel, num_infobars_after_cancel + 1); | 563 EXPECT_EQ(num_infobars_before_cancel, num_infobars_after_cancel + 1); |
| 568 } | 564 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 579 | 575 |
| 580 // Crashy, http://crbug.com/66400. | 576 // Crashy, http://crbug.com/66400. |
| 581 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DISABLED_NoInfoBarBeforeStart) { | 577 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DISABLED_NoInfoBarBeforeStart) { |
| 582 // See http://crbug.com/42789 | 578 // See http://crbug.com/42789 |
| 583 html_for_tests_ = "files/geolocation/iframes_different_origin.html"; | 579 html_for_tests_ = "files/geolocation/iframes_different_origin.html"; |
| 584 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 580 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
| 585 LoadIFrames(2); | 581 LoadIFrames(2); |
| 586 LOG(WARNING) << "frames loaded"; | 582 LOG(WARNING) << "frames loaded"; |
| 587 | 583 |
| 588 // Access navigator.geolocation, but ensure it won't request permission. | 584 // Access navigator.geolocation, but ensure it won't request permission. |
| 589 iframe_xpath_ = "//iframe[@id='iframe_1']"; | 585 iframe_xpath_ = L"//iframe[@id='iframe_1']"; |
| 590 CheckStringValueFromJavascript("object", "geoAccessNavigatorGeolocation()"); | 586 CheckStringValueFromJavascript("object", "geoAccessNavigatorGeolocation()"); |
| 591 | 587 |
| 592 iframe_xpath_ = "//iframe[@id='iframe_0']"; | 588 iframe_xpath_ = L"//iframe[@id='iframe_0']"; |
| 593 AddGeolocationWatch(true); | 589 AddGeolocationWatch(true); |
| 594 SetInfobarResponse(iframe_urls_[0], true); | 590 SetInfobarResponse(iframe_urls_[0], true); |
| 595 CheckGeoposition(fake_latitude_, fake_longitude_); | 591 CheckGeoposition(fake_latitude_, fake_longitude_); |
| 596 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); | 592 CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| 597 | 593 |
| 598 // Permission should be requested after adding a watch. | 594 // Permission should be requested after adding a watch. |
| 599 iframe_xpath_ = "//iframe[@id='iframe_1']"; | 595 iframe_xpath_ = L"//iframe[@id='iframe_1']"; |
| 600 AddGeolocationWatch(true); | 596 AddGeolocationWatch(true); |
| 601 SetInfobarResponse(iframe_urls_[1], true); | 597 SetInfobarResponse(iframe_urls_[1], true); |
| 602 CheckGeoposition(fake_latitude_, fake_longitude_); | 598 CheckGeoposition(fake_latitude_, fake_longitude_); |
| 603 } | 599 } |
| 604 | 600 |
| 605 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) { | 601 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) { |
| 606 html_for_tests_ = "files/geolocation/two_watches.html"; | 602 html_for_tests_ = "files/geolocation/two_watches.html"; |
| 607 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 603 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| 608 // First, set the JavaScript to navigate when it receives |final_position|. | 604 // First, set the JavaScript to navigate when it receives |final_position|. |
| 609 double final_position_latitude = 3.17; | 605 double final_position_latitude = 3.17; |
| 610 double final_position_longitude = 4.23; | 606 double final_position_longitude = 4.23; |
| 611 std::string script = base::StringPrintf( | 607 std::string script = base::StringPrintf( |
| 612 "window.domAutomationController.send(geoSetFinalPosition(%f, %f))", | 608 "window.domAutomationController.send(geoSetFinalPosition(%f, %f))", |
| 613 final_position_latitude, final_position_longitude); | 609 final_position_latitude, final_position_longitude); |
| 614 std::string js_result; | 610 std::string js_result; |
| 615 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractString( | 611 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractString( |
| 616 chrome::GetActiveWebContents(current_browser_)->GetRenderViewHost(), | 612 chrome::GetActiveWebContents(current_browser_)->GetRenderViewHost(), |
| 617 "", | 613 L"", UTF8ToWide(script), &js_result)); |
| 618 script, | |
| 619 &js_result)); | |
| 620 EXPECT_EQ(js_result, "ok"); | 614 EXPECT_EQ(js_result, "ok"); |
| 621 | 615 |
| 622 // Send a position which both geolocation watches will receive. | 616 // Send a position which both geolocation watches will receive. |
| 623 AddGeolocationWatch(true); | 617 AddGeolocationWatch(true); |
| 624 SetInfobarResponse(current_url_, true); | 618 SetInfobarResponse(current_url_, true); |
| 625 CheckGeoposition(fake_latitude_, fake_longitude_); | 619 CheckGeoposition(fake_latitude_, fake_longitude_); |
| 626 | 620 |
| 627 // The second watch will now have cancelled. Ensure an update still makes | 621 // The second watch will now have cancelled. Ensure an update still makes |
| 628 // its way through to the first watcher. | 622 // its way through to the first watcher. |
| 629 content::WindowedNotificationObserver observer( | 623 content::WindowedNotificationObserver observer( |
| 630 content::NOTIFICATION_LOAD_STOP, | 624 content::NOTIFICATION_LOAD_STOP, |
| 631 content::Source<NavigationController>( | 625 content::Source<NavigationController>( |
| 632 &chrome::GetActiveWebContents(current_browser_)->GetController())); | 626 &chrome::GetActiveWebContents(current_browser_)->GetController())); |
| 633 NotifyGeoposition(final_position_latitude, final_position_longitude); | 627 NotifyGeoposition(final_position_latitude, final_position_longitude); |
| 634 observer.Wait(); | 628 observer.Wait(); |
| 635 CheckGeoposition(final_position_latitude, final_position_longitude); | 629 CheckGeoposition(final_position_latitude, final_position_longitude); |
| 636 } | 630 } |
| 637 | 631 |
| 638 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TabDestroyed) { | 632 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TabDestroyed) { |
| 639 html_for_tests_ = "files/geolocation/tab_destroyed.html"; | 633 html_for_tests_ = "files/geolocation/tab_destroyed.html"; |
| 640 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); | 634 ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
| 641 LoadIFrames(3); | 635 LoadIFrames(3); |
| 642 | 636 |
| 643 iframe_xpath_ = "//iframe[@id='iframe_0']"; | 637 iframe_xpath_ = L"//iframe[@id='iframe_0']"; |
| 644 AddGeolocationWatch(true); | 638 AddGeolocationWatch(true); |
| 645 | 639 |
| 646 iframe_xpath_ = "//iframe[@id='iframe_1']"; | 640 iframe_xpath_ = L"//iframe[@id='iframe_1']"; |
| 647 AddGeolocationWatch(false); | 641 AddGeolocationWatch(false); |
| 648 | 642 |
| 649 iframe_xpath_ = "//iframe[@id='iframe_2']"; | 643 iframe_xpath_ = L"//iframe[@id='iframe_2']"; |
| 650 AddGeolocationWatch(false); | 644 AddGeolocationWatch(false); |
| 651 | 645 |
| 652 std::string script = | 646 std::string script = |
| 647 "window.domAutomationController.setAutomationId(0);" |
| 653 "window.domAutomationController.send(window.close());"; | 648 "window.domAutomationController.send(window.close());"; |
| 654 bool result = | 649 bool result = |
| 655 content::ExecuteJavaScript( | 650 content::ExecuteJavaScript( |
| 656 chrome::GetActiveWebContents(current_browser_)->GetRenderViewHost(), | 651 chrome::GetActiveWebContents(current_browser_)->GetRenderViewHost(), |
| 657 "", | 652 L"", UTF8ToWide(script)); |
| 658 script); | |
| 659 EXPECT_EQ(result, true); | 653 EXPECT_EQ(result, true); |
| 660 } | 654 } |
| 661 | 655 |
| 662 } // namespace | 656 } // namespace |
| OLD | NEW |