OLD | NEW |
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/syncable/syncable_file_system_util.h" | 5 #include "webkit/fileapi/syncable/syncable_file_system_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "webkit/fileapi/external_mount_points.h" | 11 #include "webkit/fileapi/external_mount_points.h" |
12 #include "webkit/fileapi/syncable/canned_syncable_file_system.h" | 12 #include "webkit/fileapi/syncable/canned_syncable_file_system.h" |
13 #include "webkit/fileapi/syncable/local_file_sync_context.h" | 13 #include "webkit/fileapi/syncable/local_file_sync_context.h" |
14 | 14 |
15 namespace fileapi { | 15 namespace fileapi { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 const char kSyncableFileSystemRootURI[] = | 19 const char kSyncableFileSystemRootURI[] = |
20 "filesystem:http://www.example.com/external/service/"; | 20 "filesystem:http://www.example.com/external/service/"; |
21 const char kNonRegisteredFileSystemRootURI[] = | 21 const char kNonRegisteredFileSystemRootURI[] = |
22 "filesystem:http://www.example.com/external/non_registered/"; | 22 "filesystem:http://www.example.com/external/non_registered/"; |
23 const char kNonSyncableFileSystemRootURI[] = | 23 const char kNonSyncableFileSystemRootURI[] = |
24 "filesystem:http://www.example.com/temporary/"; | 24 "filesystem:http://www.example.com/temporary/"; |
25 | 25 |
26 const char kOrigin[] = "http://www.example.com/"; | 26 const char kOrigin[] = "http://www.example.com/"; |
27 const char kServiceName[] = "service"; | 27 const char kServiceName[] = "service"; |
28 const FilePath::CharType kPath[] = FILE_PATH_LITERAL("dir/file"); | 28 const base::FilePath::CharType kPath[] = FILE_PATH_LITERAL("dir/file"); |
29 | 29 |
30 FileSystemURL CreateFileSystemURL(const std::string& url) { | 30 FileSystemURL CreateFileSystemURL(const std::string& url) { |
31 return ExternalMountPoints::GetSystemInstance()->CrackURL(GURL(url)); | 31 return ExternalMountPoints::GetSystemInstance()->CrackURL(GURL(url)); |
32 } | 32 } |
33 | 33 |
34 FilePath CreateNormalizedFilePath(const FilePath::CharType* path) { | 34 base::FilePath CreateNormalizedFilePath(const base::FilePath::CharType* path) { |
35 return FilePath(path).NormalizePathSeparators(); | 35 return base::FilePath(path).NormalizePathSeparators(); |
36 } | 36 } |
37 | 37 |
38 } // namespace | 38 } // namespace |
39 | 39 |
40 TEST(SyncableFileSystemUtilTest, GetSyncableFileSystemRootURI) { | 40 TEST(SyncableFileSystemUtilTest, GetSyncableFileSystemRootURI) { |
41 const GURL root = GetSyncableFileSystemRootURI(GURL(kOrigin), kServiceName); | 41 const GURL root = GetSyncableFileSystemRootURI(GURL(kOrigin), kServiceName); |
42 EXPECT_TRUE(root.is_valid()); | 42 EXPECT_TRUE(root.is_valid()); |
43 EXPECT_EQ(GURL(kSyncableFileSystemRootURI), root); | 43 EXPECT_EQ(GURL(kSyncableFileSystemRootURI), root); |
44 } | 44 } |
45 | 45 |
46 TEST(SyncableFileSystemUtilTest, CreateSyncableFileSystemURL) { | 46 TEST(SyncableFileSystemUtilTest, CreateSyncableFileSystemURL) { |
47 ScopedExternalFileSystem scoped_fs( | 47 ScopedExternalFileSystem scoped_fs( |
48 kServiceName, kFileSystemTypeSyncable, FilePath()); | 48 kServiceName, kFileSystemTypeSyncable, base::FilePath()); |
49 | 49 |
50 const FilePath path(kPath); | 50 const base::FilePath path(kPath); |
51 const FileSystemURL expected_url = | 51 const FileSystemURL expected_url = |
52 CreateFileSystemURL(kSyncableFileSystemRootURI + path.AsUTF8Unsafe()); | 52 CreateFileSystemURL(kSyncableFileSystemRootURI + path.AsUTF8Unsafe()); |
53 const FileSystemURL url = | 53 const FileSystemURL url = |
54 CreateSyncableFileSystemURL(GURL(kOrigin), kServiceName, path); | 54 CreateSyncableFileSystemURL(GURL(kOrigin), kServiceName, path); |
55 | 55 |
56 EXPECT_TRUE(url.is_valid()); | 56 EXPECT_TRUE(url.is_valid()); |
57 EXPECT_EQ(expected_url, url); | 57 EXPECT_EQ(expected_url, url); |
58 } | 58 } |
59 | 59 |
60 TEST(SyncableFileSystemUtilTest, | 60 TEST(SyncableFileSystemUtilTest, |
61 SerializeAndDesirializeSyncableFileSystemURL) { | 61 SerializeAndDesirializeSyncableFileSystemURL) { |
62 ScopedExternalFileSystem scoped_fs( | 62 ScopedExternalFileSystem scoped_fs( |
63 kServiceName, kFileSystemTypeSyncable, FilePath()); | 63 kServiceName, kFileSystemTypeSyncable, base::FilePath()); |
64 | 64 |
65 const std::string expected_url_str = kSyncableFileSystemRootURI + | 65 const std::string expected_url_str = kSyncableFileSystemRootURI + |
66 CreateNormalizedFilePath(kPath).AsUTF8Unsafe(); | 66 CreateNormalizedFilePath(kPath).AsUTF8Unsafe(); |
67 const FileSystemURL expected_url = CreateFileSystemURL(expected_url_str); | 67 const FileSystemURL expected_url = CreateFileSystemURL(expected_url_str); |
68 const FileSystemURL url = | 68 const FileSystemURL url = |
69 CreateSyncableFileSystemURL(GURL(kOrigin), kServiceName, FilePath(kPath)); | 69 CreateSyncableFileSystemURL(GURL(kOrigin), kServiceName, base::FilePath(kP
ath)); |
70 | 70 |
71 std::string serialized; | 71 std::string serialized; |
72 EXPECT_TRUE(SerializeSyncableFileSystemURL(url, &serialized)); | 72 EXPECT_TRUE(SerializeSyncableFileSystemURL(url, &serialized)); |
73 EXPECT_EQ(expected_url_str, serialized); | 73 EXPECT_EQ(expected_url_str, serialized); |
74 | 74 |
75 FileSystemURL deserialized; | 75 FileSystemURL deserialized; |
76 EXPECT_TRUE(DeserializeSyncableFileSystemURL(serialized, &deserialized)); | 76 EXPECT_TRUE(DeserializeSyncableFileSystemURL(serialized, &deserialized)); |
77 EXPECT_TRUE(deserialized.is_valid()); | 77 EXPECT_TRUE(deserialized.is_valid()); |
78 EXPECT_EQ(expected_url, deserialized); | 78 EXPECT_EQ(expected_url, deserialized); |
79 } | 79 } |
80 | 80 |
81 TEST(SyncableFileSystemUtilTest, | 81 TEST(SyncableFileSystemUtilTest, |
82 FailInSerializingAndDeserializingSyncableFileSystemURL) { | 82 FailInSerializingAndDeserializingSyncableFileSystemURL) { |
83 ScopedExternalFileSystem scoped_fs( | 83 ScopedExternalFileSystem scoped_fs( |
84 kServiceName, kFileSystemTypeSyncable, FilePath()); | 84 kServiceName, kFileSystemTypeSyncable, base::FilePath()); |
85 | 85 |
86 const FilePath normalized_path = CreateNormalizedFilePath(kPath); | 86 const base::FilePath normalized_path = CreateNormalizedFilePath(kPath); |
87 const std::string non_registered_url = | 87 const std::string non_registered_url = |
88 kNonRegisteredFileSystemRootURI + normalized_path.AsUTF8Unsafe(); | 88 kNonRegisteredFileSystemRootURI + normalized_path.AsUTF8Unsafe(); |
89 const std::string non_syncable_url = | 89 const std::string non_syncable_url = |
90 kNonSyncableFileSystemRootURI + normalized_path.AsUTF8Unsafe(); | 90 kNonSyncableFileSystemRootURI + normalized_path.AsUTF8Unsafe(); |
91 | 91 |
92 // Expected to fail in serializing URLs of non-registered filesystem and | 92 // Expected to fail in serializing URLs of non-registered filesystem and |
93 // non-syncable filesystem. | 93 // non-syncable filesystem. |
94 std::string serialized; | 94 std::string serialized; |
95 EXPECT_FALSE(SerializeSyncableFileSystemURL( | 95 EXPECT_FALSE(SerializeSyncableFileSystemURL( |
96 CreateFileSystemURL(non_registered_url), &serialized)); | 96 CreateFileSystemURL(non_registered_url), &serialized)); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 136 |
137 // Shutting down. | 137 // Shutting down. |
138 file_system.TearDown(); | 138 file_system.TearDown(); |
139 RevokeSyncableFileSystem(kServiceName); | 139 RevokeSyncableFileSystem(kServiceName); |
140 sync_context->ShutdownOnUIThread(); | 140 sync_context->ShutdownOnUIThread(); |
141 sync_context = NULL; | 141 sync_context = NULL; |
142 MessageLoop::current()->RunUntilIdle(); | 142 MessageLoop::current()->RunUntilIdle(); |
143 } | 143 } |
144 | 144 |
145 } // namespace fileapi | 145 } // namespace fileapi |
OLD | NEW |