OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/drive/drive_api_util.h" | 5 #include "chrome/browser/drive/drive_api_util.h" |
6 | 6 |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/md5.h" | 8 #include "base/md5.h" |
9 #include "google_apis/drive/drive_api_parser.h" | 9 #include "google_apis/drive/drive_api_parser.h" |
10 #include "google_apis/drive/gdata_wapi_parser.h" | 10 #include "google_apis/drive/gdata_wapi_parser.h" |
hashimoto
2015/01/22 08:02:01
nit: Still need to include this?
fukino
2015/01/22 09:02:32
Thanks! removed.
| |
11 #include "google_apis/drive/test_util.h" | 11 #include "google_apis/drive/test_util.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
14 | 14 |
15 namespace drive { | 15 namespace drive { |
16 namespace util { | 16 namespace util { |
17 | 17 |
18 TEST(DriveApiUtilTest, EscapeQueryStringValue) { | 18 TEST(DriveApiUtilTest, EscapeQueryStringValue) { |
19 EXPECT_EQ("abcde", EscapeQueryStringValue("abcde")); | 19 EXPECT_EQ("abcde", EscapeQueryStringValue("abcde")); |
20 EXPECT_EQ("\\'", EscapeQueryStringValue("'")); | 20 EXPECT_EQ("\\'", EscapeQueryStringValue("'")); |
(...skipping 25 matching lines...) Expand all Loading... | |
46 | 46 |
47 // Empty tokens should be simply ignored. | 47 // Empty tokens should be simply ignored. |
48 EXPECT_EQ("", TranslateQuery("-")); | 48 EXPECT_EQ("", TranslateQuery("-")); |
49 EXPECT_EQ("", TranslateQuery("\"\"")); | 49 EXPECT_EQ("", TranslateQuery("\"\"")); |
50 EXPECT_EQ("", TranslateQuery("-\"\"")); | 50 EXPECT_EQ("", TranslateQuery("-\"\"")); |
51 EXPECT_EQ("", TranslateQuery("\"\"\"\"")); | 51 EXPECT_EQ("", TranslateQuery("\"\"\"\"")); |
52 EXPECT_EQ("", TranslateQuery("\"\" \"\"")); | 52 EXPECT_EQ("", TranslateQuery("\"\" \"\"")); |
53 EXPECT_EQ("fullText contains 'dog'", TranslateQuery("\"\" dog \"\"")); | 53 EXPECT_EQ("fullText contains 'dog'", TranslateQuery("\"\" dog \"\"")); |
54 } | 54 } |
55 | 55 |
56 TEST(FileSystemUtilTest, ExtractResourceIdFromUrl) { | |
57 EXPECT_EQ("file:2_file_resource_id", ExtractResourceIdFromUrl( | |
58 GURL("https://file1_link_self/file:2_file_resource_id"))); | |
59 // %3A should be unescaped. | |
60 EXPECT_EQ("file:2_file_resource_id", ExtractResourceIdFromUrl( | |
61 GURL("https://file1_link_self/file%3A2_file_resource_id"))); | |
62 | |
63 // The resource ID cannot be extracted, hence empty. | |
64 EXPECT_EQ("", ExtractResourceIdFromUrl(GURL("https://www.example.com/"))); | |
65 } | |
66 | |
67 TEST(FileSystemUtilTest, CanonicalizeResourceId) { | 56 TEST(FileSystemUtilTest, CanonicalizeResourceId) { |
68 std::string resource_id("1YsCnrMxxgp7LDdtlFDt-WdtEIth89vA9inrILtvK-Ug"); | 57 std::string resource_id("1YsCnrMxxgp7LDdtlFDt-WdtEIth89vA9inrILtvK-Ug"); |
69 | 58 |
70 // New style ID is unchanged. | 59 // New style ID is unchanged. |
71 EXPECT_EQ(resource_id, CanonicalizeResourceId(resource_id)); | 60 EXPECT_EQ(resource_id, CanonicalizeResourceId(resource_id)); |
72 | 61 |
73 // Drop prefixes from old style IDs. | 62 // Drop prefixes from old style IDs. |
74 EXPECT_EQ(resource_id, CanonicalizeResourceId("document:" + resource_id)); | 63 EXPECT_EQ(resource_id, CanonicalizeResourceId("document:" + resource_id)); |
75 EXPECT_EQ(resource_id, CanonicalizeResourceId("spreadsheet:" + resource_id)); | 64 EXPECT_EQ(resource_id, CanonicalizeResourceId("spreadsheet:" + resource_id)); |
76 EXPECT_EQ(resource_id, CanonicalizeResourceId("presentation:" + resource_id)); | 65 EXPECT_EQ(resource_id, CanonicalizeResourceId("presentation:" + resource_id)); |
77 EXPECT_EQ(resource_id, CanonicalizeResourceId("drawing:" + resource_id)); | 66 EXPECT_EQ(resource_id, CanonicalizeResourceId("drawing:" + resource_id)); |
78 EXPECT_EQ(resource_id, CanonicalizeResourceId("table:" + resource_id)); | 67 EXPECT_EQ(resource_id, CanonicalizeResourceId("table:" + resource_id)); |
79 EXPECT_EQ(resource_id, CanonicalizeResourceId("externalapp:" + resource_id)); | 68 EXPECT_EQ(resource_id, CanonicalizeResourceId("externalapp:" + resource_id)); |
80 } | 69 } |
81 | 70 |
82 TEST(FileSystemUtilTest, ConvertFileResourceToResource_Parents) { | |
83 google_apis::FileResource file_resource; | |
84 | |
85 std::vector<GURL> expected_links; | |
86 expected_links.push_back(GURL("http://server/id1")); | |
87 expected_links.push_back(GURL("http://server/id2")); | |
88 expected_links.push_back(GURL("http://server/id3")); | |
89 | |
90 for (size_t i = 0; i < expected_links.size(); ++i) { | |
91 google_apis::ParentReference parent; | |
92 parent.set_parent_link(expected_links[i]); | |
93 file_resource.mutable_parents()->push_back(parent); | |
94 } | |
95 | |
96 scoped_ptr<google_apis::ResourceEntry> entry( | |
97 ConvertFileResourceToResourceEntry(file_resource)); | |
98 std::vector<GURL> actual_links; | |
99 for (size_t i = 0; i < entry->links().size(); ++i) { | |
100 if (entry->links()[i]->type() == google_apis::Link::LINK_PARENT) | |
101 actual_links.push_back(entry->links()[i]->href()); | |
102 } | |
103 | |
104 EXPECT_EQ(expected_links, actual_links); | |
105 } | |
106 | |
107 TEST(FileSystemUtilTest, ConvertFileResourceToResourceEntryImageMediaMetadata) { | |
108 google_apis::FileResource file_resource_all_fields; | |
109 google_apis::FileResource file_resource_zero_fields; | |
110 google_apis::FileResource file_resource_no_fields; | |
111 // Set up FileResource instances; | |
112 { | |
113 { | |
114 google_apis::ImageMediaMetadata* image_media_metadata = | |
115 file_resource_all_fields.mutable_image_media_metadata(); | |
116 image_media_metadata->set_width(640); | |
117 image_media_metadata->set_height(480); | |
118 image_media_metadata->set_rotation(90); | |
119 } | |
120 { | |
121 google_apis::ImageMediaMetadata* image_media_metadata = | |
122 file_resource_zero_fields.mutable_image_media_metadata(); | |
123 image_media_metadata->set_width(0); | |
124 image_media_metadata->set_height(0); | |
125 image_media_metadata->set_rotation(0); | |
126 } | |
127 } | |
128 | |
129 // Verify the converted values. | |
130 { | |
131 scoped_ptr<google_apis::ResourceEntry> resource_entry( | |
132 ConvertFileResourceToResourceEntry(file_resource_all_fields)); | |
133 | |
134 EXPECT_EQ(640, resource_entry->image_width()); | |
135 EXPECT_EQ(480, resource_entry->image_height()); | |
136 EXPECT_EQ(90, resource_entry->image_rotation()); | |
137 } | |
138 { | |
139 scoped_ptr<google_apis::ResourceEntry> resource_entry( | |
140 ConvertFileResourceToResourceEntry(file_resource_zero_fields)); | |
141 | |
142 EXPECT_EQ(0, resource_entry->image_width()); | |
143 EXPECT_EQ(0, resource_entry->image_height()); | |
144 EXPECT_EQ(0, resource_entry->image_rotation()); | |
145 } | |
146 { | |
147 scoped_ptr<google_apis::ResourceEntry> resource_entry( | |
148 ConvertFileResourceToResourceEntry(file_resource_no_fields)); | |
149 | |
150 EXPECT_EQ(-1, resource_entry->image_width()); | |
151 EXPECT_EQ(-1, resource_entry->image_height()); | |
152 EXPECT_EQ(-1, resource_entry->image_rotation()); | |
153 } | |
154 } | |
155 | |
156 TEST(DriveAPIUtilTest, GetMd5Digest) { | 71 TEST(DriveAPIUtilTest, GetMd5Digest) { |
157 base::ScopedTempDir temp_dir; | 72 base::ScopedTempDir temp_dir; |
158 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 73 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
159 | 74 |
160 base::FilePath path = temp_dir.path().AppendASCII("test.txt"); | 75 base::FilePath path = temp_dir.path().AppendASCII("test.txt"); |
161 const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789"; | 76 const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789"; |
162 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(path, kTestData)); | 77 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(path, kTestData)); |
163 | 78 |
164 EXPECT_EQ(base::MD5String(kTestData), GetMd5Digest(path)); | 79 EXPECT_EQ(base::MD5String(kTestData), GetMd5Digest(path)); |
165 } | 80 } |
(...skipping 21 matching lines...) Expand all Loading... | |
187 EXPECT_FALSE( | 102 EXPECT_FALSE( |
188 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.docx"))); | 103 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.docx"))); |
189 EXPECT_FALSE( | 104 EXPECT_FALSE( |
190 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.jpg"))); | 105 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.jpg"))); |
191 EXPECT_FALSE( | 106 EXPECT_FALSE( |
192 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.gmap"))); | 107 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.gmap"))); |
193 } | 108 } |
194 | 109 |
195 } // namespace util | 110 } // namespace util |
196 } // namespace drive | 111 } // namespace drive |
OLD | NEW |