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

Side by Side Diff: webkit/fileapi/isolated_context_unittest.cc

Issue 9320059: Define FilePath::NormalizePathSeparators on all platforms (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « webkit/fileapi/isolated_context.cc ('k') | webkit/fileapi/obfuscated_file_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/fileapi/isolated_context.h" 5 #include "webkit/fileapi/isolated_context.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 13 matching lines...) Expand all
24 24
25 const FilePath kTestPaths[] = { 25 const FilePath kTestPaths[] = {
26 FilePath(DRIVE FPL("/a/b")), 26 FilePath(DRIVE FPL("/a/b")),
27 FilePath(DRIVE FPL("/c/d/e")), 27 FilePath(DRIVE FPL("/c/d/e")),
28 FilePath(DRIVE FPL("/h/")), 28 FilePath(DRIVE FPL("/h/")),
29 #if defined(FILE_PATH_USES_WIN_SEPARATORS) 29 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
30 FilePath(DRIVE FPL("\\foo\\bar")), 30 FilePath(DRIVE FPL("\\foo\\bar")),
31 #endif 31 #endif
32 }; 32 };
33 33
34 static FilePath NormalizePath(const FilePath& path) {
35 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
36 return path.NormalizeWindowsPathSeparators();
37 #else
38 return path;
39 #endif
40 }
41
42 } // namespace 34 } // namespace
43 35
44 class IsolatedContextTest : public testing::Test { 36 class IsolatedContextTest : public testing::Test {
45 public: 37 public:
46 IsolatedContextTest() { 38 IsolatedContextTest() {
47 for (size_t i = 0; i < arraysize(kTestPaths); ++i) 39 for (size_t i = 0; i < arraysize(kTestPaths); ++i)
48 fileset_.insert(NormalizePath(kTestPaths[i])); 40 fileset_.insert(kTestPaths[i].NormalizePathSeparators());
49 } 41 }
50 42
51 void SetUp() { 43 void SetUp() {
52 id_ = IsolatedContext::GetInstance()->RegisterIsolatedFileSystem(fileset_); 44 id_ = IsolatedContext::GetInstance()->RegisterIsolatedFileSystem(fileset_);
53 ASSERT_FALSE(id_.empty()); 45 ASSERT_FALSE(id_.empty());
54 } 46 }
55 47
56 void TearDown() { 48 void TearDown() {
57 IsolatedContext::GetInstance()->RevokeIsolatedFileSystem(id_); 49 IsolatedContext::GetInstance()->RevokeIsolatedFileSystem(id_);
58 } 50 }
(...skipping 22 matching lines...) Expand all
81 // See if the basename of each registered kTestPaths (that is what we 73 // See if the basename of each registered kTestPaths (that is what we
82 // register in SetUp() by RegisterIsolatedFileSystem) is properly cracked as 74 // register in SetUp() by RegisterIsolatedFileSystem) is properly cracked as
83 // a valid virtual path in the isolated filesystem. 75 // a valid virtual path in the isolated filesystem.
84 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { 76 for (size_t i = 0; i < arraysize(kTestPaths); ++i) {
85 FilePath virtual_path = isolated_context()->CreateVirtualPath( 77 FilePath virtual_path = isolated_context()->CreateVirtualPath(
86 id_, kTestPaths[i].BaseName()); 78 id_, kTestPaths[i].BaseName());
87 std::string cracked_id; 79 std::string cracked_id;
88 FilePath cracked_path; 80 FilePath cracked_path;
89 ASSERT_TRUE(isolated_context()->CrackIsolatedPath( 81 ASSERT_TRUE(isolated_context()->CrackIsolatedPath(
90 virtual_path, &cracked_id, &cracked_path)); 82 virtual_path, &cracked_id, &cracked_path));
91 ASSERT_EQ(NormalizePath(kTestPaths[i]).value(), cracked_path.value()); 83 ASSERT_EQ(kTestPaths[i].NormalizePathSeparators().value(),
84 cracked_path.value());
92 ASSERT_EQ(id_, cracked_id); 85 ASSERT_EQ(id_, cracked_id);
93 } 86 }
94 87
95 // Revoking the current one and registering a new (empty) one. 88 // Revoking the current one and registering a new (empty) one.
96 isolated_context()->RevokeIsolatedFileSystem(id_); 89 isolated_context()->RevokeIsolatedFileSystem(id_);
97 std::string id2 = isolated_context()->RegisterIsolatedFileSystem( 90 std::string id2 = isolated_context()->RegisterIsolatedFileSystem(
98 std::set<FilePath>()); 91 std::set<FilePath>());
99 92
100 // Make sure the GetTopLevelPaths returns true only for the new one. 93 // Make sure the GetTopLevelPaths returns true only for the new one.
101 ASSERT_TRUE(isolated_context()->GetTopLevelPaths(id2, &toplevels)); 94 ASSERT_TRUE(isolated_context()->GetTopLevelPaths(id2, &toplevels));
(...skipping 29 matching lines...) Expand all
131 id_, kTestPaths[i].BaseName().Append(relatives[j].path)); 124 id_, kTestPaths[i].BaseName().Append(relatives[j].path));
132 std::string cracked_id; 125 std::string cracked_id;
133 FilePath cracked_path; 126 FilePath cracked_path;
134 if (!relatives[j].valid) { 127 if (!relatives[j].valid) {
135 ASSERT_FALSE(isolated_context()->CrackIsolatedPath( 128 ASSERT_FALSE(isolated_context()->CrackIsolatedPath(
136 virtual_path, &cracked_id, &cracked_path)); 129 virtual_path, &cracked_id, &cracked_path));
137 continue; 130 continue;
138 } 131 }
139 ASSERT_TRUE(isolated_context()->CrackIsolatedPath( 132 ASSERT_TRUE(isolated_context()->CrackIsolatedPath(
140 virtual_path, &cracked_id, &cracked_path)); 133 virtual_path, &cracked_id, &cracked_path));
141 ASSERT_EQ(NormalizePath(kTestPaths[i].Append(relatives[j].path)).value(), 134 ASSERT_EQ(kTestPaths[i].Append(relatives[j].path)
135 .NormalizePathSeparators().value(),
142 cracked_path.value()); 136 cracked_path.value());
143 ASSERT_EQ(id_, cracked_id); 137 ASSERT_EQ(id_, cracked_id);
144 } 138 }
145 } 139 }
146 } 140 }
147 141
148 TEST_F(IsolatedContextTest, TestWithVirtualRoot) { 142 TEST_F(IsolatedContextTest, TestWithVirtualRoot) {
149 std::string cracked_id; 143 std::string cracked_id;
150 FilePath cracked_path; 144 FilePath cracked_path;
151 const FilePath root(FPL("/")); 145 const FilePath root(FPL("/"));
152 146
153 // Trying to crack virtual root "/" returns true but with empty cracked path 147 // Trying to crack virtual root "/" returns true but with empty cracked path
154 // as "/" of the isolated filesystem is a pure virtual directory 148 // as "/" of the isolated filesystem is a pure virtual directory
155 // that has no corresponding platform directory. 149 // that has no corresponding platform directory.
156 FilePath virtual_path = isolated_context()->CreateVirtualPath(id_, root); 150 FilePath virtual_path = isolated_context()->CreateVirtualPath(id_, root);
157 ASSERT_TRUE(isolated_context()->CrackIsolatedPath( 151 ASSERT_TRUE(isolated_context()->CrackIsolatedPath(
158 virtual_path, &cracked_id, &cracked_path)); 152 virtual_path, &cracked_id, &cracked_path));
159 ASSERT_EQ(FPL(""), cracked_path.value()); 153 ASSERT_EQ(FPL(""), cracked_path.value());
160 ASSERT_EQ(id_, cracked_id); 154 ASSERT_EQ(id_, cracked_id);
161 155
162 // Trying to crack "/foo" should fail (because "foo" is not the one 156 // Trying to crack "/foo" should fail (because "foo" is not the one
163 // included in the kTestPaths). 157 // included in the kTestPaths).
164 virtual_path = isolated_context()->CreateVirtualPath( 158 virtual_path = isolated_context()->CreateVirtualPath(
165 id_, FilePath(FPL("foo"))); 159 id_, FilePath(FPL("foo")));
166 ASSERT_FALSE(isolated_context()->CrackIsolatedPath( 160 ASSERT_FALSE(isolated_context()->CrackIsolatedPath(
167 virtual_path, &cracked_id, &cracked_path)); 161 virtual_path, &cracked_id, &cracked_path));
168 } 162 }
169 163
170 } // namespace fileapi 164 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/isolated_context.cc ('k') | webkit/fileapi/obfuscated_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698