| 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 "base/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/public/browser/navigation_controller.h" | 8 #include "content/public/browser/navigation_controller.h" |
| 9 #include "content/public/browser/notification_service.h" | 9 #include "content/public/browser/notification_service.h" |
| 10 #include "content/public/browser/notification_types.h" | 10 #include "content/public/browser/notification_types.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 void SetUpOnMainThread() override { | 51 void SetUpOnMainThread() override { |
| 52 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 52 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 53 embedded_test_server()->RegisterRequestHandler( | 53 embedded_test_server()->RegisterRequestHandler( |
| 54 base::Bind(&HandleEchoTitleRequest, "/echotitle")); | 54 base::Bind(&HandleEchoTitleRequest, "/echotitle")); |
| 55 | 55 |
| 56 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 56 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 57 } | 57 } |
| 58 | 58 |
| 59 // Simulate clicking a link. Only works on the frames.html testserver page. | 59 // Simulate clicking a link. Only works on the frames.html testserver page. |
| 60 void ClickLink(std::string node_id) { | 60 void ClickLink(const std::string& node_id) { |
| 61 GURL url("javascript:clickLink('" + node_id + "')"); | 61 GURL url("javascript:clickLink('" + node_id + "')"); |
| 62 NavigateToURL(shell(), url); | 62 NavigateToURL(shell(), url); |
| 63 } | 63 } |
| 64 | 64 |
| 65 // Simulate filling in form data. Only works on the frames.html page with | 65 // Simulate filling in form data. Only works on the frames.html page with |
| 66 // subframe = form.html, and on form.html itself. | 66 // subframe = form.html, and on form.html itself. |
| 67 void FillForm(std::string node_id, std::string value) { | 67 void FillForm(const std::string& node_id, const std::string& value) { |
| 68 GURL url("javascript:fillForm('" + node_id + "', '" + value + "')"); | 68 GURL url("javascript:fillForm('" + node_id + "', '" + value + "')"); |
| 69 // This will return immediately, but since the JS executes synchronously | 69 // This will return immediately, but since the JS executes synchronously |
| 70 // on the renderer, it will complete before the next navigate message is | 70 // on the renderer, it will complete before the next navigate message is |
| 71 // processed. | 71 // processed. |
| 72 NavigateToURL(shell(), url); | 72 NavigateToURL(shell(), url); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Simulate submitting a form. Only works on the frames.html page with | 75 // Simulate submitting a form. Only works on the frames.html page with |
| 76 // subframe = form.html, and on form.html itself. | 76 // subframe = form.html, and on form.html itself. |
| 77 void SubmitForm(std::string node_id) { | 77 void SubmitForm(const std::string& node_id) { |
| 78 GURL url("javascript:submitForm('" + node_id + "')"); | 78 GURL url("javascript:submitForm('" + node_id + "')"); |
| 79 NavigateToURL(shell(), url); | 79 NavigateToURL(shell(), url); |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Navigate session history using history.go(distance). | 82 // Navigate session history using history.go(distance). |
| 83 void JavascriptGo(std::string distance) { | 83 void JavascriptGo(const std::string& distance) { |
| 84 GURL url("javascript:history.go('" + distance + "')"); | 84 GURL url("javascript:history.go('" + distance + "')"); |
| 85 NavigateToURL(shell(), url); | 85 NavigateToURL(shell(), url); |
| 86 } | 86 } |
| 87 | 87 |
| 88 std::string GetTabTitle() { | 88 std::string GetTabTitle() { |
| 89 return base::UTF16ToASCII(shell()->web_contents()->GetTitle()); | 89 return base::UTF16ToASCII(shell()->web_contents()->GetTitle()); |
| 90 } | 90 } |
| 91 | 91 |
| 92 GURL GetTabURL() { | 92 GURL GetTabURL() { |
| 93 return shell()->web_contents()->GetLastCommittedURL(); | 93 return shell()->web_contents()->GetLastCommittedURL(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 GURL GetURL(const std::string file) { | 96 GURL GetURL(const std::string& file) { |
| 97 return embedded_test_server()->GetURL( | 97 return embedded_test_server()->GetURL( |
| 98 std::string("/session_history/") + file); | 98 std::string("/session_history/") + file); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void NavigateAndCheckTitle(const char* filename, | 101 void NavigateAndCheckTitle(const char* filename, |
| 102 const std::string& expected_title) { | 102 const std::string& expected_title) { |
| 103 base::string16 expected_title16(base::ASCIIToUTF16(expected_title)); | 103 base::string16 expected_title16(base::ASCIIToUTF16(expected_title)); |
| 104 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); | 104 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); |
| 105 NavigateToURL(shell(), GetURL(filename)); | 105 NavigateToURL(shell(), GetURL(filename)); |
| 106 ASSERT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); | 106 ASSERT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 NavigateToURL(shell(), GetURL("title2.html")); | 491 NavigateToURL(shell(), GetURL("title2.html")); |
| 492 | 492 |
| 493 ASSERT_TRUE(ExecuteScriptAndExtractInt( | 493 ASSERT_TRUE(ExecuteScriptAndExtractInt( |
| 494 shell()->web_contents(), | 494 shell()->web_contents(), |
| 495 "domAutomationController.send(history.length)", | 495 "domAutomationController.send(history.length)", |
| 496 &length)); | 496 &length)); |
| 497 EXPECT_EQ(2, length); | 497 EXPECT_EQ(2, length); |
| 498 } | 498 } |
| 499 | 499 |
| 500 } // namespace content | 500 } // namespace content |
| OLD | NEW |