| 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/common/chrome_paths.h" |
| 10 #include "chrome/test/automation/tab_proxy.h" | 10 #include "chrome/test/automation/tab_proxy.h" |
| 11 #include "chrome/test/ui/ui_test.h" | 11 #include "chrome/test/ui/ui_test.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 // 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 |
| 16 // 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. |
| 17 class UrlFetchTest : public UITest { | 17 class UrlFetchTest : public UITest { |
| 18 public: | 18 public: |
| 19 UrlFetchTest() { | 19 UrlFetchTest() { |
| 20 show_window_ = true; | 20 show_window_ = true; |
| 21 dom_automation_enabled_ = true; | 21 dom_automation_enabled_ = true; |
| 22 } | 22 } |
| 23 struct UrlFetchTestResult { | 23 struct UrlFetchTestResult { |
| 24 std::string cookie_value; | 24 std::string cookie_value; |
| 25 std::string javascript_variable; | 25 std::string javascript_variable; |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 void SetUp() { | 28 void SetUp() { |
| 29 const CommandLine *cmdLine = CommandLine::ForCurrentProcess(); | 29 const CommandLine *cmdLine = CommandLine::ForCurrentProcess(); |
| 30 if (cmdLine->HasSwitch(L"reference_build")) { | 30 if (cmdLine->HasSwitch("reference_build")) { |
| 31 FilePath dir; | 31 FilePath dir; |
| 32 PathService::Get(chrome::DIR_TEST_TOOLS, &dir); | 32 PathService::Get(chrome::DIR_TEST_TOOLS, &dir); |
| 33 dir = dir.AppendASCII("reference_build"); | 33 dir = dir.AppendASCII("reference_build"); |
| 34 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
| 35 dir = dir.AppendASCII("chrome"); | 35 dir = dir.AppendASCII("chrome"); |
| 36 #elif defined(OS_LINUX) | 36 #elif defined(OS_LINUX) |
| 37 dir = dir.AppendASCII("chrome_linux"); | 37 dir = dir.AppendASCII("chrome_linux"); |
| 38 #elif defined(OS_MACOSX) | 38 #elif defined(OS_MACOSX) |
| 39 dir = dir.AppendASCII("chrome_mac"); | 39 dir = dir.AppendASCII("chrome_mac"); |
| 40 #endif | 40 #endif |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // | 102 // |
| 103 // --jsvar_output=<filepath> | 103 // --jsvar_output=<filepath> |
| 104 // 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 |
| 105 // path. | 105 // path. |
| 106 // | 106 // |
| 107 // --reference_build | 107 // --reference_build |
| 108 // Use the reference build of chrome for the test. | 108 // Use the reference build of chrome for the test. |
| 109 TEST_F(UrlFetchTest, UrlFetch) { | 109 TEST_F(UrlFetchTest, UrlFetch) { |
| 110 const CommandLine *cmdLine = CommandLine::ForCurrentProcess(); | 110 const CommandLine *cmdLine = CommandLine::ForCurrentProcess(); |
| 111 | 111 |
| 112 if (!cmdLine->HasSwitch(L"url")) { | 112 if (!cmdLine->HasSwitch("url")) { |
| 113 return; | 113 return; |
| 114 } | 114 } |
| 115 | 115 |
| 116 std::string cookieName = | 116 std::string cookieName = |
| 117 WideToASCII(cmdLine->GetSwitchValue(L"wait_cookie_name")); | 117 cmdLine->GetSwitchValueASCII("wait_cookie_name"); |
| 118 std::string cookieValue = | 118 std::string cookieValue = |
| 119 WideToASCII(cmdLine->GetSwitchValue(L"wait_cookie_value")); | 119 cmdLine->GetSwitchValueASCII("wait_cookie_value"); |
| 120 | 120 |
| 121 std::wstring jsvar = cmdLine->GetSwitchValue(L"jsvar"); | 121 std::wstring jsvar = cmdLine->GetSwitchValue("jsvar"); |
| 122 | 122 |
| 123 UrlFetchTestResult result; | 123 UrlFetchTestResult result; |
| 124 RunTest(GURL(WideToASCII(cmdLine->GetSwitchValue(L"url"))), | 124 RunTest(GURL(WideToASCII(cmdLine->GetSwitchValue("url"))), |
| 125 cookieName.length() > 0 ? cookieName.c_str() : NULL, | 125 cookieName.length() > 0 ? cookieName.c_str() : NULL, |
| 126 cookieValue.length() > 0 ? cookieValue.c_str() : NULL, | 126 cookieValue.length() > 0 ? cookieValue.c_str() : NULL, |
| 127 jsvar.length() > 0 ? jsvar.c_str() : NULL, | 127 jsvar.length() > 0 ? jsvar.c_str() : NULL, |
| 128 &result); | 128 &result); |
| 129 | 129 |
| 130 // Write out the cookie if requested | 130 // Write out the cookie if requested |
| 131 std::wstring cookieOutputPath = | 131 std::wstring cookieOutputPath = |
| 132 cmdLine->GetSwitchValue(L"wait_cookie_output"); | 132 cmdLine->GetSwitchValue("wait_cookie_output"); |
| 133 if (cookieOutputPath.length() > 0) { | 133 if (cookieOutputPath.length() > 0) { |
| 134 ASSERT_TRUE(writeValueToFile(result.cookie_value, cookieOutputPath)); | 134 ASSERT_TRUE(writeValueToFile(result.cookie_value, cookieOutputPath)); |
| 135 } | 135 } |
| 136 | 136 |
| 137 // Write out the JS Variable if requested | 137 // Write out the JS Variable if requested |
| 138 std::wstring jsvarOutputPath = cmdLine->GetSwitchValue(L"jsvar_output"); | 138 std::wstring jsvarOutputPath = cmdLine->GetSwitchValue("jsvar_output"); |
| 139 if (jsvarOutputPath.length() > 0) { | 139 if (jsvarOutputPath.length() > 0) { |
| 140 ASSERT_TRUE(writeValueToFile(result.javascript_variable, jsvarOutputPath)); | 140 ASSERT_TRUE(writeValueToFile(result.javascript_variable, jsvarOutputPath)); |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 | 143 |
| 144 } // namespace | 144 } // namespace |
| OLD | NEW |