display_prefs_unittest.cc 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834
  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
  3. // found in the LICENSE file.
  4. #include "ash/display/display_prefs.h"
  5. #include <stdint.h>
  6. #include <memory>
  7. #include <string>
  8. #include <utility>
  9. #include <vector>
  10. #include "ash/constants/ash_pref_names.h"
  11. #include "ash/constants/ash_switches.h"
  12. #include "ash/display/display_configuration_observer.h"
  13. #include "ash/display/display_util.h"
  14. #include "ash/display/resolution_notification_controller.h"
  15. #include "ash/display/screen_orientation_controller.h"
  16. #include "ash/display/window_tree_host_manager.h"
  17. #include "ash/session/test_session_controller_client.h"
  18. #include "ash/shell.h"
  19. #include "ash/test/ash_test_base.h"
  20. #include "ash/test/ash_test_helper.h"
  21. #include "ash/wm/tablet_mode/tablet_mode_controller.h"
  22. #include "base/callback.h"
  23. #include "base/command_line.h"
  24. #include "base/memory/ptr_util.h"
  25. #include "base/numerics/math_constants.h"
  26. #include "base/strings/string_number_conversions.h"
  27. #include "base/strings/string_util.h"
  28. #include "base/test/scoped_feature_list.h"
  29. #include "base/values.h"
  30. #include "components/prefs/scoped_user_pref_update.h"
  31. #include "components/prefs/testing_pref_service.h"
  32. #include "components/user_manager/user_type.h"
  33. #include "testing/gmock/include/gmock/gmock.h"
  34. #include "testing/gtest/include/gtest/gtest.h"
  35. #include "ui/display/display_layout_builder.h"
  36. #include "ui/display/display_switches.h"
  37. #include "ui/display/manager/display_configurator.h"
  38. #include "ui/display/manager/display_layout_store.h"
  39. #include "ui/display/manager/display_manager.h"
  40. #include "ui/display/manager/display_manager_utilities.h"
  41. #include "ui/display/manager/json_converter.h"
  42. #include "ui/display/manager/managed_display_info.h"
  43. #include "ui/display/manager/test/touch_device_manager_test_api.h"
  44. #include "ui/display/screen.h"
  45. #include "ui/display/test/display_manager_test_api.h"
  46. #include "ui/display/util/display_util.h"
  47. #include "ui/events/devices/touchscreen_device.h"
  48. #include "ui/gfx/geometry/vector3d_f.h"
  49. namespace ash {
  50. using testing::DoubleEq;
  51. using testing::ElementsAre;
  52. using testing::Optional;
  53. namespace {
  54. const char kPrimaryIdKey[] = "primary-id";
  55. bool IsRotationLocked() {
  56. return ash::Shell::Get()->screen_orientation_controller()->rotation_locked();
  57. }
  58. bool CompareTouchAssociations(
  59. const display::TouchDeviceManager::TouchAssociationMap& map_1,
  60. const display::TouchDeviceManager::TouchAssociationMap& map_2) {
  61. if (map_1.size() != map_2.size())
  62. return false;
  63. // Each iterator instance |entry| is a pair of type
  64. // std::pair<display::TouchDeviceIdentifier,
  65. // display::TouchDeviceManager::AssociationInfoMap>
  66. for (const auto& entry : map_1) {
  67. if (!map_2.count(entry.first))
  68. return false;
  69. const auto& association_info_map_1 = entry.second;
  70. const auto& association_info_map_2 = map_2.at(entry.first);
  71. if (association_info_map_1.size() != association_info_map_2.size())
  72. return false;
  73. // Each iterator instance is a pair of type:
  74. // std::pair<int64_t, display::TouchDeviceManager::TouchAssociationInfo>
  75. for (const auto& info_1 : association_info_map_1) {
  76. if (!association_info_map_2.count(info_1.first))
  77. return false;
  78. const auto& info_2 = association_info_map_2.at(info_1.first);
  79. if (!(info_1.second.timestamp == info_2.timestamp &&
  80. info_1.second.calibration_data == info_2.calibration_data)) {
  81. return false;
  82. }
  83. }
  84. }
  85. return true;
  86. }
  87. bool ComparePortAssociations(
  88. const display::TouchDeviceManager::PortAssociationMap& map_1,
  89. const display::TouchDeviceManager::PortAssociationMap& map_2) {
  90. if (map_1.size() != map_2.size())
  91. return false;
  92. auto it_1 = map_1.begin();
  93. auto it_2 = map_2.begin();
  94. while (it_1 != map_1.end()) {
  95. if (it_1->first != it_2->first)
  96. return false;
  97. if (it_1->second != it_2->second)
  98. return false;
  99. it_1++;
  100. it_2++;
  101. }
  102. return true;
  103. }
  104. } // namespace
  105. class DisplayPrefsTest : public AshTestBase {
  106. public:
  107. DisplayPrefsTest(const DisplayPrefsTest&) = delete;
  108. DisplayPrefsTest& operator=(const DisplayPrefsTest&) = delete;
  109. protected:
  110. DisplayPrefsTest() = default;
  111. ~DisplayPrefsTest() override = default;
  112. void SetUp() override {
  113. AshTestBase::SetUp();
  114. observer_ = std::make_unique<DisplayConfigurationObserver>();
  115. observer_->OnDisplaysInitialized();
  116. }
  117. void TearDown() override {
  118. observer_.reset();
  119. AshTestBase::TearDown();
  120. }
  121. void LoggedInAsUser() { SimulateUserLogin("user1@test.com"); }
  122. void LoggedInAsGuest() { SimulateGuestLogin(); }
  123. void LoggedInAsPublicAccount() {
  124. SimulateUserLogin("pa@test.com", user_manager::USER_TYPE_PUBLIC_ACCOUNT);
  125. }
  126. void LoadDisplayPreferences() { display_prefs()->LoadDisplayPreferences(); }
  127. // Do not use the implementation of display_prefs.cc directly to avoid
  128. // notifying the update to the system.
  129. void StoreDisplayLayoutPrefForList(
  130. const display::DisplayIdList& list,
  131. display::DisplayPlacement::Position position,
  132. int offset,
  133. int64_t primary_id) {
  134. std::string name = display::DisplayIdListToString(list);
  135. DictionaryPrefUpdate update(local_state(), prefs::kSecondaryDisplays);
  136. display::DisplayLayout display_layout;
  137. display_layout.placement_list.emplace_back(position, offset);
  138. display_layout.primary_id = primary_id;
  139. DCHECK(!name.empty());
  140. base::Value::Dict& pref_data = update->GetDict();
  141. base::Value::Dict* layout_dict = pref_data.EnsureDict(name);
  142. display::DisplayLayoutToJson(display_layout, *layout_dict);
  143. }
  144. void StoreDisplayPropertyForList(const display::DisplayIdList& list,
  145. const std::string& key,
  146. base::Value value) {
  147. std::string name = display::DisplayIdListToString(list);
  148. DictionaryPrefUpdate update(local_state(), prefs::kSecondaryDisplays);
  149. base::Value::Dict& pref_data = update->GetDict();
  150. if (base::Value::Dict* existing_layout_value = pref_data.FindDict(name)) {
  151. existing_layout_value->Set(key, std::move(value));
  152. } else {
  153. base::Value::Dict layout_dict;
  154. layout_dict.Set(key, true);
  155. pref_data.SetByDottedPath(name, std::move(layout_dict));
  156. }
  157. }
  158. void StoreDisplayBoolPropertyForList(const display::DisplayIdList& list,
  159. const std::string& key,
  160. bool value) {
  161. StoreDisplayPropertyForList(list, key, base::Value(value));
  162. }
  163. void StoreDisplayLayoutPrefForList(const display::DisplayIdList& list,
  164. display::DisplayPlacement::Position layout,
  165. int offset) {
  166. StoreDisplayLayoutPrefForList(list, layout, offset, list[0]);
  167. }
  168. void StoreDisplayOverscan(int64_t id, const gfx::Insets& insets) {
  169. DictionaryPrefUpdate update(local_state(), prefs::kDisplayProperties);
  170. const std::string name = base::NumberToString(id);
  171. base::Value* pref_data = update.Get();
  172. base::Value insets_value(base::Value::Type::DICTIONARY);
  173. insets_value.SetIntKey("insets_top", insets.top());
  174. insets_value.SetIntKey("insets_left", insets.left());
  175. insets_value.SetIntKey("insets_bottom", insets.bottom());
  176. insets_value.SetIntKey("insets_right", insets.right());
  177. pref_data->SetKey(name, std::move(insets_value));
  178. }
  179. display::Display::Rotation GetRotation() {
  180. return Shell::Get()
  181. ->display_manager()
  182. ->GetDisplayInfo(display::Display::InternalDisplayId())
  183. .GetRotation(display::Display::RotationSource::ACCELEROMETER);
  184. }
  185. void StoreExternalDisplayMirrorInfo(
  186. const std::set<int64_t>& external_display_mirror_info) {
  187. ListPrefUpdate update(local_state(), prefs::kExternalDisplayMirrorInfo);
  188. base::Value* pref_data = update.Get();
  189. pref_data->ClearList();
  190. for (const auto& id : external_display_mirror_info)
  191. pref_data->Append(base::NumberToString(id));
  192. }
  193. std::string GetRegisteredDisplayPlacementStr(
  194. const display::DisplayIdList& list) {
  195. return Shell::Get()
  196. ->display_manager()
  197. ->layout_store()
  198. ->GetRegisteredDisplayLayout(list)
  199. .placement_list[0]
  200. .ToString();
  201. }
  202. const base::Value::Dict* ReadPropertiesForDisplay(int64_t display_id) {
  203. const base::Value::Dict& properties =
  204. local_state()->GetValueDict(prefs::kDisplayProperties);
  205. const base::Value::Dict* property =
  206. properties.FindDict(base::NumberToString(display_id));
  207. EXPECT_TRUE(property);
  208. return property;
  209. }
  210. void ExpectMixedMirrorModeParamsPrefs(
  211. int64_t source_id,
  212. const display::DisplayIdList& dest_ids) {
  213. std::vector<std::string> expected_dest_id_strs;
  214. for (const int64_t id : dest_ids) {
  215. expected_dest_id_strs.push_back(base::NumberToString(id));
  216. }
  217. SCOPED_TRACE(testing::Message()
  218. << "Expected to read kDisplayMixedMirrorModeParams with "
  219. "mirroring_source_id="
  220. << source_id << " and mirroring_destination_ids="
  221. << base::JoinString(expected_dest_id_strs, ","));
  222. const base::Value::Dict& prefs =
  223. local_state()->GetValueDict(prefs::kDisplayMixedMirrorModeParams);
  224. EXPECT_THAT(prefs.FindString("mirroring_source_id"),
  225. testing::Pointee(base::NumberToString(source_id)));
  226. const auto* mirror_ids = prefs.FindList("mirroring_destination_ids");
  227. ASSERT_TRUE(mirror_ids);
  228. display::DisplayIdList pref_dest_ids;
  229. for (const auto& value : *mirror_ids) {
  230. int64_t id;
  231. EXPECT_TRUE(base::StringToInt64(value.GetString(), &id));
  232. pref_dest_ids.push_back(id);
  233. }
  234. EXPECT_EQ(pref_dest_ids, dest_ids);
  235. }
  236. void ExpectExternalDisplayMirrorPrefs(const std::set<int64_t>& display_ids) {
  237. std::vector<std::string> expected_display_id_strs;
  238. for (const int64_t id : display_ids) {
  239. expected_display_id_strs.push_back(base::NumberToString(id));
  240. }
  241. SCOPED_TRACE(
  242. testing::Message()
  243. << "Expected to read kExternalDisplayMirrorInfo with list values="
  244. << base::JoinString(expected_display_id_strs, ","));
  245. const base::Value::List& prefs =
  246. local_state()->GetValueList(prefs::kExternalDisplayMirrorInfo);
  247. std::set<int64_t> read_ids;
  248. for (const auto& value : prefs) {
  249. int64_t id;
  250. EXPECT_TRUE(base::StringToInt64(value.GetString(), &id));
  251. read_ids.insert(id);
  252. }
  253. EXPECT_EQ(read_ids, display_ids);
  254. }
  255. display::DisplayConfigurator* display_configurator() {
  256. return Shell::Get()->display_configurator();
  257. }
  258. DisplayPrefs* display_prefs() { return Shell::Get()->display_prefs(); }
  259. private:
  260. std::unique_ptr<WindowTreeHostManager::Observer> observer_;
  261. base::test::ScopedFeatureList scoped_feature_list_;
  262. };
  263. class DisplayPrefsTestGuest : public DisplayPrefsTest {
  264. public:
  265. DisplayPrefsTestGuest() { set_start_session(false); }
  266. DisplayPrefsTestGuest(const DisplayPrefsTestGuest&) = delete;
  267. DisplayPrefsTestGuest& operator=(const DisplayPrefsTestGuest&) = delete;
  268. };
  269. TEST_F(DisplayPrefsTest, ListedLayoutOverrides) {
  270. UpdateDisplay("200x100,300x200");
  271. display::DisplayIdList list = display_manager()->GetConnectedDisplayIdList();
  272. display::DisplayIdList dummy_list = display::test::CreateDisplayIdList2(
  273. list[0], display::GetNextSynthesizedDisplayId(list[1]));
  274. ASSERT_NE(list[0], dummy_list[1]);
  275. StoreDisplayLayoutPrefForList(list, display::DisplayPlacement::TOP, 20);
  276. StoreDisplayLayoutPrefForList(dummy_list, display::DisplayPlacement::LEFT,
  277. 30);
  278. display_prefs()->StoreDisplayPowerStateForTest(
  279. chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON);
  280. base::CommandLine::ForCurrentProcess()->AppendSwitch(
  281. switches::kFirstExecAfterBoot);
  282. LoadDisplayPreferences();
  283. // requested_power_state_ should be chromeos::DISPLAY_POWER_ALL_ON at boot
  284. const absl::optional<chromeos::DisplayPowerState> requested_power_state =
  285. display_configurator()->GetRequestedPowerStateForTest();
  286. ASSERT_NE(absl::nullopt, requested_power_state);
  287. EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON, *requested_power_state);
  288. // DisplayPowerState should be ignored at boot.
  289. EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON,
  290. display_configurator()->GetRequestedPowerState());
  291. Shell::Get()->display_manager()->UpdateDisplays();
  292. // Check if the layout settings are notified to the system properly.
  293. // The new layout overrides old layout.
  294. // Inverted one of for specified pair (id1, id2). Not used for the list
  295. // (id1, dummy_id) since dummy_id is not connected right now.
  296. EXPECT_EQ("id=2200000257, parent=2200000000, top, 20",
  297. Shell::Get()
  298. ->display_manager()
  299. ->GetCurrentDisplayLayout()
  300. .placement_list[0]
  301. .ToString());
  302. EXPECT_EQ("id=2200000257, parent=2200000000, top, 20",
  303. GetRegisteredDisplayPlacementStr(list));
  304. EXPECT_EQ("id=2200000258, parent=2200000000, left, 30",
  305. GetRegisteredDisplayPlacementStr(dummy_list));
  306. }
  307. TEST_F(DisplayPrefsTest, BasicStores) {
  308. WindowTreeHostManager* window_tree_host_manager =
  309. Shell::Get()->window_tree_host_manager();
  310. int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  311. // For each configuration change, we store mirror info only for external
  312. // displays. So set internal display first before adding display.
  313. display::test::ScopedSetInternalDisplayId set_internal(display_manager(),
  314. id1);
  315. UpdateDisplay("300x200*2, 400x300#500x400|300x200*1.25");
  316. display::test::DisplayManagerTestApi display_manager_test(display_manager());
  317. int64_t id2 = display_manager_test.GetSecondaryDisplay().id();
  318. int64_t dummy_id = display::GetNextSynthesizedDisplayId(id2);
  319. ASSERT_NE(id1, dummy_id);
  320. LoggedInAsUser();
  321. display_manager()->SetLayoutForCurrentDisplays(
  322. display::test::CreateDisplayLayout(display_manager(),
  323. display::DisplayPlacement::TOP, 10));
  324. const display::DisplayLayout& layout =
  325. display_manager()->GetCurrentDisplayLayout();
  326. EXPECT_EQ(display::DisplayPlacement::TOP, layout.placement_list[0].position);
  327. EXPECT_EQ(10, layout.placement_list[0].offset);
  328. display::DisplayLayoutBuilder dummy_layout_builder(id1);
  329. dummy_layout_builder.SetSecondaryPlacement(
  330. dummy_id, display::DisplayPlacement::LEFT, 20);
  331. std::unique_ptr<display::DisplayLayout> dummy_layout(
  332. dummy_layout_builder.Build());
  333. display::DisplayIdList list =
  334. display::test::CreateDisplayIdList2(id1, dummy_id);
  335. display_prefs()->StoreDisplayLayoutPrefForTest(list, *dummy_layout);
  336. // Can't switch to a display that does not exist.
  337. window_tree_host_manager->SetPrimaryDisplayId(dummy_id);
  338. EXPECT_NE(dummy_id, display::Screen::GetScreen()->GetPrimaryDisplay().id());
  339. window_tree_host_manager->SetOverscanInsets(
  340. id1, gfx::Insets::TLBR(10, 11, 12, 13));
  341. display_manager()->SetDisplayRotation(id1, display::Display::ROTATE_90,
  342. display::Display::RotationSource::USER);
  343. constexpr float zoom_factor_1 = 1.f / display::kDsf_2_252;
  344. constexpr float zoom_factor_2 = 1.60f;
  345. display_manager()->UpdateZoomFactor(id1, zoom_factor_1);
  346. display_manager()->UpdateZoomFactor(id2, zoom_factor_2);
  347. // Set touch calibration data for display |id2|.
  348. ui::TouchscreenDevice touchdevice(11, ui::InputDeviceType::INPUT_DEVICE_USB,
  349. std::string("test touch device"),
  350. gfx::Size(123, 456), 1);
  351. touchdevice.phys = "5678";
  352. display::TouchCalibrationData::CalibrationPointPairQuad point_pair_quad_1 = {
  353. {std::make_pair(gfx::Point(10, 10), gfx::Point(11, 12)),
  354. std::make_pair(gfx::Point(190, 10), gfx::Point(195, 8)),
  355. std::make_pair(gfx::Point(10, 90), gfx::Point(12, 94)),
  356. std::make_pair(gfx::Point(190, 90), gfx::Point(189, 88))}};
  357. gfx::Size touch_size_1(200, 150);
  358. ui::TouchscreenDevice touchdevice_2(12, ui::InputDeviceType::INPUT_DEVICE_USB,
  359. std::string("test touch device 2"),
  360. gfx::Size(132, 465), 1);
  361. touchdevice_2.phys = "3456";
  362. display::TouchCalibrationData::CalibrationPointPairQuad point_pair_quad_2 = {
  363. {std::make_pair(gfx::Point(10, 10), gfx::Point(11, 12)),
  364. std::make_pair(gfx::Point(190, 10), gfx::Point(195, 8)),
  365. std::make_pair(gfx::Point(10, 90), gfx::Point(12, 94)),
  366. std::make_pair(gfx::Point(190, 90), gfx::Point(189, 88))}};
  367. gfx::Size touch_size_2(150, 150);
  368. // Create a 3rd touch device which has the same primary ID as the 2nd touch
  369. // device but is connected to a different port.
  370. ui::TouchscreenDevice touchdevice_3(15, ui::InputDeviceType::INPUT_DEVICE_USB,
  371. std::string("test touch device 3"),
  372. gfx::Size(231, 416), 1);
  373. touchdevice_3.phys = "1357";
  374. display_manager()->SetTouchCalibrationData(id2, point_pair_quad_1,
  375. touch_size_1, touchdevice);
  376. display_manager()->SetTouchCalibrationData(id2, point_pair_quad_2,
  377. touch_size_2, touchdevice_2);
  378. display_manager()->SetTouchCalibrationData(id2, point_pair_quad_2,
  379. touch_size_1, touchdevice_3);
  380. const base::Value::Dict& displays =
  381. local_state()->GetValueDict(prefs::kSecondaryDisplays);
  382. std::string key = base::NumberToString(id1) + "," + base::NumberToString(id2);
  383. std::string dummy_key =
  384. base::NumberToString(id1) + "," + base::NumberToString(dummy_id);
  385. const base::Value::Dict* layout_value = displays.FindDict(dummy_key);
  386. EXPECT_TRUE(layout_value);
  387. display::DisplayLayout stored_layout;
  388. EXPECT_TRUE(display::JsonToDisplayLayout(*layout_value, &stored_layout));
  389. ASSERT_EQ(1u, stored_layout.placement_list.size());
  390. EXPECT_EQ(dummy_layout->placement_list[0].position,
  391. stored_layout.placement_list[0].position);
  392. EXPECT_EQ(dummy_layout->placement_list[0].offset,
  393. stored_layout.placement_list[0].offset);
  394. const base::Value::List* external_display_mirror_info =
  395. &local_state()->GetValueList(prefs::kExternalDisplayMirrorInfo);
  396. EXPECT_EQ(0U, external_display_mirror_info->size());
  397. const base::Value::Dict& properties =
  398. local_state()->GetValueDict(prefs::kDisplayProperties);
  399. const base::Value::Dict* property =
  400. properties.FindDict(base::NumberToString(id1));
  401. EXPECT_TRUE(property);
  402. EXPECT_EQ(1, property->FindInt("rotation"));
  403. absl::optional<double> display_zoom_1 =
  404. property->FindDouble("display_zoom_factor");
  405. ASSERT_TRUE(display_zoom_1);
  406. EXPECT_NEAR(*display_zoom_1, zoom_factor_1, 0.0001);
  407. // Internal display never registered the resolution.
  408. EXPECT_FALSE(property->FindInt("width"));
  409. EXPECT_FALSE(property->FindInt("height"));
  410. EXPECT_EQ(10, property->FindInt("insets_top"));
  411. EXPECT_EQ(11, property->FindInt("insets_left"));
  412. EXPECT_EQ(12, property->FindInt("insets_bottom"));
  413. EXPECT_EQ(13, property->FindInt("insets_right"));
  414. display::TouchDeviceManager* tdm = display_manager()->touch_device_manager();
  415. display::test::TouchDeviceManagerTestApi tdm_test_api(tdm);
  416. display::TouchDeviceManager::TouchAssociationMap
  417. expected_touch_associations_map = tdm->touch_associations();
  418. display::TouchDeviceManager::PortAssociationMap
  419. expected_port_associations_map = tdm->port_associations();
  420. tdm_test_api.ResetTouchDeviceManager();
  421. EXPECT_FALSE(CompareTouchAssociations(expected_touch_associations_map,
  422. tdm->touch_associations()));
  423. EXPECT_FALSE(ComparePortAssociations(expected_port_associations_map,
  424. tdm->port_associations()));
  425. display_prefs()->LoadTouchAssociationPreferenceForTest();
  426. display::TouchDeviceManager::TouchAssociationMap
  427. actual_touch_associations_map = tdm->touch_associations();
  428. EXPECT_TRUE(CompareTouchAssociations(actual_touch_associations_map,
  429. expected_touch_associations_map));
  430. EXPECT_TRUE(ComparePortAssociations(expected_port_associations_map,
  431. tdm->port_associations()));
  432. std::string touch_str;
  433. property = properties.FindDict(base::NumberToString(id2));
  434. ASSERT_TRUE(property);
  435. EXPECT_EQ(0, property->FindInt("rotation"));
  436. absl::optional<double> display_zoom_2 =
  437. property->FindDouble("display_zoom_factor");
  438. ASSERT_TRUE(display_zoom_2);
  439. EXPECT_NEAR(*display_zoom_2, zoom_factor_2, 0.0001);
  440. EXPECT_FALSE(property->FindInt("insets_top"));
  441. EXPECT_FALSE(property->FindInt("insets_left"));
  442. EXPECT_FALSE(property->FindInt("insets_bottom"));
  443. EXPECT_FALSE(property->FindInt("insets_right"));
  444. // Resolution is saved only when the resolution is set
  445. // by DisplayManager::SetDisplayMode
  446. EXPECT_FALSE(property->FindInt("width"));
  447. EXPECT_FALSE(property->FindInt("height"));
  448. display::ManagedDisplayMode mode(gfx::Size(300, 200), 60.0f, false, false,
  449. 1.25f /* device_scale_factor */);
  450. display_manager()->SetDisplayMode(id2, mode);
  451. window_tree_host_manager->SetPrimaryDisplayId(id2);
  452. EXPECT_EQ(id2, display::Screen::GetScreen()->GetPrimaryDisplay().id());
  453. property = properties.FindDict(base::NumberToString(id1));
  454. ASSERT_TRUE(property);
  455. // Internal display shouldn't store its resolution.
  456. EXPECT_FALSE(property->FindInt("width"));
  457. EXPECT_FALSE(property->FindInt("height"));
  458. // External display's resolution must be stored this time because
  459. // it's not best.
  460. property = properties.FindDict(base::NumberToString(id2));
  461. ASSERT_TRUE(property);
  462. EXPECT_EQ(property->FindInt("width"), 300);
  463. EXPECT_EQ(property->FindInt("height"), 200);
  464. EXPECT_EQ(property->FindInt("device-scale-factor"), 1250);
  465. // The layout is swapped.
  466. layout_value = displays.FindDict(key);
  467. ASSERT_TRUE(layout_value);
  468. EXPECT_TRUE(display::JsonToDisplayLayout(*layout_value, &stored_layout));
  469. ASSERT_EQ(1u, stored_layout.placement_list.size());
  470. const display::DisplayPlacement& stored_placement =
  471. stored_layout.placement_list[0];
  472. EXPECT_EQ(display::DisplayPlacement::BOTTOM, stored_placement.position);
  473. EXPECT_EQ(-10, stored_placement.offset);
  474. EXPECT_EQ(id1, stored_placement.display_id);
  475. EXPECT_EQ(id2, stored_placement.parent_display_id);
  476. EXPECT_EQ(id2, stored_layout.primary_id);
  477. const std::string* primary_id_str = layout_value->FindString(kPrimaryIdKey);
  478. ASSERT_TRUE(primary_id_str);
  479. EXPECT_EQ(base::NumberToString(id2), *primary_id_str);
  480. display_manager()->SetLayoutForCurrentDisplays(
  481. display::test::CreateDisplayLayout(Shell::Get()->display_manager(),
  482. display::DisplayPlacement::BOTTOM,
  483. 20));
  484. // Test Hardware Mirroring scenario.
  485. UpdateDisplay("1+0-300x200*2,1+0-300x200");
  486. EXPECT_FALSE(display_manager()->IsInSoftwareMirrorMode());
  487. EXPECT_TRUE(display_manager()->IsInHardwareMirrorMode());
  488. layout_value = displays.FindDict(key);
  489. ASSERT_TRUE(layout_value);
  490. EXPECT_TRUE(display::JsonToDisplayLayout(*layout_value, &stored_layout));
  491. EXPECT_EQ(display::DisplayPlacement::BOTTOM, stored_placement.position);
  492. EXPECT_EQ(20, stored_placement.offset);
  493. EXPECT_EQ(id1, stored_placement.display_id);
  494. EXPECT_EQ(id2, stored_placement.parent_display_id);
  495. property = properties.FindDict(base::NumberToString(id1));
  496. ASSERT_TRUE(property);
  497. EXPECT_FALSE(property->FindInt("width"));
  498. EXPECT_FALSE(property->FindInt("height"));
  499. external_display_mirror_info =
  500. &local_state()->GetValueList(prefs::kExternalDisplayMirrorInfo);
  501. EXPECT_EQ(1U, external_display_mirror_info->size());
  502. // ExternalDisplayInfo stores ID without output index.
  503. EXPECT_EQ(base::NumberToString(display::GetDisplayIdWithoutOutputIndex(id2)),
  504. (*external_display_mirror_info)[0].GetString());
  505. // External display's selected resolution must not change
  506. // by mirroring.
  507. property = properties.FindDict(base::NumberToString(id2));
  508. ASSERT_TRUE(property);
  509. EXPECT_EQ(300, property->FindInt("width"));
  510. EXPECT_EQ(200, property->FindInt("height"));
  511. // Set new display's selected resolution.
  512. display_manager()->RegisterDisplayProperty(
  513. display::GetNextSynthesizedDisplayId(id2), display::Display::ROTATE_0,
  514. nullptr, gfx::Size(500, 400), 1.0f, 1.0f, 60.f, false);
  515. UpdateDisplay("300x200*2, 600x500#600x500|500x400");
  516. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  517. // Update key as the 2nd display gets new id.
  518. id2 = display_manager_test.GetSecondaryDisplay().id();
  519. key = base::NumberToString(id1) + "," + base::NumberToString(id2);
  520. layout_value = displays.FindDict(key);
  521. ASSERT_TRUE(layout_value);
  522. EXPECT_TRUE(display::JsonToDisplayLayout(*layout_value, &stored_layout));
  523. EXPECT_EQ(display::DisplayPlacement::RIGHT, stored_placement.position);
  524. EXPECT_EQ(0, stored_placement.offset);
  525. EXPECT_EQ(id1, stored_placement.parent_display_id);
  526. EXPECT_EQ(id2, stored_placement.display_id);
  527. primary_id_str = layout_value->FindString(kPrimaryIdKey);
  528. ASSERT_TRUE(primary_id_str);
  529. EXPECT_EQ(base::NumberToString(id1), *primary_id_str);
  530. // Best resolution should not be saved.
  531. property = properties.FindDict(base::NumberToString(id2));
  532. ASSERT_TRUE(property);
  533. EXPECT_FALSE(property->FindInt("width"));
  534. EXPECT_FALSE(property->FindInt("height"));
  535. // Set yet another new display's selected resolution.
  536. display_manager()->RegisterDisplayProperty(
  537. display::GetNextSynthesizedDisplayId(id2), display::Display::ROTATE_0,
  538. nullptr, gfx::Size(500, 400), 1.0f, 1.0f, 60.f, false);
  539. // Disconnect 2nd display first to generate new id for external display.
  540. UpdateDisplay("300x200*2");
  541. UpdateDisplay("300x200*2, 500x400#600x500|500x400%60.0f");
  542. // Update key as the 2nd display gets new id.
  543. id2 = display_manager_test.GetSecondaryDisplay().id();
  544. key = base::NumberToString(id1) + "," + base::NumberToString(id2);
  545. layout_value = displays.FindDict(key);
  546. ASSERT_TRUE(layout_value);
  547. EXPECT_TRUE(display::JsonToDisplayLayout(*layout_value, &stored_layout));
  548. EXPECT_EQ(display::DisplayPlacement::RIGHT, stored_placement.position);
  549. EXPECT_EQ(0, stored_placement.offset);
  550. primary_id_str = layout_value->FindString(kPrimaryIdKey);
  551. ASSERT_TRUE(primary_id_str);
  552. EXPECT_EQ(base::NumberToString(id1), *primary_id_str);
  553. // External display's selected resolution must be updated.
  554. property = properties.FindDict(base::NumberToString(id2));
  555. ASSERT_TRUE(property);
  556. EXPECT_EQ(500, property->FindInt("width"));
  557. EXPECT_EQ(400, property->FindInt("height"));
  558. }
  559. TEST_F(DisplayPrefsTest, PreventStore) {
  560. LoggedInAsUser();
  561. UpdateDisplay("400x300#500x400|400x300|300x200");
  562. int64_t id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  563. // Set display's resolution in single display. It creates the notification and
  564. // display preferences should not stored meanwhile.
  565. Shell* shell = Shell::Get();
  566. display::ManagedDisplayMode old_mode(gfx::Size(400, 300), 60.0f, false,
  567. false);
  568. display::ManagedDisplayMode new_mode(gfx::Size(500, 400), 60.0f, false, true);
  569. EXPECT_TRUE(shell->resolution_notification_controller()
  570. ->PrepareNotificationAndSetDisplayMode(
  571. id, old_mode, new_mode,
  572. crosapi::mojom::DisplayConfigSource::kUser,
  573. base::OnceClosure()));
  574. UpdateDisplay("500x400#500x400|400x300|300x200");
  575. const base::Value::Dict& properties =
  576. local_state()->GetValueDict(prefs::kDisplayProperties);
  577. const base::Value::Dict* property =
  578. properties.FindDict(base::NumberToString(id));
  579. EXPECT_TRUE(property);
  580. EXPECT_FALSE(property->FindInt("width"));
  581. EXPECT_FALSE(property->FindInt("height"));
  582. // Revert the change.
  583. shell->resolution_notification_controller()->RevertResolutionChange(false);
  584. base::RunLoop().RunUntilIdle();
  585. // The specified resolution will be stored by SetDisplayMode.
  586. Shell::Get()->display_manager()->SetDisplayMode(
  587. id, display::ManagedDisplayMode(gfx::Size(300, 200), 60.0f, false, true));
  588. UpdateDisplay("300x200#500x400|400x300|300x200");
  589. property = properties.FindDict(base::NumberToString(id));
  590. ASSERT_TRUE(property);
  591. EXPECT_EQ(300, property->FindInt("width"));
  592. EXPECT_EQ(200, property->FindInt("height"));
  593. }
  594. TEST_F(DisplayPrefsTest, StoreForSwappedDisplay) {
  595. UpdateDisplay("200x100,300x200");
  596. display::test::DisplayManagerTestApi display_manager_test(display_manager());
  597. int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  598. int64_t id2 = display_manager_test.GetSecondaryDisplay().id();
  599. LoggedInAsUser();
  600. SwapPrimaryDisplay();
  601. ASSERT_EQ(id1, display_manager_test.GetSecondaryDisplay().id());
  602. std::string key = base::NumberToString(id1) + "," + base::NumberToString(id2);
  603. const base::Value::Dict& displays =
  604. local_state()->GetValueDict(prefs::kSecondaryDisplays);
  605. // Initial saved value is swapped.
  606. {
  607. const base::Value::Dict* new_value = displays.FindDict(key);
  608. EXPECT_TRUE(new_value);
  609. display::DisplayLayout stored_layout;
  610. EXPECT_TRUE(display::JsonToDisplayLayout(*new_value, &stored_layout));
  611. ASSERT_EQ(1u, stored_layout.placement_list.size());
  612. const display::DisplayPlacement& stored_placement =
  613. stored_layout.placement_list[0];
  614. EXPECT_EQ(display::DisplayPlacement::LEFT, stored_placement.position);
  615. EXPECT_EQ(0, stored_placement.offset);
  616. EXPECT_EQ(id1, stored_placement.display_id);
  617. EXPECT_EQ(id2, stored_placement.parent_display_id);
  618. EXPECT_EQ(id2, stored_layout.primary_id);
  619. }
  620. // Updating layout with primary swapped should save the correct value.
  621. {
  622. display_manager()->SetLayoutForCurrentDisplays(
  623. display::test::CreateDisplayLayout(display_manager(),
  624. display::DisplayPlacement::TOP, 10));
  625. const base::Value::Dict* new_value = displays.FindDict(key);
  626. ASSERT_TRUE(new_value);
  627. display::DisplayLayout stored_layout;
  628. EXPECT_TRUE(display::JsonToDisplayLayout(*new_value, &stored_layout));
  629. ASSERT_EQ(1u, stored_layout.placement_list.size());
  630. const display::DisplayPlacement& stored_placement =
  631. stored_layout.placement_list[0];
  632. EXPECT_EQ(display::DisplayPlacement::TOP, stored_placement.position);
  633. EXPECT_EQ(10, stored_placement.offset);
  634. EXPECT_EQ(id1, stored_placement.display_id);
  635. EXPECT_EQ(id2, stored_placement.parent_display_id);
  636. EXPECT_EQ(id2, stored_layout.primary_id);
  637. }
  638. // Swapping primary will save the swapped value.
  639. {
  640. SwapPrimaryDisplay();
  641. const base::Value::Dict* new_value = displays.FindDict(key);
  642. ASSERT_TRUE(new_value);
  643. display::DisplayLayout stored_layout;
  644. EXPECT_TRUE(display::JsonToDisplayLayout(*new_value, &stored_layout));
  645. ASSERT_EQ(1u, stored_layout.placement_list.size());
  646. const display::DisplayPlacement& stored_placement =
  647. stored_layout.placement_list[0];
  648. EXPECT_EQ(display::DisplayPlacement::BOTTOM, stored_placement.position);
  649. EXPECT_EQ(-10, stored_placement.offset);
  650. EXPECT_EQ(id2, stored_placement.display_id);
  651. EXPECT_EQ(id1, stored_placement.parent_display_id);
  652. EXPECT_EQ(id1, stored_layout.primary_id);
  653. }
  654. }
  655. TEST_F(DisplayPrefsTestGuest, DisplayPrefsTestGuest) {
  656. WindowTreeHostManager* window_tree_host_manager =
  657. Shell::Get()->window_tree_host_manager();
  658. UpdateDisplay("300x200*2,300x200");
  659. LoggedInAsGuest();
  660. int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  661. display::test::ScopedSetInternalDisplayId set_internal(
  662. Shell::Get()->display_manager(), id1);
  663. int64_t id2 = display::test::DisplayManagerTestApi(display_manager())
  664. .GetSecondaryDisplay()
  665. .id();
  666. display_manager()->SetLayoutForCurrentDisplays(
  667. display::test::CreateDisplayLayout(display_manager(),
  668. display::DisplayPlacement::TOP, 10));
  669. const float scale = 1.25f;
  670. display_manager()->UpdateZoomFactor(id1, 1.f / scale);
  671. window_tree_host_manager->SetPrimaryDisplayId(id2);
  672. int64_t new_primary = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  673. window_tree_host_manager->SetOverscanInsets(
  674. new_primary, gfx::Insets::TLBR(10, 11, 12, 13));
  675. display_manager()->SetDisplayRotation(new_primary,
  676. display::Display::ROTATE_90,
  677. display::Display::RotationSource::USER);
  678. // Does not store the preferences locally.
  679. EXPECT_FALSE(local_state()
  680. ->FindPreference(prefs::kSecondaryDisplays)
  681. ->HasUserSetting());
  682. EXPECT_FALSE(local_state()
  683. ->FindPreference(prefs::kDisplayProperties)
  684. ->HasUserSetting());
  685. // Settings are still notified to the system.
  686. display::Screen* screen = display::Screen::GetScreen();
  687. EXPECT_EQ(id2, screen->GetPrimaryDisplay().id());
  688. const display::DisplayPlacement& placement =
  689. display_manager()->GetCurrentDisplayLayout().placement_list[0];
  690. EXPECT_EQ(display::DisplayPlacement::BOTTOM, placement.position);
  691. EXPECT_EQ(-10, placement.offset);
  692. const display::Display& primary_display = screen->GetPrimaryDisplay();
  693. EXPECT_EQ(gfx::Size(178, 276), primary_display.bounds().size());
  694. EXPECT_EQ(display::Display::ROTATE_90, primary_display.rotation());
  695. const display::ManagedDisplayInfo& info1 =
  696. display_manager()->GetDisplayInfo(id1);
  697. EXPECT_FLOAT_EQ(1.f / scale, info1.zoom_factor());
  698. const display::ManagedDisplayInfo& info_primary =
  699. display_manager()->GetDisplayInfo(new_primary);
  700. EXPECT_EQ(display::Display::ROTATE_90, info_primary.GetActiveRotation());
  701. EXPECT_EQ(1.0f, info_primary.zoom_factor());
  702. }
  703. // Test case which accepts the boolean value of the
  704. // AllowMGSToStoreDisplayProperties policy. When set to True, this policy allows
  705. // managed guest session to store display configuration permanently in the local
  706. // state. When set to False or unset, the display configuration is not stored in
  707. // the local state.
  708. class DisplayPrefsPublicAccountTest : public DisplayPrefsTestGuest,
  709. public testing::WithParamInterface<bool> {
  710. public:
  711. bool IsMGSAllowedToStoreDisplayProperties() const { return GetParam(); }
  712. void SetUp() override {
  713. DisplayPrefsTestGuest::SetUp();
  714. UpdateDisplay("300x200*2,300x200");
  715. local_state()->SetBoolean(prefs::kAllowMGSToStoreDisplayProperties,
  716. IsMGSAllowedToStoreDisplayProperties());
  717. }
  718. };
  719. TEST_P(DisplayPrefsPublicAccountTest, StoreDisplayPrefsForPublicAccount) {
  720. WindowTreeHostManager* window_tree_host_manager =
  721. Shell::Get()->window_tree_host_manager();
  722. LoggedInAsPublicAccount();
  723. int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  724. display::test::ScopedSetInternalDisplayId set_internal(
  725. Shell::Get()->display_manager(), id1);
  726. int64_t id2 = display::test::DisplayManagerTestApi(display_manager())
  727. .GetSecondaryDisplay()
  728. .id();
  729. display_manager()->SetLayoutForCurrentDisplays(
  730. display::test::CreateDisplayLayout(display_manager(),
  731. display::DisplayPlacement::TOP, 10));
  732. const float scale = 1.25f;
  733. display_manager()->UpdateZoomFactor(id1, 1.f / scale);
  734. window_tree_host_manager->SetPrimaryDisplayId(id2);
  735. const int64_t new_primary =
  736. display::Screen::GetScreen()->GetPrimaryDisplay().id();
  737. window_tree_host_manager->SetOverscanInsets(
  738. new_primary, gfx::Insets::TLBR(10, 11, 12, 13));
  739. display_manager()->SetDisplayRotation(new_primary,
  740. display::Display::ROTATE_90,
  741. display::Display::RotationSource::USER);
  742. // Preferences should only be stored if the AllowMGSToStoreDisplayProperties
  743. // policy was set to true.
  744. EXPECT_EQ(IsMGSAllowedToStoreDisplayProperties(),
  745. local_state()
  746. ->FindPreference(prefs::kSecondaryDisplays)
  747. ->HasUserSetting());
  748. EXPECT_EQ(IsMGSAllowedToStoreDisplayProperties(),
  749. local_state()
  750. ->FindPreference(prefs::kDisplayProperties)
  751. ->HasUserSetting());
  752. // Settings are still notified to the system.
  753. display::Screen* screen = display::Screen::GetScreen();
  754. EXPECT_EQ(id2, screen->GetPrimaryDisplay().id());
  755. const display::DisplayPlacement& placement =
  756. display_manager()->GetCurrentDisplayLayout().placement_list[0];
  757. EXPECT_EQ(display::DisplayPlacement::BOTTOM, placement.position);
  758. EXPECT_EQ(-10, placement.offset);
  759. const display::Display& primary_display = screen->GetPrimaryDisplay();
  760. EXPECT_EQ(gfx::Size(178, 276), primary_display.bounds().size());
  761. EXPECT_EQ(display::Display::ROTATE_90, primary_display.rotation());
  762. const display::ManagedDisplayInfo& info1 =
  763. display_manager()->GetDisplayInfo(id1);
  764. EXPECT_FLOAT_EQ(1.f / scale, info1.zoom_factor());
  765. const display::ManagedDisplayInfo& info_primary =
  766. display_manager()->GetDisplayInfo(new_primary);
  767. EXPECT_EQ(display::Display::ROTATE_90, info_primary.GetActiveRotation());
  768. EXPECT_EQ(1.0f, info_primary.zoom_factor());
  769. }
  770. INSTANTIATE_TEST_SUITE_P(All, DisplayPrefsPublicAccountTest, testing::Bool());
  771. TEST_F(DisplayPrefsTest, StorePowerStateNoLogin) {
  772. EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState));
  773. // Stores display prefs without login, which still stores the power state.
  774. display_prefs()->MaybeStoreDisplayPrefs();
  775. EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayPowerState));
  776. }
  777. TEST_F(DisplayPrefsTest, StorePowerStateGuest) {
  778. EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState));
  779. LoggedInAsGuest();
  780. display_prefs()->MaybeStoreDisplayPrefs();
  781. EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayPowerState));
  782. }
  783. TEST_F(DisplayPrefsTest, StorePowerStateNormalUser) {
  784. EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState));
  785. LoggedInAsUser();
  786. display_prefs()->MaybeStoreDisplayPrefs();
  787. EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayPowerState));
  788. }
  789. TEST_F(DisplayPrefsTest, DisplayPowerStateAfterRestart) {
  790. display_prefs()->StoreDisplayPowerStateForTest(
  791. chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON);
  792. EXPECT_EQ("internal_off_external_on",
  793. local_state()->GetString(prefs::kDisplayPowerState));
  794. display_configurator()->reset_requested_power_state_for_test();
  795. LoadDisplayPreferences();
  796. EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON,
  797. display_configurator()->GetRequestedPowerState());
  798. }
  799. TEST_F(DisplayPrefsTest, DontSaveAndRestoreAllOff) {
  800. display_prefs()->StoreDisplayPowerStateForTest(
  801. chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON);
  802. EXPECT_EQ("internal_off_external_on",
  803. local_state()->GetString(prefs::kDisplayPowerState));
  804. // Don't save ALL_OFF.
  805. display_prefs()->StoreDisplayPowerStateForTest(
  806. chromeos::DISPLAY_POWER_ALL_OFF);
  807. EXPECT_EQ("internal_off_external_on",
  808. local_state()->GetString(prefs::kDisplayPowerState));
  809. // Don't restore ALL_OFF.
  810. local_state()->SetString(prefs::kDisplayPowerState, "all_off");
  811. display_configurator()->reset_requested_power_state_for_test();
  812. LoadDisplayPreferences();
  813. EXPECT_EQ(absl::nullopt,
  814. display_configurator()->GetRequestedPowerStateForTest());
  815. }
  816. // Tests that display configuration changes caused by TabletModeController
  817. // are not saved.
  818. TEST_F(DisplayPrefsTest, DontSaveTabletModeControllerRotations) {
  819. Shell* shell = Shell::Get();
  820. display::SetInternalDisplayIds(
  821. {display::Screen::GetScreen()->GetPrimaryDisplay().id()});
  822. LoggedInAsUser();
  823. // Populate the properties.
  824. display_manager()->SetDisplayRotation(display::Display::InternalDisplayId(),
  825. display::Display::ROTATE_180,
  826. display::Display::RotationSource::USER);
  827. // Reset property to avoid rotation lock
  828. display_manager()->SetDisplayRotation(display::Display::InternalDisplayId(),
  829. display::Display::ROTATE_0,
  830. display::Display::RotationSource::USER);
  831. // Open up 270 degrees to trigger tablet mode
  832. AccelerometerUpdate update;
  833. update.Set(ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f,
  834. -base::kMeanGravityFloat);
  835. update.Set(ACCELEROMETER_SOURCE_SCREEN, 0.0f, base::kMeanGravityFloat, 0.0f);
  836. TabletModeController* controller = Shell::Get()->tablet_mode_controller();
  837. controller->OnAccelerometerUpdated(update);
  838. EXPECT_TRUE(controller->InTabletMode());
  839. // Trigger 90 degree rotation
  840. update.Set(ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, base::kMeanGravityFloat,
  841. 0.0f, 0.0f);
  842. update.Set(ACCELEROMETER_SOURCE_SCREEN, base::kMeanGravityFloat, 0.0f, 0.0f);
  843. controller->OnAccelerometerUpdated(update);
  844. shell->screen_orientation_controller()->OnAccelerometerUpdated(update);
  845. EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
  846. const base::Value::Dict* properties =
  847. &local_state()->GetValueDict(prefs::kDisplayProperties);
  848. const base::Value::Dict* property = properties->FindDict(
  849. base::NumberToString(display::Display::InternalDisplayId()));
  850. EXPECT_TRUE(property);
  851. EXPECT_EQ(display::Display::ROTATE_0, property->FindInt("rotation"));
  852. // Trigger a save, the acceleration rotation should not be saved as the user
  853. // rotation.
  854. display_prefs()->MaybeStoreDisplayPrefs();
  855. properties = &local_state()->GetValueDict(prefs::kDisplayProperties);
  856. property = properties->FindDict(
  857. base::NumberToString(display::Display::InternalDisplayId()));
  858. EXPECT_TRUE(property);
  859. EXPECT_EQ(display::Display::ROTATE_0, property->FindInt("rotation"));
  860. }
  861. // Tests that the rotation state is saved without a user being logged in.
  862. TEST_F(DisplayPrefsTest, StoreRotationStateNoLogin) {
  863. display::SetInternalDisplayIds(
  864. {display::Screen::GetScreen()->GetPrimaryDisplay().id()});
  865. EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
  866. bool current_rotation_lock = IsRotationLocked();
  867. display_prefs()->StoreDisplayRotationPrefsForTest(GetRotation(),
  868. current_rotation_lock);
  869. EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
  870. const base::Value::Dict& properties =
  871. local_state()->GetValueDict(prefs::kDisplayRotationLock);
  872. absl::optional<bool> rotation_lock = properties.FindBool("lock");
  873. ASSERT_TRUE(rotation_lock.has_value());
  874. EXPECT_EQ(current_rotation_lock, rotation_lock.value());
  875. display::Display::Rotation current_rotation =
  876. GetCurrentInternalDisplayRotation();
  877. EXPECT_EQ(current_rotation, properties.FindInt("orientation"));
  878. }
  879. // Tests that the rotation state is saved when a guest is logged in.
  880. TEST_F(DisplayPrefsTest, StoreRotationStateGuest) {
  881. display::SetInternalDisplayIds(
  882. {display::Screen::GetScreen()->GetPrimaryDisplay().id()});
  883. EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
  884. LoggedInAsGuest();
  885. bool current_rotation_lock = IsRotationLocked();
  886. display_prefs()->StoreDisplayRotationPrefsForTest(GetRotation(),
  887. current_rotation_lock);
  888. EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
  889. const base::Value::Dict& properties =
  890. local_state()->GetValueDict(prefs::kDisplayRotationLock);
  891. absl::optional<bool> rotation_lock = properties.FindBool("lock");
  892. ASSERT_TRUE(rotation_lock.has_value());
  893. EXPECT_EQ(current_rotation_lock, rotation_lock.value());
  894. display::Display::Rotation current_rotation =
  895. GetCurrentInternalDisplayRotation();
  896. EXPECT_EQ(current_rotation, properties.FindInt("orientation"));
  897. }
  898. // Tests that the rotation state is saved when a normal user is logged in.
  899. TEST_F(DisplayPrefsTest, StoreRotationStateNormalUser) {
  900. display::SetInternalDisplayIds(
  901. {display::Screen::GetScreen()->GetPrimaryDisplay().id()});
  902. EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
  903. LoggedInAsGuest();
  904. bool current_rotation_lock = IsRotationLocked();
  905. display_prefs()->StoreDisplayRotationPrefsForTest(GetRotation(),
  906. current_rotation_lock);
  907. EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
  908. const base::Value::Dict& properties =
  909. local_state()->GetValueDict(prefs::kDisplayRotationLock);
  910. absl::optional<bool> rotation_lock = properties.FindBool("lock");
  911. ASSERT_TRUE(rotation_lock.has_value());
  912. EXPECT_EQ(current_rotation_lock, rotation_lock.value());
  913. display::Display::Rotation current_rotation =
  914. GetCurrentInternalDisplayRotation();
  915. EXPECT_EQ(current_rotation, properties.FindInt("orientation"));
  916. }
  917. // Tests that rotation state is loaded without a user being logged in, and that
  918. // entering tablet mode applies the state.
  919. TEST_F(DisplayPrefsTest, LoadRotationNoLogin) {
  920. display::SetInternalDisplayIds(
  921. {display::Screen::GetScreen()->GetPrimaryDisplay().id()});
  922. ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
  923. bool initial_rotation_lock = IsRotationLocked();
  924. ASSERT_FALSE(initial_rotation_lock);
  925. display::Display::Rotation initial_rotation =
  926. GetCurrentInternalDisplayRotation();
  927. ASSERT_EQ(display::Display::ROTATE_0, initial_rotation);
  928. display_prefs()->StoreDisplayRotationPrefsForTest(GetRotation(),
  929. initial_rotation_lock);
  930. ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
  931. display_prefs()->StoreDisplayRotationPrefsForTest(display::Display::ROTATE_90,
  932. true);
  933. LoadDisplayPreferences();
  934. bool display_rotation_lock =
  935. display_manager()->registered_internal_display_rotation_lock();
  936. bool display_rotation =
  937. display_manager()->registered_internal_display_rotation();
  938. EXPECT_TRUE(display_rotation_lock);
  939. EXPECT_EQ(display::Display::ROTATE_90, display_rotation);
  940. bool rotation_lock = IsRotationLocked();
  941. display::Display::Rotation before_tablet_mode_rotation =
  942. GetCurrentInternalDisplayRotation();
  943. // Settings should not be applied until tablet mode activates
  944. EXPECT_FALSE(rotation_lock);
  945. EXPECT_EQ(display::Display::ROTATE_0, before_tablet_mode_rotation);
  946. // Open up 270 degrees to trigger tablet mode
  947. AccelerometerUpdate update;
  948. update.Set(ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f,
  949. -base::kMeanGravityFloat);
  950. update.Set(ACCELEROMETER_SOURCE_SCREEN, 0.0f, base::kMeanGravityFloat, 0.0f);
  951. TabletModeController* tablet_mode_controller =
  952. Shell::Get()->tablet_mode_controller();
  953. tablet_mode_controller->OnAccelerometerUpdated(update);
  954. EXPECT_TRUE(tablet_mode_controller->InTabletMode());
  955. bool screen_orientation_rotation_lock = IsRotationLocked();
  956. display::Display::Rotation tablet_mode_rotation =
  957. GetCurrentInternalDisplayRotation();
  958. EXPECT_TRUE(screen_orientation_rotation_lock);
  959. EXPECT_EQ(display::Display::ROTATE_90, tablet_mode_rotation);
  960. }
  961. // Tests that rotation lock being set causes the rotation state to be saved.
  962. TEST_F(DisplayPrefsTest, RotationLockTriggersStore) {
  963. display::SetInternalDisplayIds(
  964. {display::Screen::GetScreen()->GetPrimaryDisplay().id()});
  965. ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
  966. Shell::Get()->screen_orientation_controller()->ToggleUserRotationLock();
  967. EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
  968. const base::Value::Dict& properties =
  969. local_state()->GetValueDict(prefs::kDisplayRotationLock);
  970. absl::optional<bool> rotation_lock = properties.FindBool("lock");
  971. EXPECT_TRUE(rotation_lock.has_value());
  972. }
  973. TEST_F(DisplayPrefsTest, SaveUnifiedMode) {
  974. LoggedInAsUser();
  975. display_manager()->SetUnifiedDesktopEnabled(true);
  976. UpdateDisplay("300x200,200x100");
  977. display::DisplayIdList list = display_manager()->GetConnectedDisplayIdList();
  978. EXPECT_EQ(gfx::Size(700, 200),
  979. display::Screen::GetScreen()->GetPrimaryDisplay().size());
  980. const base::Value::Dict& secondary_displays =
  981. local_state()->GetValueDict(prefs::kSecondaryDisplays);
  982. const base::Value::Dict* new_value =
  983. secondary_displays.FindDict(display::DisplayIdListToString(list));
  984. EXPECT_TRUE(new_value);
  985. display::DisplayLayout stored_layout;
  986. EXPECT_TRUE(display::JsonToDisplayLayout(*new_value, &stored_layout));
  987. EXPECT_TRUE(stored_layout.default_unified);
  988. const base::Value::Dict& displays =
  989. local_state()->GetValueDict(prefs::kDisplayProperties);
  990. int64_t unified_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  991. new_value = displays.FindDict(base::NumberToString(unified_id));
  992. EXPECT_FALSE(new_value);
  993. display::test::SetDisplayResolution(display_manager(), unified_id,
  994. gfx::Size(350, 100));
  995. EXPECT_EQ(gfx::Size(350, 100),
  996. display::Screen::GetScreen()->GetPrimaryDisplay().size());
  997. EXPECT_FALSE(displays.FindDict(base::NumberToString(unified_id)));
  998. // Mirror mode should remember if the default mode was unified.
  999. display_manager()->SetMirrorMode(display::MirrorMode::kNormal, absl::nullopt);
  1000. new_value = secondary_displays.FindDict(display::DisplayIdListToString(list));
  1001. ASSERT_TRUE(new_value);
  1002. EXPECT_TRUE(display::JsonToDisplayLayout(*new_value, &stored_layout));
  1003. EXPECT_TRUE(stored_layout.default_unified);
  1004. display_manager()->SetMirrorMode(display::MirrorMode::kOff, absl::nullopt);
  1005. new_value = secondary_displays.FindDict(display::DisplayIdListToString(list));
  1006. ASSERT_TRUE(new_value);
  1007. EXPECT_TRUE(display::JsonToDisplayLayout(*new_value, &stored_layout));
  1008. EXPECT_TRUE(stored_layout.default_unified);
  1009. // Exit unified mode.
  1010. display_manager()->SetDefaultMultiDisplayModeForCurrentDisplays(
  1011. display::DisplayManager::EXTENDED);
  1012. new_value = secondary_displays.FindDict(display::DisplayIdListToString(list));
  1013. ASSERT_TRUE(new_value);
  1014. EXPECT_TRUE(display::JsonToDisplayLayout(*new_value, &stored_layout));
  1015. EXPECT_FALSE(stored_layout.default_unified);
  1016. }
  1017. TEST_F(DisplayPrefsTest, RestoreUnifiedMode) {
  1018. const int64_t first_display_id = 210000001;
  1019. const int64_t second_display_id = 220000002;
  1020. display::ManagedDisplayInfo first_display_info =
  1021. display::CreateDisplayInfo(first_display_id, gfx::Rect(1, 1, 600, 500));
  1022. display::ManagedDisplayInfo second_display_info =
  1023. display::CreateDisplayInfo(second_display_id, gfx::Rect(2, 2, 600, 500));
  1024. std::vector<display::ManagedDisplayInfo> display_info_list;
  1025. display_info_list.emplace_back(first_display_info);
  1026. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1027. Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
  1028. first_display_id);
  1029. EXPECT_FALSE(display_manager()->IsInUnifiedMode());
  1030. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1031. display::DisplayIdList list =
  1032. display::test::CreateDisplayIdList2(first_display_id, second_display_id);
  1033. StoreDisplayBoolPropertyForList(list, "default_unified", true);
  1034. StoreDisplayPropertyForList(
  1035. list, "primary-id", base::Value(base::NumberToString(first_display_id)));
  1036. LoadDisplayPreferences();
  1037. // Should not restore to unified unless unified desktop is enabled.
  1038. display_info_list.emplace_back(second_display_info);
  1039. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1040. EXPECT_FALSE(display_manager()->IsInUnifiedMode());
  1041. // Restored to unified.
  1042. display_manager()->SetUnifiedDesktopEnabled(true);
  1043. StoreDisplayBoolPropertyForList(list, "default_unified", true);
  1044. LoadDisplayPreferences();
  1045. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1046. EXPECT_TRUE(display_manager()->IsInUnifiedMode());
  1047. // Remove the second display.
  1048. display_info_list.erase(display_info_list.end() - 1);
  1049. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1050. EXPECT_FALSE(display_manager()->IsInUnifiedMode());
  1051. // Restored to mirror, then unified.
  1052. std::set<int64_t> external_display_mirror_info;
  1053. external_display_mirror_info.emplace(
  1054. display::GetDisplayIdWithoutOutputIndex(second_display_id));
  1055. StoreExternalDisplayMirrorInfo(external_display_mirror_info);
  1056. StoreDisplayBoolPropertyForList(list, "default_unified", true);
  1057. LoadDisplayPreferences();
  1058. display_info_list.emplace_back(second_display_info);
  1059. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1060. EXPECT_TRUE(display_manager()->IsInMirrorMode());
  1061. display_manager()->SetMirrorMode(display::MirrorMode::kOff, absl::nullopt);
  1062. EXPECT_TRUE(display_manager()->IsInUnifiedMode());
  1063. // Remove the second display.
  1064. display_info_list.erase(display_info_list.end() - 1);
  1065. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1066. EXPECT_FALSE(display_manager()->IsInUnifiedMode());
  1067. // Sanity check. Restore to extended.
  1068. external_display_mirror_info.clear();
  1069. StoreExternalDisplayMirrorInfo(external_display_mirror_info);
  1070. StoreDisplayBoolPropertyForList(list, "default_unified", false);
  1071. LoadDisplayPreferences();
  1072. display_info_list.emplace_back(second_display_info);
  1073. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1074. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1075. EXPECT_FALSE(display_manager()->IsInUnifiedMode());
  1076. }
  1077. TEST_F(DisplayPrefsTest, SaveThreeDisplays) {
  1078. LoggedInAsUser();
  1079. UpdateDisplay("300x200,300x200,400x300");
  1080. display::DisplayIdList list = display_manager()->GetConnectedDisplayIdList();
  1081. ASSERT_EQ(3u, list.size());
  1082. display::DisplayLayoutBuilder builder(list[0]);
  1083. builder.AddDisplayPlacement(list[1], list[0],
  1084. display::DisplayPlacement::RIGHT, 0);
  1085. builder.AddDisplayPlacement(list[2], list[0],
  1086. display::DisplayPlacement::BOTTOM, 100);
  1087. display_manager()->SetLayoutForCurrentDisplays(builder.Build());
  1088. const base::Value::Dict& secondary_displays =
  1089. local_state()->GetValueDict(prefs::kSecondaryDisplays);
  1090. const base::Value::Dict* new_value =
  1091. secondary_displays.FindDict(display::DisplayIdListToString(list));
  1092. EXPECT_TRUE(new_value);
  1093. }
  1094. TEST_F(DisplayPrefsTest, RestoreThreeDisplays) {
  1095. LoggedInAsUser();
  1096. int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  1097. display::DisplayIdList list = display::test::CreateDisplayIdListN(id1, 3);
  1098. display::DisplayLayoutBuilder builder(list[0]);
  1099. builder.AddDisplayPlacement(list[1], list[0], display::DisplayPlacement::LEFT,
  1100. 0);
  1101. builder.AddDisplayPlacement(list[2], list[1],
  1102. display::DisplayPlacement::BOTTOM, 100);
  1103. display_prefs()->StoreDisplayLayoutPrefForTest(list, *builder.Build());
  1104. LoadDisplayPreferences();
  1105. UpdateDisplay("300x200,300x200,400x300");
  1106. display::DisplayIdList new_list =
  1107. display_manager()->GetConnectedDisplayIdList();
  1108. ASSERT_EQ(3u, list.size());
  1109. ASSERT_EQ(list[0], new_list[0]);
  1110. ASSERT_EQ(list[1], new_list[1]);
  1111. ASSERT_EQ(list[2], new_list[2]);
  1112. EXPECT_EQ(gfx::Rect(0, 0, 300, 200),
  1113. display_manager()->GetDisplayForId(list[0]).bounds());
  1114. EXPECT_EQ(gfx::Rect(-300, 0, 300, 200),
  1115. display_manager()->GetDisplayForId(list[1]).bounds());
  1116. EXPECT_EQ(gfx::Rect(-200, 200, 400, 300),
  1117. display_manager()->GetDisplayForId(list[2]).bounds());
  1118. }
  1119. TEST_F(DisplayPrefsTest, LegacyTouchCalibrationDataSupport) {
  1120. UpdateDisplay("800x600,1200x800");
  1121. LoggedInAsUser();
  1122. int64_t id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  1123. display::TouchCalibrationData::CalibrationPointPairQuad point_pair_quad = {
  1124. {std::make_pair(gfx::Point(10, 10), gfx::Point(11, 12)),
  1125. std::make_pair(gfx::Point(190, 10), gfx::Point(195, 8)),
  1126. std::make_pair(gfx::Point(10, 90), gfx::Point(12, 94)),
  1127. std::make_pair(gfx::Point(190, 90), gfx::Point(189, 88))}};
  1128. gfx::Size touch_size(200, 150);
  1129. display::TouchCalibrationData data(point_pair_quad, touch_size);
  1130. display_prefs()->StoreLegacyTouchDataForTest(id, data);
  1131. display::TouchDeviceManager* tdm = display_manager()->touch_device_manager();
  1132. display::test::TouchDeviceManagerTestApi tdm_test_api(tdm);
  1133. tdm_test_api.ResetTouchDeviceManager();
  1134. display_prefs()->LoadTouchAssociationPreferenceForTest();
  1135. const display::TouchDeviceManager::TouchAssociationMap& association_map =
  1136. tdm->touch_associations();
  1137. const display::TouchDeviceIdentifier& fallback_identifier =
  1138. display::TouchDeviceIdentifier::GetFallbackTouchDeviceIdentifier();
  1139. EXPECT_TRUE(association_map.count(fallback_identifier));
  1140. EXPECT_TRUE(association_map.at(fallback_identifier).count(id));
  1141. EXPECT_EQ(association_map.at(fallback_identifier).at(id).calibration_data,
  1142. data);
  1143. int64_t id_2 = display::test::DisplayManagerTestApi(display_manager())
  1144. .GetSecondaryDisplay()
  1145. .id();
  1146. gfx::Size touch_size_2(300, 300);
  1147. display::TouchCalibrationData data_2(point_pair_quad, touch_size_2);
  1148. const ui::TouchscreenDevice touchdevice_4(
  1149. 19, ui::InputDeviceType::INPUT_DEVICE_USB,
  1150. std::string("test touch device 4"), gfx::Size(231, 416), 1);
  1151. display::TouchDeviceIdentifier identifier =
  1152. display::TouchDeviceIdentifier::FromDevice(touchdevice_4);
  1153. display_manager()->SetTouchCalibrationData(id_2, point_pair_quad,
  1154. touch_size_2, touchdevice_4);
  1155. EXPECT_TRUE(tdm->touch_associations().count(identifier));
  1156. EXPECT_TRUE(tdm->touch_associations().at(identifier).count(id_2));
  1157. EXPECT_EQ(tdm->touch_associations().at(identifier).at(id_2).calibration_data,
  1158. data_2);
  1159. tdm_test_api.ResetTouchDeviceManager();
  1160. EXPECT_TRUE(tdm->touch_associations().empty());
  1161. display_prefs()->LoadTouchAssociationPreferenceForTest();
  1162. EXPECT_TRUE(tdm->touch_associations().count(fallback_identifier));
  1163. EXPECT_TRUE(tdm->touch_associations().at(fallback_identifier).count(id));
  1164. EXPECT_EQ(
  1165. tdm->touch_associations().at(fallback_identifier).at(id).calibration_data,
  1166. data);
  1167. EXPECT_TRUE(tdm->touch_associations().count(identifier));
  1168. EXPECT_TRUE(tdm->touch_associations().at(identifier).count(id_2));
  1169. EXPECT_EQ(tdm->touch_associations().at(identifier).at(id_2).calibration_data,
  1170. data_2);
  1171. }
  1172. TEST_F(DisplayPrefsTest, ExternalDisplayMirrorInfo) {
  1173. LoggedInAsUser();
  1174. base::CommandLine::ForCurrentProcess()->AppendSwitch(
  1175. switches::kFirstExecAfterBoot);
  1176. const int64_t internal_display_id =
  1177. display::test::DisplayManagerTestApi(display_manager())
  1178. .SetFirstDisplayAsInternalDisplay();
  1179. constexpr int64_t first_display_id = 210000001;
  1180. constexpr int64_t second_display_id = 220000002;
  1181. const int64_t first_display_masked_id =
  1182. display::GetDisplayIdWithoutOutputIndex(first_display_id);
  1183. const int64_t second_display_masked_id =
  1184. display::GetDisplayIdWithoutOutputIndex(second_display_id);
  1185. display::ManagedDisplayInfo first_display_info =
  1186. display::CreateDisplayInfo(first_display_id, gfx::Rect(1, 1, 600, 500));
  1187. display::ManagedDisplayInfo second_display_info =
  1188. display::CreateDisplayInfo(second_display_id, gfx::Rect(2, 2, 600, 500));
  1189. std::vector<display::ManagedDisplayInfo> display_info_list;
  1190. // There's no external display now.
  1191. display_info_list.push_back(display::CreateDisplayInfo(
  1192. internal_display_id, gfx::Rect(0, 0, 200, 100)));
  1193. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1194. // Add first display id to the external display mirror info.
  1195. std::set<int64_t> external_display_mirror_info;
  1196. external_display_mirror_info.emplace(first_display_masked_id);
  1197. StoreExternalDisplayMirrorInfo(external_display_mirror_info);
  1198. LoadDisplayPreferences();
  1199. const base::Value::List* pref_external_display_mirror_info =
  1200. &local_state()->GetValueList(prefs::kExternalDisplayMirrorInfo);
  1201. EXPECT_EQ(1U, pref_external_display_mirror_info->size());
  1202. EXPECT_EQ(base::NumberToString(first_display_masked_id),
  1203. (*pref_external_display_mirror_info)[0].GetString());
  1204. // Add first display, mirror mode restores and the external display mirror
  1205. // info does not change.
  1206. display_info_list.emplace_back(first_display_info);
  1207. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1208. EXPECT_TRUE(display_manager()->IsInMirrorMode());
  1209. pref_external_display_mirror_info =
  1210. &local_state()->GetValueList(prefs::kExternalDisplayMirrorInfo);
  1211. EXPECT_EQ(1U, pref_external_display_mirror_info->size());
  1212. EXPECT_EQ(base::NumberToString(first_display_masked_id),
  1213. (*pref_external_display_mirror_info)[0].GetString());
  1214. // Add second display, mirror mode persists and the second display id is added
  1215. // to the external display mirror info.
  1216. display_info_list.emplace_back(second_display_info);
  1217. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1218. EXPECT_TRUE(display_manager()->IsInMirrorMode());
  1219. pref_external_display_mirror_info =
  1220. &local_state()->GetValueList(prefs::kExternalDisplayMirrorInfo);
  1221. EXPECT_EQ(2U, pref_external_display_mirror_info->size());
  1222. EXPECT_EQ(base::NumberToString(first_display_masked_id),
  1223. (*pref_external_display_mirror_info)[0].GetString());
  1224. EXPECT_EQ(base::NumberToString(second_display_masked_id),
  1225. (*pref_external_display_mirror_info)[1].GetString());
  1226. // Disconnect all external displays.
  1227. display_info_list.erase(display_info_list.begin() + 1,
  1228. display_info_list.end());
  1229. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1230. // Clear external display mirror info and only add second display id to it.
  1231. external_display_mirror_info.clear();
  1232. external_display_mirror_info.emplace(second_display_masked_id);
  1233. StoreExternalDisplayMirrorInfo(external_display_mirror_info);
  1234. LoadDisplayPreferences();
  1235. pref_external_display_mirror_info =
  1236. &local_state()->GetValueList(prefs::kExternalDisplayMirrorInfo);
  1237. EXPECT_EQ(1U, pref_external_display_mirror_info->size());
  1238. EXPECT_EQ(base::NumberToString(second_display_masked_id),
  1239. (*pref_external_display_mirror_info)[0].GetString());
  1240. // Add first display, mirror mode is off and the external display mirror info
  1241. // does not change.
  1242. display_info_list.emplace_back(first_display_info);
  1243. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1244. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1245. pref_external_display_mirror_info =
  1246. &local_state()->GetValueList(prefs::kExternalDisplayMirrorInfo);
  1247. EXPECT_EQ(1U, pref_external_display_mirror_info->size());
  1248. EXPECT_EQ(base::NumberToString(second_display_masked_id),
  1249. (*pref_external_display_mirror_info)[0].GetString());
  1250. // Add second display, mirror mode remains off and the second display id is
  1251. // removed from the external display mirror info.
  1252. display_info_list.emplace_back(second_display_info);
  1253. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1254. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1255. pref_external_display_mirror_info =
  1256. &local_state()->GetValueList(prefs::kExternalDisplayMirrorInfo);
  1257. EXPECT_EQ(0U, pref_external_display_mirror_info->size());
  1258. }
  1259. TEST_F(DisplayPrefsTest, ExternalDisplayConnectedBeforeLoadingPrefs) {
  1260. LoggedInAsUser();
  1261. base::CommandLine::ForCurrentProcess()->AppendSwitch(
  1262. switches::kFirstExecAfterBoot);
  1263. const int64_t internal_display_id =
  1264. display::test::DisplayManagerTestApi(display_manager())
  1265. .SetFirstDisplayAsInternalDisplay();
  1266. constexpr int64_t external_display_id = 210000001;
  1267. display::ManagedDisplayInfo external_display_info =
  1268. display::CreateDisplayInfo(external_display_id,
  1269. gfx::Rect(1, 1, 600, 500));
  1270. // Both internal and external displays connect before the prefs are loaded.
  1271. std::vector<display::ManagedDisplayInfo> display_info_list;
  1272. display_info_list.push_back(display::CreateDisplayInfo(
  1273. internal_display_id, gfx::Rect(0, 0, 200, 100)));
  1274. display_info_list.push_back(external_display_info);
  1275. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1276. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1277. EXPECT_EQ(2u, display_manager()->num_connected_displays());
  1278. // Add external display id to the external display mirror info.
  1279. std::set<int64_t> external_display_mirror_info;
  1280. const int64_t external_display_masked_id =
  1281. display::GetDisplayIdWithoutOutputIndex(external_display_id);
  1282. external_display_mirror_info.emplace(external_display_masked_id);
  1283. StoreExternalDisplayMirrorInfo(external_display_mirror_info);
  1284. // Load the preferences and simulate a native display reconfiguration. Expect
  1285. // that we are mirroring now.
  1286. LoadDisplayPreferences();
  1287. // Simulate a change in display configuration between loading the prefs, and
  1288. // reconfiguring after the prefs have been loaded. Make sure that the external
  1289. // display mirror configs are not overwritten, and the loaded prefs will be
  1290. // applied.
  1291. display_manager()->SetMirrorMode(display::MirrorMode::kOff, absl::nullopt);
  1292. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1293. EXPECT_TRUE(display_manager()->IsInMirrorMode());
  1294. }
  1295. TEST_F(DisplayPrefsTest, DisplayMixedMirrorMode) {
  1296. LoggedInAsUser();
  1297. const int64_t internal_display_id =
  1298. display::test::DisplayManagerTestApi(display_manager())
  1299. .SetFirstDisplayAsInternalDisplay();
  1300. constexpr int64_t first_display_id = 210000001;
  1301. constexpr int64_t second_display_id = 220000002;
  1302. std::vector<display::ManagedDisplayInfo> display_info_list;
  1303. display_info_list.push_back(display::CreateDisplayInfo(
  1304. internal_display_id, gfx::Rect(0, 0, 200, 100)));
  1305. display_info_list.push_back(
  1306. display::CreateDisplayInfo(first_display_id, gfx::Rect(1, 1, 600, 500)));
  1307. display_info_list.push_back(
  1308. display::CreateDisplayInfo(second_display_id, gfx::Rect(2, 2, 600, 500)));
  1309. // Store mixed mirror mode parameters which specify mirroring from the
  1310. // internal display to the first external display.
  1311. display::DisplayIdList dst_ids;
  1312. dst_ids.emplace_back(first_display_id);
  1313. absl::optional<display::MixedMirrorModeParams> mixed_params(
  1314. absl::in_place, internal_display_id, dst_ids);
  1315. display_prefs()->StoreDisplayMixedMirrorModeParamsForTest(mixed_params);
  1316. LoadDisplayPreferences();
  1317. // Connect both first and second external display. Mixed mirror mode is
  1318. // restored.
  1319. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1320. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  1321. EXPECT_EQ(internal_display_id, display_manager()->mirroring_source_id());
  1322. display::DisplayIdList destination_ids =
  1323. display_manager()->GetMirroringDestinationDisplayIdList();
  1324. EXPECT_EQ(1U, destination_ids.size());
  1325. EXPECT_EQ(first_display_id, destination_ids[0]);
  1326. // Check the preferences.
  1327. const base::Value::Dict* pref_data =
  1328. &local_state()->GetValueDict(prefs::kDisplayMixedMirrorModeParams);
  1329. EXPECT_EQ(base::NumberToString(internal_display_id),
  1330. *pref_data->FindString("mirroring_source_id"));
  1331. const base::Value::List* destination_ids_list =
  1332. pref_data->FindList("mirroring_destination_ids");
  1333. EXPECT_EQ(1U, destination_ids_list->size());
  1334. EXPECT_EQ(base::NumberToString(first_display_id),
  1335. (*destination_ids_list)[0].GetString());
  1336. // Overwrite current mixed mirror mode with a new configuration. (Mirror from
  1337. // the first external display to the second external display)
  1338. dst_ids.clear();
  1339. dst_ids.emplace_back(second_display_id);
  1340. absl::optional<display::MixedMirrorModeParams> new_mixed_params(
  1341. absl::in_place, first_display_id, dst_ids);
  1342. display_manager()->SetMirrorMode(display::MirrorMode::kMixed,
  1343. new_mixed_params);
  1344. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  1345. EXPECT_EQ(first_display_id, display_manager()->mirroring_source_id());
  1346. destination_ids = display_manager()->GetMirroringDestinationDisplayIdList();
  1347. EXPECT_EQ(1U, destination_ids.size());
  1348. EXPECT_EQ(second_display_id, destination_ids[0]);
  1349. // Check the preferences.
  1350. pref_data =
  1351. &local_state()->GetValueDict(prefs::kDisplayMixedMirrorModeParams);
  1352. EXPECT_EQ(base::NumberToString(first_display_id),
  1353. *pref_data->FindString("mirroring_source_id"));
  1354. destination_ids_list = pref_data->FindList("mirroring_destination_ids");
  1355. EXPECT_EQ(1U, destination_ids_list->size());
  1356. EXPECT_EQ(base::NumberToString(second_display_id),
  1357. (*destination_ids_list)[0].GetString());
  1358. // Turn off mirror mode.
  1359. display_manager()->SetMirrorMode(display::MirrorMode::kOff, absl::nullopt);
  1360. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1361. // Check the preferences.
  1362. pref_data =
  1363. &local_state()->GetValueDict(prefs::kDisplayMixedMirrorModeParams);
  1364. EXPECT_TRUE(pref_data->empty());
  1365. }
  1366. TEST_F(DisplayPrefsTest, SaveTabletModeWithSingleDisplay) {
  1367. UpdateDisplay("480x320/r@1.25");
  1368. const int64_t id0 = display::test::DisplayManagerTestApi(display_manager())
  1369. .SetFirstDisplayAsInternalDisplay();
  1370. EXPECT_FALSE(Shell::Get()->tablet_mode_controller()->InTabletMode());
  1371. const base::Value::Dict* properties = ReadPropertiesForDisplay(id0);
  1372. EXPECT_THAT(properties->FindDouble("display_zoom_factor"),
  1373. Optional(DoubleEq(1.25f)));
  1374. EXPECT_THAT(properties->FindInt("rotation"),
  1375. Optional(static_cast<int>(display::Display::ROTATE_90)));
  1376. LoggedInAsUser();
  1377. // Turn on tablet mode.
  1378. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
  1379. base::RunLoop().RunUntilIdle();
  1380. EXPECT_TRUE(Shell::Get()->tablet_mode_controller()->InTabletMode());
  1381. // Change display settings.
  1382. display_manager()->UpdateZoomFactor(id0, 1.5);
  1383. display_manager()->SetDisplayRotation(id0, display::Display::ROTATE_270,
  1384. display::Display::RotationSource::USER);
  1385. // Verify the settings have been changed.
  1386. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(id0).zoom_factor(), 1.5);
  1387. EXPECT_EQ(display_manager()->GetDisplayInfo(id0).GetActiveRotation(),
  1388. display::Display::ROTATE_270);
  1389. properties = ReadPropertiesForDisplay(id0);
  1390. // Zoom pref should store the new value.
  1391. EXPECT_THAT(properties->FindDouble("display_zoom_factor"),
  1392. Optional(DoubleEq(1.5f)));
  1393. // Rotation pref should remain at the original value.
  1394. EXPECT_THAT(properties->FindInt("rotation"),
  1395. Optional(static_cast<int>(display::Display::ROTATE_90)));
  1396. // Turn off tablet mode.
  1397. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
  1398. base::RunLoop().RunUntilIdle();
  1399. EXPECT_FALSE(Shell::Get()->tablet_mode_controller()->InTabletMode());
  1400. // Zoom should stay at the new value.
  1401. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(id0).zoom_factor(), 1.5);
  1402. // Rotation should restore to the original value.
  1403. EXPECT_EQ(display_manager()->GetDisplayInfo(id0).GetActiveRotation(),
  1404. display::Display::ROTATE_90);
  1405. properties = ReadPropertiesForDisplay(id0);
  1406. // Zoom pref should keep the new value.
  1407. EXPECT_THAT(properties->FindDouble("display_zoom_factor"),
  1408. Optional(DoubleEq(1.5f)));
  1409. // Rotation pref should remain at the original value.
  1410. EXPECT_THAT(properties->FindInt("rotation"),
  1411. Optional(static_cast<int>(display::Display::ROTATE_90)));
  1412. }
  1413. TEST_F(DisplayPrefsTest, SaveTabletModeWithMixedExternalDisplays) {
  1414. UpdateDisplay("480x320/r@1.25,640x480/l@1.3,320x240@1.2");
  1415. display::DisplayIdList ids = display_manager()->GetConnectedDisplayIdList();
  1416. display::test::DisplayManagerTestApi(display_manager())
  1417. .SetFirstDisplayAsInternalDisplay();
  1418. // Set up mixed mirror mode. (Mirror from the first display to the second
  1419. // display, and extend to third display)
  1420. const display::MixedMirrorModeParams mixed_params(ids[0], {ids[1]});
  1421. display_manager()->SetMirrorMode(display::MirrorMode::kMixed, mixed_params);
  1422. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  1423. EXPECT_EQ(display_manager()->mirroring_source_id(), ids[0]);
  1424. EXPECT_THAT(display_manager()->GetMirroringDestinationDisplayIdList(),
  1425. ElementsAre(ids[1]));
  1426. // Mixed mirror mode params are properly set.
  1427. const auto& initial_mixed_params =
  1428. display_manager()->mixed_mirror_mode_params();
  1429. ASSERT_TRUE(initial_mixed_params);
  1430. EXPECT_EQ(initial_mixed_params->source_id, mixed_params.source_id);
  1431. EXPECT_EQ(initial_mixed_params->destination_ids,
  1432. mixed_params.destination_ids);
  1433. const std::set<int64_t> old_ext_mirror_info =
  1434. display_manager()->external_display_mirror_info();
  1435. EXPECT_FALSE(old_ext_mirror_info.empty());
  1436. // Mixed mirror mode params prefs are properly saved.
  1437. ExpectMixedMirrorModeParamsPrefs(ids[0], {ids[1]});
  1438. ExpectExternalDisplayMirrorPrefs(old_ext_mirror_info);
  1439. EXPECT_FALSE(Shell::Get()->tablet_mode_controller()->InTabletMode());
  1440. // Verify initial stored display prefs.
  1441. const base::Value::Dict* properties = ReadPropertiesForDisplay(ids[0]);
  1442. EXPECT_THAT(properties->FindDouble("display_zoom_factor"),
  1443. Optional(DoubleEq(1.25f)));
  1444. EXPECT_THAT(properties->FindInt("rotation"),
  1445. Optional(static_cast<int>(display::Display::ROTATE_90)));
  1446. properties = ReadPropertiesForDisplay(ids[1]);
  1447. EXPECT_THAT(properties->FindDouble("display_zoom_factor"),
  1448. Optional(DoubleEq(1.3f)));
  1449. EXPECT_THAT(properties->FindInt("rotation"),
  1450. Optional(static_cast<int>(display::Display::ROTATE_270)));
  1451. properties = ReadPropertiesForDisplay(ids[2]);
  1452. EXPECT_THAT(properties->FindDouble("display_zoom_factor"),
  1453. Optional(DoubleEq(1.2f)));
  1454. EXPECT_THAT(properties->FindInt("rotation"),
  1455. Optional(static_cast<int>(display::Display::ROTATE_0)));
  1456. LoggedInAsUser();
  1457. // Turn on tablet mode and make display changes.
  1458. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
  1459. base::RunLoop().RunUntilIdle();
  1460. EXPECT_TRUE(Shell::Get()->tablet_mode_controller()->InTabletMode());
  1461. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  1462. EXPECT_EQ(display_manager()->mirroring_source_id(), ids[0]);
  1463. EXPECT_THAT(display_manager()->GetMirroringDestinationDisplayIdList(),
  1464. ElementsAre(ids[1], ids[2]));
  1465. // Tablet mode forces normal mirror mode, so mixed params is empty.
  1466. EXPECT_EQ(display_manager()->mixed_mirror_mode_params(), absl::nullopt);
  1467. EXPECT_EQ(display_manager()->external_display_mirror_info(),
  1468. old_ext_mirror_info);
  1469. // Mixed mirror mode params pref should remain at the original value.
  1470. ExpectMixedMirrorModeParamsPrefs(ids[0], {ids[1]});
  1471. ExpectExternalDisplayMirrorPrefs(old_ext_mirror_info);
  1472. // Make changes to the display and verify.
  1473. display_manager()->UpdateZoomFactor(ids[0], 1.5);
  1474. display_manager()->SetDisplayRotation(ids[0], display::Display::ROTATE_180,
  1475. display::Display::RotationSource::USER);
  1476. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(ids[0]).zoom_factor(), 1.5);
  1477. EXPECT_EQ(display_manager()->GetDisplayInfo(ids[0]).GetActiveRotation(),
  1478. display::Display::ROTATE_180);
  1479. // Simulate a reboot.
  1480. LoadDisplayPreferences();
  1481. display_manager()->UpdateDisplays();
  1482. // Things should stay in tablet mode.
  1483. EXPECT_TRUE(Shell::Get()->tablet_mode_controller()->InTabletMode());
  1484. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  1485. EXPECT_EQ(display_manager()->mirroring_source_id(), ids[0]);
  1486. // Currently, restarting in tablet mode reverts back to the original mixed
  1487. // mirror mode, which may be surprising to users. This should be revisited by
  1488. // crbug.com/733092.
  1489. EXPECT_THAT(display_manager()->GetMirroringDestinationDisplayIdList(),
  1490. ElementsAre(ids[1]));
  1491. const auto& loaded_mixed_params =
  1492. display_manager()->mixed_mirror_mode_params();
  1493. ASSERT_TRUE(loaded_mixed_params);
  1494. EXPECT_EQ(loaded_mixed_params->source_id, mixed_params.source_id);
  1495. EXPECT_EQ(loaded_mixed_params->destination_ids, mixed_params.destination_ids);
  1496. EXPECT_EQ(display_manager()->external_display_mirror_info(),
  1497. old_ext_mirror_info);
  1498. // Mixed mirror mode params pref should remain at the original value.
  1499. ExpectMixedMirrorModeParamsPrefs(ids[0], {ids[1]});
  1500. ExpectExternalDisplayMirrorPrefs(old_ext_mirror_info);
  1501. // Check stored and loaded display prefs.
  1502. properties = ReadPropertiesForDisplay(ids[0]);
  1503. // Zoom factor should persist the new value.
  1504. EXPECT_THAT(properties->FindDouble("display_zoom_factor"),
  1505. Optional(DoubleEq(1.5f)));
  1506. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(ids[0]).zoom_factor(), 1.5);
  1507. // Rotation should remain at the original value.
  1508. EXPECT_THAT(properties->FindInt("rotation"),
  1509. Optional(static_cast<int>(display::Display::ROTATE_90)));
  1510. EXPECT_EQ(display_manager()->GetDisplayInfo(ids[0]).GetActiveRotation(),
  1511. display::Display::ROTATE_90);
  1512. // Properties for the second display shouldn't change.
  1513. properties = ReadPropertiesForDisplay(ids[1]);
  1514. EXPECT_THAT(properties->FindDouble("display_zoom_factor"),
  1515. Optional(DoubleEq(1.3f)));
  1516. EXPECT_THAT(properties->FindInt("rotation"),
  1517. Optional(static_cast<int>(display::Display::ROTATE_270)));
  1518. // Properties for the third display shouldn't change.
  1519. properties = ReadPropertiesForDisplay(ids[2]);
  1520. EXPECT_THAT(properties->FindDouble("display_zoom_factor"),
  1521. Optional(DoubleEq(1.2f)));
  1522. EXPECT_THAT(properties->FindInt("rotation"),
  1523. Optional(static_cast<int>(display::Display::ROTATE_0)));
  1524. // Turn off tablet mode.
  1525. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
  1526. base::RunLoop().RunUntilIdle();
  1527. EXPECT_FALSE(Shell::Get()->tablet_mode_controller()->InTabletMode());
  1528. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  1529. EXPECT_EQ(display_manager()->mirroring_source_id(), ids[0]);
  1530. EXPECT_THAT(display_manager()->GetMirroringDestinationDisplayIdList(),
  1531. ElementsAre(ids[1]));
  1532. // Original mixed mirror mode params are preserved.
  1533. const auto& restored_mixed_params =
  1534. display_manager()->mixed_mirror_mode_params();
  1535. ASSERT_TRUE(restored_mixed_params);
  1536. EXPECT_EQ(restored_mixed_params->source_id, mixed_params.source_id);
  1537. EXPECT_EQ(restored_mixed_params->destination_ids,
  1538. mixed_params.destination_ids);
  1539. EXPECT_EQ(display_manager()->external_display_mirror_info(),
  1540. old_ext_mirror_info);
  1541. // Mixed mirror mode params pref should remain at the original value.
  1542. ExpectMixedMirrorModeParamsPrefs(ids[0], {ids[1]});
  1543. ExpectExternalDisplayMirrorPrefs(old_ext_mirror_info);
  1544. // Check restored display prefs.
  1545. properties = ReadPropertiesForDisplay(ids[0]);
  1546. // Zoom factor should remain at the new value.
  1547. EXPECT_THAT(properties->FindDouble("display_zoom_factor"),
  1548. Optional(DoubleEq(1.5f)));
  1549. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(ids[0]).zoom_factor(), 1.5);
  1550. // Rotation should be restored to the original value.
  1551. EXPECT_THAT(properties->FindInt("rotation"),
  1552. Optional(static_cast<int>(display::Display::ROTATE_90)));
  1553. EXPECT_EQ(display_manager()->GetDisplayInfo(ids[0]).GetActiveRotation(),
  1554. display::Display::ROTATE_90);
  1555. // Properties for the second display shouldn't change.
  1556. properties = ReadPropertiesForDisplay(ids[1]);
  1557. EXPECT_THAT(properties->FindDouble("display_zoom_factor"),
  1558. Optional(DoubleEq(1.3f)));
  1559. EXPECT_THAT(properties->FindInt("rotation"),
  1560. Optional(static_cast<int>(display::Display::ROTATE_270)));
  1561. // Properties for the third display shouldn't change.
  1562. properties = ReadPropertiesForDisplay(ids[2]);
  1563. EXPECT_THAT(properties->FindDouble("display_zoom_factor"),
  1564. Optional(DoubleEq(1.2f)));
  1565. EXPECT_THAT(properties->FindInt("rotation"),
  1566. Optional(static_cast<int>(display::Display::ROTATE_0)));
  1567. }
  1568. } // namespace ash