Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / safe_browsing / path_sanitizer_unittest.cc
bloba23ae6b1b0d2c51e7dce432d47cd8fc946d529ea
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
3 // found in the LICENSE file.
5 #include "chrome/browser/safe_browsing/path_sanitizer.h"
7 #include <vector>
9 #include "base/logging.h"
10 #include "base/path_service.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace {
15 // Returns the root directory with a trailing separator. Works on all platforms.
16 base::FilePath GetRootDirectory() {
17 base::FilePath dir_temp;
18 if (!PathService::Get(base::DIR_TEMP, &dir_temp))
19 NOTREACHED();
21 std::vector<base::FilePath::StringType> components;
22 dir_temp.GetComponents(&components);
24 return base::FilePath(components[0]).AsEndingWithSeparator();
27 } // namespace
29 TEST(SafeBrowsingPathSanitizerTest, HomeDirectoryIsNotEmpty) {
30 safe_browsing::PathSanitizer path_sanitizer;
32 ASSERT_FALSE(path_sanitizer.GetHomeDirectory().empty());
35 TEST(SafeBrowsingPathSanitizerTest, DontStripHomeDirectoryTest) {
36 // Test with path not in home directory.
37 base::FilePath path =
38 GetRootDirectory().Append(FILE_PATH_LITERAL("not_in_home_directory.ext"));
39 base::FilePath path_expected = path;
41 safe_browsing::PathSanitizer path_sanitizer;
42 path_sanitizer.StripHomeDirectory(&path);
44 ASSERT_EQ(path.value(), path_expected.value());
47 TEST(SafeBrowsingPathSanitizerTest, DoStripHomeDirectoryTest) {
48 // Test with path in home directory.
49 safe_browsing::PathSanitizer path_sanitizer;
51 base::FilePath path = path_sanitizer.GetHomeDirectory().Append(
52 FILE_PATH_LITERAL("in_home_directory.ext"));
53 base::FilePath path_expected = base::FilePath(FILE_PATH_LITERAL("~")).Append(
54 FILE_PATH_LITERAL("in_home_directory.ext"));
56 path_sanitizer.StripHomeDirectory(&path);
58 ASSERT_EQ(path.value(), path_expected.value());