OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/public/browser/host_zoom_map.h" | 5 #include "content/public/browser/host_zoom_map.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
35 #include "url/gurl.h" | 35 #include "url/gurl.h" |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 class ZoomLevelChangeObserver { | 39 class ZoomLevelChangeObserver { |
40 public: | 40 public: |
41 explicit ZoomLevelChangeObserver(Profile* profile) | 41 explicit ZoomLevelChangeObserver(Profile* profile) |
42 : message_loop_runner_(new content::MessageLoopRunner) { | 42 : message_loop_runner_(new content::MessageLoopRunner) { |
43 content::HostZoomMap* host_zoom_map = static_cast<content::HostZoomMap*>( | 43 content::HostZoomMap* host_zoom_map = static_cast<content::HostZoomMap*>( |
44 content::HostZoomMap::GetForBrowserContext(profile)); | 44 content::HostZoomMap::GetDefaultForBrowserContext(profile)); |
45 subscription_ = host_zoom_map->AddZoomLevelChangedCallback(base::Bind( | 45 subscription_ = host_zoom_map->AddZoomLevelChangedCallback(base::Bind( |
46 &ZoomLevelChangeObserver::OnZoomLevelChanged, base::Unretained(this))); | 46 &ZoomLevelChangeObserver::OnZoomLevelChanged, base::Unretained(this))); |
47 } | 47 } |
48 | 48 |
49 void BlockUntilZoomLevelForHostHasChanged(const std::string& host) { | 49 void BlockUntilZoomLevelForHostHasChanged(const std::string& host) { |
50 while (!std::count(changed_hosts_.begin(), changed_hosts_.end(), host)) { | 50 while (!std::count(changed_hosts_.begin(), changed_hosts_.end(), host)) { |
51 message_loop_runner_->Run(); | 51 message_loop_runner_->Run(); |
52 message_loop_runner_ = new content::MessageLoopRunner; | 52 message_loop_runner_ = new content::MessageLoopRunner; |
53 } | 53 } |
54 changed_hosts_.clear(); | 54 changed_hosts_.clear(); |
(...skipping 19 matching lines...) Expand all Loading... |
74 HostZoomMapBrowserTest() {} | 74 HostZoomMapBrowserTest() {} |
75 | 75 |
76 protected: | 76 protected: |
77 void SetDefaultZoomLevel(double level) { | 77 void SetDefaultZoomLevel(double level) { |
78 browser()->profile()->GetPrefs()->SetDouble( | 78 browser()->profile()->GetPrefs()->SetDouble( |
79 prefs::kDefaultZoomLevel, level); | 79 prefs::kDefaultZoomLevel, level); |
80 } | 80 } |
81 | 81 |
82 double GetZoomLevel(const GURL& url) { | 82 double GetZoomLevel(const GURL& url) { |
83 content::HostZoomMap* host_zoom_map = static_cast<content::HostZoomMap*>( | 83 content::HostZoomMap* host_zoom_map = static_cast<content::HostZoomMap*>( |
84 content::HostZoomMap::GetForBrowserContext(browser()->profile())); | 84 content::HostZoomMap::GetDefaultForBrowserContext( |
| 85 browser()->profile())); |
85 return host_zoom_map->GetZoomLevelForHostAndScheme(url.scheme(), | 86 return host_zoom_map->GetZoomLevelForHostAndScheme(url.scheme(), |
86 url.host()); | 87 url.host()); |
87 } | 88 } |
88 | 89 |
89 std::vector<std::string> GetHostsWithZoomLevels() { | 90 std::vector<std::string> GetHostsWithZoomLevels() { |
90 typedef content::HostZoomMap::ZoomLevelVector ZoomLevelVector; | 91 typedef content::HostZoomMap::ZoomLevelVector ZoomLevelVector; |
91 content::HostZoomMap* host_zoom_map = static_cast<content::HostZoomMap*>( | 92 content::HostZoomMap* host_zoom_map = static_cast<content::HostZoomMap*>( |
92 content::HostZoomMap::GetForBrowserContext(browser()->profile())); | 93 content::HostZoomMap::GetDefaultForBrowserContext( |
| 94 browser()->profile())); |
93 content::HostZoomMap::ZoomLevelVector zoom_levels = | 95 content::HostZoomMap::ZoomLevelVector zoom_levels = |
94 host_zoom_map->GetAllZoomLevels(); | 96 host_zoom_map->GetAllZoomLevels(); |
95 std::vector<std::string> results; | 97 std::vector<std::string> results; |
96 for (ZoomLevelVector::const_iterator it = zoom_levels.begin(); | 98 for (ZoomLevelVector::const_iterator it = zoom_levels.begin(); |
97 it != zoom_levels.end(); ++it) | 99 it != zoom_levels.end(); ++it) |
98 results.push_back(it->host); | 100 results.push_back(it->host); |
99 return results; | 101 return results; |
100 } | 102 } |
101 | 103 |
102 std::vector<std::string> GetHostsWithZoomLevelsFromPrefs() { | 104 std::vector<std::string> GetHostsWithZoomLevelsFromPrefs() { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 // any per-host values saved either to Pref, or internally in HostZoomMap. | 209 // any per-host values saved either to Pref, or internally in HostZoomMap. |
208 EXPECT_TRUE(GetHostsWithZoomLevels().empty()); | 210 EXPECT_TRUE(GetHostsWithZoomLevels().empty()); |
209 EXPECT_TRUE(GetHostsWithZoomLevelsFromPrefs().empty()); | 211 EXPECT_TRUE(GetHostsWithZoomLevelsFromPrefs().empty()); |
210 } | 212 } |
211 | 213 |
212 // Test that garbage data from crbug.com/364399 is cleared up on startup. | 214 // Test that garbage data from crbug.com/364399 is cleared up on startup. |
213 IN_PROC_BROWSER_TEST_F(HostZoomMapSanitizationBrowserTest, ClearOnStartup) { | 215 IN_PROC_BROWSER_TEST_F(HostZoomMapSanitizationBrowserTest, ClearOnStartup) { |
214 EXPECT_THAT(GetHostsWithZoomLevels(), testing::ElementsAre("host2")); | 216 EXPECT_THAT(GetHostsWithZoomLevels(), testing::ElementsAre("host2")); |
215 EXPECT_THAT(GetHostsWithZoomLevelsFromPrefs(), testing::ElementsAre("host2")); | 217 EXPECT_THAT(GetHostsWithZoomLevelsFromPrefs(), testing::ElementsAre("host2")); |
216 } | 218 } |
OLD | NEW |