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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/operations/unobserve_entry_unittest.cc

Issue 674413002: [fsp] Rename ObserveEntry with AddWatcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 6 years, 1 month 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
(Empty)
1 // Copyright 2014 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.
4
5 #include "chrome/browser/chromeos/file_system_provider/operations/unobserve_entr y.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/files/file.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h"
14 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h"
15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h"
16 #include "chrome/common/extensions/api/file_system_provider.h"
17 #include "chrome/common/extensions/api/file_system_provider_internal.h"
18 #include "extensions/browser/event_router.h"
19 #include "storage/browser/fileapi/async_file_util.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 namespace chromeos {
23 namespace file_system_provider {
24 namespace operations {
25 namespace {
26
27 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
28 const char kFileSystemId[] = "testing-file-system";
29 const int kRequestId = 2;
30 const base::FilePath::CharType kEntryPath[] = "/kitty/and/puppy/happy";
31
32 } // namespace
33
34 class FileSystemProviderOperationsUnobserveEntryTest : public testing::Test {
35 protected:
36 FileSystemProviderOperationsUnobserveEntryTest() {}
37 virtual ~FileSystemProviderOperationsUnobserveEntryTest() {}
38
39 virtual void SetUp() override {
40 file_system_info_ = ProvidedFileSystemInfo(
41 kExtensionId,
42 MountOptions(kFileSystemId, "" /* display_name */),
43 base::FilePath());
44 }
45
46 ProvidedFileSystemInfo file_system_info_;
47 };
48
49 TEST_F(FileSystemProviderOperationsUnobserveEntryTest, Execute) {
50 using extensions::api::file_system_provider::UnobserveEntryRequestedOptions;
51
52 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
53 util::StatusCallbackLog callback_log;
54
55 UnobserveEntry unobserve_entry(
56 NULL,
57 file_system_info_,
58 base::FilePath::FromUTF8Unsafe(kEntryPath),
59 true /* recursive */,
60 base::Bind(&util::LogStatusCallback, &callback_log));
61 unobserve_entry.SetDispatchEventImplForTesting(
62 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
63 base::Unretained(&dispatcher)));
64
65 EXPECT_TRUE(unobserve_entry.Execute(kRequestId));
66
67 ASSERT_EQ(1u, dispatcher.events().size());
68 extensions::Event* event = dispatcher.events()[0];
69 EXPECT_EQ(extensions::api::file_system_provider::OnUnobserveEntryRequested::
70 kEventName,
71 event->event_name);
72 base::ListValue* event_args = event->event_args.get();
73 ASSERT_EQ(1u, event_args->GetSize());
74
75 const base::DictionaryValue* options_as_value = NULL;
76 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
77
78 UnobserveEntryRequestedOptions options;
79 ASSERT_TRUE(
80 UnobserveEntryRequestedOptions::Populate(*options_as_value, &options));
81 EXPECT_EQ(kFileSystemId, options.file_system_id);
82 EXPECT_EQ(kRequestId, options.request_id);
83 EXPECT_EQ(kEntryPath, options.entry_path);
84 EXPECT_TRUE(options.recursive);
85 }
86
87 TEST_F(FileSystemProviderOperationsUnobserveEntryTest, Execute_NoListener) {
88 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
89 util::StatusCallbackLog callback_log;
90
91 UnobserveEntry unobserve_entry(
92 NULL,
93 file_system_info_,
94 base::FilePath::FromUTF8Unsafe(kEntryPath),
95 true /* recursive */,
96 base::Bind(&util::LogStatusCallback, &callback_log));
97 unobserve_entry.SetDispatchEventImplForTesting(
98 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
99 base::Unretained(&dispatcher)));
100
101 EXPECT_FALSE(unobserve_entry.Execute(kRequestId));
102 }
103
104 TEST_F(FileSystemProviderOperationsUnobserveEntryTest, OnSuccess) {
105 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
106 util::StatusCallbackLog callback_log;
107
108 UnobserveEntry unobserve_entry(
109 NULL,
110 file_system_info_,
111 base::FilePath::FromUTF8Unsafe(kEntryPath),
112 true /* recursive */,
113 base::Bind(&util::LogStatusCallback, &callback_log));
114 unobserve_entry.SetDispatchEventImplForTesting(
115 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
116 base::Unretained(&dispatcher)));
117
118 EXPECT_TRUE(unobserve_entry.Execute(kRequestId));
119
120 unobserve_entry.OnSuccess(kRequestId,
121 scoped_ptr<RequestValue>(new RequestValue()),
122 false /* has_more */);
123 ASSERT_EQ(1u, callback_log.size());
124 EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
125 }
126
127 TEST_F(FileSystemProviderOperationsUnobserveEntryTest, OnError) {
128 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
129 util::StatusCallbackLog callback_log;
130
131 UnobserveEntry unobserve_entry(
132 NULL,
133 file_system_info_,
134 base::FilePath::FromUTF8Unsafe(kEntryPath),
135 true /* recursive */,
136 base::Bind(&util::LogStatusCallback, &callback_log));
137 unobserve_entry.SetDispatchEventImplForTesting(
138 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
139 base::Unretained(&dispatcher)));
140
141 EXPECT_TRUE(unobserve_entry.Execute(kRequestId));
142
143 unobserve_entry.OnError(kRequestId,
144 scoped_ptr<RequestValue>(new RequestValue()),
145 base::File::FILE_ERROR_TOO_MANY_OPENED);
146 ASSERT_EQ(1u, callback_log.size());
147 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
148 }
149
150 } // namespace operations
151 } // namespace file_system_provider
152 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698