| 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 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 24 #include "chrome/common/content_settings_pattern.h" | 24 #include "chrome/common/content_settings_pattern.h" |
| 25 #include "chrome/test/base/in_process_browser_test.h" | 25 #include "chrome/test/base/in_process_browser_test.h" |
| 26 #include "chrome/test/base/ui_test_utils.h" | 26 #include "chrome/test/base/ui_test_utils.h" |
| 27 #include "content/public/browser/dom_operation_notification_details.h" | 27 #include "content/public/browser/dom_operation_notification_details.h" |
| 28 #include "content/public/browser/navigation_controller.h" | 28 #include "content/public/browser/navigation_controller.h" |
| 29 #include "content/public/browser/notification_details.h" | 29 #include "content/public/browser/notification_details.h" |
| 30 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 31 #include "content/public/browser/render_view_host.h" | 31 #include "content/public/browser/render_view_host.h" |
| 32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 33 #include "content/public/test/browser_test_utils.h" |
| 33 #include "net/base/net_util.h" | 34 #include "net/base/net_util.h" |
| 34 #include "net/test/test_server.h" | 35 #include "net/test/test_server.h" |
| 35 | 36 |
| 36 using content::DomOperationNotificationDetails; | 37 using content::DomOperationNotificationDetails; |
| 37 using content::NavigationController; | 38 using content::NavigationController; |
| 38 using content::WebContents; | 39 using content::WebContents; |
| 39 | 40 |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 // Used to block until an iframe is loaded via a javascript call. | 43 // Used to block until an iframe is loaded via a javascript call. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 62 chrome::GetActiveWebContents(browser)->GetRenderViewHost()-> | 63 chrome::GetActiveWebContents(browser)->GetRenderViewHost()-> |
| 63 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(script)); | 64 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(script)); |
| 64 ui_test_utils::RunMessageLoop(); | 65 ui_test_utils::RunMessageLoop(); |
| 65 | 66 |
| 66 EXPECT_EQ(base::StringPrintf("\"%d\"", iframe_id), javascript_response_); | 67 EXPECT_EQ(base::StringPrintf("\"%d\"", iframe_id), javascript_response_); |
| 67 registrar_.RemoveAll(); | 68 registrar_.RemoveAll(); |
| 68 // Now that we loaded the iframe, let's fetch its src. | 69 // Now that we loaded the iframe, let's fetch its src. |
| 69 script = base::StringPrintf( | 70 script = base::StringPrintf( |
| 70 "window.domAutomationController.send(getIFrameSrc(%d))", iframe_id); | 71 "window.domAutomationController.send(getIFrameSrc(%d))", iframe_id); |
| 71 std::string iframe_src; | 72 std::string iframe_src; |
| 72 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 73 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractString( |
| 73 chrome::GetActiveWebContents(browser)->GetRenderViewHost(), | 74 chrome::GetActiveWebContents(browser)->GetRenderViewHost(), |
| 74 L"", UTF8ToWide(script), &iframe_src)); | 75 L"", UTF8ToWide(script), &iframe_src)); |
| 75 iframe_url_ = GURL(iframe_src); | 76 iframe_url_ = GURL(iframe_src); |
| 76 } | 77 } |
| 77 | 78 |
| 78 GURL iframe_url() const { return iframe_url_; } | 79 GURL iframe_url() const { return iframe_url_; } |
| 79 | 80 |
| 80 virtual void Observe(int type, | 81 virtual void Observe(int type, |
| 81 const content::NotificationSource& source, | 82 const content::NotificationSource& source, |
| 82 const content::NotificationDetails& details) { | 83 const content::NotificationDetails& details) { |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 EXPECT_EQ(expected_setting, | 321 EXPECT_EQ(expected_setting, |
| 321 settings_state.state_map().find(requesting_origin)->second); | 322 settings_state.state_map().find(requesting_origin)->second); |
| 322 } | 323 } |
| 323 | 324 |
| 324 void CheckStringValueFromJavascriptForTab( | 325 void CheckStringValueFromJavascriptForTab( |
| 325 const std::string& expected, const std::string& function, | 326 const std::string& expected, const std::string& function, |
| 326 WebContents* web_contents) { | 327 WebContents* web_contents) { |
| 327 std::string script = base::StringPrintf( | 328 std::string script = base::StringPrintf( |
| 328 "window.domAutomationController.send(%s)", function.c_str()); | 329 "window.domAutomationController.send(%s)", function.c_str()); |
| 329 std::string result; | 330 std::string result; |
| 330 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 331 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
| 331 web_contents->GetRenderViewHost(), | 332 web_contents->GetRenderViewHost(), |
| 332 iframe_xpath_, UTF8ToWide(script), &result)); | 333 iframe_xpath_, UTF8ToWide(script), &result)); |
| 333 EXPECT_EQ(expected, result); | 334 EXPECT_EQ(expected, result); |
| 334 } | 335 } |
| 335 | 336 |
| 336 void CheckStringValueFromJavascript( | 337 void CheckStringValueFromJavascript( |
| 337 const std::string& expected, const std::string& function) { | 338 const std::string& expected, const std::string& function) { |
| 338 CheckStringValueFromJavascriptForTab( | 339 CheckStringValueFromJavascriptForTab( |
| 339 expected, function, chrome::GetActiveWebContents(current_browser_)); | 340 expected, function, chrome::GetActiveWebContents(current_browser_)); |
| 340 } | 341 } |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) { | 614 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) { |
| 614 html_for_tests_ = "files/geolocation/two_watches.html"; | 615 html_for_tests_ = "files/geolocation/two_watches.html"; |
| 615 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 616 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| 616 // First, set the JavaScript to navigate when it receives |final_position|. | 617 // First, set the JavaScript to navigate when it receives |final_position|. |
| 617 double final_position_latitude = 3.17; | 618 double final_position_latitude = 3.17; |
| 618 double final_position_longitude = 4.23; | 619 double final_position_longitude = 4.23; |
| 619 std::string script = base::StringPrintf( | 620 std::string script = base::StringPrintf( |
| 620 "window.domAutomationController.send(geoSetFinalPosition(%f, %f))", | 621 "window.domAutomationController.send(geoSetFinalPosition(%f, %f))", |
| 621 final_position_latitude, final_position_longitude); | 622 final_position_latitude, final_position_longitude); |
| 622 std::string js_result; | 623 std::string js_result; |
| 623 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 624 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractString( |
| 624 chrome::GetActiveWebContents(current_browser_)->GetRenderViewHost(), | 625 chrome::GetActiveWebContents(current_browser_)->GetRenderViewHost(), |
| 625 L"", UTF8ToWide(script), &js_result)); | 626 L"", UTF8ToWide(script), &js_result)); |
| 626 EXPECT_EQ(js_result, "ok"); | 627 EXPECT_EQ(js_result, "ok"); |
| 627 | 628 |
| 628 // Send a position which both geolocation watches will receive. | 629 // Send a position which both geolocation watches will receive. |
| 629 AddGeolocationWatch(true); | 630 AddGeolocationWatch(true); |
| 630 SetInfobarResponse(current_url_, true); | 631 SetInfobarResponse(current_url_, true); |
| 631 CheckGeoposition(fake_latitude_, fake_longitude_); | 632 CheckGeoposition(fake_latitude_, fake_longitude_); |
| 632 | 633 |
| 633 // The second watch will now have cancelled. Ensure an update still makes | 634 // The second watch will now have cancelled. Ensure an update still makes |
| (...skipping 18 matching lines...) Expand all Loading... |
| 652 iframe_xpath_ = L"//iframe[@id='iframe_1']"; | 653 iframe_xpath_ = L"//iframe[@id='iframe_1']"; |
| 653 AddGeolocationWatch(false); | 654 AddGeolocationWatch(false); |
| 654 | 655 |
| 655 iframe_xpath_ = L"//iframe[@id='iframe_2']"; | 656 iframe_xpath_ = L"//iframe[@id='iframe_2']"; |
| 656 AddGeolocationWatch(false); | 657 AddGeolocationWatch(false); |
| 657 | 658 |
| 658 std::string script = | 659 std::string script = |
| 659 "window.domAutomationController.setAutomationId(0);" | 660 "window.domAutomationController.setAutomationId(0);" |
| 660 "window.domAutomationController.send(window.close());"; | 661 "window.domAutomationController.send(window.close());"; |
| 661 bool result = | 662 bool result = |
| 662 ui_test_utils::ExecuteJavaScript( | 663 content::ExecuteJavaScript( |
| 663 chrome::GetActiveWebContents(current_browser_)->GetRenderViewHost(), | 664 chrome::GetActiveWebContents(current_browser_)->GetRenderViewHost(), |
| 664 L"", UTF8ToWide(script)); | 665 L"", UTF8ToWide(script)); |
| 665 EXPECT_EQ(result, true); | 666 EXPECT_EQ(result, true); |
| 666 } | 667 } |
| 667 | 668 |
| 668 } // namespace | 669 } // namespace |
| OLD | NEW |