| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 #endif | 46 #endif |
| 47 browser_directory_ = dir; | 47 browser_directory_ = dir; |
| 48 } | 48 } |
| 49 UITest::SetUp(); | 49 UITest::SetUp(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void RunTest(const GURL& url, | 52 void RunTest(const GURL& url, |
| 53 const char* wait_cookie_name, | 53 const char* wait_cookie_name, |
| 54 const char* wait_cookie_value, | 54 const char* wait_cookie_value, |
| 55 const char* var_to_fetch, | 55 const char* var_to_fetch, |
| 56 const std::wstring& wait_js_expr, | 56 const std::string& wait_js_expr, |
| 57 const std::wstring& wait_js_frame_xpath, | 57 const std::string& wait_js_frame_xpath, |
| 58 int wait_js_timeout_ms, | 58 int wait_js_timeout_ms, |
| 59 UrlFetchTestResult* result) { | 59 UrlFetchTestResult* result) { |
| 60 scoped_refptr<TabProxy> tab(GetActiveTab()); | 60 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 61 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); | 61 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); |
| 62 | 62 |
| 63 if (wait_cookie_name) { | 63 if (wait_cookie_name) { |
| 64 if (wait_cookie_value) { | 64 if (wait_cookie_value) { |
| 65 bool completed = WaitUntilCookieValue( | 65 bool completed = WaitUntilCookieValue( |
| 66 tab.get(), url, wait_cookie_name, | 66 tab.get(), url, wait_cookie_name, |
| 67 TestTimeouts::huge_test_timeout_ms(), | 67 TestTimeouts::huge_test_timeout_ms(), |
| 68 wait_cookie_value); | 68 wait_cookie_value); |
| 69 ASSERT_TRUE(completed); | 69 ASSERT_TRUE(completed); |
| 70 } else { | 70 } else { |
| 71 result->cookie_value = WaitUntilCookieNonEmpty( | 71 result->cookie_value = WaitUntilCookieNonEmpty( |
| 72 tab.get(), url, wait_cookie_name, | 72 tab.get(), url, wait_cookie_name, |
| 73 TestTimeouts::huge_test_timeout_ms()); | 73 TestTimeouts::huge_test_timeout_ms()); |
| 74 ASSERT_TRUE(result->cookie_value.length()); | 74 ASSERT_TRUE(result->cookie_value.length()); |
| 75 } | 75 } |
| 76 } else if (!wait_js_expr.empty()) { | 76 } else if (!wait_js_expr.empty()) { |
| 77 bool completed = WaitUntilJavaScriptCondition(tab.get(), | 77 bool completed = WaitUntilJavaScriptCondition( |
| 78 wait_js_frame_xpath, | 78 tab.get(), |
| 79 wait_js_expr, | 79 UTF8ToWide(wait_js_frame_xpath), |
| 80 wait_js_timeout_ms); | 80 UTF8ToWide(wait_js_expr), |
| 81 wait_js_timeout_ms); |
| 81 ASSERT_TRUE(completed); | 82 ASSERT_TRUE(completed); |
| 82 } | 83 } |
| 83 if (var_to_fetch) { | 84 if (var_to_fetch) { |
| 84 std::string script = StringPrintf( | 85 std::string script = StringPrintf( |
| 85 "window.domAutomationController.send(%s);", var_to_fetch); | 86 "window.domAutomationController.send(%s);", var_to_fetch); |
| 86 | 87 |
| 87 std::wstring value; | 88 std::wstring value; |
| 88 bool success = tab->ExecuteAndExtractString(L"", ASCIIToWide(script), | 89 bool success = tab->ExecuteAndExtractString(L"", ASCIIToWide(script), |
| 89 &value); | 90 &value); |
| 90 ASSERT_TRUE(success); | 91 ASSERT_TRUE(success); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 TEST_F(UrlFetchTest, UrlFetch) { | 144 TEST_F(UrlFetchTest, UrlFetch) { |
| 144 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 145 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 145 | 146 |
| 146 if (!cmd_line->HasSwitch("url")) | 147 if (!cmd_line->HasSwitch("url")) |
| 147 return; | 148 return; |
| 148 | 149 |
| 149 std::string cookie_name = | 150 std::string cookie_name = |
| 150 cmd_line->GetSwitchValueASCII("wait_cookie_name"); | 151 cmd_line->GetSwitchValueASCII("wait_cookie_name"); |
| 151 std::string cookie_value = | 152 std::string cookie_value = |
| 152 cmd_line->GetSwitchValueASCII("wait_cookie_value"); | 153 cmd_line->GetSwitchValueASCII("wait_cookie_value"); |
| 153 std::wstring js_expr = | 154 std::string js_expr = |
| 154 UTF8ToWide(cmd_line->GetSwitchValueASCII("wait_js_expr")); | 155 cmd_line->GetSwitchValueASCII("wait_js_expr"); |
| 155 std::wstring js_frame_xpath = | 156 std::string js_frame_xpath = |
| 156 UTF8ToWide(cmd_line->GetSwitchValueASCII("wait_js_frame_xpath")); | 157 cmd_line->GetSwitchValueASCII("wait_js_frame_xpath"); |
| 157 std::string js_timeout_ms_str = | 158 std::string js_timeout_ms_str = |
| 158 cmd_line->GetSwitchValueASCII("wait_js_timeout"); | 159 cmd_line->GetSwitchValueASCII("wait_js_timeout"); |
| 159 | 160 |
| 160 std::string jsvar = cmd_line->GetSwitchValueASCII("jsvar"); | 161 std::string jsvar = cmd_line->GetSwitchValueASCII("jsvar"); |
| 161 int js_timeout_ms = -1; // no timeout, wait forever | 162 int js_timeout_ms = -1; // no timeout, wait forever |
| 162 | 163 |
| 163 if (!js_timeout_ms_str.empty()) | 164 if (!js_timeout_ms_str.empty()) |
| 164 base::StringToInt(js_timeout_ms_str, &js_timeout_ms); | 165 base::StringToInt(js_timeout_ms_str, &js_timeout_ms); |
| 165 | 166 |
| 166 UrlFetchTestResult result; | 167 UrlFetchTestResult result; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 182 | 183 |
| 183 // Write out the JS Variable if requested | 184 // Write out the JS Variable if requested |
| 184 FilePath jsvar_output_path = cmd_line->GetSwitchValuePath("jsvar_output"); | 185 FilePath jsvar_output_path = cmd_line->GetSwitchValuePath("jsvar_output"); |
| 185 if (jsvar_output_path.value().size() > 0) { | 186 if (jsvar_output_path.value().size() > 0) { |
| 186 ASSERT_TRUE(WriteValueToFile(result.javascript_variable, | 187 ASSERT_TRUE(WriteValueToFile(result.javascript_variable, |
| 187 jsvar_output_path)); | 188 jsvar_output_path)); |
| 188 } | 189 } |
| 189 } | 190 } |
| 190 | 191 |
| 191 } // namespace | 192 } // namespace |
| OLD | NEW |