OLD | NEW |
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 <algorithm> | 5 #include <algorithm> |
| 6 #include <memory> |
| 7 #include <utility> |
6 #include <vector> | 8 #include <vector> |
7 | 9 |
8 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
10 #include "components/prefs/pref_registry_simple.h" | 12 #include "components/prefs/pref_registry_simple.h" |
11 #include "components/prefs/scoped_user_pref_update.h" | 13 #include "components/prefs/scoped_user_pref_update.h" |
12 #include "components/prefs/testing_pref_service.h" | 14 #include "components/prefs/testing_pref_service.h" |
13 #include "components/signin/core/browser/account_fetcher_service.h" | 15 #include "components/signin/core/browser/account_fetcher_service.h" |
14 #include "components/signin/core/browser/account_info.h" | 16 #include "components/signin/core/browser/account_info.h" |
15 #include "components/signin/core/browser/account_tracker_service.h" | 17 #include "components/signin/core/browser/account_tracker_service.h" |
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 std::string email_beta = AccountIdToEmail("beta"); | 900 std::string email_beta = AccountIdToEmail("beta"); |
899 std::string gaia_beta = AccountIdToGaiaId("beta"); | 901 std::string gaia_beta = AccountIdToGaiaId("beta"); |
900 | 902 |
901 pref.registry()->RegisterListPref(AccountTrackerService::kAccountInfoPref); | 903 pref.registry()->RegisterListPref(AccountTrackerService::kAccountInfoPref); |
902 pref.registry()->RegisterIntegerPref( | 904 pref.registry()->RegisterIntegerPref( |
903 prefs::kAccountIdMigrationState, | 905 prefs::kAccountIdMigrationState, |
904 AccountTrackerService::MIGRATION_NOT_STARTED); | 906 AccountTrackerService::MIGRATION_NOT_STARTED); |
905 | 907 |
906 ListPrefUpdate update(&pref, AccountTrackerService::kAccountInfoPref); | 908 ListPrefUpdate update(&pref, AccountTrackerService::kAccountInfoPref); |
907 | 909 |
908 base::DictionaryValue* dict = new base::DictionaryValue(); | 910 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
909 update->Append(dict); | |
910 dict->SetString("account_id", base::UTF8ToUTF16(email_alpha)); | 911 dict->SetString("account_id", base::UTF8ToUTF16(email_alpha)); |
911 dict->SetString("email", base::UTF8ToUTF16(email_alpha)); | 912 dict->SetString("email", base::UTF8ToUTF16(email_alpha)); |
912 dict->SetString("gaia", base::UTF8ToUTF16(gaia_alpha)); | 913 dict->SetString("gaia", base::UTF8ToUTF16(gaia_alpha)); |
| 914 update->Append(std::move(dict)); |
913 | 915 |
914 dict = new base::DictionaryValue(); | 916 dict.reset(new base::DictionaryValue()); |
915 update->Append(dict); | |
916 dict->SetString("account_id", base::UTF8ToUTF16(email_beta)); | 917 dict->SetString("account_id", base::UTF8ToUTF16(email_beta)); |
917 dict->SetString("email", base::UTF8ToUTF16(email_beta)); | 918 dict->SetString("email", base::UTF8ToUTF16(email_beta)); |
918 dict->SetString("gaia", base::UTF8ToUTF16(gaia_beta)); | 919 dict->SetString("gaia", base::UTF8ToUTF16(gaia_beta)); |
| 920 update->Append(std::move(dict)); |
919 | 921 |
920 std::unique_ptr<TestSigninClient> client; | 922 std::unique_ptr<TestSigninClient> client; |
921 client.reset(new TestSigninClient(&pref)); | 923 client.reset(new TestSigninClient(&pref)); |
922 tracker.Initialize(client.get()); | 924 tracker.Initialize(client.get()); |
923 | 925 |
924 ASSERT_EQ(tracker.GetMigrationState(), | 926 ASSERT_EQ(tracker.GetMigrationState(), |
925 AccountTrackerService::MIGRATION_IN_PROGRESS); | 927 AccountTrackerService::MIGRATION_IN_PROGRESS); |
926 | 928 |
927 account_info = tracker.GetAccountInfo(gaia_alpha); | 929 account_info = tracker.GetAccountInfo(gaia_alpha); |
928 ASSERT_EQ(account_info.account_id, gaia_alpha); | 930 ASSERT_EQ(account_info.account_id, gaia_alpha); |
(...skipping 21 matching lines...) Expand all Loading... |
950 std::string gaia_alpha = AccountIdToGaiaId("alpha"); | 952 std::string gaia_alpha = AccountIdToGaiaId("alpha"); |
951 std::string email_beta = AccountIdToEmail("beta"); | 953 std::string email_beta = AccountIdToEmail("beta"); |
952 | 954 |
953 pref.registry()->RegisterListPref(AccountTrackerService::kAccountInfoPref); | 955 pref.registry()->RegisterListPref(AccountTrackerService::kAccountInfoPref); |
954 pref.registry()->RegisterIntegerPref( | 956 pref.registry()->RegisterIntegerPref( |
955 prefs::kAccountIdMigrationState, | 957 prefs::kAccountIdMigrationState, |
956 AccountTrackerService::MIGRATION_NOT_STARTED); | 958 AccountTrackerService::MIGRATION_NOT_STARTED); |
957 | 959 |
958 ListPrefUpdate update(&pref, AccountTrackerService::kAccountInfoPref); | 960 ListPrefUpdate update(&pref, AccountTrackerService::kAccountInfoPref); |
959 | 961 |
960 base::DictionaryValue* dict = new base::DictionaryValue(); | 962 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
961 update->Append(dict); | |
962 dict->SetString("account_id", base::UTF8ToUTF16(email_alpha)); | 963 dict->SetString("account_id", base::UTF8ToUTF16(email_alpha)); |
963 dict->SetString("email", base::UTF8ToUTF16(email_alpha)); | 964 dict->SetString("email", base::UTF8ToUTF16(email_alpha)); |
964 dict->SetString("gaia", base::UTF8ToUTF16(gaia_alpha)); | 965 dict->SetString("gaia", base::UTF8ToUTF16(gaia_alpha)); |
| 966 update->Append(std::move(dict)); |
965 | 967 |
966 dict = new base::DictionaryValue(); | 968 dict.reset(new base::DictionaryValue()); |
967 update->Append(dict); | |
968 dict->SetString("account_id", base::UTF8ToUTF16(email_beta)); | 969 dict->SetString("account_id", base::UTF8ToUTF16(email_beta)); |
969 dict->SetString("email", base::UTF8ToUTF16(email_beta)); | 970 dict->SetString("email", base::UTF8ToUTF16(email_beta)); |
970 dict->SetString("gaia", base::UTF8ToUTF16(std::string())); | 971 dict->SetString("gaia", base::UTF8ToUTF16(std::string())); |
| 972 update->Append(std::move(dict)); |
971 | 973 |
972 std::unique_ptr<TestSigninClient> client; | 974 std::unique_ptr<TestSigninClient> client; |
973 client.reset(new TestSigninClient(&pref)); | 975 client.reset(new TestSigninClient(&pref)); |
974 tracker.Initialize(client.get()); | 976 tracker.Initialize(client.get()); |
975 | 977 |
976 ASSERT_EQ(tracker.GetMigrationState(), | 978 ASSERT_EQ(tracker.GetMigrationState(), |
977 AccountTrackerService::MIGRATION_NOT_STARTED); | 979 AccountTrackerService::MIGRATION_NOT_STARTED); |
978 | 980 |
979 account_info = tracker.GetAccountInfo(email_alpha); | 981 account_info = tracker.GetAccountInfo(email_alpha); |
980 ASSERT_EQ(account_info.account_id, email_alpha); | 982 ASSERT_EQ(account_info.account_id, email_alpha); |
(...skipping 21 matching lines...) Expand all Loading... |
1002 std::string email_beta = AccountIdToEmail("beta"); | 1004 std::string email_beta = AccountIdToEmail("beta"); |
1003 std::string gaia_beta = AccountIdToGaiaId("beta"); | 1005 std::string gaia_beta = AccountIdToGaiaId("beta"); |
1004 | 1006 |
1005 pref.registry()->RegisterListPref(AccountTrackerService::kAccountInfoPref); | 1007 pref.registry()->RegisterListPref(AccountTrackerService::kAccountInfoPref); |
1006 pref.registry()->RegisterIntegerPref( | 1008 pref.registry()->RegisterIntegerPref( |
1007 prefs::kAccountIdMigrationState, | 1009 prefs::kAccountIdMigrationState, |
1008 AccountTrackerService::MIGRATION_IN_PROGRESS); | 1010 AccountTrackerService::MIGRATION_IN_PROGRESS); |
1009 | 1011 |
1010 ListPrefUpdate update(&pref, AccountTrackerService::kAccountInfoPref); | 1012 ListPrefUpdate update(&pref, AccountTrackerService::kAccountInfoPref); |
1011 | 1013 |
1012 base::DictionaryValue* dict = new base::DictionaryValue(); | 1014 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
1013 update->Append(dict); | |
1014 dict->SetString("account_id", base::UTF8ToUTF16(email_alpha)); | 1015 dict->SetString("account_id", base::UTF8ToUTF16(email_alpha)); |
1015 dict->SetString("email", base::UTF8ToUTF16(email_alpha)); | 1016 dict->SetString("email", base::UTF8ToUTF16(email_alpha)); |
1016 dict->SetString("gaia", base::UTF8ToUTF16(gaia_alpha)); | 1017 dict->SetString("gaia", base::UTF8ToUTF16(gaia_alpha)); |
| 1018 update->Append(std::move(dict)); |
1017 | 1019 |
1018 dict = new base::DictionaryValue(); | 1020 dict.reset(new base::DictionaryValue()); |
1019 update->Append(dict); | |
1020 dict->SetString("account_id", base::UTF8ToUTF16(email_beta)); | 1021 dict->SetString("account_id", base::UTF8ToUTF16(email_beta)); |
1021 dict->SetString("email", base::UTF8ToUTF16(email_beta)); | 1022 dict->SetString("email", base::UTF8ToUTF16(email_beta)); |
1022 dict->SetString("gaia", base::UTF8ToUTF16(gaia_beta)); | 1023 dict->SetString("gaia", base::UTF8ToUTF16(gaia_beta)); |
| 1024 update->Append(std::move(dict)); |
1023 | 1025 |
1024 // Succeed miggrated account. | 1026 // Succeed miggrated account. |
1025 dict = new base::DictionaryValue(); | 1027 dict.reset(new base::DictionaryValue()); |
1026 update->Append(dict); | |
1027 dict->SetString("account_id", base::UTF8ToUTF16(gaia_alpha)); | 1028 dict->SetString("account_id", base::UTF8ToUTF16(gaia_alpha)); |
1028 dict->SetString("email", base::UTF8ToUTF16(email_alpha)); | 1029 dict->SetString("email", base::UTF8ToUTF16(email_alpha)); |
1029 dict->SetString("gaia", base::UTF8ToUTF16(gaia_alpha)); | 1030 dict->SetString("gaia", base::UTF8ToUTF16(gaia_alpha)); |
| 1031 update->Append(std::move(dict)); |
1030 | 1032 |
1031 std::unique_ptr<TestSigninClient> client; | 1033 std::unique_ptr<TestSigninClient> client; |
1032 client.reset(new TestSigninClient(&pref)); | 1034 client.reset(new TestSigninClient(&pref)); |
1033 tracker.Initialize(client.get()); | 1035 tracker.Initialize(client.get()); |
1034 | 1036 |
1035 ASSERT_EQ(tracker.GetMigrationState(), | 1037 ASSERT_EQ(tracker.GetMigrationState(), |
1036 AccountTrackerService::MIGRATION_IN_PROGRESS); | 1038 AccountTrackerService::MIGRATION_IN_PROGRESS); |
1037 | 1039 |
1038 account_info = tracker.GetAccountInfo(gaia_alpha); | 1040 account_info = tracker.GetAccountInfo(gaia_alpha); |
1039 ASSERT_EQ(account_info.account_id, gaia_alpha); | 1041 ASSERT_EQ(account_info.account_id, gaia_alpha); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 ASSERT_FALSE(info.is_child_account); | 1209 ASSERT_FALSE(info.is_child_account); |
1208 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); | 1210 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); |
1209 | 1211 |
1210 SimulateTokenRevoked(child_id); | 1212 SimulateTokenRevoked(child_id); |
1211 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(REMOVED, child_id))); | 1213 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(REMOVED, child_id))); |
1212 | 1214 |
1213 tracker.RemoveObserver(&observer); | 1215 tracker.RemoveObserver(&observer); |
1214 fetcher.Shutdown(); | 1216 fetcher.Shutdown(); |
1215 tracker.Shutdown(); | 1217 tracker.Shutdown(); |
1216 } | 1218 } |
OLD | NEW |