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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/provided_file_system_unittest.cc

Issue 1870793002: Convert //chrome/browser/chromeos from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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/provided_file_system.h" 5 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h"
6 6
7 #include <memory>
7 #include <string> 8 #include <string>
8 #include <utility> 9 #include <utility>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/files/file.h" 12 #include "base/files/file.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h"
13 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
16 #include "base/run_loop.h" 17 #include "base/run_loop.h"
17 #include "base/thread_task_runner_handle.h" 18 #include "base/thread_task_runner_handle.h"
18 #include "base/values.h" 19 #include "base/values.h"
19 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" 20 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h"
20 #include "chrome/browser/chromeos/file_system_provider/notification_manager.h" 21 #include "chrome/browser/chromeos/file_system_provider/notification_manager.h"
21 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h" 22 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h"
22 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h" 23 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h"
23 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_obse rver.h" 24 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_obse rver.h"
24 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" 25 #include "chrome/browser/chromeos/file_system_provider/request_manager.h"
(...skipping 29 matching lines...) Expand all
54 class FakeEventRouter : public extensions::EventRouter { 55 class FakeEventRouter : public extensions::EventRouter {
55 public: 56 public:
56 FakeEventRouter(Profile* profile, ProvidedFileSystemInterface* file_system) 57 FakeEventRouter(Profile* profile, ProvidedFileSystemInterface* file_system)
57 : EventRouter(profile, NULL), 58 : EventRouter(profile, NULL),
58 file_system_(file_system), 59 file_system_(file_system),
59 reply_result_(base::File::FILE_OK) {} 60 reply_result_(base::File::FILE_OK) {}
60 ~FakeEventRouter() override {} 61 ~FakeEventRouter() override {}
61 62
62 // Handles an event which would normally be routed to an extension. Instead 63 // Handles an event which would normally be routed to an extension. Instead
63 // replies with a hard coded response. 64 // replies with a hard coded response.
64 void DispatchEventToExtension(const std::string& extension_id, 65 void DispatchEventToExtension(
65 scoped_ptr<extensions::Event> event) override { 66 const std::string& extension_id,
67 std::unique_ptr<extensions::Event> event) override {
66 ASSERT_TRUE(file_system_); 68 ASSERT_TRUE(file_system_);
67 std::string file_system_id; 69 std::string file_system_id;
68 const base::DictionaryValue* dictionary_value = NULL; 70 const base::DictionaryValue* dictionary_value = NULL;
69 ASSERT_TRUE(event->event_args->GetDictionary(0, &dictionary_value)); 71 ASSERT_TRUE(event->event_args->GetDictionary(0, &dictionary_value));
70 EXPECT_TRUE(dictionary_value->GetString("fileSystemId", &file_system_id)); 72 EXPECT_TRUE(dictionary_value->GetString("fileSystemId", &file_system_id));
71 EXPECT_EQ(kFileSystemId, file_system_id); 73 EXPECT_EQ(kFileSystemId, file_system_id);
72 int request_id = -1; 74 int request_id = -1;
73 EXPECT_TRUE(dictionary_value->GetInteger("requestId", &request_id)); 75 EXPECT_TRUE(dictionary_value->GetInteger("requestId", &request_id));
74 EXPECT_TRUE(event->event_name == extensions::api::file_system_provider:: 76 EXPECT_TRUE(event->event_name == extensions::api::file_system_provider::
75 OnAddWatcherRequested::kEventName || 77 OnAddWatcherRequested::kEventName ||
76 event->event_name == extensions::api::file_system_provider:: 78 event->event_name == extensions::api::file_system_provider::
77 OnRemoveWatcherRequested::kEventName || 79 OnRemoveWatcherRequested::kEventName ||
78 event->event_name == extensions::api::file_system_provider:: 80 event->event_name == extensions::api::file_system_provider::
79 OnOpenFileRequested::kEventName || 81 OnOpenFileRequested::kEventName ||
80 event->event_name == extensions::api::file_system_provider:: 82 event->event_name == extensions::api::file_system_provider::
81 OnCloseFileRequested::kEventName); 83 OnCloseFileRequested::kEventName);
82 84
83 if (reply_result_ == base::File::FILE_OK) { 85 if (reply_result_ == base::File::FILE_OK) {
84 base::ListValue value_as_list; 86 base::ListValue value_as_list;
85 value_as_list.Set(0, new base::StringValue(kFileSystemId)); 87 value_as_list.Set(0, new base::StringValue(kFileSystemId));
86 value_as_list.Set(1, new base::FundamentalValue(request_id)); 88 value_as_list.Set(1, new base::FundamentalValue(request_id));
87 value_as_list.Set(2, new base::FundamentalValue(0) /* execution_time */); 89 value_as_list.Set(2, new base::FundamentalValue(0) /* execution_time */);
88 90
89 using extensions::api::file_system_provider_internal:: 91 using extensions::api::file_system_provider_internal::
90 OperationRequestedSuccess::Params; 92 OperationRequestedSuccess::Params;
91 scoped_ptr<Params> params(Params::Create(value_as_list)); 93 std::unique_ptr<Params> params(Params::Create(value_as_list));
92 ASSERT_TRUE(params.get()); 94 ASSERT_TRUE(params.get());
93 file_system_->GetRequestManager()->FulfillRequest( 95 file_system_->GetRequestManager()->FulfillRequest(
94 request_id, 96 request_id,
95 RequestValue::CreateForOperationSuccess(std::move(params)), 97 RequestValue::CreateForOperationSuccess(std::move(params)),
96 false /* has_more */); 98 false /* has_more */);
97 } else { 99 } else {
98 file_system_->GetRequestManager()->RejectRequest( 100 file_system_->GetRequestManager()->RejectRequest(
99 request_id, make_scoped_ptr(new RequestValue()), reply_result_); 101 request_id, base::WrapUnique(new RequestValue()), reply_result_);
100 } 102 }
101 } 103 }
102 104
103 void set_reply_result(base::File::Error result) { reply_result_ = result; } 105 void set_reply_result(base::File::Error result) { reply_result_ = result; }
104 106
105 private: 107 private:
106 ProvidedFileSystemInterface* const file_system_; // Not owned. 108 ProvidedFileSystemInterface* const file_system_; // Not owned.
107 base::File::Error reply_result_; 109 base::File::Error reply_result_;
108 DISALLOW_COPY_AND_ASSIGN(FakeEventRouter); 110 DISALLOW_COPY_AND_ASSIGN(FakeEventRouter);
109 }; 111 };
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 NULL, 252 NULL,
251 kExtensionId); 253 kExtensionId);
252 event_router_->AddEventListener( 254 event_router_->AddEventListener(
253 extensions::api::file_system_provider::OnOpenFileRequested::kEventName, 255 extensions::api::file_system_provider::OnOpenFileRequested::kEventName,
254 NULL, kExtensionId); 256 NULL, kExtensionId);
255 event_router_->AddEventListener( 257 event_router_->AddEventListener(
256 extensions::api::file_system_provider::OnCloseFileRequested::kEventName, 258 extensions::api::file_system_provider::OnCloseFileRequested::kEventName,
257 NULL, kExtensionId); 259 NULL, kExtensionId);
258 provided_file_system_->SetEventRouterForTesting(event_router_.get()); 260 provided_file_system_->SetEventRouterForTesting(event_router_.get());
259 provided_file_system_->SetNotificationManagerForTesting( 261 provided_file_system_->SetNotificationManagerForTesting(
260 make_scoped_ptr(new StubNotificationManager)); 262 base::WrapUnique(new StubNotificationManager));
261 } 263 }
262 264
263 content::TestBrowserThreadBundle thread_bundle_; 265 content::TestBrowserThreadBundle thread_bundle_;
264 scoped_ptr<TestingProfile> profile_; 266 std::unique_ptr<TestingProfile> profile_;
265 scoped_ptr<FakeEventRouter> event_router_; 267 std::unique_ptr<FakeEventRouter> event_router_;
266 scoped_ptr<ProvidedFileSystemInfo> file_system_info_; 268 std::unique_ptr<ProvidedFileSystemInfo> file_system_info_;
267 scoped_ptr<ProvidedFileSystem> provided_file_system_; 269 std::unique_ptr<ProvidedFileSystem> provided_file_system_;
268 }; 270 };
269 271
270 TEST_F(FileSystemProviderProvidedFileSystemTest, AutoUpdater) { 272 TEST_F(FileSystemProviderProvidedFileSystemTest, AutoUpdater) {
271 Log log; 273 Log log;
272 base::Closure firstCallback; 274 base::Closure firstCallback;
273 base::Closure secondCallback; 275 base::Closure secondCallback;
274 276
275 { 277 {
276 // Auto updater is ref counted, and bound to all callbacks. 278 // Auto updater is ref counted, and bound to all callbacks.
277 scoped_refptr<AutoUpdater> auto_updater(new AutoUpdater( 279 scoped_refptr<AutoUpdater> auto_updater(new AutoUpdater(
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 mount_options.file_system_id = kFileSystemId; 416 mount_options.file_system_id = kFileSystemId;
415 mount_options.display_name = kDisplayName; 417 mount_options.display_name = kDisplayName;
416 mount_options.supports_notify_tag = false; 418 mount_options.supports_notify_tag = false;
417 ProvidedFileSystemInfo file_system_info( 419 ProvidedFileSystemInfo file_system_info(
418 kExtensionId, mount_options, mount_path, false /* configurable */, 420 kExtensionId, mount_options, mount_path, false /* configurable */,
419 true /* watchable */, extensions::SOURCE_FILE); 421 true /* watchable */, extensions::SOURCE_FILE);
420 ProvidedFileSystem simple_provided_file_system(profile_.get(), 422 ProvidedFileSystem simple_provided_file_system(profile_.get(),
421 file_system_info); 423 file_system_info);
422 simple_provided_file_system.SetEventRouterForTesting(event_router_.get()); 424 simple_provided_file_system.SetEventRouterForTesting(event_router_.get());
423 simple_provided_file_system.SetNotificationManagerForTesting( 425 simple_provided_file_system.SetNotificationManagerForTesting(
424 make_scoped_ptr(new StubNotificationManager)); 426 base::WrapUnique(new StubNotificationManager));
425 427
426 simple_provided_file_system.AddObserver(&observer); 428 simple_provided_file_system.AddObserver(&observer);
427 429
428 simple_provided_file_system.AddWatcher( 430 simple_provided_file_system.AddWatcher(
429 GURL(kOrigin), base::FilePath(kDirectoryPath), false /* recursive */, 431 GURL(kOrigin), base::FilePath(kDirectoryPath), false /* recursive */,
430 true /* persistent */, base::Bind(&LogStatus, base::Unretained(&log)), 432 true /* persistent */, base::Bind(&LogStatus, base::Unretained(&log)),
431 storage::WatcherManager::NotificationCallback()); 433 storage::WatcherManager::NotificationCallback());
432 base::RunLoop().RunUntilIdle(); 434 base::RunLoop().RunUntilIdle();
433 435
434 ASSERT_EQ(1u, log.size()); 436 ASSERT_EQ(1u, log.size());
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 745
744 { 746 {
745 // Notify about a change. 747 // Notify about a change.
746 const storage::WatcherManager::ChangeType change_type = 748 const storage::WatcherManager::ChangeType change_type =
747 storage::WatcherManager::CHANGED; 749 storage::WatcherManager::CHANGED;
748 const std::string tag = "hello-world"; 750 const std::string tag = "hello-world";
749 751
750 Log log; 752 Log log;
751 provided_file_system_->Notify( 753 provided_file_system_->Notify(
752 base::FilePath(kDirectoryPath), false /* recursive */, change_type, 754 base::FilePath(kDirectoryPath), false /* recursive */, change_type,
753 make_scoped_ptr(new ProvidedFileSystemObserver::Changes), tag, 755 base::WrapUnique(new ProvidedFileSystemObserver::Changes), tag,
754 base::Bind(&LogStatus, base::Unretained(&log))); 756 base::Bind(&LogStatus, base::Unretained(&log)));
755 base::RunLoop().RunUntilIdle(); 757 base::RunLoop().RunUntilIdle();
756 758
757 // Confirm that the notification callback was called. 759 // Confirm that the notification callback was called.
758 ASSERT_EQ(1u, notification_log.size()); 760 ASSERT_EQ(1u, notification_log.size());
759 EXPECT_EQ(change_type, notification_log[0]); 761 EXPECT_EQ(change_type, notification_log[0]);
760 762
761 // Verify the observer event. 763 // Verify the observer event.
762 ASSERT_EQ(1u, observer.change_events().size()); 764 ASSERT_EQ(1u, observer.change_events().size());
763 const Observer::ChangeEvent* const change_event = 765 const Observer::ChangeEvent* const change_event =
(...skipping 25 matching lines...) Expand all
789 { 791 {
790 // Notify about deleting of the watched entry. 792 // Notify about deleting of the watched entry.
791 const storage::WatcherManager::ChangeType change_type = 793 const storage::WatcherManager::ChangeType change_type =
792 storage::WatcherManager::DELETED; 794 storage::WatcherManager::DELETED;
793 const ProvidedFileSystemObserver::Changes changes; 795 const ProvidedFileSystemObserver::Changes changes;
794 const std::string tag = "chocolate-disco"; 796 const std::string tag = "chocolate-disco";
795 797
796 Log log; 798 Log log;
797 provided_file_system_->Notify( 799 provided_file_system_->Notify(
798 base::FilePath(kDirectoryPath), false /* recursive */, change_type, 800 base::FilePath(kDirectoryPath), false /* recursive */, change_type,
799 make_scoped_ptr(new ProvidedFileSystemObserver::Changes), tag, 801 base::WrapUnique(new ProvidedFileSystemObserver::Changes), tag,
800 base::Bind(&LogStatus, base::Unretained(&log))); 802 base::Bind(&LogStatus, base::Unretained(&log)));
801 base::RunLoop().RunUntilIdle(); 803 base::RunLoop().RunUntilIdle();
802 804
803 // Complete all change events. 805 // Complete all change events.
804 observer.CompleteOnWatcherChanged(); 806 observer.CompleteOnWatcherChanged();
805 base::RunLoop().RunUntilIdle(); 807 base::RunLoop().RunUntilIdle();
806 808
807 ASSERT_EQ(1u, log.size()); 809 ASSERT_EQ(1u, log.size());
808 EXPECT_EQ(base::File::FILE_OK, log[0]); 810 EXPECT_EQ(base::File::FILE_OK, log[0]);
809 811
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 916
915 ASSERT_EQ(1u, close_log.size()); 917 ASSERT_EQ(1u, close_log.size());
916 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, close_log[0]); 918 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, close_log[0]);
917 EXPECT_EQ(0u, opened_files.size()); 919 EXPECT_EQ(0u, opened_files.size());
918 920
919 provided_file_system_->RemoveObserver(&observer); 921 provided_file_system_->RemoveObserver(&observer);
920 } 922 }
921 923
922 } // namespace file_system_provider 924 } // namespace file_system_provider
923 } // namespace chromeos 925 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698