Index: webkit/fileapi/media/native_media_file_util_unittest.cc |
diff --git a/webkit/fileapi/media/native_media_file_util_unittest.cc b/webkit/fileapi/media/native_media_file_util_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8fd00db166a8bad5623603d7b650bca2186c7895 |
--- /dev/null |
+++ b/webkit/fileapi/media/native_media_file_util_unittest.cc |
@@ -0,0 +1,163 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include <string> |
+ |
+#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.
|
+#include "webkit/fileapi/file_system_operation_interface.h" |
+#include "webkit/fileapi/native_file_util.h" |
+#include "base/message_loop.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "webkit/fileapi/file_system_context.h" |
+#include "base/scoped_temp_dir.h" |
+#include "webkit/quota/mock_special_storage_policy.h" |
+#include "webkit/fileapi/mock_file_system_options.h" |
+#include "webkit/fileapi/media/native_media_file_util.h" |
+#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.
|
+ |
+#define FPL(x) FILE_PATH_LITERAL(x) |
+ |
+using namespace fileapi; |
+ |
+namespace { |
+struct FilteringTestCase { |
+ const FilePath::CharType* path; |
+ bool is_directory; |
+ bool visible; |
+}; |
+ |
+void ExpectEqHelper(base::PlatformFileError expected, |
+ base::PlatformFileError actual) { |
+ EXPECT_EQ(expected, actual); |
+} |
+} // anonymous namespace |
+ |
+class NativeMediaFileUtilTest : public testing::Test { |
+ public: |
+ NativeMediaFileUtilTest() |
+ : native_media_file_util_(NULL) { |
+ } |
+ |
+ void SetUp() { |
+ ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
+ |
+ scoped_refptr<quota::SpecialStoragePolicy> storage_policy = |
+ new quota::MockSpecialStoragePolicy(); |
+ |
+ file_system_context_ = |
+ new FileSystemContext( |
+ base::MessageLoopProxy::current(), |
+ base::MessageLoopProxy::current(), |
+ storage_policy, |
+ NULL, |
+ data_dir_.path(), |
+ CreateAllowFileAccessOptions()); |
+ |
+ native_media_file_util_ = static_cast<NativeMediaFileUtil*>( |
+ 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.
|
+ |
+ filesystem_id_ = isolated_context()->RegisterFileSystemForPath( |
+ kFileSystemTypeNativeMedia, root_path(), NULL); |
+ |
+ isolated_context()->AddReference(filesystem_id_); |
+ |
+ virtual_root_path_ = |
+ isolated_context()->CreateVirtualRootPath(filesystem_id_); |
+ } |
+ |
+ void TearDown() { |
+ isolated_context()->RemoveReference(filesystem_id_); |
+ file_system_context_ = NULL; |
+ } |
+ |
+ protected: |
+ FileSystemContext* file_system_context() { |
+ return file_system_context_.get(); |
+ } |
+ |
+ IsolatedContext* isolated_context() { |
+ return IsolatedContext::GetInstance(); |
+ } |
+ |
+ std::string filesystem_id() { |
+ return filesystem_id_; |
+ } |
kinuko
2012/07/28 01:23:35
nit: this is not used
tzik
2012/07/30 23:32:36
Done.
|
+ |
+ FilePath virtual_root_path() { |
+ return virtual_root_path_; |
+ } |
kinuko
2012/07/28 01:23:35
nit: this is not used
tzik
2012/07/30 23:32:36
Done.
|
+ |
+ FilePath root_path() { |
+ return data_dir_.path().Append(FPL("Media Directory")); |
+ } |
+ |
+ NativeMediaFileUtil* file_util() { |
+ return native_media_file_util_; |
+ } |
+ |
+ GURL origin() { |
+ return GURL("http://example.com"); |
+ } |
+ |
+ FileSystemType type() { |
+ return kFileSystemTypeNativeMedia; |
+ } |
+ |
+ FileSystemOperationInterface* NewOperation(const FileSystemURL& url) { |
+ return file_system_context_->CreateFileSystemOperation(url); |
+ } |
+ |
+ private: |
+ MessageLoop message_loop_; |
+ |
+ ScopedTempDir data_dir_; |
+ scoped_refptr<FileSystemContext> file_system_context_; |
+ |
+ NativeMediaFileUtil* native_media_file_util_; |
+ std::string filesystem_id_; |
+ FilePath virtual_root_path_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtilTest); |
+}; |
+ |
+TEST_F(NativeMediaFileUtilTest, FilteringTest) { |
+ const FilteringTestCase kTestCases[] = { |
+ { FPL("hoge"), true, true }, |
+ { FPL("hoge/fuga"), true, true }, |
+ { FPL("hoge/piyo.jpg"), true, true }, |
+ { FPL("hoge/moga.txt"), true, true }, |
+ { FPL("hoge/foo"), false, false }, |
+ { FPL("hoge/bar.jpg"), false, true }, |
+ { 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.
|
+ }; |
+ |
+ for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
+ FilePath path = root_path().Append(kTestCases[i].path); |
+ if (kTestCases[i].is_directory) { |
+ ASSERT_TRUE(file_util::CreateDirectory(path)); |
+ } else { |
+ bool created = false; |
+ ASSERT_EQ(base::PLATFORM_FILE_OK, |
+ NativeFileUtil::EnsureFileExists(path, &created)); |
+ ASSERT_TRUE(created); |
+ } |
+ } |
+ |
+ for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
+ FilePath path = root_path().Append(kTestCases[i].path); |
+ FileSystemURL url(origin(), type(), path); |
+ FileSystemOperationInterface* operation = NewOperation(url); |
+ |
+ base::PlatformFileError expectation = |
+ kTestCases[i].visible ? |
+ base::PLATFORM_FILE_OK : |
+ base::PLATFORM_FILE_ERROR_NOT_FOUND; |
+ |
+ if (kTestCases[i].is_directory) |
+ operation->DirectoryExists(url, base::Bind(&ExpectEqHelper, expectation)); |
+ else |
+ operation->FileExists(url, base::Bind(&ExpectEqHelper, expectation)); |
+ 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.
|
+ } |
+} |