OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/prefs/session_startup_pref.h" | 8 #include "chrome/browser/prefs/session_startup_pref.h" |
9 #include "chrome/browser/protector/base_setting_change.h" | 9 #include "chrome/browser/protector/base_setting_change.h" |
10 #include "chrome/browser/ui/startup/startup_tab.h" | |
11 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
14 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
15 | 14 |
16 namespace protector { | 15 namespace protector { |
17 | 16 |
18 namespace { | 17 namespace { |
19 | 18 |
20 const char kStartupUrl1[] = "http://google.com"; | 19 const char kStartupUrl1[] = "http://google.com"; |
(...skipping 15 matching lines...) Expand all Loading... |
36 } | 35 } |
37 | 36 |
38 virtual void SetUp() OVERRIDE { | 37 virtual void SetUp() OVERRIDE { |
39 // Ensure initial session startup pref. | 38 // Ensure initial session startup pref. |
40 SessionStartupPref::SetStartupPref(&profile_, initial_startup_pref_); | 39 SessionStartupPref::SetStartupPref(&profile_, initial_startup_pref_); |
41 } | 40 } |
42 | 41 |
43 protected: | 42 protected: |
44 TestingProfile profile_; | 43 TestingProfile profile_; |
45 SessionStartupPref initial_startup_pref_; | 44 SessionStartupPref initial_startup_pref_; |
46 StartupTabs empty_pinned_tabs_; | 45 PinnedTabCodec::Tabs empty_pinned_tabs_; |
47 }; | 46 }; |
48 | 47 |
49 TEST_F(SessionStartupChangeTest, InitAndApply) { | 48 TEST_F(SessionStartupChangeTest, InitAndApply) { |
50 // Create a change and apply it. | 49 // Create a change and apply it. |
51 SessionStartupPref backup_startup_pref(SessionStartupPref::LAST); | 50 SessionStartupPref backup_startup_pref(SessionStartupPref::LAST); |
52 scoped_ptr<BaseSettingChange> change( | 51 scoped_ptr<BaseSettingChange> change( |
53 CreateSessionStartupChange(initial_startup_pref_, empty_pinned_tabs_, | 52 CreateSessionStartupChange(initial_startup_pref_, empty_pinned_tabs_, |
54 backup_startup_pref, empty_pinned_tabs_)); | 53 backup_startup_pref, empty_pinned_tabs_)); |
55 ASSERT_TRUE(change->Init(&profile_)); | 54 ASSERT_TRUE(change->Init(&profile_)); |
56 // Setting is initially reverted to backup. | 55 // Setting is initially reverted to backup. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 SessionStartupPref backup_startup_pref(SessionStartupPref::DEFAULT); | 96 SessionStartupPref backup_startup_pref(SessionStartupPref::DEFAULT); |
98 scoped_ptr<BaseSettingChange> change( | 97 scoped_ptr<BaseSettingChange> change( |
99 CreateSessionStartupChange(initial_startup_pref_, empty_pinned_tabs_, | 98 CreateSessionStartupChange(initial_startup_pref_, empty_pinned_tabs_, |
100 backup_startup_pref, empty_pinned_tabs_)); | 99 backup_startup_pref, empty_pinned_tabs_)); |
101 ASSERT_TRUE(change->Init(&profile_)); | 100 ASSERT_TRUE(change->Init(&profile_)); |
102 EXPECT_EQ(open_ntp_caption, change->GetApplyButtonText()); | 101 EXPECT_EQ(open_ntp_caption, change->GetApplyButtonText()); |
103 EXPECT_EQ(GURL(), change->GetNewSettingURL()); | 102 EXPECT_EQ(GURL(), change->GetNewSettingURL()); |
104 EXPECT_EQ(kNoDisplayName, change->GetApplyDisplayName()); | 103 EXPECT_EQ(kNoDisplayName, change->GetApplyDisplayName()); |
105 | 104 |
106 // Pinned tabs count as startup URLs as well. | 105 // Pinned tabs count as startup URLs as well. |
107 StartupTabs new_pinned_tabs; | 106 PinnedTabCodec::Tabs new_pinned_tabs; |
108 StartupTab pinned_tab; | 107 StartupBrowserCreator::LaunchWithProfile::Tab pinned_tab; |
109 pinned_tab.url = GURL(kStartupUrl3); | 108 pinned_tab.url = GURL(kStartupUrl3); |
110 new_pinned_tabs.push_back(pinned_tab); | 109 new_pinned_tabs.push_back(pinned_tab); |
111 change.reset( | 110 change.reset( |
112 CreateSessionStartupChange(initial_startup_pref_, new_pinned_tabs, | 111 CreateSessionStartupChange(initial_startup_pref_, new_pinned_tabs, |
113 backup_startup_pref, empty_pinned_tabs_)); | 112 backup_startup_pref, empty_pinned_tabs_)); |
114 ASSERT_TRUE(change->Init(&profile_)); | 113 ASSERT_TRUE(change->Init(&profile_)); |
115 EXPECT_EQ(open_url3_etc_caption, change->GetApplyButtonText()); | 114 EXPECT_EQ(open_url3_etc_caption, change->GetApplyButtonText()); |
116 EXPECT_EQ(GURL(kStartupUrl3), change->GetNewSettingURL()); | 115 EXPECT_EQ(GURL(kStartupUrl3), change->GetNewSettingURL()); |
117 EXPECT_EQ(UTF8ToUTF16(kStartupHost3), change->GetApplyDisplayName().second); | 116 EXPECT_EQ(UTF8ToUTF16(kStartupHost3), change->GetApplyDisplayName().second); |
118 | 117 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 change.reset( | 181 change.reset( |
183 CreateSessionStartupChange(initial_startup_pref_, new_pinned_tabs, | 182 CreateSessionStartupChange(initial_startup_pref_, new_pinned_tabs, |
184 backup_startup_pref, empty_pinned_tabs_)); | 183 backup_startup_pref, empty_pinned_tabs_)); |
185 ASSERT_TRUE(change->Init(&profile_)); | 184 ASSERT_TRUE(change->Init(&profile_)); |
186 EXPECT_EQ(open_url3_etc_caption, change->GetApplyButtonText()); | 185 EXPECT_EQ(open_url3_etc_caption, change->GetApplyButtonText()); |
187 EXPECT_EQ(GURL(kStartupUrl3), change->GetNewSettingURL()); | 186 EXPECT_EQ(GURL(kStartupUrl3), change->GetNewSettingURL()); |
188 EXPECT_EQ(UTF8ToUTF16(kStartupHost3), change->GetApplyDisplayName().second); | 187 EXPECT_EQ(UTF8ToUTF16(kStartupHost3), change->GetApplyDisplayName().second); |
189 } | 188 } |
190 | 189 |
191 } // namespace protector | 190 } // namespace protector |
OLD | NEW |