Update V8 to version 4.7.1.
[chromium-blink-merge.git] / components / resource_provider / file_utils_unittest.cc
blob96de984df38aae37c2584a60728c1d4c74ba5fc7
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.
5 #include "components/resource_provider/file_utils.h"
7 #include "base/files/file_path.h"
8 #include "base/path_service.h"
9 #include "base/strings/string_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "url/gurl.h"
13 namespace resource_provider {
15 // Assertions for invalid app paths.
16 TEST(FileUtilsTest, InvalidAppPath) {
17 struct TestCase {
18 std::string url;
20 struct TestCase invalid_cases[]{
21 {"http://foo"}, // Must start with 'mojo:'.
22 {"mojo://."}, // Don't allow '.'.
23 {"mojo://.."}, // Don't allow '..'.
24 {"mojo://foo/."}, // Don't allow '.'.
25 {"mojo://bar/.."}, // Don't allow '..'.
28 for (size_t i = 0; i < arraysize(invalid_cases); ++i) {
29 const GURL url(invalid_cases[i].url);
30 base::FilePath resulting_path(GetPathForApplicationUrl(url));
31 EXPECT_TRUE(resulting_path.empty()) << "i=" << i
32 << " input=" << invalid_cases[i].url
33 << " result=" << resulting_path.value();
37 // Assertions for invalid app paths.
38 TEST(FileUtilsTest, InvalidResourcePath) {
39 struct TestCase {
40 std::string path;
42 struct TestCase invalid_cases[]{
43 {"."},
44 {".."},
45 {"foo/."},
46 {"bar/.."},
47 {"foo/./bar"},
48 {"bar/../baz"},
49 {"bar/baz/"},
50 {"bar//baz/"},
53 const base::FilePath app_path(GetPathForApplicationUrl(GURL("mojo:test")));
54 ASSERT_FALSE(app_path.empty());
56 for (size_t i = 0; i < arraysize(invalid_cases); ++i) {
57 base::FilePath resulting_path(
58 GetPathForResourceNamed(app_path, invalid_cases[i].path));
59 EXPECT_TRUE(resulting_path.empty()) << i
60 << " input=" << invalid_cases[i].path
61 << " result=" << resulting_path.value();
65 TEST(FileUtilsTest, ValidPaths) {
66 const base::FilePath app_path(GetPathForApplicationUrl(GURL("mojo:test")));
67 ASSERT_FALSE(app_path.empty());
69 // Trivial single path element.
70 const base::FilePath trivial_path(
71 GetPathForResourceNamed(app_path, "single"));
72 EXPECT_EQ(app_path.AppendASCII("single").value(), trivial_path.value());
74 // Two path elements.
75 const base::FilePath two_paths(GetPathForResourceNamed(app_path, "a/b"));
76 EXPECT_EQ(app_path.AppendASCII("a").AppendASCII("b").value(),
77 two_paths.value());
80 } // namespace resource_provider