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

Side by Side Diff: chrome/browser/metrics/variations/eula_accepted_notifier_unittest.cc

Issue 16129004: Consolidate EulaAcceptedNotifier implementations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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
19 // testing::Test overrides.
20 virtual void SetUp() OVERRIDE {
21 local_state_.registry()->RegisterBooleanPref(prefs::kEulaAccepted, false);
22 notifier_.reset(new EulaAcceptedNotifier(&local_state_));
23 notifier_->Init(this);
24 }
25
26 // EulaAcceptedNotifier::Observer overrides.
27 virtual void OnEulaAccepted() OVERRIDE {
28 EXPECT_FALSE(eula_accepted_called_);
29 eula_accepted_called_ = true;
30 }
31
32 void SetEulaAcceptedPref() {
33 local_state_.SetBoolean(prefs::kEulaAccepted, true);
34 }
35
36 EulaAcceptedNotifier* notifier() {
37 return notifier_.get();
38 }
39
40 bool eula_accepted_called() {
41 return eula_accepted_called_;
42 }
43
44 private:
45 TestingPrefServiceSimple local_state_;
46 scoped_ptr<EulaAcceptedNotifier> notifier_;
47 bool eula_accepted_called_;
48
49 DISALLOW_COPY_AND_ASSIGN(EulaAcceptedNotifierTest);
50 };
51
52 TEST_F(EulaAcceptedNotifierTest, EulaAlreadyAccepted) {
53 SetEulaAcceptedPref();
54 EXPECT_TRUE(notifier()->IsEulaAccepted());
55 EXPECT_FALSE(eula_accepted_called());
56 // Call it a second time, to ensure the answer doesn't change.
57 EXPECT_TRUE(notifier()->IsEulaAccepted());
58 EXPECT_FALSE(eula_accepted_called());
59 }
60
61 TEST_F(EulaAcceptedNotifierTest, EulaNotAccepted) {
62 EXPECT_FALSE(notifier()->IsEulaAccepted());
63 EXPECT_FALSE(eula_accepted_called());
64 // Call it a second time, to ensure the answer doesn't change.
65 EXPECT_FALSE(notifier()->IsEulaAccepted());
66 EXPECT_FALSE(eula_accepted_called());
67 }
68
69 TEST_F(EulaAcceptedNotifierTest, EulaNotInitiallyAccepted) {
70 EXPECT_FALSE(notifier()->IsEulaAccepted());
71 SetEulaAcceptedPref();
72 EXPECT_TRUE(notifier()->IsEulaAccepted());
73 EXPECT_TRUE(eula_accepted_called());
74 // Call it a second time, to ensure the answer doesn't change.
75 EXPECT_TRUE(notifier()->IsEulaAccepted());
76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698