1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/memory/scoped_ptr.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/protector/base_setting_change.h"
#include "chrome/test/base/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
namespace protector {
namespace {
const char kStartupUrl1[] = "http://google.com";
const char kStartupUrl2[] = "http://example.com";
} // namespace
class SessionStartupChangeTest : public testing::Test {
public:
SessionStartupChangeTest()
: initial_startup_pref_(SessionStartupPref::DEFAULT) {
}
virtual void SetUp() OVERRIDE {
// Ensure initial session startup pref.
SessionStartupPref::SetStartupPref(&profile_, initial_startup_pref_);
}
protected:
TestingProfile profile_;
SessionStartupPref initial_startup_pref_;
PinnedTabCodec::Tabs empty_pinned_tabs_;
};
TEST_F(SessionStartupChangeTest, InitAndApply) {
// Create a change and apply it.
SessionStartupPref backup_startup_pref(SessionStartupPref::LAST);
scoped_ptr<BaseSettingChange> change(
CreateSessionStartupChange(initial_startup_pref_, empty_pinned_tabs_,
backup_startup_pref, empty_pinned_tabs_));
ASSERT_TRUE(change->Init(&profile_));
// Setting is initially reverted to backup.
EXPECT_EQ(SessionStartupPref::LAST,
SessionStartupPref::GetStartupPref(&profile_).type);
change->Apply(NULL); // |browser| is unused.
// New setting active now.
EXPECT_EQ(SessionStartupPref::DEFAULT,
SessionStartupPref::GetStartupPref(&profile_).type);
}
TEST_F(SessionStartupChangeTest, InitAndDiscard) {
// Create a change and discard it.
SessionStartupPref backup_startup_pref(SessionStartupPref::LAST);
scoped_ptr<BaseSettingChange> change(
CreateSessionStartupChange(initial_startup_pref_, empty_pinned_tabs_,
backup_startup_pref, empty_pinned_tabs_));
ASSERT_TRUE(change->Init(&profile_));
// Setting is initially reverted to backup.
EXPECT_EQ(SessionStartupPref::LAST,
SessionStartupPref::GetStartupPref(&profile_).type);
change->Discard(NULL); // |browser| is unused.
// Nothing changed by Discard.
EXPECT_EQ(SessionStartupPref::LAST,
SessionStartupPref::GetStartupPref(&profile_).type);
}
TEST_F(SessionStartupChangeTest, ApplyButtonCaptions) {
// Apply button captions for "Open NTP" and "Open specific URLs" cases.
string16 open_ntp_caption =
l10n_util::GetStringUTF16(IDS_CHANGE_STARTUP_SETTINGS_NTP);
string16 open_url1_etc_caption =
l10n_util::GetStringFUTF16(IDS_CHANGE_STARTUP_SETTINGS_URLS,
UTF8ToUTF16(GURL(kStartupUrl1).host()));
string16 open_url2_etc_caption =
l10n_util::GetStringFUTF16(IDS_CHANGE_STARTUP_SETTINGS_URLS,
UTF8ToUTF16(GURL(kStartupUrl2).host()));
// Open NTP.
initial_startup_pref_.type = SessionStartupPref::DEFAULT;
SessionStartupPref backup_startup_pref(SessionStartupPref::DEFAULT);
scoped_ptr<BaseSettingChange> change(
CreateSessionStartupChange(initial_startup_pref_, empty_pinned_tabs_,
backup_startup_pref, empty_pinned_tabs_));
ASSERT_TRUE(change->Init(&profile_));
EXPECT_EQ(open_ntp_caption, change->GetApplyButtonText());
// Pinned tabs count as startup URLs as well.
PinnedTabCodec::Tabs new_pinned_tabs;
BrowserInit::LaunchWithProfile::Tab pinned_tab;
pinned_tab.url = GURL(kStartupUrl2);
new_pinned_tabs.push_back(pinned_tab);
change.reset(
CreateSessionStartupChange(initial_startup_pref_, new_pinned_tabs,
backup_startup_pref, empty_pinned_tabs_));
ASSERT_TRUE(change->Init(&profile_));
EXPECT_EQ(open_url2_etc_caption, change->GetApplyButtonText());
// "Open URLs" with no URLs is the same as "Open NTP".
initial_startup_pref_.type = SessionStartupPref::URLS;
change.reset(
CreateSessionStartupChange(initial_startup_pref_, empty_pinned_tabs_,
backup_startup_pref, empty_pinned_tabs_));
ASSERT_TRUE(change->Init(&profile_));
EXPECT_EQ(open_ntp_caption, change->GetApplyButtonText());
// Single URL.
initial_startup_pref_.urls.push_back(GURL(kStartupUrl1));
change.reset(
CreateSessionStartupChange(initial_startup_pref_, empty_pinned_tabs_,
backup_startup_pref, empty_pinned_tabs_));
ASSERT_TRUE(change->Init(&profile_));
EXPECT_EQ(open_url1_etc_caption, change->GetApplyButtonText());
// Multiple URLs: name of the first one used.
initial_startup_pref_.urls.push_back(GURL(kStartupUrl2));
change.reset(
CreateSessionStartupChange(initial_startup_pref_, empty_pinned_tabs_,
backup_startup_pref, empty_pinned_tabs_));
ASSERT_TRUE(change->Init(&profile_));
EXPECT_EQ(open_url1_etc_caption, change->GetApplyButtonText());
// Pinned tabs go after the startup URLs.
change.reset(
CreateSessionStartupChange(initial_startup_pref_, new_pinned_tabs,
backup_startup_pref, empty_pinned_tabs_));
ASSERT_TRUE(change->Init(&profile_));
EXPECT_EQ(open_url1_etc_caption, change->GetApplyButtonText());
}
} // namespace protector
|