| 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/extensions/api/file_handlers/app_file_handler_util.h" | |
| 6 | |
| 7 #include "extensions/browser/entry_info.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 namespace extensions { | |
| 11 namespace app_file_handler_util { | |
| 12 namespace { | |
| 13 | |
| 14 FileHandlerInfo CreateHandlerInfoFromExtension(const std::string& extension) { | |
| 15 FileHandlerInfo handler_info; | |
| 16 handler_info.extensions.insert(extension); | |
| 17 return handler_info; | |
| 18 } | |
| 19 | |
| 20 FileHandlerInfo CreateHandlerInfoFromIncludeDirectories( | |
| 21 bool include_directories) { | |
| 22 FileHandlerInfo handler_info; | |
| 23 handler_info.include_directories = include_directories; | |
| 24 return handler_info; | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 TEST(FileHandlersAppFileHandlerUtilTest, FileHandlerCanHandleEntry) { | |
| 30 // File handler for extension "gz" should accept "*.gz", including "*.tar.gz". | |
| 31 EXPECT_TRUE(FileHandlerCanHandleEntry( | |
| 32 CreateHandlerInfoFromExtension("gz"), | |
| 33 EntryInfo(base::FilePath::FromUTF8Unsafe("foo.gz"), | |
| 34 "application/octet-stream", false))); | |
| 35 EXPECT_FALSE(FileHandlerCanHandleEntry( | |
| 36 CreateHandlerInfoFromExtension("gz"), | |
| 37 EntryInfo(base::FilePath::FromUTF8Unsafe("foo.tgz"), | |
| 38 "application/octet-stream", false))); | |
| 39 EXPECT_TRUE(FileHandlerCanHandleEntry( | |
| 40 CreateHandlerInfoFromExtension("gz"), | |
| 41 EntryInfo(base::FilePath::FromUTF8Unsafe("foo.tar.gz"), | |
| 42 "application/octet-stream", false))); | |
| 43 EXPECT_FALSE(FileHandlerCanHandleEntry( | |
| 44 CreateHandlerInfoFromExtension("tar.gz"), | |
| 45 EntryInfo(base::FilePath::FromUTF8Unsafe("foo.gz"), | |
| 46 "application/octet-stream", false))); | |
| 47 EXPECT_TRUE(FileHandlerCanHandleEntry( | |
| 48 CreateHandlerInfoFromExtension("tar.gz"), | |
| 49 EntryInfo(base::FilePath::FromUTF8Unsafe("foo.tar.gz"), | |
| 50 "application/octet-stream", false))); | |
| 51 EXPECT_FALSE(FileHandlerCanHandleEntry( | |
| 52 CreateHandlerInfoFromExtension("gz"), | |
| 53 EntryInfo(base::FilePath::FromUTF8Unsafe("directory"), "", true))); | |
| 54 | |
| 55 EXPECT_FALSE(FileHandlerCanHandleEntry( | |
| 56 CreateHandlerInfoFromIncludeDirectories(false), | |
| 57 EntryInfo(base::FilePath::FromUTF8Unsafe("directory"), "", true))); | |
| 58 EXPECT_TRUE(FileHandlerCanHandleEntry( | |
| 59 CreateHandlerInfoFromIncludeDirectories(true), | |
| 60 EntryInfo(base::FilePath::FromUTF8Unsafe("directory"), "", true))); | |
| 61 } | |
| 62 | |
| 63 } // namespace app_file_handler_util | |
| 64 } // namespace extensions | |
| OLD | NEW |