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

Side by Side Diff: chrome/browser/safe_browsing/path_sanitizer_unittest.cc

Issue 1420053005: Move code in components/safe_browsing_db and chrome/browser/s_b/ under the safe_browsing namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@02_components_move
Patch Set: Remove '// namespace safe_browsing' for a small fwd decl block. Created 5 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/safe_browsing/path_sanitizer.h" 5 #include "chrome/browser/safe_browsing/path_sanitizer.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace { 13 namespace {
14 14
15 // Returns the root directory with a trailing separator. Works on all platforms. 15 // Returns the root directory with a trailing separator. Works on all platforms.
16 base::FilePath GetRootDirectory() { 16 base::FilePath GetRootDirectory() {
17 base::FilePath dir_temp; 17 base::FilePath dir_temp;
18 if (!PathService::Get(base::DIR_TEMP, &dir_temp)) 18 if (!PathService::Get(base::DIR_TEMP, &dir_temp))
19 NOTREACHED(); 19 NOTREACHED();
20 20
21 std::vector<base::FilePath::StringType> components; 21 std::vector<base::FilePath::StringType> components;
22 dir_temp.GetComponents(&components); 22 dir_temp.GetComponents(&components);
23 23
24 return base::FilePath(components[0]).AsEndingWithSeparator(); 24 return base::FilePath(components[0]).AsEndingWithSeparator();
25 } 25 }
26 26
27 } // namespace 27 } // namespace
28 28
29 namespace safe_browsing {
30
29 TEST(SafeBrowsingPathSanitizerTest, HomeDirectoryIsNotEmpty) { 31 TEST(SafeBrowsingPathSanitizerTest, HomeDirectoryIsNotEmpty) {
30 safe_browsing::PathSanitizer path_sanitizer; 32 PathSanitizer path_sanitizer;
31 33
32 ASSERT_FALSE(path_sanitizer.GetHomeDirectory().empty()); 34 ASSERT_FALSE(path_sanitizer.GetHomeDirectory().empty());
33 } 35 }
34 36
35 TEST(SafeBrowsingPathSanitizerTest, DontStripHomeDirectoryTest) { 37 TEST(SafeBrowsingPathSanitizerTest, DontStripHomeDirectoryTest) {
36 // Test with path not in home directory. 38 // Test with path not in home directory.
37 base::FilePath path = 39 base::FilePath path =
38 GetRootDirectory().Append(FILE_PATH_LITERAL("not_in_home_directory.ext")); 40 GetRootDirectory().Append(FILE_PATH_LITERAL("not_in_home_directory.ext"));
39 base::FilePath path_expected = path; 41 base::FilePath path_expected = path;
40 42
41 safe_browsing::PathSanitizer path_sanitizer; 43 PathSanitizer path_sanitizer;
42 path_sanitizer.StripHomeDirectory(&path); 44 path_sanitizer.StripHomeDirectory(&path);
43 45
44 ASSERT_EQ(path.value(), path_expected.value()); 46 ASSERT_EQ(path.value(), path_expected.value());
45 } 47 }
46 48
47 TEST(SafeBrowsingPathSanitizerTest, DoStripHomeDirectoryTest) { 49 TEST(SafeBrowsingPathSanitizerTest, DoStripHomeDirectoryTest) {
48 // Test with path in home directory. 50 // Test with path in home directory.
49 safe_browsing::PathSanitizer path_sanitizer; 51 PathSanitizer path_sanitizer;
50 52
51 base::FilePath path = path_sanitizer.GetHomeDirectory().Append( 53 base::FilePath path = path_sanitizer.GetHomeDirectory().Append(
52 FILE_PATH_LITERAL("in_home_directory.ext")); 54 FILE_PATH_LITERAL("in_home_directory.ext"));
53 base::FilePath path_expected = base::FilePath(FILE_PATH_LITERAL("~")).Append( 55 base::FilePath path_expected = base::FilePath(FILE_PATH_LITERAL("~")).Append(
54 FILE_PATH_LITERAL("in_home_directory.ext")); 56 FILE_PATH_LITERAL("in_home_directory.ext"));
55 57
56 path_sanitizer.StripHomeDirectory(&path); 58 path_sanitizer.StripHomeDirectory(&path);
57 59
58 ASSERT_EQ(path.value(), path_expected.value()); 60 ASSERT_EQ(path.value(), path_expected.value());
59 } 61 }
62
63 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/local_two_phase_testserver.cc ('k') | chrome/browser/safe_browsing/ping_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698