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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 chrome::GetActiveWebContents(browser)->GetRenderViewHost()-> | 62 chrome::GetActiveWebContents(browser)->GetRenderViewHost()-> |
63 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(script)); | 63 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(script)); |
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::ExecuteScriptAndExtractString( |
73 chrome::GetActiveWebContents(browser)->GetRenderViewHost(), | 73 chrome::GetActiveWebContents(browser), |
74 "", | |
75 script, | 74 script, |
76 &iframe_src)); | 75 &iframe_src)); |
77 iframe_url_ = GURL(iframe_src); | 76 iframe_url_ = GURL(iframe_src); |
78 } | 77 } |
79 | 78 |
80 GURL iframe_url() const { return iframe_url_; } | 79 GURL iframe_url() const { return iframe_url_; } |
81 | 80 |
82 virtual void Observe(int type, | 81 virtual void Observe(int type, |
83 const content::NotificationSource& source, | 82 const content::NotificationSource& source, |
84 const content::NotificationDetails& details) { | 83 const content::NotificationDetails& details) { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 EXPECT_EQ(expected_setting, | 321 EXPECT_EQ(expected_setting, |
323 settings_state.state_map().find(requesting_origin)->second); | 322 settings_state.state_map().find(requesting_origin)->second); |
324 } | 323 } |
325 | 324 |
326 void CheckStringValueFromJavascriptForTab( | 325 void CheckStringValueFromJavascriptForTab( |
327 const std::string& expected, const std::string& function, | 326 const std::string& expected, const std::string& function, |
328 WebContents* web_contents) { | 327 WebContents* web_contents) { |
329 std::string script = base::StringPrintf( | 328 std::string script = base::StringPrintf( |
330 "window.domAutomationController.send(%s)", function.c_str()); | 329 "window.domAutomationController.send(%s)", function.c_str()); |
331 std::string result; | 330 std::string result; |
332 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | 331 ASSERT_TRUE(content::ExecuteScriptInFrameAndExtractString( |
333 web_contents->GetRenderViewHost(), | 332 web_contents, |
334 iframe_xpath_, | 333 iframe_xpath_, |
335 script, | 334 script, |
336 &result)); | 335 &result)); |
337 EXPECT_EQ(expected, result); | 336 EXPECT_EQ(expected, result); |
338 } | 337 } |
339 | 338 |
340 void CheckStringValueFromJavascript( | 339 void CheckStringValueFromJavascript( |
341 const std::string& expected, const std::string& function) { | 340 const std::string& expected, const std::string& function) { |
342 CheckStringValueFromJavascriptForTab( | 341 CheckStringValueFromJavascriptForTab( |
343 expected, function, chrome::GetActiveWebContents(current_browser_)); | 342 expected, function, chrome::GetActiveWebContents(current_browser_)); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) { | 604 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) { |
606 html_for_tests_ = "files/geolocation/two_watches.html"; | 605 html_for_tests_ = "files/geolocation/two_watches.html"; |
607 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 606 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
608 // First, set the JavaScript to navigate when it receives |final_position|. | 607 // First, set the JavaScript to navigate when it receives |final_position|. |
609 double final_position_latitude = 3.17; | 608 double final_position_latitude = 3.17; |
610 double final_position_longitude = 4.23; | 609 double final_position_longitude = 4.23; |
611 std::string script = base::StringPrintf( | 610 std::string script = base::StringPrintf( |
612 "window.domAutomationController.send(geoSetFinalPosition(%f, %f))", | 611 "window.domAutomationController.send(geoSetFinalPosition(%f, %f))", |
613 final_position_latitude, final_position_longitude); | 612 final_position_latitude, final_position_longitude); |
614 std::string js_result; | 613 std::string js_result; |
615 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractString( | 614 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
616 chrome::GetActiveWebContents(current_browser_)->GetRenderViewHost(), | 615 chrome::GetActiveWebContents(current_browser_), |
617 "", | |
618 script, | 616 script, |
619 &js_result)); | 617 &js_result)); |
620 EXPECT_EQ(js_result, "ok"); | 618 EXPECT_EQ(js_result, "ok"); |
621 | 619 |
622 // Send a position which both geolocation watches will receive. | 620 // Send a position which both geolocation watches will receive. |
623 AddGeolocationWatch(true); | 621 AddGeolocationWatch(true); |
624 SetInfobarResponse(current_url_, true); | 622 SetInfobarResponse(current_url_, true); |
625 CheckGeoposition(fake_latitude_, fake_longitude_); | 623 CheckGeoposition(fake_latitude_, fake_longitude_); |
626 | 624 |
627 // The second watch will now have cancelled. Ensure an update still makes | 625 // The second watch will now have cancelled. Ensure an update still makes |
(...skipping 17 matching lines...) Expand all Loading... |
645 | 643 |
646 iframe_xpath_ = "//iframe[@id='iframe_1']"; | 644 iframe_xpath_ = "//iframe[@id='iframe_1']"; |
647 AddGeolocationWatch(false); | 645 AddGeolocationWatch(false); |
648 | 646 |
649 iframe_xpath_ = "//iframe[@id='iframe_2']"; | 647 iframe_xpath_ = "//iframe[@id='iframe_2']"; |
650 AddGeolocationWatch(false); | 648 AddGeolocationWatch(false); |
651 | 649 |
652 std::string script = | 650 std::string script = |
653 "window.domAutomationController.send(window.close());"; | 651 "window.domAutomationController.send(window.close());"; |
654 bool result = | 652 bool result = |
655 content::ExecuteJavaScript( | 653 content::ExecuteScript( |
656 chrome::GetActiveWebContents(current_browser_)->GetRenderViewHost(), | 654 chrome::GetActiveWebContents(current_browser_), |
657 "", | |
658 script); | 655 script); |
659 EXPECT_EQ(result, true); | 656 EXPECT_EQ(result, true); |
660 } | 657 } |
661 | 658 |
662 } // namespace | 659 } // namespace |
OLD | NEW |