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

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

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

Powered by Google App Engine
This is Rietveld 408576698