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

Side by Side Diff: chrome/browser/drive/drive_api_util_unittest.cc

Issue 861133002: Remove WAPI-related code, except the type definition of ResourceEntry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to review comments. Created 5 years, 11 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
OLDNEW
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"
11 #include "google_apis/drive/test_util.h" 10 #include "google_apis/drive/test_util.h"
12 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
13 #include "url/gurl.h" 12 #include "url/gurl.h"
14 13
15 namespace drive { 14 namespace drive {
16 namespace util { 15 namespace util {
17 16
18 TEST(DriveApiUtilTest, EscapeQueryStringValue) { 17 TEST(DriveApiUtilTest, EscapeQueryStringValue) {
19 EXPECT_EQ("abcde", EscapeQueryStringValue("abcde")); 18 EXPECT_EQ("abcde", EscapeQueryStringValue("abcde"));
20 EXPECT_EQ("\\'", EscapeQueryStringValue("'")); 19 EXPECT_EQ("\\'", EscapeQueryStringValue("'"));
(...skipping 25 matching lines...) Expand all
46 45
47 // Empty tokens should be simply ignored. 46 // Empty tokens should be simply ignored.
48 EXPECT_EQ("", TranslateQuery("-")); 47 EXPECT_EQ("", TranslateQuery("-"));
49 EXPECT_EQ("", TranslateQuery("\"\"")); 48 EXPECT_EQ("", TranslateQuery("\"\""));
50 EXPECT_EQ("", TranslateQuery("-\"\"")); 49 EXPECT_EQ("", TranslateQuery("-\"\""));
51 EXPECT_EQ("", TranslateQuery("\"\"\"\"")); 50 EXPECT_EQ("", TranslateQuery("\"\"\"\""));
52 EXPECT_EQ("", TranslateQuery("\"\" \"\"")); 51 EXPECT_EQ("", TranslateQuery("\"\" \"\""));
53 EXPECT_EQ("fullText contains 'dog'", TranslateQuery("\"\" dog \"\"")); 52 EXPECT_EQ("fullText contains 'dog'", TranslateQuery("\"\" dog \"\""));
54 } 53 }
55 54
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) { 55 TEST(FileSystemUtilTest, CanonicalizeResourceId) {
68 std::string resource_id("1YsCnrMxxgp7LDdtlFDt-WdtEIth89vA9inrILtvK-Ug"); 56 std::string resource_id("1YsCnrMxxgp7LDdtlFDt-WdtEIth89vA9inrILtvK-Ug");
69 57
70 // New style ID is unchanged. 58 // New style ID is unchanged.
71 EXPECT_EQ(resource_id, CanonicalizeResourceId(resource_id)); 59 EXPECT_EQ(resource_id, CanonicalizeResourceId(resource_id));
72 60
73 // Drop prefixes from old style IDs. 61 // Drop prefixes from old style IDs.
74 EXPECT_EQ(resource_id, CanonicalizeResourceId("document:" + resource_id)); 62 EXPECT_EQ(resource_id, CanonicalizeResourceId("document:" + resource_id));
75 EXPECT_EQ(resource_id, CanonicalizeResourceId("spreadsheet:" + resource_id)); 63 EXPECT_EQ(resource_id, CanonicalizeResourceId("spreadsheet:" + resource_id));
76 EXPECT_EQ(resource_id, CanonicalizeResourceId("presentation:" + resource_id)); 64 EXPECT_EQ(resource_id, CanonicalizeResourceId("presentation:" + resource_id));
77 EXPECT_EQ(resource_id, CanonicalizeResourceId("drawing:" + resource_id)); 65 EXPECT_EQ(resource_id, CanonicalizeResourceId("drawing:" + resource_id));
78 EXPECT_EQ(resource_id, CanonicalizeResourceId("table:" + resource_id)); 66 EXPECT_EQ(resource_id, CanonicalizeResourceId("table:" + resource_id));
79 EXPECT_EQ(resource_id, CanonicalizeResourceId("externalapp:" + resource_id)); 67 EXPECT_EQ(resource_id, CanonicalizeResourceId("externalapp:" + resource_id));
80 } 68 }
81 69
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) { 70 TEST(DriveAPIUtilTest, GetMd5Digest) {
157 base::ScopedTempDir temp_dir; 71 base::ScopedTempDir temp_dir;
158 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 72 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
159 73
160 base::FilePath path = temp_dir.path().AppendASCII("test.txt"); 74 base::FilePath path = temp_dir.path().AppendASCII("test.txt");
161 const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789"; 75 const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789";
162 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(path, kTestData)); 76 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(path, kTestData));
163 77
164 EXPECT_EQ(base::MD5String(kTestData), GetMd5Digest(path)); 78 EXPECT_EQ(base::MD5String(kTestData), GetMd5Digest(path));
165 } 79 }
(...skipping 21 matching lines...) Expand all
187 EXPECT_FALSE( 101 EXPECT_FALSE(
188 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.docx"))); 102 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.docx")));
189 EXPECT_FALSE( 103 EXPECT_FALSE(
190 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.jpg"))); 104 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.jpg")));
191 EXPECT_FALSE( 105 EXPECT_FALSE(
192 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.gmap"))); 106 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.gmap")));
193 } 107 }
194 108
195 } // namespace util 109 } // namespace util
196 } // namespace drive 110 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/drive/drive_api_util.cc ('k') | chrome/browser/sync_file_system/drive_backend/folder_creator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698