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

Side by Side Diff: content/browser/download/save_package_unittest.cc

Issue 1549113002: Switch to standard integer types in content/browser/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 11 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
« no previous file with comments | « content/browser/download/save_package.cc ('k') | content/browser/download/save_types.h » ('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 <stddef.h>
6 #include <stdint.h>
7
5 #include <string> 8 #include <string>
6 9
7 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
8 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/macros.h"
9 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "build/build_config.h"
11 #include "content/browser/download/save_package.h" 16 #include "content/browser/download/save_package.h"
12 #include "content/public/common/url_constants.h" 17 #include "content/public/common/url_constants.h"
13 #include "content/test/test_render_view_host.h" 18 #include "content/test/test_render_view_host.h"
14 #include "content/test/test_web_contents.h" 19 #include "content/test/test_web_contents.h"
15 #include "net/test/url_request/url_request_mock_http_job.h" 20 #include "net/test/url_request/url_request_mock_http_job.h"
16 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
17 #include "url/gurl.h" 22 #include "url/gurl.h"
18 23
19 namespace content { 24 namespace content {
20 25
21 #define FPL FILE_PATH_LITERAL 26 #define FPL FILE_PATH_LITERAL
22 #define HTML_EXTENSION ".html" 27 #define HTML_EXTENSION ".html"
23 #if defined(OS_WIN) 28 #if defined(OS_WIN)
24 #define FPL_HTML_EXTENSION L".html" 29 #define FPL_HTML_EXTENSION L".html"
25 #else 30 #else
26 #define FPL_HTML_EXTENSION ".html" 31 #define FPL_HTML_EXTENSION ".html"
27 #endif 32 #endif
28 33
29 namespace { 34 namespace {
30 35
31 // This constant copied from save_package.cc. 36 // This constant copied from save_package.cc.
32 #if defined(OS_WIN) 37 #if defined(OS_WIN)
33 const uint32 kMaxFilePathLength = MAX_PATH - 1; 38 const uint32_t kMaxFilePathLength = MAX_PATH - 1;
34 const uint32 kMaxFileNameLength = MAX_PATH - 1; 39 const uint32_t kMaxFileNameLength = MAX_PATH - 1;
35 #elif defined(OS_POSIX) 40 #elif defined(OS_POSIX)
36 const uint32 kMaxFilePathLength = PATH_MAX - 1; 41 const uint32_t kMaxFilePathLength = PATH_MAX - 1;
37 const uint32 kMaxFileNameLength = NAME_MAX; 42 const uint32_t kMaxFileNameLength = NAME_MAX;
38 #endif 43 #endif
39 44
40 // Used to make long filenames. 45 // Used to make long filenames.
41 std::string long_file_name( 46 std::string long_file_name(
42 "EFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz01234567" 47 "EFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz01234567"
43 "89ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz012345" 48 "89ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz012345"
44 "6789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz0123" 49 "6789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz0123"
45 "456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789a"); 50 "456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789a");
46 51
47 bool HasOrdinalNumber(const base::FilePath::StringType& filename) { 52 bool HasOrdinalNumber(const base::FilePath::StringType& filename) {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 const base::FilePath save_dir(FPL("test_dir")); 246 const base::FilePath save_dir(FPL("test_dir"));
242 const base::FilePath::StringType ext(FPL_HTML_EXTENSION); 247 const base::FilePath::StringType ext(FPL_HTML_EXTENSION);
243 base::FilePath::StringType filename = 248 base::FilePath::StringType filename =
244 #if defined(OS_WIN) 249 #if defined(OS_WIN)
245 base::ASCIIToUTF16(long_file_name); 250 base::ASCIIToUTF16(long_file_name);
246 #else 251 #else
247 long_file_name; 252 long_file_name;
248 #endif 253 #endif
249 254
250 // Test that the filename + extension doesn't exceed kMaxFileNameLength 255 // Test that the filename + extension doesn't exceed kMaxFileNameLength
251 uint32 max_path = SavePackage::GetMaxPathLengthForDirectory(save_dir); 256 uint32_t max_path = SavePackage::GetMaxPathLengthForDirectory(save_dir);
252 ASSERT_TRUE(SavePackage::GetSafePureFileName(save_dir, ext, max_path, 257 ASSERT_TRUE(SavePackage::GetSafePureFileName(save_dir, ext, max_path,
253 &filename)); 258 &filename));
254 EXPECT_TRUE(filename.length() <= kMaxFileNameLength-ext.length()); 259 EXPECT_TRUE(filename.length() <= kMaxFileNameLength-ext.length());
255 } 260 }
256 261
257 static const struct { 262 static const struct {
258 const base::FilePath::CharType* page_title; 263 const base::FilePath::CharType* page_title;
259 const base::FilePath::CharType* expected_name; 264 const base::FilePath::CharType* expected_name;
260 } kExtensionTestCases[] = { 265 } kExtensionTestCases[] = {
261 // Extension is preserved if it is already proper for HTML. 266 // Extension is preserved if it is already proper for HTML.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 { FPL("filename.html"), FPL("filename.html"), 323 { FPL("filename.html"), FPL("filename.html"),
319 "application/xhtml+xml" }, 324 "application/xhtml+xml" },
320 { FPL("filename"), FPL("filename.xhtml"), "application/xhtml+xml" }, 325 { FPL("filename"), FPL("filename.xhtml"), "application/xhtml+xml" },
321 { FPL("filename.txt"), FPL("filename.txt"), "text/plain" }, 326 { FPL("filename.txt"), FPL("filename.txt"), "text/plain" },
322 { FPL("filename"), FPL("filename.txt"), "text/plain" }, 327 { FPL("filename"), FPL("filename.txt"), "text/plain" },
323 { FPL("filename.css"), FPL("filename.css"), "text/css" }, 328 { FPL("filename.css"), FPL("filename.css"), "text/css" },
324 { FPL("filename"), FPL("filename.css"), "text/css" }, 329 { FPL("filename"), FPL("filename.css"), "text/css" },
325 { FPL("filename.abc"), FPL("filename.abc"), "unknown/unknown" }, 330 { FPL("filename.abc"), FPL("filename.abc"), "unknown/unknown" },
326 { FPL("filename"), FPL("filename"), "unknown/unknown" }, 331 { FPL("filename"), FPL("filename"), "unknown/unknown" },
327 }; 332 };
328 for (uint32 i = 0; i < arraysize(kExtensionTests); ++i) { 333 for (uint32_t i = 0; i < arraysize(kExtensionTests); ++i) {
329 base::FilePath original = base::FilePath(kExtensionTests[i].page_title); 334 base::FilePath original = base::FilePath(kExtensionTests[i].page_title);
330 base::FilePath expected = base::FilePath(kExtensionTests[i].expected_name); 335 base::FilePath expected = base::FilePath(kExtensionTests[i].expected_name);
331 std::string mime_type(kExtensionTests[i].contents_mime_type); 336 std::string mime_type(kExtensionTests[i].contents_mime_type);
332 base::FilePath actual = EnsureMimeExtension(original, mime_type); 337 base::FilePath actual = EnsureMimeExtension(original, mime_type);
333 EXPECT_EQ(expected.value(), actual.value()) << "Failed for page title: " << 338 EXPECT_EQ(expected.value(), actual.value()) << "Failed for page title: " <<
334 kExtensionTests[i].page_title << " MIME:" << mime_type; 339 kExtensionTests[i].page_title << " MIME:" << mime_type;
335 } 340 }
336 } 341 }
337 342
338 // Test that the suggested names generated by SavePackage are reasonable: 343 // Test that the suggested names generated by SavePackage are reasonable:
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 GURL mock_url = net::URLRequestMockHTTPJob::GetMockUrl("save_page/a.htm"); 428 GURL mock_url = net::URLRequestMockHTTPJob::GetMockUrl("save_page/a.htm");
424 GURL view_source_url = 429 GURL view_source_url =
425 GURL(kViewSourceScheme + std::string(":") + mock_url.spec()); 430 GURL(kViewSourceScheme + std::string(":") + mock_url.spec());
426 GURL actual_url = net::URLRequestMockHTTPJob::GetMockUrl("save_page/a.htm"); 431 GURL actual_url = net::URLRequestMockHTTPJob::GetMockUrl("save_page/a.htm");
427 NavigateAndCommit(view_source_url); 432 NavigateAndCommit(view_source_url);
428 EXPECT_EQ(actual_url, GetUrlToBeSaved()); 433 EXPECT_EQ(actual_url, GetUrlToBeSaved());
429 EXPECT_EQ(view_source_url, contents()->GetLastCommittedURL()); 434 EXPECT_EQ(view_source_url, contents()->GetLastCommittedURL());
430 } 435 }
431 436
432 } // namespace content 437 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/save_package.cc ('k') | content/browser/download/save_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698