Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / file_system_provider / file_system_provider_apitest.cc
blobb432309c0781ee3618ca976a17ee42b689b1cfb9
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/files/file.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/memory/scoped_vector.h"
8 #include "base/thread_task_runner_handle.h"
9 #include "base/time/time.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/file_system_provider/notification_manager_interface.h"
12 #include "chrome/browser/chromeos/file_system_provider/observer.h"
13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
15 #include "chrome/browser/chromeos/file_system_provider/request_manager.h"
16 #include "chrome/browser/chromeos/file_system_provider/request_value.h"
17 #include "chrome/browser/chromeos/file_system_provider/service.h"
18 #include "chrome/browser/extensions/extension_apitest.h"
19 #include "ui/base/ui_base_types.h"
20 #include "ui/message_center/message_center.h"
22 namespace extensions {
23 namespace {
25 using chromeos::file_system_provider::MountContext;
26 using chromeos::file_system_provider::NotificationManagerInterface;
27 using chromeos::file_system_provider::Observer;
28 using chromeos::file_system_provider::ProvidedFileSystemInterface;
29 using chromeos::file_system_provider::ProvidedFileSystemInfo;
30 using chromeos::file_system_provider::RequestManager;
31 using chromeos::file_system_provider::RequestType;
32 using chromeos::file_system_provider::RequestValue;
33 using chromeos::file_system_provider::Service;
35 // Clicks the default button on the notification as soon as request timeouts
36 // and a unresponsiveness notification is shown.
37 class NotificationButtonClicker : public RequestManager::Observer {
38 public:
39 explicit NotificationButtonClicker(
40 const ProvidedFileSystemInfo& file_system_info)
41 : file_system_info_(file_system_info) {}
42 ~NotificationButtonClicker() override {}
44 // RequestManager::Observer overrides.
45 void OnRequestCreated(int request_id, RequestType type) override {}
46 void OnRequestDestroyed(int request_id) override {}
47 void OnRequestExecuted(int request_id) override {}
48 void OnRequestFulfilled(int request_id,
49 const RequestValue& result,
50 bool has_more) override {}
51 void OnRequestRejected(int request_id,
52 const RequestValue& result,
53 base::File::Error error) override {}
54 void OnRequestTimeouted(int request_id) override {
55 // Call asynchronously so the notification is setup is completed.
56 base::ThreadTaskRunnerHandle::Get()->PostTask(
57 FROM_HERE, base::Bind(&NotificationButtonClicker::ClickButton,
58 base::Unretained(this)));
61 private:
62 void ClickButton() {
63 g_browser_process->message_center()->ClickOnNotificationButton(
64 file_system_info_.mount_path().value(), ui::DIALOG_BUTTON_OK);
67 ProvidedFileSystemInfo file_system_info_;
68 DISALLOW_COPY_AND_ASSIGN(NotificationButtonClicker);
71 // Simulates clicking on the unresponsive notification's abort button. Also,
72 // sets the timeout delay to 0 ms, so the notification is shown faster.
73 class AbortOnUnresponsivePerformer : public Observer {
74 public:
75 explicit AbortOnUnresponsivePerformer(Profile* profile)
76 : service_(Service::Get(profile)) {
77 DCHECK(profile);
78 DCHECK(service_);
79 service_->AddObserver(this);
82 ~AbortOnUnresponsivePerformer() override { service_->RemoveObserver(this); }
84 // Observer overrides.
85 void OnProvidedFileSystemMount(const ProvidedFileSystemInfo& file_system_info,
86 MountContext context,
87 base::File::Error error) override {
88 if (error != base::File::FILE_OK)
89 return;
91 ProvidedFileSystemInterface* const file_system =
92 service_->GetProvidedFileSystem(file_system_info.extension_id(),
93 file_system_info.file_system_id());
94 DCHECK(file_system);
95 file_system->GetRequestManager()->SetTimeoutForTesting(base::TimeDelta());
97 scoped_ptr<NotificationButtonClicker> clicker(
98 new NotificationButtonClicker(file_system->GetFileSystemInfo()));
100 file_system->GetRequestManager()->AddObserver(clicker.get());
101 clickers_.push_back(clicker.Pass());
104 void OnProvidedFileSystemUnmount(
105 const ProvidedFileSystemInfo& file_system_info,
106 base::File::Error error) override {}
108 private:
109 Service* service_; // Not owned.
110 ScopedVector<NotificationButtonClicker> clickers_;
111 DISALLOW_COPY_AND_ASSIGN(AbortOnUnresponsivePerformer);
114 } // namespace
116 class FileSystemProviderApiTest : public ExtensionApiTest {
117 public:
118 FileSystemProviderApiTest() {}
120 // Loads a helper testing extension.
121 void SetUpOnMainThread() override {
122 ExtensionApiTest::SetUpOnMainThread();
123 const extensions::Extension* extension = LoadExtensionWithFlags(
124 test_data_dir_.AppendASCII("file_system_provider/test_util"),
125 kFlagEnableIncognito);
126 ASSERT_TRUE(extension);
130 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, Mount) {
131 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/mount",
132 kFlagLoadAsComponent))
133 << message_;
136 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, Unmount) {
137 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/unmount",
138 kFlagLoadAsComponent))
139 << message_;
142 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, GetAll) {
143 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/get_all",
144 kFlagLoadAsComponent))
145 << message_;
148 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, GetMetadata) {
149 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/get_metadata",
150 kFlagLoadAsComponent))
151 << message_;
154 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, ReadDirectory) {
155 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/read_directory",
156 kFlagLoadAsComponent))
157 << message_;
160 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, ReadFile) {
161 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/read_file",
162 kFlagLoadAsComponent))
163 << message_;
166 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, BigFile) {
167 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/big_file",
168 kFlagLoadAsComponent))
169 << message_;
172 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, Evil) {
173 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/evil",
174 kFlagLoadAsComponent))
175 << message_;
178 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, MimeType) {
179 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/mime_type",
180 kFlagLoadAsComponent))
181 << message_;
184 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, CreateDirectory) {
185 ASSERT_TRUE(RunPlatformAppTestWithFlags(
186 "file_system_provider/create_directory", kFlagLoadAsComponent))
187 << message_;
190 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, DeleteEntry) {
191 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/delete_entry",
192 kFlagLoadAsComponent))
193 << message_;
196 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, CreateFile) {
197 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/create_file",
198 kFlagLoadAsComponent))
199 << message_;
202 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, CopyEntry) {
203 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/copy_entry",
204 kFlagLoadAsComponent))
205 << message_;
208 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, MoveEntry) {
209 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/move_entry",
210 kFlagLoadAsComponent))
211 << message_;
214 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, Truncate) {
215 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/truncate",
216 kFlagLoadAsComponent))
217 << message_;
220 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, WriteFile) {
221 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/write_file",
222 kFlagLoadAsComponent))
223 << message_;
226 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, Extension) {
227 ASSERT_TRUE(RunComponentExtensionTest("file_system_provider/extension"))
228 << message_;
231 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, Thumbnail) {
232 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/thumbnail",
233 kFlagLoadAsComponent))
234 << message_;
237 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, AddWatcher) {
238 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/add_watcher",
239 kFlagLoadAsComponent))
240 << message_;
243 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, RemoveWatcher) {
244 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/remove_watcher",
245 kFlagLoadAsComponent))
246 << message_;
249 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, Notify) {
250 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/notify",
251 kFlagLoadAsComponent))
252 << message_;
255 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, Configure) {
256 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/configure",
257 kFlagLoadAsComponent))
258 << message_;
261 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, GetActions) {
262 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/get_actions",
263 kFlagLoadAsComponent))
264 << message_;
267 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, ExecuteAction) {
268 ASSERT_TRUE(RunPlatformAppTestWithFlags("file_system_provider/execute_action",
269 kFlagLoadAsComponent))
270 << message_;
273 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, Unresponsive_Extension) {
274 AbortOnUnresponsivePerformer performer(browser()->profile());
275 ASSERT_TRUE(
276 RunComponentExtensionTest("file_system_provider/unresponsive_extension"))
277 << message_;
280 IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, Unresponsive_App) {
281 AbortOnUnresponsivePerformer performer(browser()->profile());
282 ASSERT_TRUE(RunPlatformAppTestWithFlags(
283 "file_system_provider/unresponsive_app", kFlagLoadAsComponent))
284 << message_;
287 } // namespace extensions