Content settings: remove some plugin-related code/resources when... there are no...
[chromium-blink-merge.git] / components / drive / file_system_core_util_unittest.cc
blob663da280a84681cba7f6722b393fa6e41644861d
1 // Copyright 2015 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 "components/drive/file_system_core_util.h"
7 #include <vector>
9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/thread_task_runner_handle.h"
15 #include "content/public/test/test_browser_thread_bundle.h"
16 #include "google_apis/drive/test_util.h"
17 #include "testing/gtest/include/gtest/gtest.h"
19 namespace drive {
20 namespace util {
22 class FileSystemUtilTest : public testing::Test {
23 content::TestBrowserThreadBundle thread_bundle_;
26 TEST_F(FileSystemUtilTest, EscapeUnescapeCacheFileName) {
27 const std::string kUnescapedFileName(
28 "tmp:`~!@#$%^&*()-_=+[{|]}\\\\;\',<.>/?");
29 const std::string kEscapedFileName(
30 "tmp:`~!@#$%25^&*()-_=+[{|]}\\\\;\',<%2E>%2F?");
31 EXPECT_EQ(kEscapedFileName, EscapeCacheFileName(kUnescapedFileName));
32 EXPECT_EQ(kUnescapedFileName, UnescapeCacheFileName(kEscapedFileName));
35 TEST_F(FileSystemUtilTest, NormalizeFileName) {
36 EXPECT_EQ("", NormalizeFileName(""));
37 EXPECT_EQ("foo", NormalizeFileName("foo"));
38 // Slash
39 EXPECT_EQ("foo_zzz", NormalizeFileName("foo/zzz"));
40 EXPECT_EQ("___", NormalizeFileName("///"));
41 // Japanese hiragana "hi" + semi-voiced-mark is normalized to "pi".
42 EXPECT_EQ("\xE3\x81\xB4", NormalizeFileName("\xE3\x81\xB2\xE3\x82\x9A"));
43 // Dot
44 EXPECT_EQ("_", NormalizeFileName("."));
45 EXPECT_EQ("_", NormalizeFileName(".."));
46 EXPECT_EQ("_", NormalizeFileName("..."));
47 EXPECT_EQ(".bashrc", NormalizeFileName(".bashrc"));
48 EXPECT_EQ("._", NormalizeFileName("./"));
51 TEST_F(FileSystemUtilTest, GDocFile) {
52 base::ScopedTempDir temp_dir;
53 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
55 GURL url(
56 "https://docs.google.com/document/d/"
57 "1YsCnrMxxgp7LDdtlFDt-WdtEIth89vA9inrILtvK-Ug/edit");
58 std::string resource_id("1YsCnrMxxgp7LDdtlFDt-WdtEIth89vA9inrILtvK-Ug");
60 // Read and write gdoc.
61 base::FilePath file = temp_dir.path().AppendASCII("test.gdoc");
62 EXPECT_TRUE(CreateGDocFile(file, url, resource_id));
63 EXPECT_EQ(url, ReadUrlFromGDocFile(file));
64 EXPECT_EQ(resource_id, ReadResourceIdFromGDocFile(file));
66 // Read and write gsheet.
67 file = temp_dir.path().AppendASCII("test.gsheet");
68 EXPECT_TRUE(CreateGDocFile(file, url, resource_id));
69 EXPECT_EQ(url, ReadUrlFromGDocFile(file));
70 EXPECT_EQ(resource_id, ReadResourceIdFromGDocFile(file));
72 // Read and write gslides.
73 file = temp_dir.path().AppendASCII("test.gslides");
74 EXPECT_TRUE(CreateGDocFile(file, url, resource_id));
75 EXPECT_EQ(url, ReadUrlFromGDocFile(file));
76 EXPECT_EQ(resource_id, ReadResourceIdFromGDocFile(file));
78 // Read and write gdraw.
79 file = temp_dir.path().AppendASCII("test.gdraw");
80 EXPECT_TRUE(CreateGDocFile(file, url, resource_id));
81 EXPECT_EQ(url, ReadUrlFromGDocFile(file));
82 EXPECT_EQ(resource_id, ReadResourceIdFromGDocFile(file));
84 // Read and write gtable.
85 file = temp_dir.path().AppendASCII("test.gtable");
86 EXPECT_TRUE(CreateGDocFile(file, url, resource_id));
87 EXPECT_EQ(url, ReadUrlFromGDocFile(file));
88 EXPECT_EQ(resource_id, ReadResourceIdFromGDocFile(file));
90 // Non GDoc file.
91 file = temp_dir.path().AppendASCII("test.txt");
92 std::string data = "Hello world!";
93 EXPECT_TRUE(google_apis::test_util::WriteStringToFile(file, data));
94 EXPECT_TRUE(ReadUrlFromGDocFile(file).is_empty());
95 EXPECT_TRUE(ReadResourceIdFromGDocFile(file).empty());
98 } // namespace util
99 } // namespace drive