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

Unified Diff: chrome/browser/chromeos/file_system_provider/service_unittest.cc

Issue 295413002: [fsp] Store mounted file systems in preferences. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed tests. Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/file_system_provider/service.cc ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/file_system_provider/service_unittest.cc
diff --git a/chrome/browser/chromeos/file_system_provider/service_unittest.cc b/chrome/browser/chromeos/file_system_provider/service_unittest.cc
index 491584e98b79f4ecbbd8a5d7d00396c879045c4d..d171d4f471ebfb33258ab5e4ec58c8322e3315eb 100644
--- a/chrome/browser/chromeos/file_system_provider/service_unittest.cc
+++ b/chrome/browser/chromeos/file_system_provider/service_unittest.cc
@@ -15,7 +15,10 @@
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
#include "chrome/browser/chromeos/file_system_provider/service.h"
#include "chrome/browser/chromeos/login/users/fake_user_manager.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
+#include "components/user_prefs/user_prefs.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
@@ -86,6 +89,25 @@ scoped_refptr<extensions::Extension> createFakeExtension(
&error);
}
+// Stores a provided file system information in preferences.
+void RememberFakeFileSystem(TestingProfile* profile,
+ const std::string& extension_id,
+ const std::string& file_system_id,
+ const std::string& file_system_name) {
+ TestingPrefServiceSyncable* pref_service = profile->GetTestingPrefService();
+ ASSERT_TRUE(pref_service);
+
+ base::DictionaryValue extensions;
+ base::ListValue* file_systems = new base::ListValue();
+ base::DictionaryValue* file_system = new base::DictionaryValue();
+ file_system->SetString(kPrefKeyFileSystemId, kFileSystemId);
+ file_system->SetString(kPrefKeyFileSystemName, kFileSystemName);
+ file_systems->Append(file_system);
+ extensions.Set(kExtensionId, file_systems);
+
+ pref_service->Set(prefs::kFileSystemProviderMounted, extensions);
+}
+
} // namespace
class FileSystemProviderServiceTest : public testing::Test {
@@ -284,5 +306,109 @@ TEST_F(FileSystemProviderServiceTest, UnmountFileSystem_WrongExtensionId) {
file_system_provider_service_->RemoveObserver(&observer);
}
+TEST_F(FileSystemProviderServiceTest, RestoreFileSystem_OnExtensionLoad) {
+ LoggingObserver observer;
+ file_system_provider_service_->AddObserver(&observer);
+
+ // Create a fake entry in the preferences.
+ RememberFakeFileSystem(
+ profile_.get(), kExtensionId, kFileSystemId, kFileSystemName);
+
+ EXPECT_EQ(0u, observer.mounts.size());
+
+ // Directly call the observer's method.
+ file_system_provider_service_->OnExtensionLoaded(profile_.get(),
+ extension_.get());
+
+ ASSERT_EQ(1u, observer.mounts.size());
+ EXPECT_EQ(base::File::FILE_OK, observer.mounts[0].error());
+
+ EXPECT_EQ(kExtensionId, observer.mounts[0].file_system_info().extension_id());
+ EXPECT_EQ(kFileSystemId,
+ observer.mounts[0].file_system_info().file_system_id());
+
+ std::vector<ProvidedFileSystemInfo> file_system_info_list =
+ file_system_provider_service_->GetProvidedFileSystemInfoList();
+ ASSERT_EQ(1u, file_system_info_list.size());
+
+ file_system_provider_service_->RemoveObserver(&observer);
+}
+
+TEST_F(FileSystemProviderServiceTest, ForgetFileSystem_OnExtensionUnload) {
+ LoggingObserver observer;
+ file_system_provider_service_->AddObserver(&observer);
+
+ // Create a fake entry in the preferences.
+ RememberFakeFileSystem(
+ profile_.get(), kExtensionId, kFileSystemId, kFileSystemName);
+
+ // Directly call the observer's methods.
+ file_system_provider_service_->OnExtensionLoaded(profile_.get(),
+ extension_.get());
+
+ file_system_provider_service_->OnExtensionUnloaded(
+ profile_.get(),
+ extension_.get(),
+ extensions::UnloadedExtensionInfo::REASON_DISABLE);
+
+ ASSERT_EQ(1u, observer.mounts.size());
+ EXPECT_EQ(base::File::FILE_OK, observer.mounts[0].error());
+ ASSERT_EQ(1u, observer.unmounts.size());
+ EXPECT_EQ(base::File::FILE_OK, observer.unmounts[0].error());
+
+ TestingPrefServiceSyncable* pref_service = profile_->GetTestingPrefService();
+ ASSERT_TRUE(pref_service);
+
+ const base::DictionaryValue* extensions =
+ pref_service->GetDictionary(prefs::kFileSystemProviderMounted);
+ ASSERT_TRUE(extensions);
+
+ const base::ListValue* file_systems;
+ EXPECT_FALSE(extensions->GetList(kExtensionId, &file_systems));
+
+ file_system_provider_service_->RemoveObserver(&observer);
+}
+
+TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnShutdown) {
+ {
+ scoped_ptr<Service> service(
+ new Service(profile_.get(), extension_registry_.get()));
+ service->SetFileSystemFactoryForTests(
+ base::Bind(&FakeProvidedFileSystem::Create));
+
+ LoggingObserver observer;
+ service->AddObserver(&observer);
+
+ const bool result =
+ service->MountFileSystem(kExtensionId, kFileSystemId, kFileSystemName);
+ EXPECT_TRUE(result);
+ ASSERT_EQ(1u, observer.mounts.size());
+
+ service->RemoveObserver(&observer);
+ }
+
+ TestingPrefServiceSyncable* pref_service = profile_->GetTestingPrefService();
+ ASSERT_TRUE(pref_service);
+
+ const base::DictionaryValue* extensions =
+ pref_service->GetDictionary(prefs::kFileSystemProviderMounted);
+ ASSERT_TRUE(extensions);
+
+ const base::ListValue* file_systems;
+ ASSERT_TRUE(extensions->GetList(kExtensionId, &file_systems));
+ ASSERT_EQ(1u, file_systems->GetSize());
+
+ const base::DictionaryValue* file_system = NULL;
+ ASSERT_TRUE(file_systems->GetDictionary(0, &file_system));
+
+ std::string file_system_id;
+ file_system->GetString(kPrefKeyFileSystemId, &file_system_id);
+ EXPECT_EQ(kFileSystemId, file_system_id);
+
+ std::string file_system_name;
+ file_system->GetString(kPrefKeyFileSystemName, &file_system_name);
+ EXPECT_EQ(kFileSystemName, file_system_name);
+}
+
} // namespace file_system_provider
} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/file_system_provider/service.cc ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698