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

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

Issue 1190203002: Move (most of) chrome/browser/drive into components/drive/service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing... Created 5 years, 5 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
« no previous file with comments | « chrome/browser/drive/drive_api_util.cc ('k') | chrome/browser/drive/drive_app_registry.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/drive/drive_api_util.h"
6
7 #include "base/files/scoped_temp_dir.h"
8 #include "base/md5.h"
9 #include "google_apis/drive/drive_api_parser.h"
10 #include "google_apis/drive/test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "url/gurl.h"
13
14 namespace drive {
15 namespace util {
16
17 TEST(DriveApiUtilTest, EscapeQueryStringValue) {
18 EXPECT_EQ("abcde", EscapeQueryStringValue("abcde"));
19 EXPECT_EQ("\\'", EscapeQueryStringValue("'"));
20 EXPECT_EQ("\\'abcde\\'", EscapeQueryStringValue("'abcde'"));
21 EXPECT_EQ("\\\\", EscapeQueryStringValue("\\"));
22 EXPECT_EQ("\\\\\\'", EscapeQueryStringValue("\\'"));
23 }
24
25 TEST(DriveApiUtilTest, TranslateQuery) {
26 EXPECT_EQ("", TranslateQuery(""));
27 EXPECT_EQ("fullText contains 'dog'", TranslateQuery("dog"));
28 EXPECT_EQ("fullText contains 'dog' and fullText contains 'cat'",
29 TranslateQuery("dog cat"));
30 EXPECT_EQ("not fullText contains 'cat'", TranslateQuery("-cat"));
31 EXPECT_EQ("fullText contains 'dog cat'", TranslateQuery("\"dog cat\""));
32
33 // Should handles full-width white space correctly.
34 // Note: \xE3\x80\x80 (\u3000) is Ideographic Space (a.k.a. Japanese
35 // full-width whitespace).
36 EXPECT_EQ("fullText contains 'dog' and fullText contains 'cat'",
37 TranslateQuery("dog" "\xE3\x80\x80" "cat"));
38
39 // If the quoted token is not closed (i.e. the last '"' is missing),
40 // we handle the remaining string is one token, as a fallback.
41 EXPECT_EQ("fullText contains 'dog cat'", TranslateQuery("\"dog cat"));
42
43 // For quoted text with leading '-'.
44 EXPECT_EQ("not fullText contains 'dog cat'", TranslateQuery("-\"dog cat\""));
45
46 // Empty tokens should be simply ignored.
47 EXPECT_EQ("", TranslateQuery("-"));
48 EXPECT_EQ("", TranslateQuery("\"\""));
49 EXPECT_EQ("", TranslateQuery("-\"\""));
50 EXPECT_EQ("", TranslateQuery("\"\"\"\""));
51 EXPECT_EQ("", TranslateQuery("\"\" \"\""));
52 EXPECT_EQ("fullText contains 'dog'", TranslateQuery("\"\" dog \"\""));
53 }
54
55 TEST(DriveAPIUtilTest, CanonicalizeResourceId) {
56 std::string resource_id("1YsCnrMxxgp7LDdtlFDt-WdtEIth89vA9inrILtvK-Ug");
57
58 // New style ID is unchanged.
59 EXPECT_EQ(resource_id, CanonicalizeResourceId(resource_id));
60
61 // Drop prefixes from old style IDs.
62 EXPECT_EQ(resource_id, CanonicalizeResourceId("document:" + resource_id));
63 EXPECT_EQ(resource_id, CanonicalizeResourceId("spreadsheet:" + resource_id));
64 EXPECT_EQ(resource_id, CanonicalizeResourceId("presentation:" + resource_id));
65 EXPECT_EQ(resource_id, CanonicalizeResourceId("drawing:" + resource_id));
66 EXPECT_EQ(resource_id, CanonicalizeResourceId("table:" + resource_id));
67 EXPECT_EQ(resource_id, CanonicalizeResourceId("externalapp:" + resource_id));
68 }
69
70 TEST(DriveAPIUtilTest, GetMd5Digest) {
71 base::ScopedTempDir temp_dir;
72 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
73
74 base::FilePath path = temp_dir.path().AppendASCII("test.txt");
75 const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789";
76 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(path, kTestData));
77
78 EXPECT_EQ(base::MD5String(kTestData), GetMd5Digest(path, nullptr));
79 }
80
81 TEST(DriveAPIUtilTest, HasHostedDocumentExtension) {
82 EXPECT_TRUE(
83 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.gdoc")));
84 EXPECT_TRUE(
85 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.gsheet")));
86 EXPECT_TRUE(
87 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.gslides")));
88 EXPECT_TRUE(
89 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.gdraw")));
90 EXPECT_TRUE(
91 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.gtable")));
92 EXPECT_TRUE(
93 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.gform")));
94 EXPECT_TRUE(
95 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.gmaps")));
96 EXPECT_TRUE(
97 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.glink")));
98
99 EXPECT_FALSE(
100 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.gdocs")));
101 EXPECT_FALSE(
102 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.docx")));
103 EXPECT_FALSE(
104 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.jpg")));
105 EXPECT_FALSE(
106 HasHostedDocumentExtension(base::FilePath::FromUTF8Unsafe("xx.gmap")));
107 }
108
109 } // namespace util
110 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/drive/drive_api_util.cc ('k') | chrome/browser/drive/drive_app_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698