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.
5 #include "chrome/browser/web_resource/eula_accepted_notifier.h"
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"
13 class EulaAcceptedNotifierTest
: public testing::Test
,
14 public EulaAcceptedNotifier::Observer
{
16 EulaAcceptedNotifierTest() : eula_accepted_called_(false) {
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);
26 // EulaAcceptedNotifier::Observer overrides.
27 virtual void OnEulaAccepted() OVERRIDE
{
28 EXPECT_FALSE(eula_accepted_called_
);
29 eula_accepted_called_
= true;
32 void SetEulaAcceptedPref() {
33 local_state_
.SetBoolean(prefs::kEulaAccepted
, true);
36 EulaAcceptedNotifier
* notifier() {
37 return notifier_
.get();
40 bool eula_accepted_called() {
41 return eula_accepted_called_
;
45 TestingPrefServiceSimple local_state_
;
46 scoped_ptr
<EulaAcceptedNotifier
> notifier_
;
47 bool eula_accepted_called_
;
49 DISALLOW_COPY_AND_ASSIGN(EulaAcceptedNotifierTest
);
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());
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());
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());