OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/common/chrome_paths.h" |
9 #include "chrome/test/automation/tab_proxy.h" | 10 #include "chrome/test/automation/tab_proxy.h" |
10 #include "chrome/test/ui/ui_test.h" | 11 #include "chrome/test/ui/ui_test.h" |
11 | 12 |
12 namespace { | 13 namespace { |
13 | 14 |
14 // Provides a UI Test that lets us take the browser to a url, and | 15 // Provides a UI Test that lets us take the browser to a url, and |
15 // wait for a cookie value to be set before closing the page. | 16 // wait for a cookie value to be set before closing the page. |
16 class UrlFetchTest : public UITest { | 17 class UrlFetchTest : public UITest { |
17 public: | 18 public: |
18 UrlFetchTest() { | 19 UrlFetchTest() { |
19 show_window_ = true; | 20 show_window_ = true; |
20 dom_automation_enabled_ = true; | 21 dom_automation_enabled_ = true; |
21 } | 22 } |
22 struct UrlFetchTestResult { | 23 struct UrlFetchTestResult { |
23 std::string cookie_value; | 24 std::string cookie_value; |
24 std::string javascript_variable; | 25 std::string javascript_variable; |
25 }; | 26 }; |
26 | 27 |
| 28 void SetUp() { |
| 29 const CommandLine *cmdLine = CommandLine::ForCurrentProcess(); |
| 30 if (cmdLine->HasSwitch(L"reference_build")) { |
| 31 FilePath dir; |
| 32 PathService::Get(chrome::DIR_TEST_TOOLS, &dir); |
| 33 dir = dir.AppendASCII("reference_build"); |
| 34 #if defined(OS_WIN) |
| 35 dir = dir.AppendASCII("chrome"); |
| 36 #elif defined(OS_LINUX) |
| 37 dir = dir.AppendASCII("chrome_linux"); |
| 38 #elif defined(OS_MACOSX) |
| 39 dir = dir.AppendASCII("chrome_mac"); |
| 40 #endif |
| 41 browser_directory_ = dir; |
| 42 } |
| 43 UITest::SetUp(); |
| 44 } |
| 45 |
27 void RunTest(const GURL& url, const char *waitCookieName, | 46 void RunTest(const GURL& url, const char *waitCookieName, |
28 const char *waitCookieValue, const wchar_t *varToFetch, | 47 const char *waitCookieValue, const wchar_t *varToFetch, |
29 UrlFetchTestResult *result) { | 48 UrlFetchTestResult *result) { |
30 scoped_refptr<TabProxy> tab(GetActiveTab()); | 49 scoped_refptr<TabProxy> tab(GetActiveTab()); |
31 tab->NavigateToURL(url); | 50 tab->NavigateToURL(url); |
32 | 51 |
33 if (waitCookieName) { | 52 if (waitCookieName) { |
34 if (waitCookieValue) { | 53 if (waitCookieValue) { |
35 bool completed = WaitUntilCookieValue(tab.get(), url, waitCookieName, | 54 bool completed = WaitUntilCookieValue(tab.get(), url, waitCookieName, |
36 3000, UITest::test_timeout_ms(), | 55 3000, UITest::test_timeout_ms(), |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // --wait_cookie_output=<filepath> | 96 // --wait_cookie_output=<filepath> |
78 // In conjunction with --wait_cookie_name, this saves the cookie value to | 97 // In conjunction with --wait_cookie_name, this saves the cookie value to |
79 // a file at the given path. (Incompatible with --wait_cookie_value) | 98 // a file at the given path. (Incompatible with --wait_cookie_value) |
80 // | 99 // |
81 // --jsvar=<name> | 100 // --jsvar=<name> |
82 // At the end of the test, fetch the named javascript variable from the page. | 101 // At the end of the test, fetch the named javascript variable from the page. |
83 // | 102 // |
84 // --jsvar_output=<filepath> | 103 // --jsvar_output=<filepath> |
85 // Write the value of the variable named by '--jsvar' to a file at the given | 104 // Write the value of the variable named by '--jsvar' to a file at the given |
86 // path. | 105 // path. |
| 106 // |
| 107 // --reference_build |
| 108 // Use the reference build of chrome for the test. |
87 TEST_F(UrlFetchTest, UrlFetch) { | 109 TEST_F(UrlFetchTest, UrlFetch) { |
88 const CommandLine *cmdLine = CommandLine::ForCurrentProcess(); | 110 const CommandLine *cmdLine = CommandLine::ForCurrentProcess(); |
89 | 111 |
90 if (!cmdLine->HasSwitch(L"url")) { | 112 if (!cmdLine->HasSwitch(L"url")) { |
91 return; | 113 return; |
92 } | 114 } |
93 | 115 |
94 std::string cookieName = | 116 std::string cookieName = |
95 WideToASCII(cmdLine->GetSwitchValue(L"wait_cookie_name")); | 117 WideToASCII(cmdLine->GetSwitchValue(L"wait_cookie_name")); |
96 std::string cookieValue = | 118 std::string cookieValue = |
(...skipping 16 matching lines...) Expand all Loading... |
113 } | 135 } |
114 | 136 |
115 // Write out the JS Variable if requested | 137 // Write out the JS Variable if requested |
116 std::wstring jsvarOutputPath = cmdLine->GetSwitchValue(L"jsvar_output"); | 138 std::wstring jsvarOutputPath = cmdLine->GetSwitchValue(L"jsvar_output"); |
117 if (jsvarOutputPath.length() > 0) { | 139 if (jsvarOutputPath.length() > 0) { |
118 ASSERT_TRUE(writeValueToFile(result.javascript_variable, jsvarOutputPath)); | 140 ASSERT_TRUE(writeValueToFile(result.javascript_variable, jsvarOutputPath)); |
119 } | 141 } |
120 } | 142 } |
121 | 143 |
122 } // namespace | 144 } // namespace |
OLD | NEW |