| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/test/histogram_tester.h" | 7 #include "base/test/histogram_tester.h" |
| 8 #include "components/prefs/pref_registry_simple.h" | 8 #include "components/prefs/pref_registry_simple.h" |
| 9 #include "components/prefs/testing_pref_service.h" | 9 #include "components/prefs/testing_pref_service.h" |
| 10 #include "components/signin/core/browser/signin_investigator.h" | 10 #include "components/signin/core/browser/signin_investigator.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 TestingPrefServiceSimple prefs_; | 35 TestingPrefServiceSimple prefs_; |
| 36 }; | 36 }; |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 class SigninInvestigatorTest : public testing::Test { | 39 class SigninInvestigatorTest : public testing::Test { |
| 40 protected: | 40 protected: |
| 41 void AssertAccountEquality(const std::string& email, | 41 void AssertAccountEquality(const std::string& email, |
| 42 const std::string& id, | 42 const std::string& id, |
| 43 bool equals_expectated, | 43 bool equals_expectated, |
| 44 AccountEquality histogram_expected) { | 44 AccountEquality histogram_expected) { |
| 45 base::HistogramTester histogram_tester; | |
| 46 FakeProvider provider(email, id); | 45 FakeProvider provider(email, id); |
| 47 SigninInvestigator investigator(kSameEmail, kSameId, &provider); | 46 SigninInvestigator investigator(kSameEmail, kSameId, &provider); |
| 48 bool equals_actual = investigator.AreAccountsEqualWithFallback(); | 47 AssertAccountEquality(&investigator, equals_expectated, histogram_expected); |
| 48 } |
| 49 |
| 50 void AssertAccountEquality(SigninInvestigator* investigator, |
| 51 bool equals_expectated, |
| 52 AccountEquality histogram_expected) { |
| 53 base::HistogramTester histogram_tester; |
| 54 bool equals_actual = investigator->AreAccountsEqualWithFallback(); |
| 49 ASSERT_EQ(equals_expectated, equals_actual); | 55 ASSERT_EQ(equals_expectated, equals_actual); |
| 50 histogram_tester.ExpectUniqueSample( | 56 histogram_tester.ExpectUniqueSample( |
| 51 "Signin.AccountEquality", static_cast<int>(histogram_expected), 1); | 57 "Signin.AccountEquality", static_cast<int>(histogram_expected), 1); |
| 52 } | 58 } |
| 53 | 59 |
| 54 void AssertInvestigatedScenario(const std::string& email, | 60 void AssertInvestigatedScenario(const std::string& email, |
| 55 const std::string& id, | 61 const std::string& id, |
| 56 InvestigatedScenario expected) { | 62 InvestigatedScenario expected) { |
| 57 base::HistogramTester histogram_tester; | 63 base::HistogramTester histogram_tester; |
| 58 FakeProvider provider(email, id); | 64 FakeProvider provider(email, id); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 86 TEST_F(SigninInvestigatorTest, EqualitySameEmailFallback) { | 92 TEST_F(SigninInvestigatorTest, EqualitySameEmailFallback) { |
| 87 AssertAccountEquality(kSameEmail, kEmptyId, true, | 93 AssertAccountEquality(kSameEmail, kEmptyId, true, |
| 88 AccountEquality::EMAIL_FALLBACK); | 94 AccountEquality::EMAIL_FALLBACK); |
| 89 } | 95 } |
| 90 | 96 |
| 91 TEST_F(SigninInvestigatorTest, EqualityDifferentEmailFallback) { | 97 TEST_F(SigninInvestigatorTest, EqualityDifferentEmailFallback) { |
| 92 AssertAccountEquality(kDifferentEmail, kEmptyId, false, | 98 AssertAccountEquality(kDifferentEmail, kEmptyId, false, |
| 93 AccountEquality::EMAIL_FALLBACK); | 99 AccountEquality::EMAIL_FALLBACK); |
| 94 } | 100 } |
| 95 | 101 |
| 102 TEST_F(SigninInvestigatorTest, EqualitySameEmailFallbackEmptyCurrentId) { |
| 103 FakeProvider provider(kSameEmail, kDifferentId); |
| 104 SigninInvestigator investigator(kSameEmail, kEmptyId, &provider); |
| 105 AssertAccountEquality(&investigator, true, AccountEquality::EMAIL_FALLBACK); |
| 106 } |
| 107 |
| 108 TEST_F(SigninInvestigatorTest, EqualityDifferentEmailFallbackEmptyCurrentId) { |
| 109 FakeProvider provider(kDifferentId, kDifferentId); |
| 110 SigninInvestigator investigator(kSameEmail, kEmptyId, &provider); |
| 111 AssertAccountEquality(&investigator, false, AccountEquality::EMAIL_FALLBACK); |
| 112 } |
| 113 |
| 96 TEST_F(SigninInvestigatorTest, InvestigateSameAccount) { | 114 TEST_F(SigninInvestigatorTest, InvestigateSameAccount) { |
| 97 AssertInvestigatedScenario(kSameEmail, kSameId, | 115 AssertInvestigatedScenario(kSameEmail, kSameId, |
| 98 InvestigatedScenario::SAME_ACCOUNT); | 116 InvestigatedScenario::SAME_ACCOUNT); |
| 99 } | 117 } |
| 100 | 118 |
| 101 TEST_F(SigninInvestigatorTest, InvestigateUpgrade) { | 119 TEST_F(SigninInvestigatorTest, InvestigateUpgrade) { |
| 102 AssertInvestigatedScenario("", "", InvestigatedScenario::UPGRADE_LOW_RISK); | 120 AssertInvestigatedScenario("", "", InvestigatedScenario::UPGRADE_LOW_RISK); |
| 103 } | 121 } |
| 104 | 122 |
| 105 TEST_F(SigninInvestigatorTest, InvestigateDifferentAccount) { | 123 TEST_F(SigninInvestigatorTest, InvestigateDifferentAccount) { |
| 106 AssertInvestigatedScenario(kDifferentEmail, kDifferentId, | 124 AssertInvestigatedScenario(kDifferentEmail, kDifferentId, |
| 107 InvestigatedScenario::DIFFERENT_ACCOUNT); | 125 InvestigatedScenario::DIFFERENT_ACCOUNT); |
| 108 } | 126 } |
| OLD | NEW |