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

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

Issue 1744003: Send content settings based on the URL to the renderer instead of just the host. (Closed)
Patch Set: nits Created 10 years, 8 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
« no previous file with comments | « chrome/browser/host_zoom_map.cc ('k') | chrome/browser/renderer_host/async_resource_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/chrome_thread.h" 9 #include "chrome/browser/chrome_thread.h"
10 #include "chrome/browser/host_zoom_map.h" 10 #include "chrome/browser/host_zoom_map.h"
11 #include "chrome/browser/pref_service.h" 11 #include "chrome/browser/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_registrar.h" 14 #include "chrome/common/notification_registrar.h"
15 #include "chrome/common/notification_service.h" 15 #include "chrome/common/notification_service.h"
16 #include "chrome/common/notification_type.h" 16 #include "chrome/common/notification_type.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "chrome/test/testing_profile.h" 18 #include "chrome/test/testing_profile.h"
19 #include "googleurl/src/gurl.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 using testing::_; 23 using testing::_;
23 using testing::Pointee; 24 using testing::Pointee;
24 using testing::Property; 25 using testing::Property;
25 26
26 class HostZoomMapTest : public testing::Test { 27 class HostZoomMapTest : public testing::Test {
27 public: 28 public:
28 static const int kZoomLevel; 29 static const int kZoomLevel;
29 HostZoomMapTest() 30 HostZoomMapTest()
30 : ui_thread_(ChromeThread::UI, &message_loop_), 31 : ui_thread_(ChromeThread::UI, &message_loop_),
31 prefs_(profile_.GetPrefs()), 32 prefs_(profile_.GetPrefs()),
32 per_host_zoom_levels_pref_(prefs::kPerHostZoomLevels), 33 per_host_zoom_levels_pref_(prefs::kPerHostZoomLevels),
33 host_name_("http://example/com/") {} 34 url_("http://example.com/test"),
35 host_("example.com") {}
34 36
35 protected: 37 protected:
36 void SetPrefObserverExpectation() { 38 void SetPrefObserverExpectation() {
37 EXPECT_CALL( 39 EXPECT_CALL(
38 pref_observer_, 40 pref_observer_,
39 Observe(NotificationType(NotificationType::PREF_CHANGED), 41 Observe(NotificationType(NotificationType::PREF_CHANGED),
40 _, 42 _,
41 Property(&Details<std::wstring>::ptr, 43 Property(&Details<std::wstring>::ptr,
42 Pointee(per_host_zoom_levels_pref_)))); 44 Pointee(per_host_zoom_levels_pref_))));
43 } 45 }
44 46
45 MessageLoopForUI message_loop_; 47 MessageLoopForUI message_loop_;
46 ChromeThread ui_thread_; 48 ChromeThread ui_thread_;
47 TestingProfile profile_; 49 TestingProfile profile_;
48 PrefService* prefs_; 50 PrefService* prefs_;
49 std::wstring per_host_zoom_levels_pref_; // For the observe matcher. 51 std::wstring per_host_zoom_levels_pref_; // For the observe matcher.
50 std::string host_name_; 52 GURL url_;
53 std::string host_;
51 NotificationObserverMock pref_observer_; 54 NotificationObserverMock pref_observer_;
52 }; 55 };
53 const int HostZoomMapTest::kZoomLevel = 42; 56 const int HostZoomMapTest::kZoomLevel = 42;
54 57
55 TEST_F(HostZoomMapTest, LoadNoPrefs) { 58 TEST_F(HostZoomMapTest, LoadNoPrefs) {
56 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_)); 59 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
57 EXPECT_EQ(0, map->GetZoomLevel(host_name_)); 60 EXPECT_EQ(0, map->GetZoomLevel(url_));
58 } 61 }
59 62
60 TEST_F(HostZoomMapTest, Load) { 63 TEST_F(HostZoomMapTest, Load) {
61 DictionaryValue* dict = 64 DictionaryValue* dict =
62 prefs_->GetMutableDictionary(prefs::kPerHostZoomLevels); 65 prefs_->GetMutableDictionary(prefs::kPerHostZoomLevels);
63 dict->SetWithoutPathExpansion(UTF8ToWide(host_name_), 66 dict->SetWithoutPathExpansion(UTF8ToWide(host_),
64 Value::CreateIntegerValue(kZoomLevel)); 67 Value::CreateIntegerValue(kZoomLevel));
65 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_)); 68 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
66 EXPECT_EQ(kZoomLevel, map->GetZoomLevel(host_name_)); 69 EXPECT_EQ(kZoomLevel, map->GetZoomLevel(url_));
67 } 70 }
68 71
69 TEST_F(HostZoomMapTest, SetZoomLevel) { 72 TEST_F(HostZoomMapTest, SetZoomLevel) {
70 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_)); 73 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
71 prefs_->AddPrefObserver(prefs::kPerHostZoomLevels, &pref_observer_); 74 prefs_->AddPrefObserver(prefs::kPerHostZoomLevels, &pref_observer_);
72 SetPrefObserverExpectation(); 75 SetPrefObserverExpectation();
73 map->SetZoomLevel(host_name_, kZoomLevel); 76 map->SetZoomLevel(url_, kZoomLevel);
74 EXPECT_EQ(kZoomLevel, map->GetZoomLevel(host_name_)); 77 EXPECT_EQ(kZoomLevel, map->GetZoomLevel(url_));
75 const DictionaryValue* dict = 78 const DictionaryValue* dict =
76 prefs_->GetDictionary(prefs::kPerHostZoomLevels); 79 prefs_->GetDictionary(prefs::kPerHostZoomLevels);
77 int zoom_level = 0; 80 int zoom_level = 0;
78 EXPECT_TRUE(dict->GetIntegerWithoutPathExpansion(UTF8ToWide(host_name_), 81 EXPECT_TRUE(dict->GetIntegerWithoutPathExpansion(UTF8ToWide(host_),
79 &zoom_level)); 82 &zoom_level));
80 EXPECT_EQ(kZoomLevel, zoom_level); 83 EXPECT_EQ(kZoomLevel, zoom_level);
81 84
82 SetPrefObserverExpectation(); 85 SetPrefObserverExpectation();
83 map->SetZoomLevel(host_name_, 0); 86 map->SetZoomLevel(url_, 0);
84 EXPECT_EQ(0, map->GetZoomLevel(host_name_)); 87 EXPECT_EQ(0, map->GetZoomLevel(url_));
85 EXPECT_FALSE(dict->HasKey(UTF8ToWide(host_name_))); 88 EXPECT_FALSE(dict->HasKey(UTF8ToWide(host_)));
86 prefs_->RemovePrefObserver(prefs::kPerHostZoomLevels, &pref_observer_); 89 prefs_->RemovePrefObserver(prefs::kPerHostZoomLevels, &pref_observer_);
87 } 90 }
88 91
89 TEST_F(HostZoomMapTest, ResetToDefaults) { 92 TEST_F(HostZoomMapTest, ResetToDefaults) {
90 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_)); 93 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
91 map->SetZoomLevel(host_name_, kZoomLevel); 94 map->SetZoomLevel(url_, kZoomLevel);
92 95
93 prefs_->AddPrefObserver(prefs::kPerHostZoomLevels, &pref_observer_); 96 prefs_->AddPrefObserver(prefs::kPerHostZoomLevels, &pref_observer_);
94 SetPrefObserverExpectation(); 97 SetPrefObserverExpectation();
95 map->ResetToDefaults(); 98 map->ResetToDefaults();
96 EXPECT_EQ(0, map->GetZoomLevel(host_name_)); 99 EXPECT_EQ(0, map->GetZoomLevel(url_));
97 EXPECT_EQ(NULL, prefs_->GetDictionary(prefs::kPerHostZoomLevels)); 100 EXPECT_EQ(NULL, prefs_->GetDictionary(prefs::kPerHostZoomLevels));
98 prefs_->RemovePrefObserver(prefs::kPerHostZoomLevels, &pref_observer_); 101 prefs_->RemovePrefObserver(prefs::kPerHostZoomLevels, &pref_observer_);
99 } 102 }
100 103
101 TEST_F(HostZoomMapTest, ReloadOnPrefChange) { 104 TEST_F(HostZoomMapTest, ReloadOnPrefChange) {
102 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_)); 105 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
103 map->SetZoomLevel(host_name_, kZoomLevel); 106 map->SetZoomLevel(url_, kZoomLevel);
104 107
105 DictionaryValue dict; 108 DictionaryValue dict;
106 dict.SetWithoutPathExpansion(UTF8ToWide(host_name_), 109 dict.SetWithoutPathExpansion(UTF8ToWide(host_),
107 Value::CreateIntegerValue(0)); 110 Value::CreateIntegerValue(0));
108 prefs_->Set(prefs::kPerHostZoomLevels, dict); 111 prefs_->Set(prefs::kPerHostZoomLevels, dict);
109 EXPECT_EQ(0, map->GetZoomLevel(host_name_)); 112 EXPECT_EQ(0, map->GetZoomLevel(url_));
110 } 113 }
114
115 TEST_F(HostZoomMapTest, NoHost) {
116 scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
117 GURL file_url1_("file:///tmp/test.html");
118 GURL file_url2_("file:///tmp/other.html");
119 map->SetZoomLevel(file_url1_, kZoomLevel);
120
121 EXPECT_EQ(kZoomLevel, map->GetZoomLevel(file_url1_));
122 EXPECT_EQ(0, map->GetZoomLevel(file_url2_));
123 }
OLDNEW
« no previous file with comments | « chrome/browser/host_zoom_map.cc ('k') | chrome/browser/renderer_host/async_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698