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

Side by Side Diff: webkit/fileapi/syncable/syncable_file_system_util_unittest.cc

Issue 15806012: Move webkit/fileapi/syncable/* code to webkit/browser/fileapi (final!) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/fileapi/syncable/syncable_file_system_util.h"
6
7 #include "base/logging.h"
8 #include "base/message_loop.h"
9 #include "base/message_loop_proxy.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "webkit/browser/fileapi/external_mount_points.h"
12 #include "webkit/common/fileapi/file_system_types.h"
13 #include "webkit/fileapi/syncable/canned_syncable_file_system.h"
14 #include "webkit/fileapi/syncable/local_file_sync_context.h"
15
16 using fileapi::ExternalMountPoints;
17 using fileapi::FileSystemURL;
18 using fileapi::ScopedExternalFileSystem;
19
20 namespace sync_file_system {
21
22 namespace {
23
24 const char kSyncableFileSystemRootURI[] =
25 "filesystem:http://www.example.com/external/service/";
26 const char kNonRegisteredFileSystemRootURI[] =
27 "filesystem:http://www.example.com/external/non_registered/";
28 const char kNonSyncableFileSystemRootURI[] =
29 "filesystem:http://www.example.com/temporary/";
30
31 const char kOrigin[] = "http://www.example.com/";
32 const char kServiceName[] = "service";
33 const base::FilePath::CharType kPath[] = FILE_PATH_LITERAL("dir/file");
34
35 FileSystemURL CreateFileSystemURL(const std::string& url) {
36 return ExternalMountPoints::GetSystemInstance()->CrackURL(GURL(url));
37 }
38
39 base::FilePath CreateNormalizedFilePath(const base::FilePath::CharType* path) {
40 return base::FilePath(path).NormalizePathSeparators();
41 }
42
43 } // namespace
44
45 TEST(SyncableFileSystemUtilTest, GetSyncableFileSystemRootURI) {
46 const GURL root = GetSyncableFileSystemRootURI(GURL(kOrigin), kServiceName);
47 EXPECT_TRUE(root.is_valid());
48 EXPECT_EQ(GURL(kSyncableFileSystemRootURI), root);
49 }
50
51 TEST(SyncableFileSystemUtilTest, CreateSyncableFileSystemURL) {
52 ScopedExternalFileSystem scoped_fs(
53 kServiceName, fileapi::kFileSystemTypeSyncable, base::FilePath());
54
55 const base::FilePath path(kPath);
56 const FileSystemURL expected_url =
57 CreateFileSystemURL(kSyncableFileSystemRootURI + path.AsUTF8Unsafe());
58 const FileSystemURL url =
59 CreateSyncableFileSystemURL(GURL(kOrigin), kServiceName, path);
60
61 EXPECT_TRUE(url.is_valid());
62 EXPECT_EQ(expected_url, url);
63 }
64
65 TEST(SyncableFileSystemUtilTest,
66 SerializeAndDesirializeSyncableFileSystemURL) {
67 ScopedExternalFileSystem scoped_fs(
68 kServiceName, fileapi::kFileSystemTypeSyncable, base::FilePath());
69
70 const std::string expected_url_str = kSyncableFileSystemRootURI +
71 CreateNormalizedFilePath(kPath).AsUTF8Unsafe();
72 const FileSystemURL expected_url = CreateFileSystemURL(expected_url_str);
73 const FileSystemURL url = CreateSyncableFileSystemURL(
74 GURL(kOrigin), kServiceName, base::FilePath(kPath));
75
76 std::string serialized;
77 EXPECT_TRUE(SerializeSyncableFileSystemURL(url, &serialized));
78 EXPECT_EQ(expected_url_str, serialized);
79
80 FileSystemURL deserialized;
81 EXPECT_TRUE(DeserializeSyncableFileSystemURL(serialized, &deserialized));
82 EXPECT_TRUE(deserialized.is_valid());
83 EXPECT_EQ(expected_url, deserialized);
84 }
85
86 TEST(SyncableFileSystemUtilTest,
87 FailInSerializingAndDeserializingSyncableFileSystemURL) {
88 ScopedExternalFileSystem scoped_fs(
89 kServiceName, fileapi::kFileSystemTypeSyncable, base::FilePath());
90
91 const base::FilePath normalized_path = CreateNormalizedFilePath(kPath);
92 const std::string non_registered_url =
93 kNonRegisteredFileSystemRootURI + normalized_path.AsUTF8Unsafe();
94 const std::string non_syncable_url =
95 kNonSyncableFileSystemRootURI + normalized_path.AsUTF8Unsafe();
96
97 // Expected to fail in serializing URLs of non-registered filesystem and
98 // non-syncable filesystem.
99 std::string serialized;
100 EXPECT_FALSE(SerializeSyncableFileSystemURL(
101 CreateFileSystemURL(non_registered_url), &serialized));
102 EXPECT_FALSE(SerializeSyncableFileSystemURL(
103 CreateFileSystemURL(non_syncable_url), &serialized));
104
105 // Expected to fail in deserializing a string that represents URLs of
106 // non-registered filesystem and non-syncable filesystem.
107 FileSystemURL deserialized;
108 EXPECT_FALSE(DeserializeSyncableFileSystemURL(
109 non_registered_url, &deserialized));
110 EXPECT_FALSE(DeserializeSyncableFileSystemURL(
111 non_syncable_url, &deserialized));
112 }
113
114 TEST(SyncableFileSystemUtilTest, SerializeBeforeOpenFileSystem) {
115 const std::string serialized = kSyncableFileSystemRootURI +
116 CreateNormalizedFilePath(kPath).AsUTF8Unsafe();
117 FileSystemURL deserialized;
118 base::MessageLoop message_loop;
119
120 // Setting up a full syncable filesystem environment.
121 CannedSyncableFileSystem file_system(GURL(kOrigin), kServiceName,
122 base::MessageLoopProxy::current(),
123 base::MessageLoopProxy::current());
124 file_system.SetUp();
125 scoped_refptr<LocalFileSyncContext> sync_context =
126 new LocalFileSyncContext(base::MessageLoopProxy::current(),
127 base::MessageLoopProxy::current());
128
129 // Before calling initialization we would not be able to get a valid
130 // deserialized URL.
131 EXPECT_FALSE(DeserializeSyncableFileSystemURL(serialized, &deserialized));
132 EXPECT_FALSE(deserialized.is_valid());
133
134 ASSERT_EQ(sync_file_system::SYNC_STATUS_OK,
135 file_system.MaybeInitializeFileSystemContext(sync_context));
136
137 // After initialization this should be ok (even before opening the file
138 // system).
139 EXPECT_TRUE(DeserializeSyncableFileSystemURL(serialized, &deserialized));
140 EXPECT_TRUE(deserialized.is_valid());
141
142 // Shutting down.
143 file_system.TearDown();
144 RevokeSyncableFileSystem(kServiceName);
145 sync_context->ShutdownOnUIThread();
146 sync_context = NULL;
147 base::MessageLoop::current()->RunUntilIdle();
148 }
149
150 TEST(SyncableFileSystemUtilTest, SyncableFileSystemURL_IsParent) {
151 ScopedExternalFileSystem scoped1("foo", fileapi::kFileSystemTypeSyncable,
152 base::FilePath());
153 ScopedExternalFileSystem scoped2("bar", fileapi::kFileSystemTypeSyncable,
154 base::FilePath());
155
156 const std::string root1 = sync_file_system::GetSyncableFileSystemRootURI(
157 GURL("http://example.com"), "foo").spec();
158 const std::string root2 = sync_file_system::GetSyncableFileSystemRootURI(
159 GURL("http://example.com"), "bar").spec();
160
161 const std::string parent("dir");
162 const std::string child("dir/child");
163
164 // True case.
165 EXPECT_TRUE(CreateFileSystemURL(root1 + parent).IsParent(
166 CreateFileSystemURL(root1 + child)));
167 EXPECT_TRUE(CreateFileSystemURL(root2 + parent).IsParent(
168 CreateFileSystemURL(root2 + child)));
169
170 // False case: different filesystem ID.
171 EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent(
172 CreateFileSystemURL(root2 + child)));
173 EXPECT_FALSE(CreateFileSystemURL(root2 + parent).IsParent(
174 CreateFileSystemURL(root1 + child)));
175 }
176
177 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « webkit/fileapi/syncable/syncable_file_system_util.cc ('k') | webkit/fileapi/webkit_fileapi.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698