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

Side by Side Diff: chrome/browser/host_zoom_map_unittest.cc

Issue 6538111: Move the rest of the core files in chrome\browser to content\browser.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/host_zoom_map.cc ('k') | chrome/browser/mime_registry_message_filter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/message_loop.h"
6 #include "base/ref_counted.h"
7 #include "base/utf_string_conversions.h"
8 #include "base/values.h"
9 #include "chrome/browser/browser_thread.h"
10 #include "chrome/browser/host_zoom_map.h"
11 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/common/notification_details.h"
13 #include "chrome/common/notification_observer_mock.h"
14 #include "chrome/common/notification_source.h"
15 #include "chrome/common/notification_type.h"
16 #include "chrome/common/pref_names.h"
17 #include "chrome/test/testing_profile.h"
18 #include "googleurl/src/gurl.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 using testing::_;
23 using testing::Pointee;
24 using testing::Property;
25
26 class HostZoomMapTest : public testing::Test {
27 public:
28 static const double kZoomLevel;
29 static const double kDefaultZoomLevel;
30 HostZoomMapTest()
31 : ui_thread_(BrowserThread::UI, &message_loop_),
32 prefs_(profile_.GetPrefs()),
33 per_host_zoom_levels_pref_(prefs::kPerHostZoomLevels),
34 url_("http://example.com/test"),
35 host_("example.com") {}
36
37 protected:
38 void SetPrefObserverExpectation() {
39 EXPECT_CALL(
40 pref_observer_,
41 Observe(NotificationType(NotificationType::PREF_CHANGED),
42 _,
43 Property(&Details<std::string>::ptr,
44 Pointee(per_host_zoom_levels_pref_))));
45 }
46
47 MessageLoopForUI message_loop_;
48 BrowserThread ui_thread_;
49 TestingProfile profile_;
50 PrefService* prefs_;
51 std::string per_host_zoom_levels_pref_; // For the observe matcher.
52 GURL url_;
53 std::string host_;
54 NotificationObserverMock pref_observer_;
55 };
56 const double HostZoomMapTest::kZoomLevel = 4;
57 const double HostZoomMapTest::kDefaultZoomLevel = -2;
58
59 TEST_F(HostZoomMapTest, LoadNoPrefs) {
60 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
61 EXPECT_EQ(0, map->GetZoomLevel(url_));
62 }
63
64 TEST_F(HostZoomMapTest, Load) {
65 DictionaryValue* dict =
66 prefs_->GetMutableDictionary(prefs::kPerHostZoomLevels);
67 dict->SetWithoutPathExpansion(host_, Value::CreateDoubleValue(kZoomLevel));
68 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
69 EXPECT_EQ(kZoomLevel, map->GetZoomLevel(url_));
70 }
71
72 TEST_F(HostZoomMapTest, SetZoomLevel) {
73 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
74 PrefChangeRegistrar registrar;
75 registrar.Init(prefs_);
76 registrar.Add(prefs::kPerHostZoomLevels, &pref_observer_);
77 SetPrefObserverExpectation();
78 map->SetZoomLevel(url_, kZoomLevel);
79 EXPECT_EQ(kZoomLevel, map->GetZoomLevel(url_));
80 const DictionaryValue* dict =
81 prefs_->GetDictionary(prefs::kPerHostZoomLevels);
82 double zoom_level = 0;
83 EXPECT_TRUE(dict->GetDoubleWithoutPathExpansion(host_, &zoom_level));
84 EXPECT_EQ(kZoomLevel, zoom_level);
85
86 SetPrefObserverExpectation();
87 map->SetZoomLevel(url_, 0);
88 EXPECT_EQ(0, map->GetZoomLevel(url_));
89 EXPECT_FALSE(dict->HasKey(host_));
90 }
91
92 TEST_F(HostZoomMapTest, ResetToDefaults) {
93 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
94 map->SetZoomLevel(url_, kZoomLevel);
95
96 PrefChangeRegistrar registrar;
97 registrar.Init(prefs_);
98 registrar.Add(prefs::kPerHostZoomLevels, &pref_observer_);
99 SetPrefObserverExpectation();
100 map->ResetToDefaults();
101 EXPECT_EQ(0, map->GetZoomLevel(url_));
102 DictionaryValue empty;
103 EXPECT_TRUE(
104 Value::Equals(&empty, prefs_->GetDictionary(prefs::kPerHostZoomLevels)));
105 }
106
107 TEST_F(HostZoomMapTest, ReloadOnPrefChange) {
108 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
109 map->SetZoomLevel(url_, kZoomLevel);
110
111 DictionaryValue dict;
112 dict.SetWithoutPathExpansion(host_, Value::CreateDoubleValue(0));
113 prefs_->Set(prefs::kPerHostZoomLevels, dict);
114 EXPECT_EQ(0, map->GetZoomLevel(url_));
115 }
116
117 TEST_F(HostZoomMapTest, NoHost) {
118 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
119 GURL file_url1_("file:///tmp/test.html");
120 GURL file_url2_("file:///tmp/other.html");
121 map->SetZoomLevel(file_url1_, kZoomLevel);
122
123 EXPECT_EQ(kZoomLevel, map->GetZoomLevel(file_url1_));
124 EXPECT_EQ(0, map->GetZoomLevel(file_url2_));
125 }
126
127 TEST_F(HostZoomMapTest, ChangeDefaultZoomLevel) {
128 FundamentalValue zoom_level(kDefaultZoomLevel);
129 prefs_->Set(prefs::kDefaultZoomLevel, zoom_level);
130 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
131 EXPECT_EQ(kDefaultZoomLevel, map->GetZoomLevel(url_));
132 }
OLDNEW
« no previous file with comments | « chrome/browser/host_zoom_map.cc ('k') | chrome/browser/mime_registry_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698