Give names to all utility processes.
[chromium-blink-merge.git] / chrome / browser / drive / drive_api_util_unittest.cc
blob70592f4ea8bc08fada93941a94ffa6d2d02148a9
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.
5 #include "chrome/browser/drive/drive_api_util.h"
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"
14 namespace drive {
15 namespace util {
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("\\'"));
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\""));
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"));
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"));
43 // For quoted text with leading '-'.
44 EXPECT_EQ("not fullText contains 'dog cat'", TranslateQuery("-\"dog cat\""));
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 \"\""));
55 TEST(FileSystemUtilTest, CanonicalizeResourceId) {
56 std::string resource_id("1YsCnrMxxgp7LDdtlFDt-WdtEIth89vA9inrILtvK-Ug");
58 // New style ID is unchanged.
59 EXPECT_EQ(resource_id, CanonicalizeResourceId(resource_id));
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));
70 TEST(DriveAPIUtilTest, GetMd5Digest) {
71 base::ScopedTempDir temp_dir;
72 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
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));
78 EXPECT_EQ(base::MD5String(kTestData), GetMd5Digest(path));
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")));
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")));
109 } // namespace util
110 } // namespace drive