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 |