Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / fileapi / external_file_url_util_unittest.cc
blobe166c085ce5343846ee9e1c7cd9556d1281f380d
1 // Copyright 2014 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/chromeos/fileapi/external_file_url_util.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/test/base/testing_browser_process.h"
9 #include "chrome/test/base/testing_profile_manager.h"
10 #include "components/drive/file_system_core_util.h"
11 #include "content/public/test/test_browser_thread_bundle.h"
12 #include "storage/browser/fileapi/file_system_url.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 namespace chromeos {
17 namespace {
19 // Sets up ProfileManager for testing and marks the current thread as UI by
20 // TestBrowserThreadBundle. We need the thread since Profile objects must be
21 // touched from UI and hence has CHECK/DCHECKs for it.
22 class ExternalFileURLUtilTest : public testing::Test {
23 protected:
24 ExternalFileURLUtilTest()
25 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {}
27 void SetUp() override { ASSERT_TRUE(testing_profile_manager_.SetUp()); }
29 TestingProfileManager& testing_profile_manager() {
30 return testing_profile_manager_;
33 storage::FileSystemURL CreateExpectedURL(const base::FilePath& path) {
34 return storage::FileSystemURL::CreateForTest(
35 GURL("chrome-extension://xxx"),
36 storage::kFileSystemTypeExternal,
37 base::FilePath("drive-test-user-hash").Append(path),
38 "",
39 storage::kFileSystemTypeDrive,
40 base::FilePath(),
41 "",
42 storage::FileSystemMountOption());
45 private:
46 content::TestBrowserThreadBundle thread_bundle_;
47 TestingProfileManager testing_profile_manager_;
50 } // namespace
52 TEST_F(ExternalFileURLUtilTest, FilePathToExternalFileURL) {
53 storage::FileSystemURL url;
55 // Path with alphabets and numbers.
56 url = CreateExpectedURL(base::FilePath("foo/bar012.txt"));
57 EXPECT_EQ(url.virtual_path(),
58 ExternalFileURLToVirtualPath(FileSystemURLToExternalFileURL(url)));
60 // Path with symbols.
61 url = CreateExpectedURL(base::FilePath(" !\"#$%&'()*+,-.:;<=>?@[\\]^_`{|}~"));
62 EXPECT_EQ(url.virtual_path(),
63 ExternalFileURLToVirtualPath(FileSystemURLToExternalFileURL(url)));
65 // Path with '%'.
66 url = CreateExpectedURL(base::FilePath("%19%20%21.txt"));
67 EXPECT_EQ(url.virtual_path(),
68 ExternalFileURLToVirtualPath(FileSystemURLToExternalFileURL(url)));
70 // Path with multi byte characters.
71 base::string16 utf16_string;
72 utf16_string.push_back(0x307b); // HIRAGANA_LETTER_HO
73 utf16_string.push_back(0x3052); // HIRAGANA_LETTER_GE
74 url = CreateExpectedURL(
75 base::FilePath::FromUTF8Unsafe(base::UTF16ToUTF8(utf16_string) + ".txt"));
76 EXPECT_EQ(url.virtual_path().AsUTF8Unsafe(),
77 ExternalFileURLToVirtualPath(FileSystemURLToExternalFileURL(url))
78 .AsUTF8Unsafe());
81 } // namespace chromeos