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 "chrome/browser/chromeos/display/display_preferences.h" | 5 #include "chrome/browser/chromeos/display/display_preferences.h" |
6 | 6 |
7 #include "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
8 #include "ash/display/display_layout_store.h" | 8 #include "ash/display/display_layout_store.h" |
9 #include "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
10 #include "ash/display/resolution_notification_controller.h" | 10 #include "ash/display/resolution_notification_controller.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 local_state()->GetDictionary(prefs::kDisplayProperties); | 224 local_state()->GetDictionary(prefs::kDisplayProperties); |
225 const base::DictionaryValue* property = NULL; | 225 const base::DictionaryValue* property = NULL; |
226 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); | 226 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); |
227 int ui_scale = 0; | 227 int ui_scale = 0; |
228 int rotation = 0; | 228 int rotation = 0; |
229 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); | 229 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); |
230 EXPECT_TRUE(property->GetInteger("ui-scale", &ui_scale)); | 230 EXPECT_TRUE(property->GetInteger("ui-scale", &ui_scale)); |
231 EXPECT_EQ(1, rotation); | 231 EXPECT_EQ(1, rotation); |
232 EXPECT_EQ(1250, ui_scale); | 232 EXPECT_EQ(1250, ui_scale); |
233 | 233 |
234 // Internal display never registere the resolution. | 234 // Internal display never registered the resolution. |
235 int width = 0, height = 0; | 235 int width = 0, height = 0; |
236 float refresh_rate = 0.0f; | |
236 EXPECT_FALSE(property->GetInteger("width", &width)); | 237 EXPECT_FALSE(property->GetInteger("width", &width)); |
237 EXPECT_FALSE(property->GetInteger("height", &height)); | 238 EXPECT_FALSE(property->GetInteger("height", &height)); |
238 | 239 |
239 int top = 0, left = 0, bottom = 0, right = 0; | 240 int top = 0, left = 0, bottom = 0, right = 0; |
240 EXPECT_TRUE(property->GetInteger("insets_top", &top)); | 241 EXPECT_TRUE(property->GetInteger("insets_top", &top)); |
241 EXPECT_TRUE(property->GetInteger("insets_left", &left)); | 242 EXPECT_TRUE(property->GetInteger("insets_left", &left)); |
242 EXPECT_TRUE(property->GetInteger("insets_bottom", &bottom)); | 243 EXPECT_TRUE(property->GetInteger("insets_bottom", &bottom)); |
243 EXPECT_TRUE(property->GetInteger("insets_right", &right)); | 244 EXPECT_TRUE(property->GetInteger("insets_right", &right)); |
244 EXPECT_EQ(10, top); | 245 EXPECT_EQ(10, top); |
245 EXPECT_EQ(11, left); | 246 EXPECT_EQ(11, left); |
(...skipping 18 matching lines...) Expand all Loading... | |
264 EXPECT_FALSE(property->GetInteger("width", &width)); | 265 EXPECT_FALSE(property->GetInteger("width", &width)); |
265 EXPECT_FALSE(property->GetInteger("height", &height)); | 266 EXPECT_FALSE(property->GetInteger("height", &height)); |
266 | 267 |
267 display_manager->SetDisplayResolution(id2, gfx::Size(300, 200)); | 268 display_manager->SetDisplayResolution(id2, gfx::Size(300, 200)); |
268 | 269 |
269 display_controller->SetPrimaryDisplayId(id2); | 270 display_controller->SetPrimaryDisplayId(id2); |
270 | 271 |
271 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); | 272 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); |
272 width = 0; | 273 width = 0; |
273 height = 0; | 274 height = 0; |
274 // Internal dispaly shouldn't store its resolution. | 275 // Internal display shouldn't store its resolution. |
275 EXPECT_FALSE(property->GetInteger("width", &width)); | 276 EXPECT_FALSE(property->GetInteger("width", &width)); |
276 EXPECT_FALSE(property->GetInteger("height", &height)); | 277 EXPECT_FALSE(property->GetInteger("height", &height)); |
277 | 278 |
278 // External dispaly's resolution must be stored this time because | 279 // External display's resolution must be stored this time because |
279 // it's not best. | 280 // it's not best. |
280 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 281 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
281 EXPECT_TRUE(property->GetInteger("width", &width)); | 282 EXPECT_TRUE(property->GetInteger("width", &width)); |
282 EXPECT_TRUE(property->GetInteger("height", &height)); | 283 EXPECT_TRUE(property->GetInteger("height", &height)); |
283 EXPECT_EQ(300, width); | 284 EXPECT_EQ(300, width); |
284 EXPECT_EQ(200, height); | 285 EXPECT_EQ(200, height); |
285 | 286 |
286 // The layout remains the same. | 287 // The layout remains the same. |
287 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 288 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
288 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*layout_value, | 289 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*layout_value, |
(...skipping 24 matching lines...) Expand all Loading... | |
313 mirrored = false; | 314 mirrored = false; |
314 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); | 315 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
315 EXPECT_TRUE(mirrored); | 316 EXPECT_TRUE(mirrored); |
316 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); | 317 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
317 EXPECT_EQ(base::Int64ToString(id2), primary_id_str); | 318 EXPECT_EQ(base::Int64ToString(id2), primary_id_str); |
318 | 319 |
319 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); | 320 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); |
320 EXPECT_FALSE(property->GetInteger("width", &width)); | 321 EXPECT_FALSE(property->GetInteger("width", &width)); |
321 EXPECT_FALSE(property->GetInteger("height", &height)); | 322 EXPECT_FALSE(property->GetInteger("height", &height)); |
322 | 323 |
323 // External dispaly's selected resolution must not change | 324 // External display's selected resolution must not change |
324 // by mirroring. | 325 // by mirroring. |
325 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 326 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
326 EXPECT_TRUE(property->GetInteger("width", &width)); | 327 EXPECT_TRUE(property->GetInteger("width", &width)); |
327 EXPECT_TRUE(property->GetInteger("height", &height)); | 328 EXPECT_TRUE(property->GetInteger("height", &height)); |
328 EXPECT_EQ(300, width); | 329 EXPECT_EQ(300, width); |
329 EXPECT_EQ(200, height); | 330 EXPECT_EQ(200, height); |
330 | 331 |
331 // Set new display's selected resolution. | 332 // Set new display's selected resolution. |
332 display_manager->RegisterDisplayProperty(id2 + 1, | 333 display_manager->RegisterDisplayProperty( |
333 gfx::Display::ROTATE_0, | 334 id2 + 1, gfx::Display::ROTATE_0, 1.0f, NULL, gfx::Size(500, 400)); |
334 1.0f, | |
335 NULL, | |
336 gfx::Size(500, 400)); | |
337 | 335 |
338 UpdateDisplay("200x200*2, 600x500#600x500|500x400"); | 336 UpdateDisplay("200x200*2, 600x500#600x500|500x400"); |
339 | 337 |
340 // Update key as the 2nd display gets new id. | 338 // Update key as the 2nd display gets new id. |
341 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 339 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
342 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 340 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
343 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 341 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
344 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); | 342 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); |
345 EXPECT_EQ("right", position); | 343 EXPECT_EQ("right", position); |
346 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); | 344 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); |
347 EXPECT_EQ(0, offset); | 345 EXPECT_EQ(0, offset); |
348 mirrored = true; | 346 mirrored = true; |
349 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); | 347 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
350 EXPECT_FALSE(mirrored); | 348 EXPECT_FALSE(mirrored); |
351 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); | 349 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
352 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); | 350 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); |
353 | 351 |
354 // Best resolution should not be saved. | 352 // Best resolution should not be saved. |
355 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 353 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
356 EXPECT_FALSE(property->GetInteger("width", &width)); | 354 EXPECT_FALSE(property->GetInteger("width", &width)); |
357 EXPECT_FALSE(property->GetInteger("height", &height)); | 355 EXPECT_FALSE(property->GetInteger("height", &height)); |
358 | 356 |
359 // Set yet another new display's selected resolution. | 357 // Set yet another new display's selected resolution. |
360 display_manager->RegisterDisplayProperty(id2 + 1, | 358 display_manager->RegisterDisplayProperty( |
361 gfx::Display::ROTATE_0, | 359 id2 + 1, gfx::Display::ROTATE_0, 1.0f, NULL, gfx::Size(500, 400)); |
362 1.0f, | |
363 NULL, | |
364 gfx::Size(500, 400)); | |
365 // Disconnect 2nd display first to generate new id for external display. | 360 // Disconnect 2nd display first to generate new id for external display. |
366 UpdateDisplay("200x200*2"); | 361 UpdateDisplay("200x200*2"); |
367 UpdateDisplay("200x200*2, 500x400#600x500|500x400"); | 362 UpdateDisplay("200x200*2, 500x400#600x500|500x400%60.0f"); |
368 // Update key as the 2nd display gets new id. | 363 // Update key as the 2nd display gets new id. |
369 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 364 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
370 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 365 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
371 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 366 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
372 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); | 367 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); |
373 EXPECT_EQ("right", position); | 368 EXPECT_EQ("right", position); |
374 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); | 369 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); |
375 EXPECT_EQ(0, offset); | 370 EXPECT_EQ(0, offset); |
376 mirrored = true; | 371 mirrored = true; |
377 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); | 372 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
378 EXPECT_FALSE(mirrored); | 373 EXPECT_FALSE(mirrored); |
379 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); | 374 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
380 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); | 375 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); |
381 | 376 |
382 // External dispaly's selected resolution must be updated. | 377 // External display's selected resolution must be updated. |
383 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 378 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
384 EXPECT_TRUE(property->GetInteger("width", &width)); | 379 EXPECT_TRUE(property->GetInteger("width", &width)); |
385 EXPECT_TRUE(property->GetInteger("height", &height)); | 380 EXPECT_TRUE(property->GetInteger("height", &height)); |
381 EXPECT_TRUE(property->GetFloat("refresh-rate", &refresh_rate); | |
oshima
2014/01/29 19:00:35
you don't need this right?
sheu
2014/01/29 22:43:36
Done.
| |
386 EXPECT_EQ(500, width); | 382 EXPECT_EQ(500, width); |
387 EXPECT_EQ(400, height); | 383 EXPECT_EQ(400, height); |
384 // Refresh rate should use value reported by the display. | |
385 EXPECT_EQ(60.0f, refresh_rate); | |
388 } | 386 } |
389 | 387 |
390 TEST_F(DisplayPreferencesTest, PreventStore) { | 388 TEST_F(DisplayPreferencesTest, PreventStore) { |
391 ResolutionNotificationController::SuppressTimerForTest(); | 389 ResolutionNotificationController::SuppressTimerForTest(); |
392 LoggedInAsUser(); | 390 LoggedInAsUser(); |
393 UpdateDisplay("400x300#500x400|400x300|300x200"); | 391 UpdateDisplay("400x300#500x400|400x300|300x200"); |
394 int64 id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); | 392 int64 id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); |
395 // Set display's resolution in single display. It creates the notification and | 393 // Set display's resolution in single display. It creates the notification and |
396 // display preferences should not stored meanwhile. | 394 // display preferences should not stored meanwhile. |
397 ash::Shell::GetInstance()->resolution_notification_controller()-> | 395 ash::Shell::GetInstance()->resolution_notification_controller()-> |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 local_state()->GetString(prefs::kDisplayPowerState)); | 559 local_state()->GetString(prefs::kDisplayPowerState)); |
562 | 560 |
563 // Don't try to load | 561 // Don't try to load |
564 local_state()->SetString(prefs::kDisplayPowerState, "all_off"); | 562 local_state()->SetString(prefs::kDisplayPowerState, "all_off"); |
565 LoadDisplayPreferences(false); | 563 LoadDisplayPreferences(false); |
566 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, | 564 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
567 shell->output_configurator()->power_state()); | 565 shell->output_configurator()->power_state()); |
568 } | 566 } |
569 | 567 |
570 } // namespace chromeos | 568 } // namespace chromeos |
OLD | NEW |