Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 <string> | |
| 6 | |
| 7 #include "base/bind.h" | |
|
kinuko
2012/07/28 01:23:35
not necessary?
tzik
2012/07/30 23:32:36
It's needed for l158.
| |
| 8 #include "webkit/fileapi/file_system_operation_interface.h" | |
| 9 #include "webkit/fileapi/native_file_util.h" | |
| 10 #include "base/message_loop.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 #include "webkit/fileapi/file_system_context.h" | |
| 13 #include "base/scoped_temp_dir.h" | |
| 14 #include "webkit/quota/mock_special_storage_policy.h" | |
| 15 #include "webkit/fileapi/mock_file_system_options.h" | |
| 16 #include "webkit/fileapi/media/native_media_file_util.h" | |
| 17 #include "webkit/fileapi/isolated_context.h" | |
|
kinuko
2012/07/28 01:23:35
please sort headers
tzik
2012/07/30 23:32:36
Done. I forgot it.
| |
| 18 | |
| 19 #define FPL(x) FILE_PATH_LITERAL(x) | |
| 20 | |
| 21 using namespace fileapi; | |
| 22 | |
| 23 namespace { | |
| 24 struct FilteringTestCase { | |
| 25 const FilePath::CharType* path; | |
| 26 bool is_directory; | |
| 27 bool visible; | |
| 28 }; | |
| 29 | |
| 30 void ExpectEqHelper(base::PlatformFileError expected, | |
| 31 base::PlatformFileError actual) { | |
| 32 EXPECT_EQ(expected, actual); | |
| 33 } | |
| 34 } // anonymous namespace | |
| 35 | |
| 36 class NativeMediaFileUtilTest : public testing::Test { | |
| 37 public: | |
| 38 NativeMediaFileUtilTest() | |
| 39 : native_media_file_util_(NULL) { | |
| 40 } | |
| 41 | |
| 42 void SetUp() { | |
| 43 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | |
| 44 | |
| 45 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | |
| 46 new quota::MockSpecialStoragePolicy(); | |
| 47 | |
| 48 file_system_context_ = | |
| 49 new FileSystemContext( | |
| 50 base::MessageLoopProxy::current(), | |
| 51 base::MessageLoopProxy::current(), | |
| 52 storage_policy, | |
| 53 NULL, | |
| 54 data_dir_.path(), | |
| 55 CreateAllowFileAccessOptions()); | |
| 56 | |
| 57 native_media_file_util_ = static_cast<NativeMediaFileUtil*>( | |
| 58 file_system_context_->GetFileUtil(kFileSystemTypeNativeMedia)); | |
|
kinuko
2012/07/28 01:23:35
Does this need to be down-casted?
tzik
2012/07/30 23:32:36
Done.
| |
| 59 | |
| 60 filesystem_id_ = isolated_context()->RegisterFileSystemForPath( | |
| 61 kFileSystemTypeNativeMedia, root_path(), NULL); | |
| 62 | |
| 63 isolated_context()->AddReference(filesystem_id_); | |
| 64 | |
| 65 virtual_root_path_ = | |
| 66 isolated_context()->CreateVirtualRootPath(filesystem_id_); | |
| 67 } | |
| 68 | |
| 69 void TearDown() { | |
| 70 isolated_context()->RemoveReference(filesystem_id_); | |
| 71 file_system_context_ = NULL; | |
| 72 } | |
| 73 | |
| 74 protected: | |
| 75 FileSystemContext* file_system_context() { | |
| 76 return file_system_context_.get(); | |
| 77 } | |
| 78 | |
| 79 IsolatedContext* isolated_context() { | |
| 80 return IsolatedContext::GetInstance(); | |
| 81 } | |
| 82 | |
| 83 std::string filesystem_id() { | |
| 84 return filesystem_id_; | |
| 85 } | |
|
kinuko
2012/07/28 01:23:35
nit: this is not used
tzik
2012/07/30 23:32:36
Done.
| |
| 86 | |
| 87 FilePath virtual_root_path() { | |
| 88 return virtual_root_path_; | |
| 89 } | |
|
kinuko
2012/07/28 01:23:35
nit: this is not used
tzik
2012/07/30 23:32:36
Done.
| |
| 90 | |
| 91 FilePath root_path() { | |
| 92 return data_dir_.path().Append(FPL("Media Directory")); | |
| 93 } | |
| 94 | |
| 95 NativeMediaFileUtil* file_util() { | |
| 96 return native_media_file_util_; | |
| 97 } | |
| 98 | |
| 99 GURL origin() { | |
| 100 return GURL("http://example.com"); | |
| 101 } | |
| 102 | |
| 103 FileSystemType type() { | |
| 104 return kFileSystemTypeNativeMedia; | |
| 105 } | |
| 106 | |
| 107 FileSystemOperationInterface* NewOperation(const FileSystemURL& url) { | |
| 108 return file_system_context_->CreateFileSystemOperation(url); | |
| 109 } | |
| 110 | |
| 111 private: | |
| 112 MessageLoop message_loop_; | |
| 113 | |
| 114 ScopedTempDir data_dir_; | |
| 115 scoped_refptr<FileSystemContext> file_system_context_; | |
| 116 | |
| 117 NativeMediaFileUtil* native_media_file_util_; | |
| 118 std::string filesystem_id_; | |
| 119 FilePath virtual_root_path_; | |
| 120 | |
| 121 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtilTest); | |
| 122 }; | |
| 123 | |
| 124 TEST_F(NativeMediaFileUtilTest, FilteringTest) { | |
| 125 const FilteringTestCase kTestCases[] = { | |
| 126 { FPL("hoge"), true, true }, | |
| 127 { FPL("hoge/fuga"), true, true }, | |
| 128 { FPL("hoge/piyo.jpg"), true, true }, | |
| 129 { FPL("hoge/moga.txt"), true, true }, | |
| 130 { FPL("hoge/foo"), false, false }, | |
| 131 { FPL("hoge/bar.jpg"), false, true }, | |
| 132 { FPL("hoge/baz.txt"), false, false }, | |
|
kinuko
2012/07/28 01:23:35
Can you add comments which line is testing what?
tzik
2012/07/30 23:32:36
Done.
| |
| 133 }; | |
| 134 | |
| 135 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
| 136 FilePath path = root_path().Append(kTestCases[i].path); | |
| 137 if (kTestCases[i].is_directory) { | |
| 138 ASSERT_TRUE(file_util::CreateDirectory(path)); | |
| 139 } else { | |
| 140 bool created = false; | |
| 141 ASSERT_EQ(base::PLATFORM_FILE_OK, | |
| 142 NativeFileUtil::EnsureFileExists(path, &created)); | |
| 143 ASSERT_TRUE(created); | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
| 148 FilePath path = root_path().Append(kTestCases[i].path); | |
| 149 FileSystemURL url(origin(), type(), path); | |
| 150 FileSystemOperationInterface* operation = NewOperation(url); | |
| 151 | |
| 152 base::PlatformFileError expectation = | |
| 153 kTestCases[i].visible ? | |
| 154 base::PLATFORM_FILE_OK : | |
| 155 base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
| 156 | |
| 157 if (kTestCases[i].is_directory) | |
| 158 operation->DirectoryExists(url, base::Bind(&ExpectEqHelper, expectation)); | |
| 159 else | |
| 160 operation->FileExists(url, base::Bind(&ExpectEqHelper, expectation)); | |
| 161 MessageLoop::current()->RunAllPending(); | |
|
kinuko
2012/07/28 01:23:35
I think we'll also need tests for ReadDirectory (p
tzik
2012/07/30 23:32:36
Done.
| |
| 162 } | |
| 163 } | |
| OLD | NEW |