summaryrefslogtreecommitdiffstats
path: root/content/browser/host_zoom_map_unittest.cc
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-23 03:55:40 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-23 03:55:40 +0000
commita0421736a8a437ff97eb7deb6050f08b75810343 (patch)
tree0df2ac04070f1fa41b1a3dfbd5582f0f9bb9817e /content/browser/host_zoom_map_unittest.cc
parenta6d8357a9702c6ce48e15914760708c1970a03e2 (diff)
downloadchromium_src-a0421736a8a437ff97eb7deb6050f08b75810343.zip
chromium_src-a0421736a8a437ff97eb7deb6050f08b75810343.tar.gz
chromium_src-a0421736a8a437ff97eb7deb6050f08b75810343.tar.bz2
Move the rest of the core files in chrome\browser to content\browser.
TBR=avi Review URL: http://codereview.chromium.org/6538111 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75711 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/host_zoom_map_unittest.cc')
-rw-r--r--content/browser/host_zoom_map_unittest.cc132
1 files changed, 132 insertions, 0 deletions
diff --git a/content/browser/host_zoom_map_unittest.cc b/content/browser/host_zoom_map_unittest.cc
new file mode 100644
index 0000000..82e0e58
--- /dev/null
+++ b/content/browser/host_zoom_map_unittest.cc
@@ -0,0 +1,132 @@
+// Copyright (c) 2011 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/message_loop.h"
+#include "base/ref_counted.h"
+#include "base/utf_string_conversions.h"
+#include "base/values.h"
+#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/host_zoom_map.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/common/notification_details.h"
+#include "chrome/common/notification_observer_mock.h"
+#include "chrome/common/notification_source.h"
+#include "chrome/common/notification_type.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/testing_profile.h"
+#include "googleurl/src/gurl.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using testing::_;
+using testing::Pointee;
+using testing::Property;
+
+class HostZoomMapTest : public testing::Test {
+ public:
+ static const double kZoomLevel;
+ static const double kDefaultZoomLevel;
+ HostZoomMapTest()
+ : ui_thread_(BrowserThread::UI, &message_loop_),
+ prefs_(profile_.GetPrefs()),
+ per_host_zoom_levels_pref_(prefs::kPerHostZoomLevels),
+ url_("http://example.com/test"),
+ host_("example.com") {}
+
+ protected:
+ void SetPrefObserverExpectation() {
+ EXPECT_CALL(
+ pref_observer_,
+ Observe(NotificationType(NotificationType::PREF_CHANGED),
+ _,
+ Property(&Details<std::string>::ptr,
+ Pointee(per_host_zoom_levels_pref_))));
+ }
+
+ MessageLoopForUI message_loop_;
+ BrowserThread ui_thread_;
+ TestingProfile profile_;
+ PrefService* prefs_;
+ std::string per_host_zoom_levels_pref_; // For the observe matcher.
+ GURL url_;
+ std::string host_;
+ NotificationObserverMock pref_observer_;
+};
+const double HostZoomMapTest::kZoomLevel = 4;
+const double HostZoomMapTest::kDefaultZoomLevel = -2;
+
+TEST_F(HostZoomMapTest, LoadNoPrefs) {
+ scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
+ EXPECT_EQ(0, map->GetZoomLevel(url_));
+}
+
+TEST_F(HostZoomMapTest, Load) {
+ DictionaryValue* dict =
+ prefs_->GetMutableDictionary(prefs::kPerHostZoomLevels);
+ dict->SetWithoutPathExpansion(host_, Value::CreateDoubleValue(kZoomLevel));
+ scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
+ EXPECT_EQ(kZoomLevel, map->GetZoomLevel(url_));
+}
+
+TEST_F(HostZoomMapTest, SetZoomLevel) {
+ scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
+ PrefChangeRegistrar registrar;
+ registrar.Init(prefs_);
+ registrar.Add(prefs::kPerHostZoomLevels, &pref_observer_);
+ SetPrefObserverExpectation();
+ map->SetZoomLevel(url_, kZoomLevel);
+ EXPECT_EQ(kZoomLevel, map->GetZoomLevel(url_));
+ const DictionaryValue* dict =
+ prefs_->GetDictionary(prefs::kPerHostZoomLevels);
+ double zoom_level = 0;
+ EXPECT_TRUE(dict->GetDoubleWithoutPathExpansion(host_, &zoom_level));
+ EXPECT_EQ(kZoomLevel, zoom_level);
+
+ SetPrefObserverExpectation();
+ map->SetZoomLevel(url_, 0);
+ EXPECT_EQ(0, map->GetZoomLevel(url_));
+ EXPECT_FALSE(dict->HasKey(host_));
+}
+
+TEST_F(HostZoomMapTest, ResetToDefaults) {
+ scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
+ map->SetZoomLevel(url_, kZoomLevel);
+
+ PrefChangeRegistrar registrar;
+ registrar.Init(prefs_);
+ registrar.Add(prefs::kPerHostZoomLevels, &pref_observer_);
+ SetPrefObserverExpectation();
+ map->ResetToDefaults();
+ EXPECT_EQ(0, map->GetZoomLevel(url_));
+ DictionaryValue empty;
+ EXPECT_TRUE(
+ Value::Equals(&empty, prefs_->GetDictionary(prefs::kPerHostZoomLevels)));
+}
+
+TEST_F(HostZoomMapTest, ReloadOnPrefChange) {
+ scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
+ map->SetZoomLevel(url_, kZoomLevel);
+
+ DictionaryValue dict;
+ dict.SetWithoutPathExpansion(host_, Value::CreateDoubleValue(0));
+ prefs_->Set(prefs::kPerHostZoomLevels, dict);
+ EXPECT_EQ(0, map->GetZoomLevel(url_));
+}
+
+TEST_F(HostZoomMapTest, NoHost) {
+ scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
+ GURL file_url1_("file:///tmp/test.html");
+ GURL file_url2_("file:///tmp/other.html");
+ map->SetZoomLevel(file_url1_, kZoomLevel);
+
+ EXPECT_EQ(kZoomLevel, map->GetZoomLevel(file_url1_));
+ EXPECT_EQ(0, map->GetZoomLevel(file_url2_));
+}
+
+TEST_F(HostZoomMapTest, ChangeDefaultZoomLevel) {
+ FundamentalValue zoom_level(kDefaultZoomLevel);
+ prefs_->Set(prefs::kDefaultZoomLevel, zoom_level);
+ scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
+ EXPECT_EQ(kDefaultZoomLevel, map->GetZoomLevel(url_));
+}