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

Side by Side Diff: chrome/browser/chromeos/display/display_preferences_unittest.cc

Issue 22703004: Creates notifications for display resolution change. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_confirmation_dialog.h"
10 #include "ash/screen_ash.h" 11 #include "ash/screen_ash.h"
11 #include "ash/shell.h" 12 #include "ash/shell.h"
12 #include "ash/test/ash_test_base.h" 13 #include "ash/test/ash_test_base.h"
13 #include "base/prefs/testing_pref_service.h" 14 #include "base/prefs/testing_pref_service.h"
14 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "chrome/browser/chromeos/display/display_configuration_observer.h" 17 #include "chrome/browser/chromeos/display/display_configuration_observer.h"
17 #include "chrome/browser/chromeos/login/mock_user_manager.h" 18 #include "chrome/browser/chromeos/login/mock_user_manager.h"
18 #include "chrome/browser/chromeos/login/user_manager.h" 19 #include "chrome/browser/chromeos/login/user_manager.h"
19 #include "chrome/browser/prefs/scoped_user_pref_update.h" 20 #include "chrome/browser/prefs/scoped_user_pref_update.h"
(...skipping 13 matching lines...) Expand all
33 DisplayPreferencesTest() : ash::test::AshTestBase(), 34 DisplayPreferencesTest() : ash::test::AshTestBase(),
34 mock_user_manager_(new MockUserManager), 35 mock_user_manager_(new MockUserManager),
35 user_manager_enabler_(mock_user_manager_) { 36 user_manager_enabler_(mock_user_manager_) {
36 } 37 }
37 38
38 virtual ~DisplayPreferencesTest() {} 39 virtual ~DisplayPreferencesTest() {}
39 40
40 virtual void SetUp() OVERRIDE { 41 virtual void SetUp() OVERRIDE {
41 EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn()) 42 EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn())
42 .WillRepeatedly(testing::Return(false)); 43 .WillRepeatedly(testing::Return(false));
44 EXPECT_CALL(*mock_user_manager_, Shutdown());
43 ash::test::AshTestBase::SetUp(); 45 ash::test::AshTestBase::SetUp();
44 RegisterDisplayLocalStatePrefs(local_state_.registry()); 46 RegisterDisplayLocalStatePrefs(local_state_.registry());
45 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); 47 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_);
46 observer_.reset(new DisplayConfigurationObserver()); 48 observer_.reset(new DisplayConfigurationObserver());
47 } 49 }
48 50
49 virtual void TearDown() OVERRIDE { 51 virtual void TearDown() OVERRIDE {
50 observer_.reset(); 52 observer_.reset();
51 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); 53 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL);
52 ash::test::AshTestBase::TearDown(); 54 ash::test::AshTestBase::TearDown();
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); 347 EXPECT_EQ(base::Int64ToString(id1), primary_id_str);
346 348
347 // External dispaly's selected resolution must be updated. 349 // External dispaly's selected resolution must be updated.
348 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); 350 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property));
349 EXPECT_TRUE(property->GetInteger("width", &width)); 351 EXPECT_TRUE(property->GetInteger("width", &width));
350 EXPECT_TRUE(property->GetInteger("height", &height)); 352 EXPECT_TRUE(property->GetInteger("height", &height));
351 EXPECT_EQ(500, width); 353 EXPECT_EQ(500, width);
352 EXPECT_EQ(400, height); 354 EXPECT_EQ(400, height);
353 } 355 }
354 356
357 TEST_F(DisplayPreferencesTest, PreventStore) {
358 LoggedInAsUser();
359 UpdateDisplay("200x200*2,400x300");
360 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id();
361 ash::internal::ResolutionConfirmationDialog::SetDisplayResolutionAndConfirm(
362 id2, gfx::Size(400, 300), gfx::Size(500, 400), base::Closure());
363 UpdateDisplay("200x200*2,500x400");
364
365 // SetDisplayResolutionAndConfirm invokes DisplayManager::SetDisplayResolution
366 // implicitly but doesn't store the preferences.
367
368 const base::DictionaryValue* properties =
369 local_state()->GetDictionary(prefs::kDisplayProperties);
370 const base::DictionaryValue* property = NULL;
371 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property));
372 int width = 0, height = 0;
373 EXPECT_FALSE(property->GetInteger("width", &width));
374 EXPECT_FALSE(property->GetInteger("height", &height));
375
376 // Close the dialog.
377 ash::internal::ResolutionConfirmationDialog* dialog =
378 ash::internal::ResolutionConfirmationDialog::GetCurrentDialog();
379 dialog->GetWidget()->Close();
380 RunAllPendingInMessageLoop();
381 EXPECT_FALSE(ash::internal::ResolutionConfirmationDialog::GetCurrentDialog());
382
383 // Once the dialog is closed, the specified resolution will be stored by
384 // SetDisplayResolution.
385 ash::Shell::GetInstance()->display_manager()->SetDisplayResolution(
386 id2, gfx::Size(300, 200));
387 UpdateDisplay("200x200*2,300x300");
388
389 property = NULL;
390 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property));
391 EXPECT_TRUE(property->GetInteger("width", &width));
392 EXPECT_TRUE(property->GetInteger("height", &height));
393 EXPECT_EQ(300, width);
394 EXPECT_EQ(200, height);
395 }
396
355 TEST_F(DisplayPreferencesTest, StoreForSwappedDisplay) { 397 TEST_F(DisplayPreferencesTest, StoreForSwappedDisplay) {
356 UpdateDisplay("100x100,200x200"); 398 UpdateDisplay("100x100,200x200");
357 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); 399 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id();
358 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); 400 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id();
359 401
360 ash::DisplayController* display_controller = 402 ash::DisplayController* display_controller =
361 ash::Shell::GetInstance()->display_controller(); 403 ash::Shell::GetInstance()->display_controller();
362 display_controller->SwapPrimaryDisplay(); 404 display_controller->SwapPrimaryDisplay();
363 ASSERT_EQ(id1, ash::ScreenAsh::GetSecondaryDisplay().id()); 405 ASSERT_EQ(id1, ash::ScreenAsh::GetSecondaryDisplay().id());
364 406
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 StoreDisplayPowerStateForTest( 482 StoreDisplayPowerStateForTest(
441 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); 483 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON);
442 LoadDisplayPreferences(false); 484 LoadDisplayPreferences(false);
443 EXPECT_EQ( 485 EXPECT_EQ(
444 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, 486 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON,
445 ash::Shell::GetInstance()->output_configurator()->power_state()); 487 ash::Shell::GetInstance()->output_configurator()->power_state());
446 } 488 }
447 489
448 } // namespace 490 } // namespace
449 } // namespace chromeos 491 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698