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