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

Unified Diff: chrome/browser/protector/session_startup_change_unittest.cc

Issue 9688002: [protector] Added SessionStartupChange for representing changes in SessionStartupPref. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments. Created 8 years, 9 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/protector/session_startup_change.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/protector/session_startup_change_unittest.cc
diff --git a/chrome/browser/protector/session_startup_change_unittest.cc b/chrome/browser/protector/session_startup_change_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..083d1c64bc7bcf2d5bc84264529fc5a085982d4b
--- /dev/null
+++ b/chrome/browser/protector/session_startup_change_unittest.cc
@@ -0,0 +1,131 @@
+// 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_;
+};
+
+TEST_F(SessionStartupChangeTest, InitAndApply) {
+ // Create a change and apply it.
+ SessionStartupPref backup_startup_pref(SessionStartupPref::LAST);
+ scoped_ptr<BaseSettingChange> change(
+ CreateSessionStartupChange(initial_startup_pref_, backup_startup_pref));
+ 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_, backup_startup_pref));
+ 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()));
+
+ // "Open URLs" with no URLs is the same as "Open NTP".
+ initial_startup_pref_.type = SessionStartupPref::URLS;
+ SessionStartupPref backup_startup_pref(SessionStartupPref::DEFAULT);
+ scoped_ptr<BaseSettingChange> change(
+ CreateSessionStartupChange(initial_startup_pref_, backup_startup_pref));
+ 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_, backup_startup_pref));
+ 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_, backup_startup_pref));
+ ASSERT_TRUE(change->Init(&profile_));
+ EXPECT_EQ(open_url1_etc_caption, change->GetApplyButtonText());
+}
+
+TEST_F(SessionStartupChangeTest, DiscardButtonCaptions) {
+ // Discard button captions for "Open NTP" and "Open specific URLs" cases.
+ string16 open_ntp_caption =
+ l10n_util::GetStringUTF16(IDS_KEEP_STARTUP_SETTINGS_NTP);
+ string16 open_url1_etc_caption =
+ l10n_util::GetStringFUTF16(IDS_KEEP_STARTUP_SETTINGS_URLS,
+ UTF8ToUTF16(GURL(kStartupUrl1).host()));
+
+ // "Open URLs" with no URLs is the same as "Open NTP".
+ SessionStartupPref backup_startup_pref(SessionStartupPref::URLS);
+ scoped_ptr<BaseSettingChange> change(
+ CreateSessionStartupChange(initial_startup_pref_, backup_startup_pref));
+ ASSERT_TRUE(change->Init(&profile_));
+ EXPECT_EQ(open_ntp_caption, change->GetDiscardButtonText());
+
+ // Single URL.
+ backup_startup_pref.urls.push_back(GURL(kStartupUrl1));
+ change.reset(
+ CreateSessionStartupChange(initial_startup_pref_, backup_startup_pref));
+ ASSERT_TRUE(change->Init(&profile_));
+ EXPECT_EQ(open_url1_etc_caption, change->GetDiscardButtonText());
+
+ // Multiple URLs: name of the first one used.
+ backup_startup_pref.urls.push_back(GURL(kStartupUrl2));
+ change.reset(
+ CreateSessionStartupChange(initial_startup_pref_, backup_startup_pref));
+ ASSERT_TRUE(change->Init(&profile_));
+ EXPECT_EQ(open_url1_etc_caption, change->GetDiscardButtonText());
+}
+
+} // namespace protector
« no previous file with comments | « chrome/browser/protector/session_startup_change.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698