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

Unified Diff: chrome/browser/sync/credential_cache_service_win_unittest.cc

Issue 10656033: [sync] Automatic bootstrapping of Sync on Win 8 from cached credentials (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix TokenServiceTests Created 8 years, 5 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
Index: chrome/browser/sync/credential_cache_service_win_unittest.cc
diff --git a/chrome/browser/sync/credential_cache_service_win_unittest.cc b/chrome/browser/sync/credential_cache_service_win_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..42aea3fcdbc8d16d072c8b35424035f86dea3a51
--- /dev/null
+++ b/chrome/browser/sync/credential_cache_service_win_unittest.cc
@@ -0,0 +1,144 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
+#include "base/scoped_temp_dir.h"
+#include "base/values.h"
+#include "chrome/browser/sync/credential_cache_service_win.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/common/net/gaia/gaia_constants.h"
+#include "chrome/common/pref_names.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace syncer {
+
+class CredentialCacheServiceTest : public CredentialCacheService {
+ public:
+ CredentialCacheServiceTest()
+ : CredentialCacheService(NULL),
+ file_message_loop_(MessageLoop::TYPE_IO) {
+ SetUp();
+ }
+
+ virtual ~CredentialCacheServiceTest() {
+ file_message_loop_.RunAllPending();
+ }
+
+ void SetUp() {
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ local_store_ = new JsonPrefStore(
+ temp_dir_.path().Append(chrome::kSyncCredentialsFilename),
+ file_message_loop_.message_loop_proxy());
+ }
+
+ // ProfileKeyedService implementation.
+ virtual void Shutdown() OVERRIDE {}
+
+ // PrefStore::Observer implementation.
+ virtual void OnInitializationCompleted(bool succeeded) OVERRIDE {}
+ virtual void OnPrefValueChanged(const std::string& key) OVERRIDE {}
+
+ scoped_refptr<JsonPrefStore> local_store() { return local_store_; }
+
+ private:
+ ScopedTempDir temp_dir_;
+ MessageLoop file_message_loop_;
+ DISALLOW_COPY_AND_ASSIGN(CredentialCacheServiceTest);
+};
+
+} // namespace syncer
+
+namespace {
+
+TEST(CredentialCacheServiceTest, TestPackAndUnpack) {
+ // Pack a sample credential string.
+ std::string original = "sample_credential";
+ scoped_ptr<base::StringValue> packed(
+ syncer::CredentialCacheService::PackCredential(original));
+
+ // Unpack the result and make sure it matches the original.
+ std::string unpacked =
+ syncer::CredentialCacheService::UnpackCredential(*packed);
+ ASSERT_EQ(original, unpacked);
+}
+
+TEST(CredentialCacheServiceTest, TestPackAndUnpackEmpty) {
+ // Pack an empty credential string.
+ std::string original = "";
+ scoped_ptr<base::StringValue> packed(
+ syncer::CredentialCacheService::PackCredential(original));
+
+ // Make sure the packed value is an empty string.
+ std::string packed_string;
+ packed->GetAsString(&packed_string);
+ ASSERT_EQ(original, packed_string);
+
+ // Unpack it and make sure it matches the original.
+ std::string unpacked =
+ syncer::CredentialCacheService::UnpackCredential(*packed);
+ ASSERT_EQ(original, unpacked);
+}
+
+TEST(CredentialCacheServiceTest, TestWriteAndReadCredentials) {
+ syncer::CredentialCacheServiceTest ccs;
+ std::string username = "user@gmail.com";
+ std::string lsid = "lsid";
+ bool sync_everything = true;
+
+ // Write a string pref, a token and a boolean pref.
+ ccs.UpdateStringPref(prefs::kGoogleServicesUsername, username);
+ ccs.UpdateStringPref(GaiaConstants::kGaiaLsid, lsid);
+ ccs.UpdateBooleanPref(prefs::kSyncKeepEverythingSynced, sync_everything);
+
+ // Verify that they can be read, and that they contain the original values.
+ ASSERT_TRUE(ccs.HasPref(ccs.local_store(), prefs::kGoogleServicesUsername));
+ ASSERT_EQ(username, ccs.GetStringPref(ccs.local_store(),
+ prefs::kGoogleServicesUsername));
+ ASSERT_TRUE(ccs.HasPref(ccs.local_store(), GaiaConstants::kGaiaLsid));
+ ASSERT_EQ(lsid, ccs.GetStringPref(ccs.local_store(),
+ GaiaConstants::kGaiaLsid));
+ ASSERT_TRUE(ccs.HasPref(ccs.local_store(), prefs::kSyncKeepEverythingSynced));
+ ASSERT_TRUE(sync_everything ==
+ ccs.GetBooleanPref(ccs.local_store(),
+ prefs::kSyncKeepEverythingSynced));
+}
+
+TEST(CredentialCacheServiceTest, TestWriteAndReadCredentialsAfterSignOut) {
+ syncer::CredentialCacheServiceTest ccs;
+ std::string username = "user@gmail.com";
+ std::string lsid = "lsid";
+ bool sync_everything = true;
+
+ // Write a non-empty username, indicating that the user is signed in.
+ ccs.UpdateStringPref(prefs::kGoogleServicesUsername, username);
+ ASSERT_TRUE(ccs.HasPref(ccs.local_store(), prefs::kGoogleServicesUsername));
+ ASSERT_EQ(username, ccs.GetStringPref(ccs.local_store(),
+ prefs::kGoogleServicesUsername));
+
+ // Write an empty username, indicating that the user is signed out.
+ ccs.UpdateStringPref(prefs::kGoogleServicesUsername, "");
+ ASSERT_TRUE(ccs.HasPref(ccs.local_store(), prefs::kGoogleServicesUsername));
+ ASSERT_EQ(std::string(), ccs.GetStringPref(ccs.local_store(),
+ prefs::kGoogleServicesUsername));
+
+ // Try to write a non-empty string and make sure an empty string is written in
+ // its place.
+ ccs.UpdateStringPref(GaiaConstants::kGaiaLsid, lsid);
+ ASSERT_TRUE(ccs.HasPref(ccs.local_store(), GaiaConstants::kGaiaLsid));
+ ASSERT_EQ(std::string(), ccs.GetStringPref(ccs.local_store(),
+ GaiaConstants::kGaiaLsid));
+
+ // Try to write a boolean pref with value true, and make sure an the default
+ // value of false is written in its place.
+ ccs.UpdateBooleanPref(prefs::kSyncKeepEverythingSynced, sync_everything);
+ ASSERT_TRUE(ccs.HasPref(ccs.local_store(), prefs::kSyncKeepEverythingSynced));
+ ASSERT_TRUE(false == ccs.GetBooleanPref(ccs.local_store(),
+ prefs::kSyncKeepEverythingSynced));
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698