OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 class PreferenceServiceTest : public InProcessBrowserTest { | 59 class PreferenceServiceTest : public InProcessBrowserTest { |
60 public: | 60 public: |
61 explicit PreferenceServiceTest(bool new_profile) : new_profile_(new_profile) { | 61 explicit PreferenceServiceTest(bool new_profile) : new_profile_(new_profile) { |
62 } | 62 } |
63 | 63 |
64 virtual bool SetUpUserDataDirectory() OVERRIDE { | 64 virtual bool SetUpUserDataDirectory() OVERRIDE { |
65 base::FilePath user_data_directory; | 65 base::FilePath user_data_directory; |
66 PathService::Get(chrome::DIR_USER_DATA, &user_data_directory); | 66 PathService::Get(chrome::DIR_USER_DATA, &user_data_directory); |
67 | 67 |
68 base::FilePath reference_pref_file; | |
69 if (new_profile_) { | 68 if (new_profile_) { |
70 reference_pref_file = ui_test_utils::GetTestFilePath( | 69 original_pref_file_ = ui_test_utils::GetTestFilePath( |
71 base::FilePath().AppendASCII("profiles"). | 70 base::FilePath().AppendASCII("profiles"). |
72 AppendASCII("window_placement"). | 71 AppendASCII("window_placement"). |
73 AppendASCII("Default"), | 72 AppendASCII("Default"), |
74 base::FilePath().Append(chrome::kPreferencesFilename)); | 73 base::FilePath().Append(chrome::kPreferencesFilename)); |
75 tmp_pref_file_ = | 74 tmp_pref_file_ = |
76 user_data_directory.AppendASCII(TestingProfile::kTestUserProfileDir); | 75 user_data_directory.AppendASCII(TestingProfile::kTestUserProfileDir); |
77 CHECK(base::CreateDirectory(tmp_pref_file_)); | 76 CHECK(base::CreateDirectory(tmp_pref_file_)); |
78 tmp_pref_file_ = tmp_pref_file_.Append(chrome::kPreferencesFilename); | 77 tmp_pref_file_ = tmp_pref_file_.Append(chrome::kPreferencesFilename); |
79 } else { | 78 } else { |
80 reference_pref_file = ui_test_utils::GetTestFilePath( | 79 original_pref_file_ = ui_test_utils::GetTestFilePath( |
81 base::FilePath().AppendASCII("profiles"). | 80 base::FilePath().AppendASCII("profiles"). |
82 AppendASCII("window_placement"), | 81 AppendASCII("window_placement"), |
83 base::FilePath().Append(chrome::kLocalStateFilename)); | 82 base::FilePath().Append(chrome::kLocalStateFilename)); |
84 tmp_pref_file_ = user_data_directory.Append(chrome::kLocalStateFilename); | 83 tmp_pref_file_ = user_data_directory.Append(chrome::kLocalStateFilename); |
85 } | 84 } |
86 | 85 |
87 CHECK(base::PathExists(reference_pref_file)); | 86 CHECK(base::PathExists(original_pref_file_)); |
88 // Copy only the Preferences file if |new_profile_|, or Local State if not, | 87 // Copy only the Preferences file if |new_profile_|, or Local State if not, |
89 // and the rest will be automatically created. | 88 // and the rest will be automatically created. |
90 CHECK(base::CopyFile(reference_pref_file, tmp_pref_file_)); | 89 CHECK(base::CopyFile(original_pref_file_, tmp_pref_file_)); |
91 | 90 |
92 #if defined(OS_WIN) | 91 #if defined(OS_WIN) |
93 // Make the copy writable. On POSIX we assume the umask allows files | 92 // Make the copy writable. On POSIX we assume the umask allows files |
94 // we create to be writable. | 93 // we create to be writable. |
95 CHECK(::SetFileAttributesW(tmp_pref_file_.value().c_str(), | 94 CHECK(::SetFileAttributesW(tmp_pref_file_.value().c_str(), |
96 FILE_ATTRIBUTE_NORMAL)); | 95 FILE_ATTRIBUTE_NORMAL)); |
97 #endif | 96 #endif |
98 return true; | 97 return true; |
99 } | 98 } |
100 | 99 |
101 protected: | 100 protected: |
| 101 base::FilePath original_pref_file_; |
102 base::FilePath tmp_pref_file_; | 102 base::FilePath tmp_pref_file_; |
103 | 103 |
104 private: | 104 private: |
105 bool new_profile_; | 105 bool new_profile_; |
106 }; | 106 }; |
107 | 107 |
108 #if defined(OS_WIN) || defined(OS_MACOSX) | 108 #if defined(OS_WIN) || defined(OS_MACOSX) |
109 // This test verifies that the window position from the prefs file is restored | 109 // This test verifies that the window position from the prefs file is restored |
110 // when the app restores. This doesn't really make sense on Linux, where | 110 // when the app restores. This doesn't really make sense on Linux, where |
111 // the window manager might fight with you over positioning. However, we | 111 // the window manager might fight with you over positioning. However, we |
112 // might be able to make this work on buildbots. | 112 // might be able to make this work on buildbots. |
113 // TODO(port): revisit this. | 113 // TODO(port): revisit this. |
114 | 114 |
115 class PreservedWindowPlacementIsLoaded : public PreferenceServiceTest { | 115 class PreservedWindowPlacementIsLoaded : public PreferenceServiceTest { |
116 public: | 116 public: |
117 PreservedWindowPlacementIsLoaded() : PreferenceServiceTest(true) { | 117 PreservedWindowPlacementIsLoaded() : PreferenceServiceTest(true) { |
118 } | 118 } |
119 }; | 119 }; |
120 | 120 |
121 IN_PROC_BROWSER_TEST_F(PreservedWindowPlacementIsLoaded, Test) { | 121 IN_PROC_BROWSER_TEST_F(PreservedWindowPlacementIsLoaded, Test) { |
122 #if defined(OS_WIN) && defined(USE_ASH) | 122 #if defined(OS_WIN) && defined(USE_ASH) |
123 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 123 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
124 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 124 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
125 return; | 125 return; |
126 #endif | 126 #endif |
127 | 127 |
128 // The window should open with the new reference profile, with window | 128 // The window should open with the new reference profile, with window |
129 // placement values stored in the user data directory. | 129 // placement values stored in the user data directory. |
130 JSONFileValueSerializer deserializer(tmp_pref_file_); | 130 JSONFileValueSerializer deserializer(original_pref_file_); |
131 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, NULL)); | 131 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, NULL)); |
132 | 132 |
133 ASSERT_TRUE(root.get()); | 133 ASSERT_TRUE(root.get()); |
134 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY)); | 134 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY)); |
135 | 135 |
136 base::DictionaryValue* root_dict = | 136 base::DictionaryValue* root_dict = |
137 static_cast<base::DictionaryValue*>(root.get()); | 137 static_cast<base::DictionaryValue*>(root.get()); |
138 | 138 |
139 // Retrieve the screen rect for the launched window | 139 // Retrieve the screen rect for the launched window |
140 gfx::Rect bounds = browser()->window()->GetRestoredBounds(); | 140 gfx::Rect bounds = browser()->window()->GetRestoredBounds(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 IN_PROC_BROWSER_TEST_F(PreservedWindowPlacementIsMigrated, Test) { | 181 IN_PROC_BROWSER_TEST_F(PreservedWindowPlacementIsMigrated, Test) { |
182 #if defined(OS_WIN) && defined(USE_ASH) | 182 #if defined(OS_WIN) && defined(USE_ASH) |
183 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 183 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
184 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 184 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
185 return; | 185 return; |
186 #endif | 186 #endif |
187 | 187 |
188 // The window should open with the old reference profile, with window | 188 // The window should open with the old reference profile, with window |
189 // placement values stored in Local State. | 189 // placement values stored in Local State. |
190 | 190 |
191 JSONFileValueSerializer deserializer(tmp_pref_file_); | 191 JSONFileValueSerializer deserializer(original_pref_file_); |
192 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, NULL)); | 192 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, NULL)); |
193 | 193 |
194 ASSERT_TRUE(root.get()); | 194 ASSERT_TRUE(root.get()); |
195 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY)); | 195 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY)); |
196 | 196 |
197 // Retrieve the screen rect for the launched window | 197 // Retrieve the screen rect for the launched window |
198 gfx::Rect bounds = browser()->window()->GetRestoredBounds(); | 198 gfx::Rect bounds = browser()->window()->GetRestoredBounds(); |
199 | 199 |
200 // Values from old reference profile in Local State should have been | 200 // Values from old reference profile in Local State should have been |
201 // correctly migrated to the user's Preferences -- if so, the window | 201 // correctly migrated to the user's Preferences -- if so, the window |
(...skipping 25 matching lines...) Expand all Loading... |
227 EXPECT_EQ(right, bounds.x() + bounds.width()); | 227 EXPECT_EQ(right, bounds.x() + bounds.width()); |
228 | 228 |
229 // Find if launched window is maximized. | 229 // Find if launched window is maximized. |
230 bool is_window_maximized = browser()->window()->IsMaximized(); | 230 bool is_window_maximized = browser()->window()->IsMaximized(); |
231 bool is_maximized = false; | 231 bool is_maximized = false; |
232 EXPECT_TRUE(root_dict->GetBoolean(kBrowserWindowPlacement + ".maximized", | 232 EXPECT_TRUE(root_dict->GetBoolean(kBrowserWindowPlacement + ".maximized", |
233 &is_maximized)); | 233 &is_maximized)); |
234 EXPECT_EQ(is_maximized, is_window_maximized); | 234 EXPECT_EQ(is_maximized, is_window_maximized); |
235 } | 235 } |
236 #endif | 236 #endif |
OLD | NEW |