OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/tools/dump_cache/url_to_filename_encoder.h" | 5 #include "net/tools/dump_cache/url_to_filename_encoder.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
| 10 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
12 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 using base::StringPiece; | 16 using base::StringPiece; |
16 using std::string; | 17 using std::string; |
17 | 18 |
18 namespace net { | 19 namespace net { |
19 | 20 |
20 #ifdef WIN32 | 21 #ifdef WIN32 |
21 char kDirSeparator = '\\'; | 22 char kDirSeparator = '\\'; |
22 char kOtherDirSeparator = '/'; | 23 char kOtherDirSeparator = '/'; |
23 #else | 24 #else |
24 char kDirSeparator = '/'; | 25 char kDirSeparator = '/'; |
25 char kOtherDirSeparator = '\\'; | 26 char kOtherDirSeparator = '\\'; |
26 #endif | 27 #endif |
27 | 28 |
28 class UrlToFilenameEncoderTest : public ::testing::Test { | 29 class UrlToFilenameEncoderTest : public ::testing::Test { |
29 protected: | 30 protected: |
30 UrlToFilenameEncoderTest() : escape_(1, UrlToFilenameEncoder::kEscapeChar), | 31 UrlToFilenameEncoderTest() : escape_(1, UrlToFilenameEncoder::kEscapeChar), |
31 dir_sep_(1, kDirSeparator) { | 32 dir_sep_(1, kDirSeparator) { |
32 } | 33 } |
33 | 34 |
34 void CheckSegmentLength(const StringPiece& escaped_word) { | 35 void CheckSegmentLength(const StringPiece& escaped_word) { |
35 std::vector<StringPiece> components; | 36 for (const base::StringPiece& component : |
36 Tokenize(escaped_word, StringPiece("/"), &components); | 37 base::SplitStringPiece(escaped_word, "/", base::KEEP_WHITESPACE, |
37 for (size_t i = 0; i < components.size(); ++i) { | 38 base::SPLIT_WANT_NONEMPTY)) { |
38 EXPECT_GE(UrlToFilenameEncoder::kMaximumSubdirectoryLength, | 39 EXPECT_GE(UrlToFilenameEncoder::kMaximumSubdirectoryLength, |
39 components[i].size()); | 40 component.size()); |
40 } | 41 } |
41 } | 42 } |
42 | 43 |
43 void CheckValidChars(const StringPiece& escaped_word, char invalid_slash) { | 44 void CheckValidChars(const StringPiece& escaped_word, char invalid_slash) { |
44 // These characters are invalid in Windows. We add in ', as that's pretty | 45 // These characters are invalid in Windows. We add in ', as that's pretty |
45 // inconvenient in a Unix filename. | 46 // inconvenient in a Unix filename. |
46 // | 47 // |
47 // See http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx | 48 // See http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx |
48 const string kInvalidChars = "<>:\"|?*'"; | 49 const string kInvalidChars = "<>:\"|?*'"; |
49 for (size_t i = 0; i < escaped_word.size(); ++i) { | 50 for (size_t i = 0; i < escaped_word.size(); ++i) { |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 EXPECT_EQ(long_word.size() + 4, escaped_word.size()); | 337 EXPECT_EQ(long_word.size() + 4, escaped_word.size()); |
337 ASSERT_LT(UrlToFilenameEncoder::kMaximumSubdirectoryLength, | 338 ASSERT_LT(UrlToFilenameEncoder::kMaximumSubdirectoryLength, |
338 escaped_word.size()); | 339 escaped_word.size()); |
339 // Check that the backslash got inserted at the correct spot. | 340 // Check that the backslash got inserted at the correct spot. |
340 EXPECT_EQ('\\', escaped_word[ | 341 EXPECT_EQ('\\', escaped_word[ |
341 UrlToFilenameEncoder::kMaximumSubdirectoryLength]); | 342 UrlToFilenameEncoder::kMaximumSubdirectoryLength]); |
342 } | 343 } |
343 | 344 |
344 } // namespace net | 345 } // namespace net |
345 | 346 |
OLD | NEW |