Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root_unittest.cc

Issue 2715473003: mediaview: Support watchers in ArcDocumentsProviderRoot. (Closed)
Patch Set: Review ready. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string.h> 5 #include <string.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root.h" 14 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root.h"
15 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" 15 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h"
16 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner.h " 16 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner.h "
17 #include "components/arc/arc_bridge_service.h" 17 #include "components/arc/arc_bridge_service.h"
18 #include "components/arc/arc_service_manager.h" 18 #include "components/arc/arc_service_manager.h"
19 #include "components/arc/common/file_system.mojom.h"
19 #include "components/arc/test/fake_file_system_instance.h" 20 #include "components/arc/test/fake_file_system_instance.h"
20 #include "content/public/test/test_browser_thread_bundle.h" 21 #include "content/public/test/test_browser_thread_bundle.h"
21 #include "storage/common/fileapi/directory_entry.h" 22 #include "storage/common/fileapi/directory_entry.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 #include "url/gurl.h" 24 #include "url/gurl.h"
24 25
26 using ChangeType = arc::ArcDocumentsProviderRoot::ChangeType;
25 using storage::DirectoryEntry; 27 using storage::DirectoryEntry;
26 using Document = arc::FakeFileSystemInstance::Document; 28 using Document = arc::FakeFileSystemInstance::Document;
27 using EntryList = storage::AsyncFileUtil::EntryList; 29 using EntryList = storage::AsyncFileUtil::EntryList;
28 30
29 namespace arc { 31 namespace arc {
30 32
31 namespace { 33 namespace {
32 34
33 // Simliar as FakeFileSystemInstance::Document, but all fields are primitives 35 // Simliar as FakeFileSystemInstance::Document, but all fields are primitives
34 // so that values can be constexpr. 36 // so that values can be constexpr.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 fake_file_system_.AddDocument(ToDocument(spec)); 115 fake_file_system_.AddDocument(ToDocument(spec));
114 } 116 }
115 117
116 arc_service_manager_ = base::MakeUnique<ArcServiceManager>(nullptr); 118 arc_service_manager_ = base::MakeUnique<ArcServiceManager>(nullptr);
117 arc_service_manager_->AddService( 119 arc_service_manager_->AddService(
118 ArcFileSystemOperationRunner::CreateForTesting( 120 ArcFileSystemOperationRunner::CreateForTesting(
119 arc_service_manager_->arc_bridge_service())); 121 arc_service_manager_->arc_bridge_service()));
120 arc_service_manager_->arc_bridge_service()->file_system()->SetInstance( 122 arc_service_manager_->arc_bridge_service()->file_system()->SetInstance(
121 &fake_file_system_); 123 &fake_file_system_);
122 124
125 // Run the message loop until FileSystemInstance::Init() is called.
126 base::RunLoop().RunUntilIdle();
127 ASSERT_TRUE(fake_file_system_.InitCalled());
128
123 root_ = base::MakeUnique<ArcDocumentsProviderRoot>(kAuthority, 129 root_ = base::MakeUnique<ArcDocumentsProviderRoot>(kAuthority,
124 kRootSpec.document_id); 130 kRootSpec.document_id);
125 } 131 }
126 132
127 protected: 133 protected:
128 content::TestBrowserThreadBundle thread_bundle_; 134 content::TestBrowserThreadBundle thread_bundle_;
129 FakeFileSystemInstance fake_file_system_; 135 FakeFileSystemInstance fake_file_system_;
130 std::unique_ptr<ArcServiceManager> arc_service_manager_; 136 std::unique_ptr<ArcServiceManager> arc_service_manager_;
131 std::unique_ptr<ArcDocumentsProviderRoot> root_; 137 std::unique_ptr<ArcDocumentsProviderRoot> root_;
132 138
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 EXPECT_FALSE(file_list[2].is_directory); 286 EXPECT_FALSE(file_list[2].is_directory);
281 EXPECT_EQ(FILE_PATH_LITERAL("dup.mp4"), file_list[3].name); 287 EXPECT_EQ(FILE_PATH_LITERAL("dup.mp4"), file_list[3].name);
282 EXPECT_FALSE(file_list[3].is_directory); 288 EXPECT_FALSE(file_list[3].is_directory);
283 EXPECT_FALSE(has_more); 289 EXPECT_FALSE(has_more);
284 run_loop->Quit(); 290 run_loop->Quit();
285 }, 291 },
286 &run_loop)); 292 &run_loop));
287 run_loop.Run(); 293 run_loop.Run();
288 } 294 }
289 295
296 TEST_F(ArcDocumentsProviderRootTest, WatchChanged) {
297 int num_called = 0;
298 auto watcher_callback = base::Bind(
299 [](int* num_called, ChangeType type) {
300 EXPECT_EQ(ChangeType::CHANGED, type);
301 ++(*num_called);
302 },
303 &num_called);
304
305 {
306 base::RunLoop run_loop;
307 root_->AddWatcher(base::FilePath(FILE_PATH_LITERAL("dir")),
308 watcher_callback,
309 base::Bind(
310 [](base::RunLoop* run_loop, base::File::Error error) {
311 EXPECT_EQ(base::File::FILE_OK, error);
312 run_loop->Quit();
313 },
314 &run_loop));
315 run_loop.Run();
316 }
317
318 EXPECT_EQ(0, num_called);
319 fake_file_system_.TriggerWatchers(kAuthority, kDirSpec.document_id,
320 mojom::ChangeType::CHANGED);
321 base::RunLoop().RunUntilIdle();
322 EXPECT_EQ(1, num_called);
323
324 {
325 base::RunLoop run_loop;
326 root_->RemoveWatcher(
327 base::FilePath(FILE_PATH_LITERAL("dir")),
328 base::Bind(
329 [](base::RunLoop* run_loop, base::File::Error error) {
330 EXPECT_EQ(base::File::FILE_OK, error);
331 run_loop->Quit();
332 },
333 &run_loop));
334 run_loop.Run();
335 }
336 }
337
338 TEST_F(ArcDocumentsProviderRootTest, WatchDeleted) {
339 int num_called = 0;
340 auto watcher_callback = base::Bind(
341 [](int* num_called, ChangeType type) {
342 EXPECT_EQ(ChangeType::DELETED, type);
343 ++(*num_called);
344 },
345 &num_called);
346
347 {
348 base::RunLoop run_loop;
349 root_->AddWatcher(base::FilePath(FILE_PATH_LITERAL("dir")),
350 watcher_callback,
351 base::Bind(
352 [](base::RunLoop* run_loop, base::File::Error error) {
353 EXPECT_EQ(base::File::FILE_OK, error);
354 run_loop->Quit();
355 },
356 &run_loop));
357 run_loop.Run();
358 }
359
360 EXPECT_EQ(0, num_called);
361 fake_file_system_.TriggerWatchers(kAuthority, kDirSpec.document_id,
362 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
363 base::RunLoop().RunUntilIdle();
364 EXPECT_EQ(1, num_called);
365
366 // The watcher has already been deleted, so RemoveWatcher() should fail.
367 {
368 base::RunLoop run_loop;
369 root_->RemoveWatcher(
370 base::FilePath(FILE_PATH_LITERAL("dir")),
371 base::Bind(
372 [](base::RunLoop* run_loop, base::File::Error error) {
373 EXPECT_EQ(base::File::FILE_ERROR_FAILED, error);
374 run_loop->Quit();
375 },
376 &run_loop));
377 run_loop.Run();
378 }
379 }
380
290 TEST_F(ArcDocumentsProviderRootTest, ResolveToContentUrl) { 381 TEST_F(ArcDocumentsProviderRootTest, ResolveToContentUrl) {
291 base::RunLoop run_loop; 382 base::RunLoop run_loop;
292 root_->ResolveToContentUrl( 383 root_->ResolveToContentUrl(
293 base::FilePath(FILE_PATH_LITERAL("dir/photo.jpg")), 384 base::FilePath(FILE_PATH_LITERAL("dir/photo.jpg")),
294 base::Bind( 385 base::Bind(
295 [](base::RunLoop* run_loop, const GURL& url) { 386 [](base::RunLoop* run_loop, const GURL& url) {
296 EXPECT_EQ(GURL("content://org.chromium.test/document/photo-id"), 387 EXPECT_EQ(GURL("content://org.chromium.test/document/photo-id"),
297 url); 388 url);
298 run_loop->Quit(); 389 run_loop->Quit();
299 }, 390 },
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 [](base::RunLoop* run_loop, const GURL& url) { 428 [](base::RunLoop* run_loop, const GURL& url) {
338 EXPECT_EQ(GURL("content://org.chromium.test/document/dup3-id"), 429 EXPECT_EQ(GURL("content://org.chromium.test/document/dup3-id"),
339 url); 430 url);
340 run_loop->Quit(); 431 run_loop->Quit();
341 }, 432 },
342 &run_loop)); 433 &run_loop));
343 run_loop.Run(); 434 run_loop.Run();
344 } 435 }
345 436
346 } // namespace arc 437 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698