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" |
11 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
14 #include "chrome/test/automation/tab_proxy.h" | 14 #include "chrome/test/automation/tab_proxy.h" |
15 #include "chrome/test/ui/ui_test.h" | 15 #include "chrome/test/ui/ui_perf_test.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // Provides a UI Test that lets us take the browser to a url, and | 19 // Provides a UI Test that lets us take the browser to a url, and |
20 // wait for a cookie value to be set or a JavaScript expression to evaluate | 20 // wait for a cookie value to be set or a JavaScript expression to evaluate |
21 // true before closing the page. It is undefined what happens if you specify | 21 // true before closing the page. It is undefined what happens if you specify |
22 // both a cookie and a JS expression. | 22 // both a cookie and a JS expression. |
23 class UrlFetchTest : public UITest { | 23 class UrlFetchTest : public UIPerfTest { |
24 public: | 24 public: |
25 UrlFetchTest() { | 25 UrlFetchTest() { |
26 show_window_ = true; | 26 show_window_ = true; |
27 dom_automation_enabled_ = true; | 27 dom_automation_enabled_ = true; |
28 } | 28 } |
29 struct UrlFetchTestResult { | 29 struct UrlFetchTestResult { |
30 std::string cookie_value; | 30 std::string cookie_value; |
31 std::string javascript_variable; | 31 std::string javascript_variable; |
32 }; | 32 }; |
33 | 33 |
34 void SetUp() { | 34 void SetUp() { |
35 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 35 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
36 if (cmd_line->HasSwitch("reference_build")) { | 36 if (cmd_line->HasSwitch("reference_build")) { |
37 FilePath dir; | 37 UseReferenceBuild(); |
38 PathService::Get(chrome::DIR_TEST_TOOLS, &dir); | |
39 dir = dir.AppendASCII("reference_build"); | |
40 #if defined(OS_WIN) | |
41 dir = dir.AppendASCII("chrome"); | |
42 #elif defined(OS_LINUX) | |
43 dir = dir.AppendASCII("chrome_linux"); | |
44 #elif defined(OS_MACOSX) | |
45 dir = dir.AppendASCII("chrome_mac"); | |
46 #endif | |
47 browser_directory_ = dir; | |
48 } | 38 } |
49 UITest::SetUp(); | 39 UITest::SetUp(); |
50 } | 40 } |
51 | 41 |
52 void RunTest(const GURL& url, | 42 void RunTest(const GURL& url, |
53 const char* wait_cookie_name, | 43 const char* wait_cookie_name, |
54 const char* wait_cookie_value, | 44 const char* wait_cookie_value, |
55 const char* var_to_fetch, | 45 const char* var_to_fetch, |
56 const std::string& wait_js_expr, | 46 const std::string& wait_js_expr, |
57 const std::string& wait_js_frame_xpath, | 47 const std::string& wait_js_frame_xpath, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 } | 83 } |
94 } | 84 } |
95 }; | 85 }; |
96 | 86 |
97 bool WriteValueToFile(std::string value, const FilePath& path) { | 87 bool WriteValueToFile(std::string value, const FilePath& path) { |
98 int retval = file_util::WriteFile(path, value.c_str(), value.length()); | 88 int retval = file_util::WriteFile(path, value.c_str(), value.length()); |
99 return retval == static_cast<int>(value.length()); | 89 return retval == static_cast<int>(value.length()); |
100 } | 90 } |
101 | 91 |
102 // To actually do anything useful, this test should have a url | 92 // To actually do anything useful, this test should have a url |
103 // passed on the command line, eg. | 93 // passed on the command line, eg. |
jrt
2011/06/17 19:50:46
Why does this test use command line arguments?
| |
104 // | 94 // |
105 // --url=http://foo.bar.com | 95 // --url=http://foo.bar.com |
106 // | 96 // |
107 // Additional arguments: | 97 // Additional arguments: |
108 // | 98 // |
109 // --wait_cookie_name=<name> | 99 // --wait_cookie_name=<name> |
110 // Waits for a cookie named <name> to be set before exiting successfully. | 100 // Waits for a cookie named <name> to be set before exiting successfully. |
111 // | 101 // |
112 // --wait_cookie_value=<value> | 102 // --wait_cookie_value=<value> |
113 // In conjunction with --wait_cookie_name, this waits for a specific value | 103 // In conjunction with --wait_cookie_name, this waits for a specific value |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 | 173 |
184 // Write out the JS Variable if requested | 174 // Write out the JS Variable if requested |
185 FilePath jsvar_output_path = cmd_line->GetSwitchValuePath("jsvar_output"); | 175 FilePath jsvar_output_path = cmd_line->GetSwitchValuePath("jsvar_output"); |
186 if (!jsvar_output_path.value().empty()) { | 176 if (!jsvar_output_path.value().empty()) { |
187 ASSERT_TRUE(WriteValueToFile(result.javascript_variable, | 177 ASSERT_TRUE(WriteValueToFile(result.javascript_variable, |
188 jsvar_output_path)); | 178 jsvar_output_path)); |
189 } | 179 } |
190 } | 180 } |
191 | 181 |
192 } // namespace | 182 } // namespace |
OLD | NEW |