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

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

Issue 2715493002: mediaview: Support watchers in ArcFileSystemOperationRunner. (Closed)
Patch Set: Rebased to ToT. Created 3 years, 9 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 23 matching lines...) Expand all
34 ArcFileSystemOperationRunnerTest() = default; 34 ArcFileSystemOperationRunnerTest() = default;
35 ~ArcFileSystemOperationRunnerTest() override = default; 35 ~ArcFileSystemOperationRunnerTest() override = default;
36 36
37 void SetUp() override { 37 void SetUp() override {
38 arc_service_manager_ = base::MakeUnique<ArcServiceManager>(nullptr); 38 arc_service_manager_ = base::MakeUnique<ArcServiceManager>(nullptr);
39 arc_service_manager_->arc_bridge_service()->file_system()->SetInstance( 39 arc_service_manager_->arc_bridge_service()->file_system()->SetInstance(
40 &file_system_instance_); 40 &file_system_instance_);
41 arc_service_manager_->AddService( 41 arc_service_manager_->AddService(
42 ArcFileSystemOperationRunner::CreateForTesting( 42 ArcFileSystemOperationRunner::CreateForTesting(
43 arc_service_manager_->arc_bridge_service())); 43 arc_service_manager_->arc_bridge_service()));
44
45 // Run the message loop until FileSystemInstance::Init() is called.
46 base::RunLoop().RunUntilIdle();
47 ASSERT_TRUE(file_system_instance_.InitCalled());
48
44 runner_ = arc_service_manager_->GetService<ArcFileSystemOperationRunner>(); 49 runner_ = arc_service_manager_->GetService<ArcFileSystemOperationRunner>();
45 } 50 }
46 51
47 protected: 52 protected:
48 // Calls private ArcFileSystemOperationRunner::SetShouldDefer(). 53 // Calls private ArcFileSystemOperationRunner::SetShouldDefer().
49 void CallSetShouldDefer(bool should_defer) { 54 void CallSetShouldDefer(bool should_defer) {
50 runner_->SetShouldDefer(should_defer); 55 runner_->SetShouldDefer(should_defer);
51 } 56 }
52 57
58 // Calls all functions implemented by ArcFileSystemOperationRunner.
59 void CallAllFunctions(int* counter) {
60 // Following functions are deferred.
61 runner_->AddWatcher(
62 kAuthority, kDocumentId,
63 base::Bind([](ArcFileSystemOperationRunner::ChangeType type) {}),
64 base::Bind([](int* counter, int64_t watcher_id) { ++*counter; },
65 counter));
66 runner_->GetChildDocuments(
67 kAuthority, kDocumentId,
68 base::Bind(
69 [](int* counter,
70 base::Optional<std::vector<mojom::DocumentPtr>> documents) {
71 ++*counter;
72 },
73 counter));
74 runner_->GetDocument(
75 kAuthority, kDocumentId,
76 base::Bind(
77 [](int* counter, mojom::DocumentPtr document) { ++*counter; },
78 counter));
79 runner_->GetFileSize(
80 GURL(kUrl),
81 base::Bind([](int* counter, int64_t size) { ++*counter; }, counter));
82 runner_->OpenFileToRead(
83 GURL(kUrl),
84 base::Bind([](int* counter, mojo::ScopedHandle handle) { ++*counter; },
85 counter));
86
87 // RemoveWatcher() is never deferred.
88 runner_->RemoveWatcher(
89 123,
Luis Héctor Chávez 2017/03/06 17:10:48 can you make this a named constant? Maybe kInvalid
90 base::Bind([](int* counter, bool success) { ++*counter; }, counter));
91 }
92
53 content::TestBrowserThreadBundle thread_bundle_; 93 content::TestBrowserThreadBundle thread_bundle_;
54 FakeFileSystemInstance file_system_instance_; 94 FakeFileSystemInstance file_system_instance_;
55 std::unique_ptr<ArcServiceManager> arc_service_manager_; 95 std::unique_ptr<ArcServiceManager> arc_service_manager_;
56 // Owned by |arc_service_manager_|. 96 // Owned by |arc_service_manager_|.
57 ArcFileSystemOperationRunner* runner_; 97 ArcFileSystemOperationRunner* runner_;
58 98
59 private: 99 private:
60 DISALLOW_COPY_AND_ASSIGN(ArcFileSystemOperationRunnerTest); 100 DISALLOW_COPY_AND_ASSIGN(ArcFileSystemOperationRunnerTest);
61 }; 101 };
62 102
63 TEST_F(ArcFileSystemOperationRunnerTest, RunImmediately) { 103 TEST_F(ArcFileSystemOperationRunnerTest, RunImmediately) {
64 int counter = 0; 104 int counter = 0;
65 CallSetShouldDefer(false); 105 CallSetShouldDefer(false);
66 runner_->GetChildDocuments( 106 CallAllFunctions(&counter);
67 kAuthority, kDocumentId,
68 base::Bind(
69 [](int* counter,
70 base::Optional<std::vector<mojom::DocumentPtr>> documents) {
71 ++*counter;
72 },
73 &counter));
74 runner_->GetDocument(
75 kAuthority, kDocumentId,
76 base::Bind([](int* counter, mojom::DocumentPtr document) { ++*counter; },
77 &counter));
78 runner_->GetFileSize(
79 GURL(kUrl),
80 base::Bind([](int* counter, int64_t size) { ++*counter; }, &counter));
81 runner_->OpenFileToRead(
82 GURL(kUrl),
83 base::Bind([](int* counter, mojo::ScopedHandle handle) { ++*counter; },
84 &counter));
85 base::RunLoop().RunUntilIdle(); 107 base::RunLoop().RunUntilIdle();
86 EXPECT_EQ(4, counter); 108 EXPECT_EQ(6, counter);
87 } 109 }
88 110
89 TEST_F(ArcFileSystemOperationRunnerTest, DeferAndRun) { 111 TEST_F(ArcFileSystemOperationRunnerTest, DeferAndRun) {
90 int counter = 0; 112 int counter = 0;
91 CallSetShouldDefer(true); 113 CallSetShouldDefer(true);
92 runner_->GetChildDocuments( 114 CallAllFunctions(&counter);
93 kAuthority, kDocumentId,
94 base::Bind(
95 [](int* counter,
96 base::Optional<std::vector<mojom::DocumentPtr>> documents) {
97 ++*counter;
98 },
99 &counter));
100 runner_->GetDocument(
101 kAuthority, kDocumentId,
102 base::Bind([](int* counter, mojom::DocumentPtr document) { ++*counter; },
103 &counter));
104 runner_->GetFileSize(
105 GURL(kUrl),
106 base::Bind([](int* counter, int64_t size) { ++*counter; }, &counter));
107 runner_->OpenFileToRead(
108 GURL(kUrl),
109 base::Bind([](int* counter, mojo::ScopedHandle handle) { ++*counter; },
110 &counter));
111 base::RunLoop().RunUntilIdle(); 115 base::RunLoop().RunUntilIdle();
112 EXPECT_EQ(0, counter); 116 EXPECT_EQ(1, counter);
113 117
114 CallSetShouldDefer(false); 118 CallSetShouldDefer(false);
115 base::RunLoop().RunUntilIdle(); 119 base::RunLoop().RunUntilIdle();
116 EXPECT_EQ(4, counter); 120 EXPECT_EQ(6, counter);
117 } 121 }
118 122
119 TEST_F(ArcFileSystemOperationRunnerTest, DeferAndDiscard) { 123 TEST_F(ArcFileSystemOperationRunnerTest, DeferAndDiscard) {
120 int counter = 0; 124 int counter = 0;
121 CallSetShouldDefer(true); 125 CallSetShouldDefer(true);
122 runner_->GetChildDocuments( 126 CallAllFunctions(&counter);
123 kAuthority, kDocumentId,
124 base::Bind(
125 [](int* counter,
126 base::Optional<std::vector<mojom::DocumentPtr>> documents) {
127 ++*counter;
128 },
129 &counter));
130 runner_->GetDocument(
131 kAuthority, kDocumentId,
132 base::Bind([](int* counter, mojom::DocumentPtr document) { ++*counter; },
133 &counter));
134 runner_->GetFileSize(
135 GURL(kUrl),
136 base::Bind([](int* counter, int64_t size) { ++*counter; }, &counter));
137 runner_->OpenFileToRead(
138 GURL(kUrl),
139 base::Bind([](int* counter, mojo::ScopedHandle handle) { ++*counter; },
140 &counter));
141 base::RunLoop().RunUntilIdle(); 127 base::RunLoop().RunUntilIdle();
142 EXPECT_EQ(0, counter); 128 EXPECT_EQ(1, counter);
143 129
144 arc_service_manager_.reset(); 130 arc_service_manager_.reset();
145 base::RunLoop().RunUntilIdle(); 131 base::RunLoop().RunUntilIdle();
146 EXPECT_EQ(0, counter); 132 EXPECT_EQ(1, counter);
147 } 133 }
148 134
149 TEST_F(ArcFileSystemOperationRunnerTest, FileInstanceUnavailable) { 135 TEST_F(ArcFileSystemOperationRunnerTest, FileInstanceUnavailable) {
150 arc_service_manager_->arc_bridge_service()->file_system()->SetInstance( 136 arc_service_manager_->arc_bridge_service()->file_system()->SetInstance(
151 nullptr); 137 nullptr);
152 138
153 int counter = 0; 139 int counter = 0;
154 CallSetShouldDefer(false); 140 CallSetShouldDefer(false);
155 runner_->GetChildDocuments( 141 CallAllFunctions(&counter);
156 kAuthority, kDocumentId,
157 base::Bind(
158 [](int* counter,
159 base::Optional<std::vector<mojom::DocumentPtr>> documents) {
160 ++*counter;
161 },
162 &counter));
163 runner_->GetDocument(
164 kAuthority, kDocumentId,
165 base::Bind([](int* counter, mojom::DocumentPtr document) { ++*counter; },
166 &counter));
167 runner_->GetFileSize(
168 GURL(kUrl),
169 base::Bind([](int* counter, int64_t size) { ++*counter; }, &counter));
170 runner_->OpenFileToRead(
171 GURL(kUrl),
172 base::Bind([](int* counter, mojo::ScopedHandle handle) { ++*counter; },
173 &counter));
174 base::RunLoop().RunUntilIdle(); 142 base::RunLoop().RunUntilIdle();
175 EXPECT_EQ(4, counter); 143 EXPECT_EQ(6, counter);
176 } 144 }
177 145
178 } // namespace arc 146 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698