Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/metrics/variations/eula_accepted_notifier.h" | |
| 6 | |
| 7 #include "base/prefs/pref_registry_simple.h" | |
| 8 #include "chrome/common/pref_names.h" | |
| 9 #include "chrome/test/base/scoped_testing_local_state.h" | |
| 10 #include "chrome/test/base/testing_browser_process.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 class EulaAcceptedNotifierTest : public testing::Test, | |
| 14 public EulaAcceptedNotifier::Observer { | |
| 15 public: | |
| 16 EulaAcceptedNotifierTest() : eula_accepted_called_(false) { | |
| 17 } | |
| 18 | |
|
SteveT
2013/05/31 12:20:08
Optional nit: Mind adding a comment here?
// test
Alexei Svitkine (slow)
2013/05/31 15:25:17
Done.
| |
| 19 virtual void SetUp() OVERRIDE { | |
| 20 local_state_.registry()->RegisterBooleanPref(prefs::kEulaAccepted, false); | |
| 21 notifier_.reset(new EulaAcceptedNotifier(&local_state_)); | |
| 22 notifier_->Init(this); | |
| 23 } | |
| 24 | |
|
SteveT
2013/05/31 12:20:08
Optional nit: Mind adding a comment here?
// Eula
Alexei Svitkine (slow)
2013/05/31 15:25:17
Done.
| |
| 25 virtual void OnEulaAccepted() OVERRIDE { | |
| 26 EXPECT_FALSE(eula_accepted_called_); | |
| 27 eula_accepted_called_ = true; | |
| 28 } | |
| 29 | |
| 30 void SetEulaAcceptedPref() { | |
| 31 local_state_.SetBoolean(prefs::kEulaAccepted, true); | |
| 32 } | |
| 33 | |
| 34 EulaAcceptedNotifier* notifier() { | |
| 35 return notifier_.get(); | |
| 36 } | |
| 37 | |
| 38 bool eula_accepted_called() { | |
| 39 return eula_accepted_called_; | |
| 40 } | |
| 41 | |
| 42 private: | |
| 43 TestingPrefServiceSimple local_state_; | |
| 44 scoped_ptr<EulaAcceptedNotifier> notifier_; | |
| 45 bool eula_accepted_called_; | |
| 46 | |
| 47 DISALLOW_COPY_AND_ASSIGN(EulaAcceptedNotifierTest); | |
| 48 }; | |
| 49 | |
| 50 TEST_F(EulaAcceptedNotifierTest, EulaAlreadyAccepted) { | |
| 51 SetEulaAcceptedPref(); | |
| 52 EXPECT_TRUE(notifier()->IsEulaAccepted()); | |
| 53 EXPECT_FALSE(eula_accepted_called()); | |
| 54 // Call it a second time, to ensure the answer doesn't change. | |
| 55 EXPECT_TRUE(notifier()->IsEulaAccepted()); | |
| 56 EXPECT_FALSE(eula_accepted_called()); | |
| 57 } | |
| 58 | |
| 59 TEST_F(EulaAcceptedNotifierTest, EulaNotAccepted) { | |
| 60 EXPECT_FALSE(notifier()->IsEulaAccepted()); | |
| 61 EXPECT_FALSE(eula_accepted_called()); | |
| 62 // Call it a second time, to ensure the answer doesn't change. | |
| 63 EXPECT_FALSE(notifier()->IsEulaAccepted()); | |
| 64 EXPECT_FALSE(eula_accepted_called()); | |
| 65 } | |
| 66 | |
| 67 TEST_F(EulaAcceptedNotifierTest, EulaNotInitiallyAccepted) { | |
| 68 EXPECT_FALSE(notifier()->IsEulaAccepted()); | |
| 69 SetEulaAcceptedPref(); | |
| 70 EXPECT_TRUE(eula_accepted_called()); | |
| 71 EXPECT_TRUE(notifier()->IsEulaAccepted()); | |
|
SteveT
2013/05/31 12:20:08
Would it be more consistent to check notifier()->I
Alexei Svitkine (slow)
2013/05/31 15:25:17
Done.
| |
| 72 // Call it a second time, to ensure the answer doesn't change. | |
| 73 EXPECT_TRUE(notifier()->IsEulaAccepted()); | |
|
SteveT
2013/05/31 12:20:08
Is it worth checking eula_accepted_called() here?
Alexei Svitkine (slow)
2013/05/31 15:25:17
Once TRUE, it shouldn't change. There's a check fo
| |
| 74 } | |
| OLD | NEW |