Chromium Code Reviews| 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 |
| deleted file mode 100644 |
| index 63a43b68cfa3b89862fd773c60dda374d73c7243..0000000000000000000000000000000000000000 |
| --- a/components/dom_distiller/core/distilled_page_prefs_unittests.cc |
| +++ /dev/null |
| @@ -1,149 +0,0 @@ |
| -// Copyright 2014 The Chromium Authors. All rights reserved. |
|
nyquist
2014/07/09 23:49:03
I don't think you want to delete this unittest.
sunangel
2014/07/10 14:31:52
Done.
|
| -// 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/bind.h" |
| -#include "base/memory/weak_ptr.h" |
| -#include "base/message_loop/message_loop.h" |
| -#include "base/observer_list.h" |
| -#include "base/prefs/pref_registry_simple.h" |
| -#include "base/prefs/testing_pref_service.h" |
| -#include "base/run_loop.h" |
| -#include "base/values.h" |
| -#include "testing/gtest/include/gtest/gtest.h" |
| - |
| -namespace { |
| -const char kThemePref[] = "dom_distiller.theme"; |
| -} |
| - |
| -namespace dom_distiller { |
| - |
| -class TestingDistilledPagePrefs { |
| - public: |
| - // Possible themes for distilled page. |
| - enum Theme { |
| - kLight, |
| - kDark, |
| - kSepia |
| - }; |
| - |
| - class Observer { |
| - public: |
| - virtual void OnChangeTheme(Theme theme) = 0; |
| - }; |
| - |
| - void AddObserver(Observer* obs); |
| - void RemoveObserver(Observer* obs); |
| - int GetNumberOfObservers(); |
| - |
| - TestingDistilledPagePrefs(); |
| - ~TestingDistilledPagePrefs(); |
| - |
| - void SetTheme(Theme new_theme); |
| - Theme GetTheme(); |
| - |
| - private: |
| - void NotifyOnChangeTheme(Theme theme); |
| - void RegisterPrefs(); |
| - |
| - ObserverList<Observer> observers_; |
| - TestingPrefServiceSimple* pref_service_; |
| - |
| - base::WeakPtrFactory<TestingDistilledPagePrefs> weak_ptr_factory_; |
| -}; |
| - |
| -class TestingDistilledPagePrefsObserver |
| - : public TestingDistilledPagePrefs::Observer { |
| - public: |
| - virtual void OnChangeTheme(TestingDistilledPagePrefs::Theme) OVERRIDE; |
| - TestingDistilledPagePrefs::Theme GetTheme(); |
| - |
| - private: |
| - TestingDistilledPagePrefs::Theme theme; |
| -}; |
| - |
| -TestingDistilledPagePrefs::TestingDistilledPagePrefs() |
| - : pref_service_(new TestingPrefServiceSimple()), |
| - weak_ptr_factory_(this) { |
| - RegisterPrefs(); |
| -} |
| - |
| -TestingDistilledPagePrefs::~TestingDistilledPagePrefs() { |
| - pref_service_->~TestingPrefServiceSimple(); |
| -} |
| - |
| -void TestingDistilledPagePrefs::AddObserver(Observer* obs) { |
| - observers_.AddObserver(obs); |
| -} |
| - |
| -void TestingDistilledPagePrefs::RemoveObserver(Observer* obs) { |
| - observers_.RemoveObserver(obs); |
| -} |
| - |
| -int TestingDistilledPagePrefs::GetNumberOfObservers() { |
| - ObserverListBase<dom_distiller::TestingDistilledPagePrefs::Observer>::Iterator* iter = new ObserverListBase<TestingDistilledPagePrefs::Observer>::Iterator(observers_); |
| - Observer* obs; |
| - int count = 0; |
| - while((obs = iter->GetNext()) != NULL) { |
| - count++; |
| - } |
| - //iter->ObserverListBase<dom_distiller::TestingDistilledPagePrefs::Observer>::~Iterator(); |
| - return count; |
| -} |
| - |
| -void TestingDistilledPagePrefs::RegisterPrefs() { |
| - pref_service_->registry()->RegisterIntegerPref(kThemePref, Theme::kLight); |
| -} |
| - |
| - |
| -void TestingDistilledPagePrefs::SetTheme(Theme new_theme) { |
| - pref_service_->SetUserPref(kThemePref, new base::FundamentalValue(new_theme)); |
| - base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&TestingDistilledPagePrefs::NotifyOnChangeTheme, weak_ptr_factory_.GetWeakPtr(), new_theme)); |
| -} |
| - |
| -TestingDistilledPagePrefs::Theme TestingDistilledPagePrefs::GetTheme() { |
| - int temp; |
| - pref_service_->GetUserPref(kThemePref)->GetAsInteger(&temp); |
| - return (Theme) temp; |
| -} |
| - |
| -void TestingDistilledPagePrefs::NotifyOnChangeTheme(Theme theme) { |
| - FOR_EACH_OBSERVER(Observer, observers_, OnChangeTheme(theme)); |
| -} |
| - |
| -void TestingDistilledPagePrefsObserver::OnChangeTheme( |
| - TestingDistilledPagePrefs::Theme new_theme) { |
| - theme = new_theme; |
| -} |
| - |
| -TestingDistilledPagePrefs::Theme TestingDistilledPagePrefsObserver::GetTheme() { |
| - return theme; |
| -} |
| - |
| -class DistilledPagePrefsTest : public testing::Test { |
| -}; |
| - |
| -TEST_F(DistilledPagePrefsTest, TestingOnChangeThemeIsBeingCalled) { |
| - scoped_ptr<TestingDistilledPagePrefs> distilled_page_prefs(new TestingDistilledPagePrefs); |
| - TestingDistilledPagePrefsObserver* obs = new TestingDistilledPagePrefsObserver(); |
| - distilled_page_prefs->AddObserver(obs); |
| - distilled_page_prefs->SetTheme(TestingDistilledPagePrefs::Theme::kDark); |
| - base::RunLoop run_loop; |
| - run_loop.RunUntilIdle(); |
| - EXPECT_EQ(distilled_page_prefs->GetTheme(), obs->GetTheme()); |
| -} |
| - |
| -TEST_F(DistilledPagePrefsTest, TestingAddRemoveObserver) { |
| -/* scoped_ptr<TestingDistilledPagePrefs> distilled_page_prefs(new TestingDistilledPagePrefs); |
| - TestingDistilledPagePrefsObserver* obs = new TestingDistilledPagePrefsObserver(); |
| - int count = 0; |
| - ObserverListBase<TestingDistilledPagePrefs::Observer>::Iterator iter = new ObserverListBase<TestingDistilledPagePrefs::Observer>::Iterator(distilled_page_prefs->observers_); |
| - distilled_page_prefs->AddObserver(obs);*/ |
| -// EXPECT_EQ(distilled_page_prefs->observers_. |
| -/* base::MessageLoop* message_loop(base::MessageLoop::Type::TYPE_DEFAULT); |
| - distilled_page_prefs->SetTheme(TestingDistilledPagePrefs::Theme::kSepia, message_loop);*/ |
| -} |
| - |
| -} // namespace dom_distiller |