Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: chrome/test/url_fetch_test/url_fetch_test.cc

Issue 3057033: Remove GetSwitchValue() from chrome/* where easy. (Closed)
Patch Set: finally Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_util.h" 9 #include "base/string_util.h"
10 #include "chrome/common/chrome_paths.h" 10 #include "chrome/common/chrome_paths.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 browser_directory_ = dir; 42 browser_directory_ = dir;
43 } 43 }
44 UITest::SetUp(); 44 UITest::SetUp();
45 45
46 // We've shortened the default timeouts, but dom_perf on Vista needs longer 46 // We've shortened the default timeouts, but dom_perf on Vista needs longer
47 // timeouts. Setting timeouts to the previous values before r52666. 47 // timeouts. Setting timeouts to the previous values before r52666.
48 set_action_timeout_ms(std::max(60000, action_timeout_ms())); 48 set_action_timeout_ms(std::max(60000, action_timeout_ms()));
49 } 49 }
50 50
51 void RunTest(const GURL& url, const char* wait_cookie_name, 51 void RunTest(const GURL& url, const char* wait_cookie_name,
52 const char* wait_cookie_value, const wchar_t* var_to_fetch, 52 const char* wait_cookie_value, const char* var_to_fetch,
53 UrlFetchTestResult* result) { 53 UrlFetchTestResult* result) {
54 scoped_refptr<TabProxy> tab(GetActiveTab()); 54 scoped_refptr<TabProxy> tab(GetActiveTab());
55 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); 55 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url));
56 56
57 if (wait_cookie_name) { 57 if (wait_cookie_name) {
58 if (wait_cookie_value) { 58 if (wait_cookie_value) {
59 bool completed = WaitUntilCookieValue(tab.get(), url, wait_cookie_name, 59 bool completed = WaitUntilCookieValue(tab.get(), url, wait_cookie_name,
60 UITest::test_timeout_ms(), 60 UITest::test_timeout_ms(),
61 wait_cookie_value); 61 wait_cookie_value);
62 ASSERT_TRUE(completed); 62 ASSERT_TRUE(completed);
63 } else { 63 } else {
64 result->cookie_value = WaitUntilCookieNonEmpty( 64 result->cookie_value = WaitUntilCookieNonEmpty(
65 tab.get(), url, wait_cookie_name, UITest::test_timeout_ms()); 65 tab.get(), url, wait_cookie_name, UITest::test_timeout_ms());
66 ASSERT_TRUE(result->cookie_value.length()); 66 ASSERT_TRUE(result->cookie_value.length());
67 } 67 }
68 } 68 }
69 if (var_to_fetch) { 69 if (var_to_fetch) {
70 std::wstring script = StringPrintf( 70 std::string script = StringPrintf(
71 L"window.domAutomationController.send(%ls);", var_to_fetch); 71 "window.domAutomationController.send(%s);", var_to_fetch);
72 72
73 std::wstring value; 73 std::wstring value;
74 bool success = tab->ExecuteAndExtractString(L"", script, &value); 74 bool success = tab->ExecuteAndExtractString(L"", ASCIIToWide(script),
75 &value);
75 ASSERT_TRUE(success); 76 ASSERT_TRUE(success);
76 result->javascript_variable = WideToUTF8(value); 77 result->javascript_variable = WideToUTF8(value);
77 } 78 }
78 } 79 }
79 }; 80 };
80 81
81 bool WriteValueToFile(std::string value, const FilePath& path) { 82 bool WriteValueToFile(std::string value, const FilePath& path) {
82 int retval = file_util::WriteFile(path, value.c_str(), value.length()); 83 int retval = file_util::WriteFile(path, value.c_str(), value.length());
83 return retval == static_cast<int>(value.length()); 84 return retval == static_cast<int>(value.length());
84 } 85 }
(...skipping 29 matching lines...) Expand all
114 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); 115 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
115 116
116 if (!cmd_line->HasSwitch("url")) 117 if (!cmd_line->HasSwitch("url"))
117 return; 118 return;
118 119
119 std::string cookie_name = 120 std::string cookie_name =
120 cmd_line->GetSwitchValueASCII("wait_cookie_name"); 121 cmd_line->GetSwitchValueASCII("wait_cookie_name");
121 std::string cookie_value = 122 std::string cookie_value =
122 cmd_line->GetSwitchValueASCII("wait_cookie_value"); 123 cmd_line->GetSwitchValueASCII("wait_cookie_value");
123 124
124 std::wstring jsvar = cmd_line->GetSwitchValue("jsvar"); 125 std::string jsvar = cmd_line->GetSwitchValueASCII("jsvar");
125 126
126 UrlFetchTestResult result; 127 UrlFetchTestResult result;
127 RunTest(GURL(WideToASCII(cmd_line->GetSwitchValue("url"))), 128 RunTest(GURL(cmd_line->GetSwitchValueASCII("url")),
128 cookie_name.length() > 0 ? cookie_name.c_str() : NULL, 129 cookie_name.length() > 0 ? cookie_name.c_str() : NULL,
129 cookie_value.length() > 0 ? cookie_value.c_str() : NULL, 130 cookie_value.length() > 0 ? cookie_value.c_str() : NULL,
130 jsvar.length() > 0 ? jsvar.c_str() : NULL, 131 jsvar.length() > 0 ? jsvar.c_str() : NULL,
131 &result); 132 &result);
132 133
133 // Write out the cookie if requested 134 // Write out the cookie if requested
134 FilePath cookie_output_path = 135 FilePath cookie_output_path =
135 cmd_line->GetSwitchValuePath("wait_cookie_output"); 136 cmd_line->GetSwitchValuePath("wait_cookie_output");
136 if (cookie_output_path.value().size() > 0) { 137 if (cookie_output_path.value().size() > 0) {
137 ASSERT_TRUE(WriteValueToFile(result.cookie_value, cookie_output_path)); 138 ASSERT_TRUE(WriteValueToFile(result.cookie_value, cookie_output_path));
138 } 139 }
139 140
140 // Write out the JS Variable if requested 141 // Write out the JS Variable if requested
141 FilePath jsvar_output_path = cmd_line->GetSwitchValuePath("jsvar_output"); 142 FilePath jsvar_output_path = cmd_line->GetSwitchValuePath("jsvar_output");
142 if (jsvar_output_path.value().size() > 0) { 143 if (jsvar_output_path.value().size() > 0) {
143 ASSERT_TRUE(WriteValueToFile(result.javascript_variable, 144 ASSERT_TRUE(WriteValueToFile(result.javascript_variable,
144 jsvar_output_path)); 145 jsvar_output_path));
145 } 146 }
146 } 147 }
147 148
148 } // namespace 149 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698