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

Side by Side Diff: chrome_frame/test/test_with_web_server.cc

Issue 12211108: Rename FilePath -> base::FilePath in various toplevel directories (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome_frame/test/test_with_web_server.h ('k') | chrome_frame/test/ui_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome_frame/test/test_with_web_server.h" 5 #include "chrome_frame/test/test_with_web_server.h"
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/file_version_info.h" 8 #include "base/file_version_info.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 << "Content-Type: " << content_type << "\r\n"; 46 << "Content-Type: " << content_type << "\r\n";
47 if (invocation.type() == CFInvocation::HTTP_HEADER) 47 if (invocation.type() == CFInvocation::HTTP_HEADER)
48 ss << "X-UA-Compatible: chrome=1\r\n"; 48 ss << "X-UA-Compatible: chrome=1\r\n";
49 if (add_no_cache_header) { 49 if (add_no_cache_header) {
50 ss << "Cache-Control: no-cache\r\n"; 50 ss << "Cache-Control: no-cache\r\n";
51 ss << "Expires: Tue, 15 Nov 1994 08:12:31 GMT\r\n"; 51 ss << "Expires: Tue, 15 Nov 1994 08:12:31 GMT\r\n";
52 } 52 }
53 return ss.str(); 53 return ss.str();
54 } 54 }
55 55
56 std::string GetMockHttpHeaders(const FilePath& mock_http_headers_path) { 56 std::string GetMockHttpHeaders(const base::FilePath& mock_http_headers_path) {
57 std::string headers; 57 std::string headers;
58 file_util::ReadFileToString(mock_http_headers_path, &headers); 58 file_util::ReadFileToString(mock_http_headers_path, &headers);
59 return headers; 59 return headers;
60 } 60 }
61 61
62 class ChromeFrameTestEnvironment: public testing::Environment { 62 class ChromeFrameTestEnvironment: public testing::Environment {
63 public: 63 public:
64 virtual ~ChromeFrameTestEnvironment() {} 64 virtual ~ChromeFrameTestEnvironment() {}
65 virtual void SetUp() OVERRIDE { 65 virtual void SetUp() OVERRIDE {
66 ScopedChromeFrameRegistrar::RegisterDefaults(); 66 ScopedChromeFrameRegistrar::RegisterDefaults();
67 } 67 }
68 }; 68 };
69 69
70 ::testing::Environment* const chrome_frame_env = 70 ::testing::Environment* const chrome_frame_env =
71 ::testing::AddGlobalTestEnvironment(new ChromeFrameTestEnvironment); 71 ::testing::AddGlobalTestEnvironment(new ChromeFrameTestEnvironment);
72 72
73 } // namespace 73 } // namespace
74 74
75 FilePath ChromeFrameTestWithWebServer::test_file_path_; 75 base::FilePath ChromeFrameTestWithWebServer::test_file_path_;
76 FilePath ChromeFrameTestWithWebServer::results_dir_; 76 base::FilePath ChromeFrameTestWithWebServer::results_dir_;
77 FilePath ChromeFrameTestWithWebServer::CFInstall_path_; 77 base::FilePath ChromeFrameTestWithWebServer::CFInstall_path_;
78 FilePath ChromeFrameTestWithWebServer::CFInstance_path_; 78 base::FilePath ChromeFrameTestWithWebServer::CFInstance_path_;
79 base::ScopedTempDir ChromeFrameTestWithWebServer::temp_dir_; 79 base::ScopedTempDir ChromeFrameTestWithWebServer::temp_dir_;
80 FilePath ChromeFrameTestWithWebServer::chrome_user_data_dir_; 80 base::FilePath ChromeFrameTestWithWebServer::chrome_user_data_dir_;
81 chrome_frame_test::TimedMsgLoop* ChromeFrameTestWithWebServer::loop_; 81 chrome_frame_test::TimedMsgLoop* ChromeFrameTestWithWebServer::loop_;
82 std::string ChromeFrameTestWithWebServer::local_address_; 82 std::string ChromeFrameTestWithWebServer::local_address_;
83 testing::StrictMock<MockWebServerListener>* 83 testing::StrictMock<MockWebServerListener>*
84 ChromeFrameTestWithWebServer::listener_mock_; 84 ChromeFrameTestWithWebServer::listener_mock_;
85 testing::StrictMock<MockWebServer>* ChromeFrameTestWithWebServer::server_mock_; 85 testing::StrictMock<MockWebServer>* ChromeFrameTestWithWebServer::server_mock_;
86 86
87 ChromeFrameTestWithWebServer::ChromeFrameTestWithWebServer() { 87 ChromeFrameTestWithWebServer::ChromeFrameTestWithWebServer() {
88 } 88 }
89 89
90 // static 90 // static
91 void ChromeFrameTestWithWebServer::SetUpTestCase() { 91 void ChromeFrameTestWithWebServer::SetUpTestCase() {
92 FilePath chrome_frame_source_path; 92 base::FilePath chrome_frame_source_path;
93 PathService::Get(base::DIR_SOURCE_ROOT, &chrome_frame_source_path); 93 PathService::Get(base::DIR_SOURCE_ROOT, &chrome_frame_source_path);
94 chrome_frame_source_path = chrome_frame_source_path.Append( 94 chrome_frame_source_path = chrome_frame_source_path.Append(
95 FILE_PATH_LITERAL("chrome_frame")); 95 FILE_PATH_LITERAL("chrome_frame"));
96 96
97 test_file_path_ = chrome_frame_source_path 97 test_file_path_ = chrome_frame_source_path
98 .Append(FILE_PATH_LITERAL("test")) 98 .Append(FILE_PATH_LITERAL("test"))
99 .Append(FILE_PATH_LITERAL("data")); 99 .Append(FILE_PATH_LITERAL("data"));
100 100
101 results_dir_ = chrome_frame_test::GetTestDataFolder().AppendASCII("dump"); 101 results_dir_ = chrome_frame_test::GetTestDataFolder().AppendASCII("dump");
102 102
103 // Copy the CFInstance.js and CFInstall.js files from src\chrome_frame to 103 // Copy the CFInstance.js and CFInstall.js files from src\chrome_frame to
104 // src\chrome_frame\test\data. 104 // src\chrome_frame\test\data.
105 FilePath CFInstance_src_path; 105 base::FilePath CFInstance_src_path;
106 FilePath CFInstall_src_path; 106 base::FilePath CFInstall_src_path;
107 107
108 CFInstance_src_path = chrome_frame_source_path.AppendASCII("CFInstance.js"); 108 CFInstance_src_path = chrome_frame_source_path.AppendASCII("CFInstance.js");
109 CFInstance_path_ = test_file_path_.AppendASCII("CFInstance.js"); 109 CFInstance_path_ = test_file_path_.AppendASCII("CFInstance.js");
110 110
111 ASSERT_TRUE(file_util::CopyFile(CFInstance_src_path, CFInstance_path_)); 111 ASSERT_TRUE(file_util::CopyFile(CFInstance_src_path, CFInstance_path_));
112 112
113 CFInstall_src_path = chrome_frame_source_path.AppendASCII("CFInstall.js"); 113 CFInstall_src_path = chrome_frame_source_path.AppendASCII("CFInstall.js");
114 CFInstall_path_ = test_file_path_.AppendASCII("CFInstall.js"); 114 CFInstall_path_ = test_file_path_.AppendASCII("CFInstall.js");
115 115
116 ASSERT_TRUE(file_util::CopyFile(CFInstall_src_path, CFInstall_path_)); 116 ASSERT_TRUE(file_util::CopyFile(CFInstall_src_path, CFInstall_path_));
(...skipping 17 matching lines...) Expand all
134 local_address_.clear(); 134 local_address_.clear();
135 delete loop_; 135 delete loop_;
136 loop_ = NULL; 136 loop_ = NULL;
137 file_util::Delete(CFInstall_path_, false); 137 file_util::Delete(CFInstall_path_, false);
138 file_util::Delete(CFInstance_path_, false); 138 file_util::Delete(CFInstance_path_, false);
139 if (temp_dir_.IsValid()) 139 if (temp_dir_.IsValid())
140 EXPECT_TRUE(temp_dir_.Delete()); 140 EXPECT_TRUE(temp_dir_.Delete());
141 } 141 }
142 142
143 // static 143 // static
144 const FilePath& ChromeFrameTestWithWebServer::GetChromeUserDataDirectory() { 144 const base::FilePath&
145 ChromeFrameTestWithWebServer::GetChromeUserDataDirectory() {
145 if (!temp_dir_.IsValid()) { 146 if (!temp_dir_.IsValid()) {
146 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 147 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
147 chrome_user_data_dir_ = temp_dir_.path().AppendASCII("User Data"); 148 chrome_user_data_dir_ = temp_dir_.path().AppendASCII("User Data");
148 } 149 }
149 return chrome_user_data_dir_; 150 return chrome_user_data_dir_;
150 } 151 }
151 152
152 void ChromeFrameTestWithWebServer::SetUp() { 153 void ChromeFrameTestWithWebServer::SetUp() {
153 // Make sure that we are not accidentally enabling gcf protocol. 154 // Make sure that we are not accidentally enabling gcf protocol.
154 SetConfigBool(kAllowUnsafeURLs, false); 155 SetConfigBool(kAllowUnsafeURLs, false);
(...skipping 17 matching lines...) Expand all
172 // We should resolve the URL only if it is a relative url. 173 // We should resolve the URL only if it is a relative url.
173 GURL parsed_url(WideToUTF8(page)); 174 GURL parsed_url(WideToUTF8(page));
174 if (!parsed_url.has_scheme()) { 175 if (!parsed_url.has_scheme()) {
175 url = server_mock().Resolve(page); 176 url = server_mock().Resolve(page);
176 } 177 }
177 178
178 browser_ = browser; 179 browser_ = browser;
179 if (browser == IE) { 180 if (browser == IE) {
180 browser_handle_.Set(chrome_frame_test::LaunchIE(url)); 181 browser_handle_.Set(chrome_frame_test::LaunchIE(url));
181 } else if (browser == CHROME) { 182 } else if (browser == CHROME) {
182 const FilePath& user_data_dir = GetChromeUserDataDirectory(); 183 const base::FilePath& user_data_dir = GetChromeUserDataDirectory();
183 chrome_frame_test::OverrideDataDirectoryForThisTest(user_data_dir.value()); 184 chrome_frame_test::OverrideDataDirectoryForThisTest(user_data_dir.value());
184 browser_handle_.Set(chrome_frame_test::LaunchChrome(url, user_data_dir)); 185 browser_handle_.Set(chrome_frame_test::LaunchChrome(url, user_data_dir));
185 } else { 186 } else {
186 NOTREACHED(); 187 NOTREACHED();
187 } 188 }
188 189
189 return browser_handle_.IsValid(); 190 return browser_handle_.IsValid();
190 } 191 }
191 192
192 void ChromeFrameTestWithWebServer::CloseBrowser() { 193 void ChromeFrameTestWithWebServer::CloseBrowser() {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 void ChromeFrameTestWithWebServer::ExpectAndHandlePostedResult() { 281 void ChromeFrameTestWithWebServer::ExpectAndHandlePostedResult() {
281 EXPECT_CALL(listener_mock(), OnExpectedResponse()) 282 EXPECT_CALL(listener_mock(), OnExpectedResponse())
282 .WillRepeatedly(QUIT_LOOP_SOON(loop(), 283 .WillRepeatedly(QUIT_LOOP_SOON(loop(),
283 base::TimeDelta::FromMilliseconds(100))); 284 base::TimeDelta::FromMilliseconds(100)));
284 server_mock().ExpectAndHandlePostedResult(CFInvocation(CFInvocation::NONE), 285 server_mock().ExpectAndHandlePostedResult(CFInvocation(CFInvocation::NONE),
285 kPostedResultSubstring); 286 kPostedResultSubstring);
286 } 287 }
287 288
288 void ChromeFrameTestWithWebServer::VersionTest(BrowserKind browser, 289 void ChromeFrameTestWithWebServer::VersionTest(BrowserKind browser,
289 const wchar_t* page) { 290 const wchar_t* page) {
290 FilePath plugin_path; 291 base::FilePath plugin_path;
291 PathService::Get(base::DIR_MODULE, &plugin_path); 292 PathService::Get(base::DIR_MODULE, &plugin_path);
292 plugin_path = plugin_path.Append(kChromeFrameDllName); 293 plugin_path = plugin_path.Append(kChromeFrameDllName);
293 294
294 static FileVersionInfo* version_info = 295 static FileVersionInfo* version_info =
295 FileVersionInfo::CreateFileVersionInfo(plugin_path); 296 FileVersionInfo::CreateFileVersionInfo(plugin_path);
296 297
297 std::wstring version; 298 std::wstring version;
298 if (version_info) 299 if (version_info)
299 version = version_info->product_version(); 300 version = version_info->product_version();
300 301
301 // If we can't find the Chrome Frame DLL in the src tree, we turn to 302 // If we can't find the Chrome Frame DLL in the src tree, we turn to
302 // the directory where chrome is installed. 303 // the directory where chrome is installed.
303 if (!version_info) { 304 if (!version_info) {
304 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 305 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
305 Version ver_system; 306 Version ver_system;
306 InstallUtil::GetChromeVersion(dist, true, &ver_system); 307 InstallUtil::GetChromeVersion(dist, true, &ver_system);
307 Version ver_user; 308 Version ver_user;
308 InstallUtil::GetChromeVersion(dist, false, &ver_system); 309 InstallUtil::GetChromeVersion(dist, false, &ver_system);
309 ASSERT_TRUE(ver_system.IsValid() || ver_user.IsValid()); 310 ASSERT_TRUE(ver_system.IsValid() || ver_user.IsValid());
310 311
311 bool system_install = ver_system.IsValid(); 312 bool system_install = ver_system.IsValid();
312 FilePath cf_dll_path(installer::GetChromeInstallPath(system_install, dist)); 313 base::FilePath cf_dll_path(installer::GetChromeInstallPath(system_install, d ist));
313 cf_dll_path = cf_dll_path.Append(UTF8ToWide( 314 cf_dll_path = cf_dll_path.Append(UTF8ToWide(
314 ver_system.IsValid() ? ver_system.GetString() : ver_user.GetString())); 315 ver_system.IsValid() ? ver_system.GetString() : ver_user.GetString()));
315 cf_dll_path = cf_dll_path.Append(kChromeFrameDllName); 316 cf_dll_path = cf_dll_path.Append(kChromeFrameDllName);
316 version_info = FileVersionInfo::CreateFileVersionInfo(cf_dll_path); 317 version_info = FileVersionInfo::CreateFileVersionInfo(cf_dll_path);
317 if (version_info) 318 if (version_info)
318 version = version_info->product_version(); 319 version = version_info->product_version();
319 } 320 }
320 321
321 server_mock().set_expected_result(WideToUTF8(version)); 322 server_mock().set_expected_result(WideToUTF8(version));
322 323
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 WideToUTF8(header), request.headers()); 384 WideToUTF8(header), request.headers());
384 connection->Send(header_value, ""); 385 connection->Send(header_value, "");
385 return; 386 return;
386 } 387 }
387 // Convert |request_uri| to a path. 388 // Convert |request_uri| to a path.
388 std::wstring path = request_uri; 389 std::wstring path = request_uri;
389 size_t query_index = request_uri.find(L"?"); 390 size_t query_index = request_uri.find(L"?");
390 if (query_index != std::string::npos) { 391 if (query_index != std::string::npos) {
391 path = path.erase(query_index); 392 path = path.erase(query_index);
392 } 393 }
393 FilePath file_path = root_dir_; 394 base::FilePath file_path = root_dir_;
394 if (path.size()) 395 if (path.size())
395 file_path = file_path.Append(path.substr(1)); // remove first '/' 396 file_path = file_path.Append(path.substr(1)); // remove first '/'
396 397
397 std::string headers, body; 398 std::string headers, body;
398 std::string content_type; 399 std::string content_type;
399 if (file_util::PathExists(file_path) && 400 if (file_util::PathExists(file_path) &&
400 !file_util::DirectoryExists(file_path)) { 401 !file_util::DirectoryExists(file_path)) {
401 FilePath mock_http_headers(file_path.value() + L".mock-http-headers"); 402 base::FilePath mock_http_headers(file_path.value() + L".mock-http-headers");
402 if (file_util::PathExists(mock_http_headers)) { 403 if (file_util::PathExists(mock_http_headers)) {
403 headers = GetMockHttpHeaders(mock_http_headers); 404 headers = GetMockHttpHeaders(mock_http_headers);
404 content_type = http_utils::GetHttpHeaderFromHeaderList("Content-type", 405 content_type = http_utils::GetHttpHeaderFromHeaderList("Content-type",
405 headers); 406 headers);
406 } else { 407 } else {
407 EXPECT_TRUE(net::GetMimeTypeFromFile(file_path, &content_type)); 408 EXPECT_TRUE(net::GetMimeTypeFromFile(file_path, &content_type));
408 VLOG(1) << "Going to send file (" << WideToUTF8(file_path.value()) 409 VLOG(1) << "Going to send file (" << WideToUTF8(file_path.value())
409 << ") with content type (" << content_type << ")"; 410 << ") with content type (" << content_type << ")";
410 headers = CreateHttpHeaders(invocation, add_no_cache_header, 411 headers = CreateHttpHeaders(invocation, add_no_cache_header,
411 content_type); 412 content_type);
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 } 869 }
869 870
870 // Specialized implementation of test_server::FileResponse that supports 871 // Specialized implementation of test_server::FileResponse that supports
871 // adding the request's User-Agent header to the returned document. 872 // adding the request's User-Agent header to the returned document.
872 // The class also supports $request_id$ which will be replaced with an 873 // The class also supports $request_id$ which will be replaced with an
873 // id that's incremented each time the response is sent over a socket. 874 // id that's incremented each time the response is sent over a socket.
874 class UaTemplateFileResponse : public test_server::FileResponse { 875 class UaTemplateFileResponse : public test_server::FileResponse {
875 public: 876 public:
876 typedef test_server::FileResponse SuperClass; 877 typedef test_server::FileResponse SuperClass;
877 878
878 UaTemplateFileResponse(const char* request_path, const FilePath& file_path) 879 UaTemplateFileResponse(const char* request_path,
880 const base::FilePath& file_path)
879 : test_server::FileResponse(request_path, file_path), request_id_(0) { 881 : test_server::FileResponse(request_path, file_path), request_id_(0) {
880 } 882 }
881 883
882 virtual bool Matches(const test_server::Request& r) const { 884 virtual bool Matches(const test_server::Request& r) const {
883 bool ret = SuperClass::Matches(r); 885 bool ret = SuperClass::Matches(r);
884 if (ret) 886 if (ret)
885 ua_ = GetHeaderValue(r.headers(), "User-Agent"); 887 ua_ = GetHeaderValue(r.headers(), "User-Agent");
886 return ret; 888 return ret;
887 } 889 }
888 890
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 server.web_server()->AddResponse(response); 1077 server.web_server()->AddResponse(response);
1076 1078
1077 std::wstring url(server.FormatHttpPath(L"form.html")); 1079 std::wstring url(server.FormatHttpPath(L"form.html"));
1078 1080
1079 ASSERT_TRUE(LaunchBrowser(IE, url.c_str())); 1081 ASSERT_TRUE(LaunchBrowser(IE, url.c_str()));
1080 loop().RunFor(kChromeFrameLongNavigationTimeout); 1082 loop().RunFor(kChromeFrameLongNavigationTimeout);
1081 1083
1082 EXPECT_EQ(1, response->get_request_count()); 1084 EXPECT_EQ(1, response->get_request_count());
1083 EXPECT_EQ(1, response->post_request_count()); 1085 EXPECT_EQ(1, response->post_request_count());
1084 } 1086 }
OLDNEW
« no previous file with comments | « chrome_frame/test/test_with_web_server.h ('k') | chrome_frame/test/ui_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698