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

Unified Diff: components/dom_distiller/core/distilled_page_prefs_unittests.cc

Issue 341563002: Theme Preferences for Distilled Pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Formatting changes and enum name change Created 6 years, 5 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
Index: components/dom_distiller/core/distilled_page_prefs_unittests.cc
diff --git a/components/dom_distiller/core/distilled_page_prefs_unittests.cc b/components/dom_distiller/core/distilled_page_prefs_unittests.cc
new file mode 100644
index 0000000000000000000000000000000000000000..de9109111a6ee4edf4c056bf61b24ccd94b1c2a2
--- /dev/null
+++ b/components/dom_distiller/core/distilled_page_prefs_unittests.cc
@@ -0,0 +1,75 @@
+// Copyright 2014 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 "components/dom_distiller/core/distilled_page_prefs.h"
+
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "components/pref_registry/testing_pref_service_syncable.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace dom_distiller {
+
+namespace {
+
+class TestingObserver : public DistilledPagePrefs::Observer {
+ public:
+ TestingObserver() : theme_(DistilledPagePrefs::Theme::LIGHT) {}
+
+ virtual void OnChangeTheme(DistilledPagePrefs::Theme new_theme) OVERRIDE {
+ theme_ = new_theme;
+ }
+
+ DistilledPagePrefs::Theme GetTheme() { return theme_; }
+
+ private:
+ DistilledPagePrefs::Theme theme_;
+};
+
+} // namespace
+
+class DistilledPagePrefsTest : public testing::Test {
+ protected:
+ virtual void SetUp() OVERRIDE {
+ user_prefs::TestingPrefServiceSyncable* pref_service =
+ new user_prefs::TestingPrefServiceSyncable();
+ DistilledPagePrefs::RegisterProfilePrefs(pref_service->registry());
+ distilled_page_prefs_ = new DistilledPagePrefs(pref_service);
+ }
+
+ DistilledPagePrefs* distilled_page_prefs_;
+
+ private:
+ base::MessageLoop message_loop_;
+};
+
+TEST_F(DistilledPagePrefsTest, TestingOnChangeThemeIsBeingCalled) {
+ TestingObserver* obs = new TestingObserver();
+ distilled_page_prefs_->AddObserver(obs);
+ distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::SEPIA);
+ EXPECT_EQ(DistilledPagePrefs::Theme::LIGHT, obs->GetTheme());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(DistilledPagePrefs::Theme::SEPIA, obs->GetTheme());
+ distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::DARK);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(DistilledPagePrefs::Theme::DARK, obs->GetTheme());
+}
+
+TEST_F(DistilledPagePrefsTest, TestingMultipleObservers) {
+ TestingObserver* obs = new TestingObserver();
+ distilled_page_prefs_->AddObserver(obs);
+ TestingObserver* obs2 = new TestingObserver();
+ distilled_page_prefs_->AddObserver(obs2);
+ distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::SEPIA);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(DistilledPagePrefs::Theme::SEPIA, obs->GetTheme());
+ EXPECT_EQ(DistilledPagePrefs::Theme::SEPIA, obs2->GetTheme());
+ distilled_page_prefs_->RemoveObserver(obs);
+ distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::LIGHT);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(DistilledPagePrefs::Theme::SEPIA, obs->GetTheme());
+ EXPECT_EQ(DistilledPagePrefs::Theme::LIGHT, obs2->GetTheme());
+}
+
+} // namespace dom_distiller

Powered by Google App Engine
This is Rietveld 408576698