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

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

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

Powered by Google App Engine
This is Rietveld 408576698