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 "components/web_resource/eula_accepted_notifier.h"
7 #include "base/prefs/pref_registry_simple.h"
8 #include "base/prefs/testing_pref_service.h"
9 #include "components/web_resource/web_resource_pref_names.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace web_resource
{
14 class EulaAcceptedNotifierTest
: public testing::Test
,
15 public EulaAcceptedNotifier::Observer
{
17 EulaAcceptedNotifierTest() : eula_accepted_called_(false) {
20 // testing::Test overrides.
21 void SetUp() override
{
22 local_state_
.registry()->RegisterBooleanPref(prefs::kEulaAccepted
, false);
23 notifier_
.reset(new EulaAcceptedNotifier(&local_state_
));
24 notifier_
->Init(this);
27 // EulaAcceptedNotifier::Observer overrides.
28 void OnEulaAccepted() override
{
29 EXPECT_FALSE(eula_accepted_called_
);
30 eula_accepted_called_
= true;
33 void SetEulaAcceptedPref() {
34 local_state_
.SetBoolean(prefs::kEulaAccepted
, true);
37 EulaAcceptedNotifier
* notifier() {
38 return notifier_
.get();
41 bool eula_accepted_called() {
42 return eula_accepted_called_
;
46 TestingPrefServiceSimple local_state_
;
47 scoped_ptr
<EulaAcceptedNotifier
> notifier_
;
48 bool eula_accepted_called_
;
50 DISALLOW_COPY_AND_ASSIGN(EulaAcceptedNotifierTest
);
53 TEST_F(EulaAcceptedNotifierTest
, EulaAlreadyAccepted
) {
54 SetEulaAcceptedPref();
55 EXPECT_TRUE(notifier()->IsEulaAccepted());
56 EXPECT_FALSE(eula_accepted_called());
57 // Call it a second time, to ensure the answer doesn't change.
58 EXPECT_TRUE(notifier()->IsEulaAccepted());
59 EXPECT_FALSE(eula_accepted_called());
62 TEST_F(EulaAcceptedNotifierTest
, EulaNotAccepted
) {
63 EXPECT_FALSE(notifier()->IsEulaAccepted());
64 EXPECT_FALSE(eula_accepted_called());
65 // Call it a second time, to ensure the answer doesn't change.
66 EXPECT_FALSE(notifier()->IsEulaAccepted());
67 EXPECT_FALSE(eula_accepted_called());
70 TEST_F(EulaAcceptedNotifierTest
, EulaNotInitiallyAccepted
) {
71 EXPECT_FALSE(notifier()->IsEulaAccepted());
72 SetEulaAcceptedPref();
73 EXPECT_TRUE(notifier()->IsEulaAccepted());
74 EXPECT_TRUE(eula_accepted_called());
75 // Call it a second time, to ensure the answer doesn't change.
76 EXPECT_TRUE(notifier()->IsEulaAccepted());
79 } // namespace web_resource