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

Unified Diff: chrome/browser/profiles/host_zoom_map_browsertest.cc

Issue 541103002: Introduce ChromeZoomLevelPref, make zoom level prefs independent of profile prefs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Convert to using only profile prefs. Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profiles/host_zoom_map_browsertest.cc
diff --git a/chrome/browser/profiles/host_zoom_map_browsertest.cc b/chrome/browser/profiles/host_zoom_map_browsertest.cc
index e14a579048bbc586f142f9d74482c5069cd71ffa..64cc3672bcb572659c7c99cb550225b4f3cdf00d 100644
--- a/chrome/browser/profiles/host_zoom_map_browsertest.cc
+++ b/chrome/browser/profiles/host_zoom_map_browsertest.cc
@@ -21,6 +21,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
@@ -75,8 +76,7 @@ class HostZoomMapBrowserTest : public InProcessBrowserTest {
protected:
void SetDefaultZoomLevel(double level) {
- browser()->profile()->GetPrefs()->SetDouble(
- prefs::kDefaultZoomLevel, level);
+ browser()->profile()->GetZoomLevelPrefs()->SetDefaultZoomLevel(level);
Bernhard Bauer 2014/10/01 15:09:14 If you want to, you could pull these changes out i
}
double GetZoomLevel(const GURL& url) {
@@ -103,8 +103,10 @@ class HostZoomMapBrowserTest : public InProcessBrowserTest {
std::vector<std::string> GetHostsWithZoomLevelsFromPrefs() {
PrefService* prefs = browser()->profile()->GetPrefs();
- const base::DictionaryValue* values =
+ const base::DictionaryValue* dictionaries =
prefs->GetDictionary(prefs::kPerHostZoomLevels);
+ const base::DictionaryValue* values = NULL;
+ dictionaries->GetDictionary("0", &values);
std::vector<std::string> results;
if (values) {
for (base::DictionaryValue::Iterator it(*values);
@@ -137,35 +139,53 @@ class HostZoomMapBrowserTest : public InProcessBrowserTest {
DISALLOW_COPY_AND_ASSIGN(HostZoomMapBrowserTest);
};
-class HostZoomMapSanitizationBrowserTest : public HostZoomMapBrowserTest {
+class HostZoomMapBrowserTestWithPrefs : public HostZoomMapBrowserTest {
public:
- HostZoomMapSanitizationBrowserTest() {}
+ HostZoomMapBrowserTestWithPrefs(const std::string& prefs_data,
+ const std::string& prefs_filename)
+ : prefs_data_(prefs_data), prefs_filename_(prefs_filename) {}
private:
// InProcessBrowserTest:
virtual bool SetUpUserDataDirectory() OVERRIDE {
- // Zoom-related preferences demonstrating the two problems that could be
- // caused by the bug. They incorrectly contain a per-host zoom level for the
- // empty host; and a value for 'host1' that only differs from the default by
- // epsilon. Neither should have been persisted.
- const char kBrokenPrefs[] =
- "{'profile': {"
- " 'default_zoom_level': 1.2,"
- " 'per_host_zoom_levels': {'': 1.1, 'host1': 1.20001, 'host2': 1.3}"
- "}}";
- std::string broken_prefs(kBrokenPrefs);
- std::replace(broken_prefs.begin(), broken_prefs.end(), '\'', '\"');
+ std::replace(prefs_data_.begin(), prefs_data_.end(), '\'', '\"');
base::FilePath user_data_directory, path_to_prefs;
PathService::Get(chrome::DIR_USER_DATA, &user_data_directory);
path_to_prefs = user_data_directory
.AppendASCII(TestingProfile::kTestUserProfileDir)
- .Append(chrome::kPreferencesFilename);
+ .Append(prefs_filename_);
base::CreateDirectory(path_to_prefs.DirName());
- base::WriteFile(path_to_prefs, broken_prefs.c_str(), broken_prefs.size());
+ base::WriteFile(
+ path_to_prefs, prefs_data_.c_str(), prefs_data_.size());
return true;
}
+ std::string prefs_data_;
+ std::string prefs_filename_;
+
+ DISALLOW_COPY_AND_ASSIGN(HostZoomMapBrowserTestWithPrefs);
+};
+
+class HostZoomMapSanitizationBrowserTest
+ : public HostZoomMapBrowserTestWithPrefs {
+ public:
+ HostZoomMapSanitizationBrowserTest()
+ : HostZoomMapBrowserTestWithPrefs(
+ // Zoom-related preferences demonstrating the two problems that
+ // could be caused by the bug. They incorrectly contain a per-host
+ // zoom level for the empty host; and a value for 'host1' that only
+ // differs from the default by epsilon. Neither should have been
+ // persisted.
+ "{'partition': {"
Bernhard Bauer 2014/10/01 15:09:14 Could you put this together with the comment into
wjmaclean 2014/10/01 20:32:59 Done.
+ " 'default_zoom_level': { '0': 1.2 },"
+ " 'per_host_zoom_levels': {"
+ " '0': { '': 1.1, 'host1': 1.20001, 'host2': 1.3 }"
+ " }"
+ "}}",
+ chrome::kPreferencesFilename) {}
+
+ private:
DISALLOW_COPY_AND_ASSIGN(HostZoomMapSanitizationBrowserTest);
};
@@ -216,3 +236,92 @@ IN_PROC_BROWSER_TEST_F(HostZoomMapSanitizationBrowserTest, ClearOnStartup) {
EXPECT_THAT(GetHostsWithZoomLevels(), testing::ElementsAre("host2"));
EXPECT_THAT(GetHostsWithZoomLevelsFromPrefs(), testing::ElementsAre("host2"));
}
+
+class HostZoomMapMigrationBrowserTest : public HostZoomMapBrowserTestWithPrefs {
+ public:
+ HostZoomMapMigrationBrowserTest()
+ : // In this case we migrate the zoom level data from the profile prefs.
+ HostZoomMapBrowserTestWithPrefs(
+ "{'profile': {"
+ " 'default_zoom_level': 1.2,"
+ " 'per_host_zoom_levels': {'': 1.1, 'host1': 1.20001, 'host2': "
+ "1.3}"
+ "}}",
+ chrome::kPreferencesFilename) {}
+
+ static const double kOriginalDefaultZoomLevel;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(HostZoomMapMigrationBrowserTest);
+};
+
+const double HostZoomMapMigrationBrowserTest::kOriginalDefaultZoomLevel = 1.2;
+
+// This test is the same as HostZoomMapSanitizationBrowserTest, except that the
+// zoom level data is loaded from the profile prefs, transfered to the
+// zoom-level prefs, and we verify that the profile zoom level prefs are
+// erased in the process. We also test that changes to the host zoom map and the
+// default zoom level don't propagate back to the profile prefs.
+IN_PROC_BROWSER_TEST_F(HostZoomMapMigrationBrowserTest,
+ MigrateProfileZoomPreferences) {
+ EXPECT_THAT(GetHostsWithZoomLevels(), testing::ElementsAre("host2"));
+ EXPECT_THAT(GetHostsWithZoomLevelsFromPrefs(), testing::ElementsAre("host2"));
+
+ PrefService* profile_prefs =
+ browser()->profile()->GetPrefs();
+ chrome::ChromeZoomLevelPrefs* zoom_level_prefs =
+ browser()->profile()->GetZoomLevelPrefs();
+ // Make sure that the profile pref for default zoom level has been set to
+ // its default value of 0.0.
+ EXPECT_EQ(0.0, profile_prefs->GetDouble(prefs::kProfileDefaultZoomLevel));
+ EXPECT_EQ(kOriginalDefaultZoomLevel,
+ profile_prefs->GetDouble(
+ zoom_level_prefs->GetDefaultZoomLevelPath().c_str()));
+
+ // Make sure that the profile prefs for per-host zoom levels are erased.
+ {
+ const base::DictionaryValue* profile_host_zoom_dictionary =
+ profile_prefs->GetDictionary(prefs::kProfilePerHostZoomLevels);
+ EXPECT_EQ(0UL, profile_host_zoom_dictionary->size());
+ }
+
+ ZoomLevelChangeObserver observer(browser()->profile());
+ content::HostZoomMap* host_zoom_map = static_cast<content::HostZoomMap*>(
+ content::HostZoomMap::GetDefaultForBrowserContext(
+ browser()->profile()));
+
+ // Make sure that a change to a host zoom level doesn't propagate to the
+ // profile prefs.
+ std::string host3("host3");
+ host_zoom_map->SetZoomLevelForHost(host3, 1.3);
+ observer.BlockUntilZoomLevelForHostHasChanged(host3);
+ EXPECT_THAT(GetHostsWithZoomLevelsFromPrefs(),
+ testing::ElementsAre("host2", host3));
+ {
+ const base::DictionaryValue* profile_host_zoom_dictionary =
+ profile_prefs->GetDictionary(prefs::kProfilePerHostZoomLevels);
+ EXPECT_EQ(0UL, profile_host_zoom_dictionary->size());
+ }
+
+ // Make sure a change to the default zoom level doesn't propagate to the
+ // profile prefs.
+
+ // First, we need a host at the default zoom level to respond when the
+ // default zoom level changes.
+ const double kNewDefaultZoomLevel = 1.5;
+ GURL test_url = ConstructTestServerURL("http://host4:%d/");
+ ui_test_utils::NavigateToURL(browser(), test_url);
+ EXPECT_TRUE(content::ZoomValuesEqual(kOriginalDefaultZoomLevel,
+ GetZoomLevel(test_url)));
+
+ // Change the default zoom level and observe.
+ zoom_level_prefs->SetDefaultZoomLevel(kNewDefaultZoomLevel);
+ observer.BlockUntilZoomLevelForHostHasChanged(test_url.host());
+ EXPECT_TRUE(
+ content::ZoomValuesEqual(kNewDefaultZoomLevel, GetZoomLevel(test_url)));
+ EXPECT_EQ(kNewDefaultZoomLevel,
+ profile_prefs->GetDouble(
+ zoom_level_prefs->GetDefaultZoomLevelPath().c_str()));
+ EXPECT_EQ(0.0, profile_prefs->GetDouble(prefs::kProfileDefaultZoomLevel));
+}
+

Powered by Google App Engine
This is Rietveld 408576698