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

Side by Side Diff: chrome/browser/protector/homepage_change_unittest.cc

Issue 11493003: Remove the protector service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix implicit ExtensionSystem -> TemplateURLService dependency Created 8 years 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
« no previous file with comments | « chrome/browser/protector/homepage_change.cc ('k') | chrome/browser/protector/keys.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "base/memory/scoped_ptr.h"
6 #include "base/utf_string_conversions.h"
7 #include "base/values.h"
8 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/protector/base_setting_change.h"
10 #include "chrome/common/pref_names.h"
11 #include "chrome/test/base/testing_profile.h"
12 #include "grit/generated_resources.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/base/l10n/l10n_util.h"
15
16 namespace protector {
17
18 namespace {
19
20 std::string kHomepage1 = "http://google.com/";
21 std::string kHomepage2 = "http://example.com/";
22
23 }
24
25 class HomepageChangeTest : public testing::Test {
26 virtual void SetUp() OVERRIDE {
27 prefs_ = profile_.GetPrefs();
28 }
29
30 protected:
31 TestingProfile profile_;
32 PrefService* prefs_;
33 };
34
35 TEST_F(HomepageChangeTest, InitAndApply) {
36 prefs_->SetString(prefs::kHomePage, kHomepage1);
37
38 // Create a change and apply it.
39 scoped_ptr<BaseSettingChange> change(
40 CreateHomepageChange(kHomepage1, false, true, kHomepage2, false, true));
41 ASSERT_TRUE(change->Init(&profile_));
42 // Setting is initially reverted to backup.
43 EXPECT_EQ(kHomepage2, prefs_->GetString(prefs::kHomePage));
44
45 change->Apply(NULL); // |browser| is unused.
46 // New setting active now.
47 EXPECT_EQ(kHomepage1, prefs_->GetString(prefs::kHomePage));
48 }
49
50 TEST_F(HomepageChangeTest, InitAndDiscard) {
51 prefs_->SetString(prefs::kHomePage, kHomepage1);
52
53 // Create a change and apply it.
54 scoped_ptr<BaseSettingChange> change(
55 CreateHomepageChange(kHomepage1, false, true, kHomepage2, false, true));
56 ASSERT_TRUE(change->Init(&profile_));
57 // Setting is initially reverted to backup.
58 EXPECT_EQ(kHomepage2, prefs_->GetString(prefs::kHomePage));
59
60 change->Discard(NULL); // |browser| is unused.
61 // Nothing changed by Discard.
62 EXPECT_EQ(kHomepage2, prefs_->GetString(prefs::kHomePage));
63 }
64
65 TEST_F(HomepageChangeTest, DiscardButtonCaptionsSameSetting) {
66 // New and backup setting have the same URL (or both are NTP).
67
68 // NTP can be represented both by an empty URL or a |homepage_is_ntp| flag.
69 // NTP -> NTP.
70 scoped_ptr<BaseSettingChange> change(
71 CreateHomepageChange(kHomepage1, true, true, kHomepage2, true, true));
72 ASSERT_TRUE(change->Init(&profile_));
73 string16 generic_caption(l10n_util::GetStringUTF16(IDS_KEEP_SETTING));
74 EXPECT_EQ(generic_caption, change->GetDiscardButtonText());
75
76 // NTP -> NTP.
77 change.reset(
78 CreateHomepageChange("", false, true, kHomepage2, true, true));
79 ASSERT_TRUE(change->Init(&profile_));
80 EXPECT_EQ(generic_caption, change->GetDiscardButtonText());
81
82 // NTP -> NTP.
83 change.reset(
84 CreateHomepageChange(kHomepage1, true, true, "", false, true));
85 ASSERT_TRUE(change->Init(&profile_));
86 EXPECT_EQ(generic_caption, change->GetDiscardButtonText());
87
88 // kHomepage1 -> kHomepage1.
89 change.reset(
90 CreateHomepageChange(kHomepage1, false, true, kHomepage1, false, true));
91 ASSERT_TRUE(change->Init(&profile_));
92 EXPECT_EQ(generic_caption, change->GetDiscardButtonText());
93 }
94
95 TEST_F(HomepageChangeTest, DiscardButtonCaptionsDifferentSettings) {
96 // New and backup settings differ.
97
98 // NTP -> kHomepage2.
99 scoped_ptr<BaseSettingChange> change(
100 CreateHomepageChange(kHomepage1, true, true, kHomepage2, false, true));
101 ASSERT_TRUE(change->Init(&profile_));
102 string16 generic_caption(l10n_util::GetStringUTF16(IDS_KEEP_SETTING));
103 EXPECT_NE(generic_caption, change->GetDiscardButtonText());
104
105 // kHomepage1 -> NTP.
106 change.reset(
107 CreateHomepageChange(kHomepage1, false, true, kHomepage2, true, true));
108 ASSERT_TRUE(change->Init(&profile_));
109 EXPECT_NE(generic_caption, change->GetDiscardButtonText());
110
111 // kHomepage1 -> kHomepage2.
112 change.reset(
113 CreateHomepageChange(kHomepage1, false, true, kHomepage2, false, true));
114 ASSERT_TRUE(change->Init(&profile_));
115 EXPECT_NE(generic_caption, change->GetDiscardButtonText());
116 }
117
118 } // namespace protector
OLDNEW
« no previous file with comments | « chrome/browser/protector/homepage_change.cc ('k') | chrome/browser/protector/keys.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698