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

Side by Side Diff: components/resource_provider/file_utils_unittest.cc

Issue 1942473002: Eliminate mojo:resource_provider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 7 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 | « components/resource_provider/file_utils.cc ('k') | components/resource_provider/main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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.
4
5 #include "components/resource_provider/file_utils.h"
6
7 #include <stddef.h>
8
9 #include "base/files/file_path.h"
10 #include "base/macros.h"
11 #include "base/path_service.h"
12 #include "base/strings/string_util.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace resource_provider {
16
17 // Assertions for invalid app paths.
18 TEST(FileUtilsTest, InvalidAppPath) {
19 struct TestCase {
20 std::string name;
21 };
22 struct TestCase invalid_cases[]{
23 {"http://foo"}, // Must start with 'mojo:'.
24 {"mojo:."}, // Don't allow '.'.
25 {"mojo:.."}, // Don't allow '..'.
26 {"mojo:foo/."}, // Don't allow '.'.
27 {"mojo:bar/.."}, // Don't allow '..'.
28 };
29
30 for (size_t i = 0; i < arraysize(invalid_cases); ++i) {
31 base::FilePath resulting_path(GetPathForApplicationName(
32 invalid_cases[i].name));
33 EXPECT_TRUE(resulting_path.empty()) << "i=" << i
34 << " input=" << invalid_cases[i].name
35 << " result=" << resulting_path.value();
36 }
37 }
38
39 // Assertions for invalid app paths.
40 TEST(FileUtilsTest, InvalidResourcePath) {
41 struct TestCase {
42 std::string path;
43 };
44 struct TestCase invalid_cases[]{
45 {"."},
46 {".."},
47 {"foo/."},
48 {"bar/.."},
49 {"foo/./bar"},
50 {"bar/../baz"},
51 {"bar/baz/"},
52 {"bar//baz/"},
53 };
54
55 const base::FilePath app_path(GetPathForApplicationName("mojo:test"));
56 ASSERT_FALSE(app_path.empty());
57
58 for (size_t i = 0; i < arraysize(invalid_cases); ++i) {
59 base::FilePath resulting_path(
60 GetPathForResourceNamed(app_path, invalid_cases[i].path));
61 EXPECT_TRUE(resulting_path.empty()) << i
62 << " input=" << invalid_cases[i].path
63 << " result=" << resulting_path.value();
64 }
65 }
66
67 TEST(FileUtilsTest, ValidPaths) {
68 const base::FilePath app_path(GetPathForApplicationName("mojo:test"));
69 ASSERT_FALSE(app_path.empty());
70
71 // Trivial single path element.
72 const base::FilePath trivial_path(
73 GetPathForResourceNamed(app_path, "single"));
74 EXPECT_EQ(app_path.AppendASCII("single").value(), trivial_path.value());
75
76 // Two path elements.
77 const base::FilePath two_paths(GetPathForResourceNamed(app_path, "a/b"));
78 EXPECT_EQ(app_path.AppendASCII("a").AppendASCII("b").value(),
79 two_paths.value());
80 }
81
82 } // namespace resource_provider
OLDNEW
« no previous file with comments | « components/resource_provider/file_utils.cc ('k') | components/resource_provider/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698