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

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: Changed names and added tests 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..dc32bbc4c6dabfb78ae249a3e778cf7a4dd04c5b
--- /dev/null
+++ b/components/dom_distiller/core/distilled_page_prefs_unittests.cc
@@ -0,0 +1,80 @@
+// 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 {
nyquist 2014/07/07 19:12:49 I think you can end this namespace after the obser
smaslo 2014/07/08 19:58:11 Done.
+
+void RunLoop() {
nyquist 2014/07/07 19:12:49 Could you inline this to base::RunLoop().RunUntilI
smaslo 2014/07/08 19:58:11 Done.
+ base::RunLoop run_loop;
+ run_loop.RunUntilIdle();
+}
+
+class TestingObserver
+ : public DistilledPagePrefs::Observer {
nyquist 2014/07/07 19:12:49 Nit: Does this really need to be on its own line?
smaslo 2014/07/08 19:58:11 Done.
+ public:
+ virtual void OnChangeTheme(DistilledPagePrefs::Theme) OVERRIDE;
nyquist 2014/07/07 19:12:48 I think this method and GetTheme can probably just
smaslo 2014/07/08 19:58:11 Done.
+ DistilledPagePrefs::Theme GetTheme();
nyquist 2014/07/07 19:12:49 How about adding using DistilledPagePrefs::Observe
smaslo 2014/07/08 19:58:11 Could not add "using DistilledPagePrefs::Theme;" b
+
+ private:
+ DistilledPagePrefs::Theme theme;
nyquist 2014/07/07 19:12:48 theme_
smaslo 2014/07/08 19:58:11 Done.
+};
+
+void TestingObserver::OnChangeTheme(
nyquist 2014/07/07 19:12:48 same line after adding 'using'?
smaslo 2014/07/08 19:58:11 Done.
+ DistilledPagePrefs::Theme new_theme) {
+ theme = new_theme;
+}
+
+DistilledPagePrefs::Theme TestingObserver::GetTheme() {
+ return theme;
+}
+
+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::kLight);
+ RunLoop();
nyquist 2014/07/07 19:12:49 Add an EXPECT_EQ("", ...) before the call to RunLo
smaslo 2014/07/08 19:58:11 Done. Constructor for TestingObserver now initiali
+ EXPECT_EQ(DistilledPagePrefs::Theme::kLight, obs->GetTheme());
+ distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::kDark);
+ RunLoop();
+ EXPECT_EQ(DistilledPagePrefs::Theme::kDark, obs->GetTheme());
+}
+
+TEST_F(DistilledPagePrefsTest, TestingMultipleObservers) {
nyquist 2014/07/07 19:12:48 This is not currently testing multiple observers,
smaslo 2014/07/08 19:58:11 Done.
+ TestingObserver* obs = new TestingObserver();
+ distilled_page_prefs_->AddObserver(obs);
+ distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::kSepia);
nyquist 2014/07/07 19:12:49 This has already been tested in the method above.
smaslo 2014/07/08 19:58:11 Done.
+ RunLoop();
+ EXPECT_EQ(DistilledPagePrefs::Theme::kSepia, obs->GetTheme());
+ distilled_page_prefs_->RemoveObserver(obs);
+ distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::kLight);
+ RunLoop();
+ EXPECT_EQ(DistilledPagePrefs::Theme::kSepia, obs->GetTheme());
+}
+
+} // namespace
+
+} // namespace dom_distiller

Powered by Google App Engine
This is Rietveld 408576698