OLD | NEW |
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 }, | 72 }, |
73 counter)); | 73 counter)); |
74 runner_->GetDocument( | 74 runner_->GetDocument( |
75 kAuthority, kDocumentId, | 75 kAuthority, kDocumentId, |
76 base::Bind( | 76 base::Bind( |
77 [](int* counter, mojom::DocumentPtr document) { ++*counter; }, | 77 [](int* counter, mojom::DocumentPtr document) { ++*counter; }, |
78 counter)); | 78 counter)); |
79 runner_->GetFileSize( | 79 runner_->GetFileSize( |
80 GURL(kUrl), | 80 GURL(kUrl), |
81 base::Bind([](int* counter, int64_t size) { ++*counter; }, counter)); | 81 base::Bind([](int* counter, int64_t size) { ++*counter; }, counter)); |
| 82 runner_->GetMimeType( |
| 83 GURL(kUrl), |
| 84 base::Bind( |
| 85 [](int* counter, const base::Optional<std::string>& mime_type) { |
| 86 ++*counter; |
| 87 }, |
| 88 counter)); |
82 runner_->OpenFileToRead( | 89 runner_->OpenFileToRead( |
83 GURL(kUrl), | 90 GURL(kUrl), |
84 base::Bind([](int* counter, mojo::ScopedHandle handle) { ++*counter; }, | 91 base::Bind([](int* counter, mojo::ScopedHandle handle) { ++*counter; }, |
85 counter)); | 92 counter)); |
86 | 93 |
87 // RemoveWatcher() is never deferred. | 94 // RemoveWatcher() is never deferred. |
88 runner_->RemoveWatcher( | 95 runner_->RemoveWatcher( |
89 123, | 96 123, |
90 base::Bind([](int* counter, bool success) { ++*counter; }, counter)); | 97 base::Bind([](int* counter, bool success) { ++*counter; }, counter)); |
91 } | 98 } |
92 | 99 |
93 content::TestBrowserThreadBundle thread_bundle_; | 100 content::TestBrowserThreadBundle thread_bundle_; |
94 FakeFileSystemInstance file_system_instance_; | 101 FakeFileSystemInstance file_system_instance_; |
95 std::unique_ptr<ArcServiceManager> arc_service_manager_; | 102 std::unique_ptr<ArcServiceManager> arc_service_manager_; |
96 // Owned by |arc_service_manager_|. | 103 // Owned by |arc_service_manager_|. |
97 ArcFileSystemOperationRunner* runner_; | 104 ArcFileSystemOperationRunner* runner_; |
98 | 105 |
99 private: | 106 private: |
100 DISALLOW_COPY_AND_ASSIGN(ArcFileSystemOperationRunnerTest); | 107 DISALLOW_COPY_AND_ASSIGN(ArcFileSystemOperationRunnerTest); |
101 }; | 108 }; |
102 | 109 |
103 TEST_F(ArcFileSystemOperationRunnerTest, RunImmediately) { | 110 TEST_F(ArcFileSystemOperationRunnerTest, RunImmediately) { |
104 int counter = 0; | 111 int counter = 0; |
105 CallSetShouldDefer(false); | 112 CallSetShouldDefer(false); |
106 CallAllFunctions(&counter); | 113 CallAllFunctions(&counter); |
107 base::RunLoop().RunUntilIdle(); | 114 base::RunLoop().RunUntilIdle(); |
108 EXPECT_EQ(6, counter); | 115 EXPECT_EQ(7, counter); |
109 } | 116 } |
110 | 117 |
111 TEST_F(ArcFileSystemOperationRunnerTest, DeferAndRun) { | 118 TEST_F(ArcFileSystemOperationRunnerTest, DeferAndRun) { |
112 int counter = 0; | 119 int counter = 0; |
113 CallSetShouldDefer(true); | 120 CallSetShouldDefer(true); |
114 CallAllFunctions(&counter); | 121 CallAllFunctions(&counter); |
115 base::RunLoop().RunUntilIdle(); | 122 base::RunLoop().RunUntilIdle(); |
116 EXPECT_EQ(1, counter); | 123 EXPECT_EQ(1, counter); |
117 | 124 |
118 CallSetShouldDefer(false); | 125 CallSetShouldDefer(false); |
119 base::RunLoop().RunUntilIdle(); | 126 base::RunLoop().RunUntilIdle(); |
120 EXPECT_EQ(6, counter); | 127 EXPECT_EQ(7, counter); |
121 } | 128 } |
122 | 129 |
123 TEST_F(ArcFileSystemOperationRunnerTest, DeferAndDiscard) { | 130 TEST_F(ArcFileSystemOperationRunnerTest, DeferAndDiscard) { |
124 int counter = 0; | 131 int counter = 0; |
125 CallSetShouldDefer(true); | 132 CallSetShouldDefer(true); |
126 CallAllFunctions(&counter); | 133 CallAllFunctions(&counter); |
127 base::RunLoop().RunUntilIdle(); | 134 base::RunLoop().RunUntilIdle(); |
128 EXPECT_EQ(1, counter); | 135 EXPECT_EQ(1, counter); |
129 | 136 |
130 arc_service_manager_.reset(); | 137 arc_service_manager_.reset(); |
131 base::RunLoop().RunUntilIdle(); | 138 base::RunLoop().RunUntilIdle(); |
132 EXPECT_EQ(1, counter); | 139 EXPECT_EQ(1, counter); |
133 } | 140 } |
134 | 141 |
135 TEST_F(ArcFileSystemOperationRunnerTest, FileInstanceUnavailable) { | 142 TEST_F(ArcFileSystemOperationRunnerTest, FileInstanceUnavailable) { |
136 arc_service_manager_->arc_bridge_service()->file_system()->SetInstance( | 143 arc_service_manager_->arc_bridge_service()->file_system()->SetInstance( |
137 nullptr); | 144 nullptr); |
138 | 145 |
139 int counter = 0; | 146 int counter = 0; |
140 CallSetShouldDefer(false); | 147 CallSetShouldDefer(false); |
141 CallAllFunctions(&counter); | 148 CallAllFunctions(&counter); |
142 base::RunLoop().RunUntilIdle(); | 149 base::RunLoop().RunUntilIdle(); |
143 EXPECT_EQ(6, counter); | 150 EXPECT_EQ(7, counter); |
144 } | 151 } |
145 | 152 |
146 } // namespace arc | 153 } // namespace arc |
OLD | NEW |