OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/chromeos/fileapi/external_file_url_util.h" |
| 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 9 #include "chrome/test/base/testing_browser_process.h" |
| 10 #include "chrome/test/base/testing_profile_manager.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" |
| 14 |
| 15 namespace chromeos { |
| 16 |
| 17 namespace { |
| 18 |
| 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()) {} |
| 26 |
| 27 virtual void SetUp() OVERRIDE { |
| 28 ASSERT_TRUE(testing_profile_manager_.SetUp()); |
| 29 } |
| 30 |
| 31 TestingProfileManager& testing_profile_manager() { |
| 32 return testing_profile_manager_; |
| 33 } |
| 34 |
| 35 private: |
| 36 content::TestBrowserThreadBundle thread_bundle_; |
| 37 TestingProfileManager testing_profile_manager_; |
| 38 }; |
| 39 |
| 40 } // namespace |
| 41 |
| 42 TEST(ExternalFileURLUtilTest, FilePathToExternalFileURL) { |
| 43 base::FilePath path; |
| 44 |
| 45 // Path with alphabets and numbers. |
| 46 path = drive::util::GetDriveMyDriveRootPath().AppendASCII("foo/bar012.txt"); |
| 47 EXPECT_EQ(path, ExternalFileURLToFilePath(FilePathToExternalFileURL(path))); |
| 48 |
| 49 // Path with symbols. |
| 50 path = drive::util::GetDriveMyDriveRootPath().AppendASCII( |
| 51 " !\"#$%&'()*+,-.:;<=>?@[\\]^_`{|}~"); |
| 52 EXPECT_EQ(path, ExternalFileURLToFilePath(FilePathToExternalFileURL(path))); |
| 53 |
| 54 // Path with '%'. |
| 55 path = drive::util::GetDriveMyDriveRootPath().AppendASCII("%19%20%21.txt"); |
| 56 EXPECT_EQ(path, ExternalFileURLToFilePath(FilePathToExternalFileURL(path))); |
| 57 |
| 58 // Path with multi byte characters. |
| 59 base::string16 utf16_string; |
| 60 utf16_string.push_back(0x307b); // HIRAGANA_LETTER_HO |
| 61 utf16_string.push_back(0x3052); // HIRAGANA_LETTER_GE |
| 62 path = drive::util::GetDriveMyDriveRootPath().Append( |
| 63 base::FilePath::FromUTF8Unsafe(base::UTF16ToUTF8(utf16_string) + ".txt")); |
| 64 EXPECT_EQ(path, ExternalFileURLToFilePath(FilePathToExternalFileURL(path))); |
| 65 } |
| 66 |
| 67 TEST(ExternalFileURLUtilTest, ParseFileURLWithExternalFileOrigin) { |
| 68 // filesystem:externalfile:/*** is used only internally. It should not parsed |
| 69 // directly. |
| 70 ASSERT_FALSE(storage::FileSystemURL::CreateForTest( |
| 71 GURL("filesystem:externalfile:/")).is_valid()); |
| 72 ASSERT_FALSE( |
| 73 storage::FileSystemURL::CreateForTest( |
| 74 GURL("filesystem:externalfile:/external/drive/file.txt")).is_valid()); |
| 75 } |
| 76 |
| 77 } // namespace chromeos |
OLD | NEW |