Chromium Code Reviews| Index: chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root_unittest.cc |
| diff --git a/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root_unittest.cc b/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root_unittest.cc |
| index 7919b209628077cfda042bde3083475fb682a633..1be0fd0c8a94c619e4a9b5b8f072165bf9a0c967 100644 |
| --- a/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root_unittest.cc |
| +++ b/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root_unittest.cc |
| @@ -16,12 +16,14 @@ |
| #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner.h" |
| #include "components/arc/arc_bridge_service.h" |
| #include "components/arc/arc_service_manager.h" |
| +#include "components/arc/common/file_system.mojom.h" |
| #include "components/arc/test/fake_file_system_instance.h" |
| #include "content/public/test/test_browser_thread_bundle.h" |
| #include "storage/common/fileapi/directory_entry.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "url/gurl.h" |
| +using ChangeType = arc::ArcDocumentsProviderRoot::ChangeType; |
| using storage::DirectoryEntry; |
| using Document = arc::FakeFileSystemInstance::Document; |
| using EntryList = storage::AsyncFileUtil::EntryList; |
| @@ -120,6 +122,10 @@ class ArcDocumentsProviderRootTest : public testing::Test { |
| arc_service_manager_->arc_bridge_service()->file_system()->SetInstance( |
| &fake_file_system_); |
| + // Run the message loop until FileSystemInstance::Init() is called. |
| + base::RunLoop().RunUntilIdle(); |
| + ASSERT_TRUE(fake_file_system_.InitCalled()); |
| + |
| root_ = base::MakeUnique<ArcDocumentsProviderRoot>(kAuthority, |
| kRootSpec.document_id); |
| } |
| @@ -287,6 +293,91 @@ TEST_F(ArcDocumentsProviderRootTest, ReadDirectoryDups) { |
| run_loop.Run(); |
| } |
| +TEST_F(ArcDocumentsProviderRootTest, WatchChanged) { |
| + int num_called = 0; |
| + auto watcher_callback = base::Bind( |
| + [](int* num_called, ChangeType type) { |
| + EXPECT_EQ(ChangeType::CHANGED, type); |
| + ++(*num_called); |
| + }, |
| + &num_called); |
| + |
| + { |
| + base::RunLoop run_loop; |
| + root_->AddWatcher(base::FilePath(FILE_PATH_LITERAL("dir")), |
| + watcher_callback, |
| + base::Bind( |
| + [](base::RunLoop* run_loop, base::File::Error error) { |
| + EXPECT_EQ(base::File::FILE_OK, error); |
| + run_loop->Quit(); |
| + }, |
| + &run_loop)); |
| + run_loop.Run(); |
| + } |
| + |
| + EXPECT_EQ(0, num_called); |
| + fake_file_system_.TriggerWatchers(kAuthority, kDirSpec.document_id, |
| + mojom::ChangeType::CHANGED); |
| + base::RunLoop().RunUntilIdle(); |
| + EXPECT_EQ(1, num_called); |
| + |
| + { |
| + base::RunLoop run_loop; |
| + root_->RemoveWatcher( |
| + base::FilePath(FILE_PATH_LITERAL("dir")), |
| + base::Bind( |
| + [](base::RunLoop* run_loop, base::File::Error error) { |
| + EXPECT_EQ(base::File::FILE_OK, error); |
| + run_loop->Quit(); |
| + }, |
| + &run_loop)); |
| + run_loop.Run(); |
| + } |
| +} |
| + |
| +TEST_F(ArcDocumentsProviderRootTest, WatchDeleted) { |
| + int num_called = 0; |
| + auto watcher_callback = base::Bind( |
| + [](int* num_called, ChangeType type) { |
| + EXPECT_EQ(ChangeType::DELETED, type); |
| + ++(*num_called); |
| + }, |
| + &num_called); |
| + |
| + { |
| + base::RunLoop run_loop; |
| + root_->AddWatcher(base::FilePath(FILE_PATH_LITERAL("dir")), |
| + watcher_callback, |
| + base::Bind( |
| + [](base::RunLoop* run_loop, base::File::Error error) { |
| + EXPECT_EQ(base::File::FILE_OK, error); |
| + run_loop->Quit(); |
| + }, |
| + &run_loop)); |
| + run_loop.Run(); |
| + } |
| + |
| + EXPECT_EQ(0, num_called); |
| + fake_file_system_.TriggerWatchers(kAuthority, kDirSpec.document_id, |
| + mojom::ChangeType::CHANGED); |
|
hidehiko
2017/02/23 12:10:54
DELETED?
Shuhei Takahashi
2017/03/02 07:06:01
Ugh, I somehow failed to run unit tests for this C
|
| + base::RunLoop().RunUntilIdle(); |
| + EXPECT_EQ(1, num_called); |
| + |
| + // The watcher has already been deleted, so RemoveWatcher() should fail. |
| + { |
| + base::RunLoop run_loop; |
| + root_->RemoveWatcher( |
| + base::FilePath(FILE_PATH_LITERAL("dir")), |
| + base::Bind( |
| + [](base::RunLoop* run_loop, base::File::Error error) { |
| + EXPECT_EQ(base::File::FILE_ERROR_FAILED, error); |
| + run_loop->Quit(); |
| + }, |
| + &run_loop)); |
| + run_loop.Run(); |
| + } |
| +} |
| + |
| TEST_F(ArcDocumentsProviderRootTest, ResolveToContentUrl) { |
| base::RunLoop run_loop; |
| root_->ResolveToContentUrl( |