| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "base/prefs/testing_pref_service.h" | 6 #include "base/prefs/testing_pref_service.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/profiles/profile_info_cache.h" | 9 #include "chrome/browser/profiles/profile_info_cache.h" |
| 10 #include "chrome/browser/signin/signin_manager.h" | 10 #include "chrome/browser/signin/signin_manager.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 void SigninNamesOnIOThreadTest::SetUp() { | 46 void SigninNamesOnIOThreadTest::SetUp() { |
| 47 ASSERT_TRUE(testing_profile_manager_.SetUp()); | 47 ASSERT_TRUE(testing_profile_manager_.SetUp()); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void SigninNamesOnIOThreadTest::TearDown() { | 50 void SigninNamesOnIOThreadTest::TearDown() { |
| 51 signin_names_.ReleaseResourcesOnUIThread(); | 51 signin_names_.ReleaseResourcesOnUIThread(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void SigninNamesOnIOThreadTest::SimulateSignin(const base::string16& email) { | 54 void SigninNamesOnIOThreadTest::SimulateSignin(const base::string16& email) { |
| 55 GoogleServiceSigninSuccessDetails details(UTF16ToUTF8(email), "password"); | 55 GoogleServiceSigninSuccessDetails details( |
| 56 base::UTF16ToUTF8(email), "password"); |
| 56 content::NotificationService::current()->Notify( | 57 content::NotificationService::current()->Notify( |
| 57 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | 58 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
| 58 content::Source<Profile>(NULL), | 59 content::Source<Profile>(NULL), |
| 59 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); | 60 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); |
| 60 } | 61 } |
| 61 | 62 |
| 62 void SigninNamesOnIOThreadTest::SimulateSignout(const base::string16& email) { | 63 void SigninNamesOnIOThreadTest::SimulateSignout(const base::string16& email) { |
| 63 GoogleServiceSignoutDetails details(UTF16ToUTF8(email)); | 64 GoogleServiceSignoutDetails details(base::UTF16ToUTF8(email)); |
| 64 content::NotificationService::current()->Notify( | 65 content::NotificationService::current()->Notify( |
| 65 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | 66 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, |
| 66 content::Source<Profile>(NULL), | 67 content::Source<Profile>(NULL), |
| 67 content::Details<const GoogleServiceSignoutDetails>(&details)); | 68 content::Details<const GoogleServiceSignoutDetails>(&details)); |
| 68 } | 69 } |
| 69 | 70 |
| 70 void SigninNamesOnIOThreadTest::AddNewProfile(const base::string16& name, | 71 void SigninNamesOnIOThreadTest::AddNewProfile(const base::string16& name, |
| 71 const base::string16& email) { | 72 const base::string16& email) { |
| 72 ProfileInfoCache* cache = testing_profile_manager_.profile_info_cache(); | 73 ProfileInfoCache* cache = testing_profile_manager_.profile_info_cache(); |
| 73 const base::FilePath& user_data_dir = cache->GetUserDataDir(); | 74 const base::FilePath& user_data_dir = cache->GetUserDataDir(); |
| 74 #if defined(OS_POSIX) | 75 #if defined(OS_POSIX) |
| 75 const base::FilePath profile_dir = user_data_dir.Append(UTF16ToUTF8(name)); | 76 const base::FilePath profile_dir = |
| 77 user_data_dir.Append(base::UTF16ToUTF8(name)); |
| 76 #else | 78 #else |
| 77 const base::FilePath profile_dir = user_data_dir.Append(name); | 79 const base::FilePath profile_dir = user_data_dir.Append(name); |
| 78 #endif | 80 #endif |
| 79 cache->AddProfileToCache(profile_dir, name, email, 0, std::string()); | 81 cache->AddProfileToCache(profile_dir, name, email, 0, std::string()); |
| 80 } | 82 } |
| 81 | 83 |
| 82 } // namespace | 84 } // namespace |
| 83 | 85 |
| 84 TEST_F(SigninNamesOnIOThreadTest, Basic) { | 86 TEST_F(SigninNamesOnIOThreadTest, Basic) { |
| 85 ASSERT_EQ(0u, signin_names_.GetEmails().size()); | 87 ASSERT_EQ(0u, signin_names_.GetEmails().size()); |
| 86 } | 88 } |
| 87 | 89 |
| 88 TEST_F(SigninNamesOnIOThreadTest, Signin) { | 90 TEST_F(SigninNamesOnIOThreadTest, Signin) { |
| 89 const base::string16 email = UTF8ToUTF16("foo@gmail.com"); | 91 const base::string16 email = base::UTF8ToUTF16("foo@gmail.com"); |
| 90 SimulateSignin(email); | 92 SimulateSignin(email); |
| 91 | 93 |
| 92 const SigninNamesOnIOThread::EmailSet& emails = signin_names_.GetEmails(); | 94 const SigninNamesOnIOThread::EmailSet& emails = signin_names_.GetEmails(); |
| 93 ASSERT_EQ(1u, emails.size()); | 95 ASSERT_EQ(1u, emails.size()); |
| 94 ASSERT_EQ(1u, emails.count(email)); | 96 ASSERT_EQ(1u, emails.count(email)); |
| 95 } | 97 } |
| 96 | 98 |
| 97 TEST_F(SigninNamesOnIOThreadTest, Signout) { | 99 TEST_F(SigninNamesOnIOThreadTest, Signout) { |
| 98 const base::string16 email = UTF8ToUTF16("foo@gmail.com"); | 100 const base::string16 email = base::UTF8ToUTF16("foo@gmail.com"); |
| 99 SimulateSignin(email); | 101 SimulateSignin(email); |
| 100 SimulateSignout(email); | 102 SimulateSignout(email); |
| 101 | 103 |
| 102 const SigninNamesOnIOThread::EmailSet& emails = signin_names_.GetEmails(); | 104 const SigninNamesOnIOThread::EmailSet& emails = signin_names_.GetEmails(); |
| 103 ASSERT_EQ(0u, emails.size()); | 105 ASSERT_EQ(0u, emails.size()); |
| 104 } | 106 } |
| 105 | 107 |
| 106 TEST_F(SigninNamesOnIOThreadTest, HandleUnknownSignout) { | 108 TEST_F(SigninNamesOnIOThreadTest, HandleUnknownSignout) { |
| 107 const base::string16 email = UTF8ToUTF16("foo@gmail.com"); | 109 const base::string16 email = base::UTF8ToUTF16("foo@gmail.com"); |
| 108 SimulateSignin(email); | 110 SimulateSignin(email); |
| 109 SimulateSignout(UTF8ToUTF16("bar@gmail.com")); | 111 SimulateSignout(base::UTF8ToUTF16("bar@gmail.com")); |
| 110 | 112 |
| 111 const SigninNamesOnIOThread::EmailSet& emails = signin_names_.GetEmails(); | 113 const SigninNamesOnIOThread::EmailSet& emails = signin_names_.GetEmails(); |
| 112 ASSERT_EQ(1u, emails.size()); | 114 ASSERT_EQ(1u, emails.size()); |
| 113 ASSERT_EQ(1u, emails.count(email)); | 115 ASSERT_EQ(1u, emails.count(email)); |
| 114 } | 116 } |
| 115 | 117 |
| 116 TEST_F(SigninNamesOnIOThreadTest, StartWithConnectedProfiles) { | 118 TEST_F(SigninNamesOnIOThreadTest, StartWithConnectedProfiles) { |
| 117 // Setup a couple of connected profiles, and one unconnected. | 119 // Setup a couple of connected profiles, and one unconnected. |
| 118 const base::string16 email1 = UTF8ToUTF16("foo@gmail.com"); | 120 const base::string16 email1 = base::UTF8ToUTF16("foo@gmail.com"); |
| 119 const base::string16 email2 = UTF8ToUTF16("bar@gmail.com"); | 121 const base::string16 email2 = base::UTF8ToUTF16("bar@gmail.com"); |
| 120 AddNewProfile(UTF8ToUTF16("foo"), email1); | 122 AddNewProfile(base::UTF8ToUTF16("foo"), email1); |
| 121 AddNewProfile(UTF8ToUTF16("bar"), email2); | 123 AddNewProfile(base::UTF8ToUTF16("bar"), email2); |
| 122 AddNewProfile(UTF8ToUTF16("toto"), base::string16()); | 124 AddNewProfile(base::UTF8ToUTF16("toto"), base::string16()); |
| 123 | 125 |
| 124 SigninNamesOnIOThread signin_names; | 126 SigninNamesOnIOThread signin_names; |
| 125 | 127 |
| 126 const SigninNamesOnIOThread::EmailSet& emails = signin_names.GetEmails(); | 128 const SigninNamesOnIOThread::EmailSet& emails = signin_names.GetEmails(); |
| 127 ASSERT_EQ(2u, emails.size()); | 129 ASSERT_EQ(2u, emails.size()); |
| 128 ASSERT_EQ(1u, emails.count(email1)); | 130 ASSERT_EQ(1u, emails.count(email1)); |
| 129 ASSERT_EQ(1u, emails.count(email2)); | 131 ASSERT_EQ(1u, emails.count(email2)); |
| 130 | 132 |
| 131 signin_names.ReleaseResourcesOnUIThread(); | 133 signin_names.ReleaseResourcesOnUIThread(); |
| 132 } | 134 } |
| OLD | NEW |