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/files/file_util.h" | 8 #include "base/files/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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 return; | 45 return; |
46 #endif | 46 #endif |
47 | 47 |
48 gfx::Rect bounds = browser()->window()->GetBounds(); | 48 gfx::Rect bounds = browser()->window()->GetBounds(); |
49 gfx::Rect expected_bounds(gfx::Rect(20, 30, 400, 500)); | 49 gfx::Rect expected_bounds(gfx::Rect(20, 30, 400, 500)); |
50 ASSERT_EQ(expected_bounds.ToString(), bounds.ToString()); | 50 ASSERT_EQ(expected_bounds.ToString(), bounds.ToString()); |
51 } | 51 } |
52 | 52 |
53 class PreferenceServiceTest : public InProcessBrowserTest { | 53 class PreferenceServiceTest : public InProcessBrowserTest { |
54 public: | 54 public: |
55 explicit PreferenceServiceTest(bool new_profile) : new_profile_(new_profile) { | 55 explicit PreferenceServiceTest(bool new_profile) : new_profile_(new_profile) { |
gab
2015/03/02 17:21:18
Remove bool param (and member) here (now never use
rkaplow
2015/03/02 19:23:26
Done. Sorry I'm being a bit myopic with changes!
| |
56 } | 56 } |
57 | 57 |
58 bool SetUpUserDataDirectory() override { | 58 bool SetUpUserDataDirectory() override { |
59 base::FilePath user_data_directory; | 59 base::FilePath user_data_directory; |
60 PathService::Get(chrome::DIR_USER_DATA, &user_data_directory); | 60 PathService::Get(chrome::DIR_USER_DATA, &user_data_directory); |
61 | 61 |
62 if (new_profile_) { | 62 if (new_profile_) { |
63 original_pref_file_ = ui_test_utils::GetTestFilePath( | 63 original_pref_file_ = ui_test_utils::GetTestFilePath( |
64 base::FilePath().AppendASCII("profiles"). | 64 base::FilePath().AppendASCII("profiles"). |
65 AppendASCII("window_placement"). | 65 AppendASCII("window_placement"). |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 EXPECT_EQ(right, bounds.x() + bounds.width()); | 157 EXPECT_EQ(right, bounds.x() + bounds.width()); |
158 | 158 |
159 // Find if launched window is maximized. | 159 // Find if launched window is maximized. |
160 bool is_window_maximized = browser()->window()->IsMaximized(); | 160 bool is_window_maximized = browser()->window()->IsMaximized(); |
161 bool is_maximized = false; | 161 bool is_maximized = false; |
162 EXPECT_TRUE(root_dict->GetBoolean(kBrowserWindowPlacement + ".maximized", | 162 EXPECT_TRUE(root_dict->GetBoolean(kBrowserWindowPlacement + ".maximized", |
163 &is_maximized)); | 163 &is_maximized)); |
164 EXPECT_EQ(is_maximized, is_window_maximized); | 164 EXPECT_EQ(is_maximized, is_window_maximized); |
165 } | 165 } |
166 #endif | 166 #endif |
167 | |
168 #if defined(OS_WIN) || defined(OS_MACOSX) | |
169 | |
170 class PreservedWindowPlacementIsMigrated : public PreferenceServiceTest { | |
171 public: | |
172 PreservedWindowPlacementIsMigrated() : PreferenceServiceTest(false) { | |
173 } | |
174 }; | |
175 | |
176 IN_PROC_BROWSER_TEST_F(PreservedWindowPlacementIsMigrated, Test) { | |
177 #if defined(OS_WIN) && defined(USE_ASH) | |
178 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | |
179 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
180 switches::kAshBrowserTests)) | |
181 return; | |
182 #endif | |
183 | |
184 // The window should open with the old reference profile, with window | |
185 // placement values stored in Local State. | |
186 | |
187 JSONFileValueSerializer deserializer(original_pref_file_); | |
188 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, NULL)); | |
189 | |
190 ASSERT_TRUE(root.get()); | |
191 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY)); | |
192 | |
193 // Retrieve the screen rect for the launched window | |
194 gfx::Rect bounds = browser()->window()->GetRestoredBounds(); | |
195 | |
196 // Values from old reference profile in Local State should have been | |
197 // correctly migrated to the user's Preferences -- if so, the window | |
198 // should be set to values taken from the user's Local State. | |
199 base::DictionaryValue* root_dict = | |
200 static_cast<base::DictionaryValue*>(root.get()); | |
201 | |
202 // Retrieve the expected rect values from User Preferences, where they | |
203 // should have been migrated from Local State. | |
204 int bottom = 0; | |
205 std::string kBrowserWindowPlacement(prefs::kBrowserWindowPlacement); | |
206 EXPECT_TRUE(root_dict->GetInteger(kBrowserWindowPlacement + ".bottom", | |
207 &bottom)); | |
208 EXPECT_EQ(bottom, bounds.y() + bounds.height()); | |
209 | |
210 int top = 0; | |
211 EXPECT_TRUE(root_dict->GetInteger(kBrowserWindowPlacement + ".top", | |
212 &top)); | |
213 EXPECT_EQ(top, bounds.y()); | |
214 | |
215 int left = 0; | |
216 EXPECT_TRUE(root_dict->GetInteger(kBrowserWindowPlacement + ".left", | |
217 &left)); | |
218 EXPECT_EQ(left, bounds.x()); | |
219 | |
220 int right = 0; | |
221 EXPECT_TRUE(root_dict->GetInteger(kBrowserWindowPlacement + ".right", | |
222 &right)); | |
223 EXPECT_EQ(right, bounds.x() + bounds.width()); | |
224 | |
225 // Find if launched window is maximized. | |
226 bool is_window_maximized = browser()->window()->IsMaximized(); | |
227 bool is_maximized = false; | |
228 EXPECT_TRUE(root_dict->GetBoolean(kBrowserWindowPlacement + ".maximized", | |
229 &is_maximized)); | |
230 EXPECT_EQ(is_maximized, is_window_maximized); | |
231 } | |
232 #endif | |
OLD | NEW |