| 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 27 matching lines...) Expand all Loading... |
| 38 } | 38 } |
| 39 UITest::SetUp(); | 39 UITest::SetUp(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void RunTest(const GURL& url, | 42 void RunTest(const GURL& url, |
| 43 const char* wait_cookie_name, | 43 const char* wait_cookie_name, |
| 44 const char* wait_cookie_value, | 44 const char* wait_cookie_value, |
| 45 const char* var_to_fetch, | 45 const char* var_to_fetch, |
| 46 const std::string& wait_js_expr, | 46 const std::string& wait_js_expr, |
| 47 const std::string& wait_js_frame_xpath, | 47 const std::string& wait_js_frame_xpath, |
| 48 int wait_js_timeout_ms, | 48 base::TimeDelta wait_js_timeout, |
| 49 UrlFetchTestResult* result) { | 49 UrlFetchTestResult* result) { |
| 50 scoped_refptr<TabProxy> tab(GetActiveTab()); | 50 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 51 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); | 51 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); |
| 52 | 52 |
| 53 if (wait_cookie_name) { | 53 if (wait_cookie_name) { |
| 54 if (wait_cookie_value) { | 54 if (wait_cookie_value) { |
| 55 bool completed = WaitUntilCookieValue( | 55 bool completed = WaitUntilCookieValue( |
| 56 tab.get(), url, wait_cookie_name, | 56 tab.get(), url, wait_cookie_name, |
| 57 TestTimeouts::large_test_timeout_ms(), | 57 TestTimeouts::large_test_timeout(), |
| 58 wait_cookie_value); | 58 wait_cookie_value); |
| 59 ASSERT_TRUE(completed); | 59 ASSERT_TRUE(completed); |
| 60 } else { | 60 } else { |
| 61 result->cookie_value = WaitUntilCookieNonEmpty( | 61 result->cookie_value = WaitUntilCookieNonEmpty( |
| 62 tab.get(), url, wait_cookie_name, | 62 tab.get(), url, wait_cookie_name, |
| 63 TestTimeouts::large_test_timeout_ms()); | 63 TestTimeouts::large_test_timeout()); |
| 64 ASSERT_TRUE(result->cookie_value.length()); | 64 ASSERT_TRUE(result->cookie_value.length()); |
| 65 } | 65 } |
| 66 } else if (!wait_js_expr.empty()) { | 66 } else if (!wait_js_expr.empty()) { |
| 67 bool completed = WaitUntilJavaScriptCondition( | 67 bool completed = WaitUntilJavaScriptCondition( |
| 68 tab.get(), | 68 tab.get(), |
| 69 UTF8ToWide(wait_js_frame_xpath), | 69 UTF8ToWide(wait_js_frame_xpath), |
| 70 UTF8ToWide(wait_js_expr), | 70 UTF8ToWide(wait_js_expr), |
| 71 wait_js_timeout_ms); | 71 wait_js_timeout); |
| 72 ASSERT_TRUE(completed); | 72 ASSERT_TRUE(completed); |
| 73 } | 73 } |
| 74 if (var_to_fetch) { | 74 if (var_to_fetch) { |
| 75 std::string script = StringPrintf( | 75 std::string script = StringPrintf( |
| 76 "window.domAutomationController.send(%s);", var_to_fetch); | 76 "window.domAutomationController.send(%s);", var_to_fetch); |
| 77 | 77 |
| 78 std::wstring value; | 78 std::wstring value; |
| 79 bool success = tab->ExecuteAndExtractString(L"", ASCIIToWide(script), | 79 bool success = tab->ExecuteAndExtractString(L"", ASCIIToWide(script), |
| 80 &value); | 80 &value); |
| 81 ASSERT_TRUE(success); | 81 ASSERT_TRUE(success); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 if (!js_timeout_ms_str.empty()) | 154 if (!js_timeout_ms_str.empty()) |
| 155 base::StringToInt(js_timeout_ms_str, &js_timeout_ms); | 155 base::StringToInt(js_timeout_ms_str, &js_timeout_ms); |
| 156 | 156 |
| 157 UrlFetchTestResult result; | 157 UrlFetchTestResult result; |
| 158 RunTest(GURL(cmd_line->GetSwitchValueASCII("url")), | 158 RunTest(GURL(cmd_line->GetSwitchValueASCII("url")), |
| 159 cookie_name.length() > 0 ? cookie_name.c_str() : NULL, | 159 cookie_name.length() > 0 ? cookie_name.c_str() : NULL, |
| 160 cookie_value.length() > 0 ? cookie_value.c_str() : NULL, | 160 cookie_value.length() > 0 ? cookie_value.c_str() : NULL, |
| 161 jsvar.length() > 0 ? jsvar.c_str() : NULL, | 161 jsvar.length() > 0 ? jsvar.c_str() : NULL, |
| 162 js_expr, | 162 js_expr, |
| 163 js_frame_xpath, | 163 js_frame_xpath, |
| 164 js_timeout_ms, | 164 base::TimeDelta::FromMilliseconds(js_timeout_ms), |
| 165 &result); | 165 &result); |
| 166 | 166 |
| 167 // Write out the cookie if requested | 167 // Write out the cookie if requested |
| 168 FilePath cookie_output_path = | 168 FilePath cookie_output_path = |
| 169 cmd_line->GetSwitchValuePath("wait_cookie_output"); | 169 cmd_line->GetSwitchValuePath("wait_cookie_output"); |
| 170 if (!cookie_output_path.value().empty()) { | 170 if (!cookie_output_path.value().empty()) { |
| 171 ASSERT_TRUE(WriteValueToFile(result.cookie_value, cookie_output_path)); | 171 ASSERT_TRUE(WriteValueToFile(result.cookie_value, cookie_output_path)); |
| 172 } | 172 } |
| 173 | 173 |
| 174 // Write out the JS Variable if requested | 174 // Write out the JS Variable if requested |
| 175 FilePath jsvar_output_path = cmd_line->GetSwitchValuePath("jsvar_output"); | 175 FilePath jsvar_output_path = cmd_line->GetSwitchValuePath("jsvar_output"); |
| 176 if (!jsvar_output_path.value().empty()) { | 176 if (!jsvar_output_path.value().empty()) { |
| 177 ASSERT_TRUE(WriteValueToFile(result.javascript_variable, | 177 ASSERT_TRUE(WriteValueToFile(result.javascript_variable, |
| 178 jsvar_output_path)); | 178 jsvar_output_path)); |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| 182 } // namespace | 182 } // namespace |
| OLD | NEW |