display_manager_unittest.cc 202 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886
  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 "ui/display/manager/display_manager.h"
  5. #include "ash/accelerators/accelerator_commands.h"
  6. #include "ash/accelerometer/accelerometer_reader.h"
  7. #include "ash/accelerometer/accelerometer_types.h"
  8. #include "ash/app_list/app_list_controller_impl.h"
  9. #include "ash/constants/app_types.h"
  10. #include "ash/constants/ash_switches.h"
  11. #include "ash/display/cursor_window_controller.h"
  12. #include "ash/display/display_configuration_controller.h"
  13. #include "ash/display/display_util.h"
  14. #include "ash/display/mirror_window_controller.h"
  15. #include "ash/display/mirror_window_test_api.h"
  16. #include "ash/display/screen_orientation_controller.h"
  17. #include "ash/display/screen_orientation_controller_test_api.h"
  18. #include "ash/display/window_tree_host_manager.h"
  19. #include "ash/root_window_controller.h"
  20. #include "ash/screen_util.h"
  21. #include "ash/session/session_controller_impl.h"
  22. #include "ash/shelf/shelf.h"
  23. #include "ash/shell.h"
  24. #include "ash/strings/grit/ash_strings.h"
  25. #include "ash/test/ash_test_base.h"
  26. #include "ash/wm/tablet_mode/tablet_mode_controller.h"
  27. #include "ash/wm/tablet_mode/tablet_mode_controller_test_api.h"
  28. #include "ash/wm/window_state.h"
  29. #include "ash/wm/window_util.h"
  30. #include "base/command_line.h"
  31. #include "base/format_macros.h"
  32. #include "base/numerics/math_constants.h"
  33. #include "base/run_loop.h"
  34. #include "base/strings/string_number_conversions.h"
  35. #include "base/strings/stringprintf.h"
  36. #include "base/test/scoped_feature_list.h"
  37. #include "build/build_config.h"
  38. #include "ui/aura/client/aura_constants.h"
  39. #include "ui/aura/env.h"
  40. #include "ui/aura/window_observer.h"
  41. #include "ui/aura/window_tree_host.h"
  42. #include "ui/base/l10n/l10n_util.h"
  43. #include "ui/compositor/layer.h"
  44. #include "ui/display/display.h"
  45. #include "ui/display/display_features.h"
  46. #include "ui/display/display_layout.h"
  47. #include "ui/display/display_layout_builder.h"
  48. #include "ui/display/display_observer.h"
  49. #include "ui/display/display_switches.h"
  50. #include "ui/display/fake/fake_display_snapshot.h"
  51. #include "ui/display/manager/display_change_observer.h"
  52. #include "ui/display/manager/display_layout_store.h"
  53. #include "ui/display/manager/display_manager_util.h"
  54. #include "ui/display/manager/display_manager_utilities.h"
  55. #include "ui/display/manager/managed_display_info.h"
  56. #include "ui/display/manager/test/touch_device_manager_test_api.h"
  57. #include "ui/display/screen.h"
  58. #include "ui/display/test/display_manager_test_api.h"
  59. #include "ui/display/types/display_constants.h"
  60. #include "ui/display/util/display_util.h"
  61. #include "ui/events/devices/touchscreen_device.h"
  62. #include "ui/events/test/event_generator.h"
  63. #include "ui/gfx/font_render_params.h"
  64. #include "ui/gfx/geometry/rect_conversions.h"
  65. #include "ui/gfx/overlay_transform.h"
  66. namespace ash {
  67. using std::string;
  68. using std::vector;
  69. using base::StringPrintf;
  70. namespace {
  71. std::string ToDisplayName(int64_t id) {
  72. return "x-" + base::NumberToString(id);
  73. }
  74. } // namespace
  75. class DisplayManagerTest : public AshTestBase,
  76. public display::DisplayObserver,
  77. public aura::WindowObserver {
  78. public:
  79. DisplayManagerTest() = default;
  80. DisplayManagerTest(const DisplayManagerTest&) = delete;
  81. DisplayManagerTest& operator=(const DisplayManagerTest&) = delete;
  82. ~DisplayManagerTest() override = default;
  83. void SetUp() override {
  84. AshTestBase::SetUp();
  85. display_observer_.emplace(this);
  86. Shell::GetPrimaryRootWindow()->AddObserver(this);
  87. }
  88. void TearDown() override {
  89. Shell::GetPrimaryRootWindow()->RemoveObserver(this);
  90. display_observer_.reset();
  91. AshTestBase::TearDown();
  92. }
  93. const vector<display::Display>& changed() const { return changed_; }
  94. const vector<display::Display>& added() const { return added_; }
  95. uint32_t changed_metrics() const { return changed_metrics_; }
  96. string GetCountSummary() const {
  97. return StringPrintf("%" PRIuS " %" PRIuS " %" PRIuS " %" PRIuS " %" PRIuS,
  98. changed_.size(), added_.size(), removed_count_,
  99. will_process_count_, did_process_count_);
  100. }
  101. void reset() {
  102. changed_.clear();
  103. added_.clear();
  104. removed_count_ = will_process_count_ = did_process_count_ = 0U;
  105. changed_metrics_ = 0U;
  106. root_window_destroyed_ = false;
  107. }
  108. bool root_window_destroyed() const { return root_window_destroyed_; }
  109. const display::ManagedDisplayInfo& GetDisplayInfo(
  110. const display::Display& display) {
  111. return display_manager()->GetDisplayInfo(display.id());
  112. }
  113. const display::ManagedDisplayInfo& GetDisplayInfoAt(int index) {
  114. return GetDisplayInfo(display_manager()->GetDisplayAt(index));
  115. }
  116. const display::Display& GetDisplayForId(int64_t id) {
  117. return display_manager()->GetDisplayForId(id);
  118. }
  119. const display::ManagedDisplayInfo& GetDisplayInfoForId(int64_t id) {
  120. return GetDisplayInfo(display_manager()->GetDisplayForId(id));
  121. }
  122. // aura::DisplayObserver overrides:
  123. void OnWillProcessDisplayChanges() override { ++will_process_count_; }
  124. void OnDidProcessDisplayChanges() override { ++did_process_count_; }
  125. void OnDisplayMetricsChanged(const display::Display& display,
  126. uint32_t changed_metrics) override {
  127. changed_.push_back(display);
  128. changed_metrics_ |= changed_metrics;
  129. }
  130. void OnDisplayAdded(const display::Display& new_display) override {
  131. added_.push_back(new_display);
  132. }
  133. void OnDisplayRemoved(const display::Display& old_display) override {
  134. ++removed_count_;
  135. }
  136. // aura::WindowObserver overrides:
  137. void OnWindowDestroying(aura::Window* window) override {
  138. if (check_root_window_on_destruction_)
  139. ASSERT_EQ(Shell::GetPrimaryRootWindow(), window);
  140. root_window_destroyed_ = true;
  141. }
  142. // Returns true if there exists any overlapping mirroring displays.
  143. bool OverlappingMirroringDisplaysExist() {
  144. const auto& mirroring_displays =
  145. display_manager()->software_mirroring_display_list();
  146. for (size_t i = 0; i < mirroring_displays.size() - 1; ++i) {
  147. for (size_t j = i + 1; j < mirroring_displays.size(); ++j) {
  148. const gfx::Rect& bounds_1 = mirroring_displays[i].bounds();
  149. const gfx::Rect& bounds_2 = mirroring_displays[j].bounds();
  150. if (bounds_1.Intersects(bounds_2))
  151. return true;
  152. }
  153. }
  154. return false;
  155. }
  156. void SetSoftwareMirrorMode(bool active) {
  157. display_manager()->SetMirrorMode(
  158. active ? display::MirrorMode::kNormal : display::MirrorMode::kOff,
  159. absl::nullopt);
  160. base::RunLoop().RunUntilIdle();
  161. }
  162. void disable_check_root_window_on_destruction() {
  163. check_root_window_on_destruction_ = false;
  164. }
  165. private:
  166. vector<display::Display> changed_;
  167. vector<display::Display> added_;
  168. size_t removed_count_ = 0u;
  169. size_t will_process_count_ = 0u;
  170. size_t did_process_count_ = 0u;
  171. bool root_window_destroyed_ = false;
  172. uint32_t changed_metrics_ = 0u;
  173. bool check_root_window_on_destruction_ = true;
  174. absl::optional<display::ScopedDisplayObserver> display_observer_;
  175. };
  176. TEST_F(DisplayManagerTest, UpdateDisplayTest) {
  177. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  178. // Update primary and add seconary.
  179. UpdateDisplay("100+0-500x400,0+501-400x300");
  180. EXPECT_EQ(2U, display_manager()->GetNumDisplays());
  181. EXPECT_EQ(gfx::Rect(0, 0, 500, 400),
  182. display_manager()->GetDisplayAt(0).bounds());
  183. EXPECT_EQ("2 1 0 1 1", GetCountSummary());
  184. // Metrics change immediately when new displays set shelf work area insets.
  185. // After that, DisplayManager::OnNativeDisplaysChanged trigger changes of the
  186. // primary display's metrics. So the observed order of changes is [1, 0].
  187. EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[1].id());
  188. EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), changed()[0].id());
  189. EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
  190. EXPECT_EQ(gfx::Rect(0, 0, 500, 400), changed()[1].bounds());
  191. EXPECT_EQ(gfx::Rect(500, 0, 400, 300), changed()[0].bounds());
  192. // Secondary display is on right.
  193. EXPECT_EQ(gfx::Rect(500, 0, 400, 300), added()[0].bounds());
  194. EXPECT_EQ(gfx::Rect(0, 501, 400, 300),
  195. GetDisplayInfo(added()[0]).bounds_in_native());
  196. reset();
  197. // Delete secondary.
  198. UpdateDisplay("100+0-500x400");
  199. EXPECT_EQ("0 0 1 1 1", GetCountSummary());
  200. reset();
  201. // Change primary.
  202. UpdateDisplay("1+1-1000x600");
  203. EXPECT_EQ("1 0 0 1 1", GetCountSummary());
  204. EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
  205. EXPECT_EQ(gfx::Rect(0, 0, 1000, 600), changed()[0].bounds());
  206. reset();
  207. // Add secondary.
  208. UpdateDisplay("1+1-1000x600,1002+0-600x400");
  209. EXPECT_EQ(2U, display_manager()->GetNumDisplays());
  210. EXPECT_EQ("1 1 0 1 1", GetCountSummary());
  211. EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), changed()[0].id());
  212. EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
  213. // Secondary display is on right.
  214. EXPECT_EQ(gfx::Rect(1000, 0, 600, 400), added()[0].bounds());
  215. EXPECT_EQ(gfx::Rect(1002, 0, 600, 400),
  216. GetDisplayInfo(added()[0]).bounds_in_native());
  217. reset();
  218. // Secondary removed, primary changed.
  219. UpdateDisplay("1+1-800x300");
  220. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  221. EXPECT_EQ("1 0 1 1 1", GetCountSummary());
  222. EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
  223. EXPECT_EQ(gfx::Rect(0, 0, 800, 300), changed()[0].bounds());
  224. reset();
  225. // # of display can go to zero when screen is off.
  226. const vector<display::ManagedDisplayInfo> empty;
  227. display_manager()->OnNativeDisplaysChanged(empty);
  228. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  229. // Going to 0 displays doesn't actually change the list and is effectively
  230. // ignored.
  231. EXPECT_EQ("0 0 0 0 0", GetCountSummary());
  232. EXPECT_FALSE(root_window_destroyed());
  233. // Display configuration stays the same
  234. EXPECT_EQ(gfx::Rect(0, 0, 800, 300),
  235. display_manager()->GetDisplayAt(0).bounds());
  236. reset();
  237. // Connect to display again
  238. UpdateDisplay("100+100-500x400");
  239. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  240. EXPECT_EQ("1 0 0 1 1", GetCountSummary());
  241. EXPECT_FALSE(root_window_destroyed());
  242. EXPECT_EQ(gfx::Rect(0, 0, 500, 400), changed()[0].bounds());
  243. EXPECT_EQ(gfx::Rect(100, 100, 500, 400),
  244. GetDisplayInfo(changed()[0]).bounds_in_native());
  245. reset();
  246. // Go back to zero and wake up with multiple displays.
  247. display_manager()->OnNativeDisplaysChanged(empty);
  248. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  249. EXPECT_FALSE(root_window_destroyed());
  250. reset();
  251. // Add secondary.
  252. UpdateDisplay("0+0-1000x600,1000+1000-600x400");
  253. EXPECT_EQ(2U, display_manager()->GetNumDisplays());
  254. EXPECT_EQ(gfx::Rect(0, 0, 1000, 600),
  255. display_manager()->GetDisplayAt(0).bounds());
  256. // Secondary display is on right.
  257. EXPECT_EQ(gfx::Rect(1000, 0, 600, 400),
  258. display_manager()->GetDisplayAt(1).bounds());
  259. EXPECT_EQ(gfx::Rect(1000, 1000, 600, 400),
  260. GetDisplayInfoAt(1).bounds_in_native());
  261. reset();
  262. // Changing primary will update secondary as well.
  263. UpdateDisplay("0+0-800x600,1000+1000-600x400");
  264. EXPECT_EQ("2 0 0 1 1", GetCountSummary());
  265. reset();
  266. EXPECT_EQ(gfx::Rect(0, 0, 800, 600),
  267. display_manager()->GetDisplayAt(0).bounds());
  268. EXPECT_EQ(gfx::Rect(800, 0, 600, 400),
  269. display_manager()->GetDisplayAt(1).bounds());
  270. }
  271. // Test in emulation mode (use_fullscreen_host_window=false)
  272. TEST_F(DisplayManagerTest, EmulatorTest) {
  273. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  274. display_manager()->AddRemoveDisplay();
  275. // Update primary and add seconary.
  276. EXPECT_EQ(2U, display_manager()->GetNumDisplays());
  277. EXPECT_EQ("1 1 0 1 1", GetCountSummary());
  278. reset();
  279. display_manager()->AddRemoveDisplay();
  280. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  281. EXPECT_EQ("0 0 1 1 1", GetCountSummary());
  282. reset();
  283. display_manager()->AddRemoveDisplay();
  284. EXPECT_EQ(2U, display_manager()->GetNumDisplays());
  285. EXPECT_EQ("1 1 0 1 1", GetCountSummary());
  286. }
  287. // Tests support for 3 displays.
  288. TEST_F(DisplayManagerTest, UpdateThreeDisplaysWithDefaultLayout) {
  289. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  290. // Test with three displays. Native origin will not affect ash
  291. // display layout.
  292. UpdateDisplay("0+0-640x480,1000+0-320x200,2000+0-400x300");
  293. EXPECT_EQ(3U, display_manager()->GetNumDisplays());
  294. EXPECT_EQ(gfx::Rect(0, 0, 640, 480),
  295. display_manager()->GetDisplayAt(0).bounds());
  296. EXPECT_EQ(gfx::Rect(640, 0, 320, 200),
  297. display_manager()->GetDisplayAt(1).bounds());
  298. EXPECT_EQ(gfx::Rect(960, 0, 400, 300),
  299. display_manager()->GetDisplayAt(2).bounds());
  300. EXPECT_EQ("3 2 0 1 1", GetCountSummary());
  301. // Metrics change immediately when new displays set shelf work area insets.
  302. // After that, DisplayManager::OnNativeDisplaysChanged trigger changes of the
  303. // primary display's metrics. So the observed order of changes is [1, 2, 0].
  304. EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[2].id());
  305. EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), changed()[0].id());
  306. EXPECT_EQ(display_manager()->GetDisplayAt(2).id(), changed()[1].id());
  307. EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
  308. EXPECT_EQ(display_manager()->GetDisplayAt(2).id(), added()[1].id());
  309. EXPECT_EQ(gfx::Rect(0, 0, 640, 480), changed()[2].bounds());
  310. EXPECT_EQ(gfx::Rect(640, 0, 320, 200), changed()[0].bounds());
  311. EXPECT_EQ(gfx::Rect(960, 0, 400, 300), changed()[1].bounds());
  312. // Secondary and terniary displays are on right.
  313. EXPECT_EQ(gfx::Rect(640, 0, 320, 200), added()[0].bounds());
  314. EXPECT_EQ(gfx::Rect(1000, 0, 320, 200),
  315. GetDisplayInfo(added()[0]).bounds_in_native());
  316. EXPECT_EQ(gfx::Rect(960, 0, 400, 300), added()[1].bounds());
  317. EXPECT_EQ(gfx::Rect(2000, 0, 400, 300),
  318. GetDisplayInfo(added()[1]).bounds_in_native());
  319. // Verify calling ReconfigureDisplays doesn't change anything.
  320. display_manager()->ReconfigureDisplays();
  321. EXPECT_EQ(3U, display_manager()->GetNumDisplays());
  322. EXPECT_EQ(gfx::Rect(0, 0, 640, 480),
  323. display_manager()->GetDisplayAt(0).bounds());
  324. EXPECT_EQ(gfx::Rect(640, 0, 320, 200),
  325. display_manager()->GetDisplayAt(1).bounds());
  326. EXPECT_EQ(gfx::Rect(960, 0, 400, 300),
  327. display_manager()->GetDisplayAt(2).bounds());
  328. display::DisplayPlacement default_placement(display::DisplayPlacement::BOTTOM,
  329. 10);
  330. display_manager()->layout_store()->SetDefaultDisplayPlacement(
  331. default_placement);
  332. // Test with new displays.
  333. UpdateDisplay("640x480");
  334. UpdateDisplay("640x480,320x200,400x300");
  335. EXPECT_EQ(gfx::Rect(0, 0, 640, 480),
  336. display_manager()->GetDisplayAt(0).bounds());
  337. EXPECT_EQ(gfx::Rect(10, 480, 320, 200),
  338. display_manager()->GetDisplayAt(1).bounds());
  339. EXPECT_EQ(gfx::Rect(20, 680, 400, 300),
  340. display_manager()->GetDisplayAt(2).bounds());
  341. }
  342. TEST_F(DisplayManagerTest, LayoutMorethanThreeDisplaysTest) {
  343. int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  344. display::DisplayIdList list =
  345. display::test::CreateDisplayIdListN(primary_id, 3);
  346. {
  347. // Layout: [2]
  348. // [1][P]
  349. display::DisplayLayoutBuilder builder(primary_id);
  350. builder.AddDisplayPlacement(list[1], primary_id,
  351. display::DisplayPlacement::LEFT, 10);
  352. builder.AddDisplayPlacement(list[2], list[1],
  353. display::DisplayPlacement::TOP, 10);
  354. display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
  355. list, builder.Build());
  356. UpdateDisplay("640x480,320x200,400x300");
  357. EXPECT_EQ(3U, display_manager()->GetNumDisplays());
  358. EXPECT_EQ(gfx::Rect(0, 0, 640, 480),
  359. display_manager()->GetDisplayAt(0).bounds());
  360. EXPECT_EQ(gfx::Rect(-320, 10, 320, 200),
  361. display_manager()->GetDisplayAt(1).bounds());
  362. // The above layout causes an overlap between [P] and [2], making [2]'s
  363. // bounds be "-310,-290 400x300" if the overlap is not fixed. The overlap
  364. // must be detected and fixed and [2] is shifted up to remove the overlap.
  365. EXPECT_EQ(gfx::Rect(-310, -300, 400, 300),
  366. display_manager()->GetDisplayAt(2).bounds());
  367. }
  368. {
  369. // Layout: [1]
  370. // [P][2]
  371. display::DisplayLayoutBuilder builder(primary_id);
  372. builder.AddDisplayPlacement(list[1], primary_id,
  373. display::DisplayPlacement::TOP, 10);
  374. builder.AddDisplayPlacement(list[2], primary_id,
  375. display::DisplayPlacement::RIGHT, 10);
  376. display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
  377. list, builder.Build());
  378. UpdateDisplay("640x480,320x200,400x300");
  379. EXPECT_EQ(3U, display_manager()->GetNumDisplays());
  380. EXPECT_EQ(gfx::Rect(0, 0, 640, 480),
  381. display_manager()->GetDisplayAt(0).bounds());
  382. EXPECT_EQ(gfx::Rect(10, -200, 320, 200),
  383. display_manager()->GetDisplayAt(1).bounds());
  384. EXPECT_EQ(gfx::Rect(640, 10, 400, 300),
  385. display_manager()->GetDisplayAt(2).bounds());
  386. }
  387. {
  388. // Layout: [P]
  389. // [2]
  390. // [1]
  391. display::DisplayLayoutBuilder builder(primary_id);
  392. builder.AddDisplayPlacement(list[1], list[2],
  393. display::DisplayPlacement::BOTTOM, 10);
  394. builder.AddDisplayPlacement(list[2], primary_id,
  395. display::DisplayPlacement::BOTTOM, 10);
  396. display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
  397. list, builder.Build());
  398. UpdateDisplay("640x480,320x200,400x300");
  399. EXPECT_EQ(3U, display_manager()->GetNumDisplays());
  400. EXPECT_EQ(gfx::Rect(0, 0, 640, 480),
  401. display_manager()->GetDisplayAt(0).bounds());
  402. EXPECT_EQ(gfx::Rect(20, 780, 320, 200),
  403. display_manager()->GetDisplayAt(1).bounds());
  404. EXPECT_EQ(gfx::Rect(10, 480, 400, 300),
  405. display_manager()->GetDisplayAt(2).bounds());
  406. }
  407. {
  408. list = display::test::CreateDisplayIdListN(primary_id, 5);
  409. // Layout: [P][2]
  410. // [3][4]
  411. // [1]
  412. display::DisplayLayoutBuilder builder(primary_id);
  413. builder.AddDisplayPlacement(list[2], primary_id,
  414. display::DisplayPlacement::RIGHT, 10);
  415. builder.AddDisplayPlacement(list[1], list[3],
  416. display::DisplayPlacement::BOTTOM, 10);
  417. builder.AddDisplayPlacement(list[3], list[4],
  418. display::DisplayPlacement::LEFT, 10);
  419. builder.AddDisplayPlacement(list[4], primary_id,
  420. display::DisplayPlacement::BOTTOM, 10);
  421. display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
  422. list, builder.Build());
  423. UpdateDisplay("640x480,320x200,400x300,300x200,200x100");
  424. EXPECT_EQ(5U, display_manager()->GetNumDisplays());
  425. EXPECT_EQ(gfx::Rect(0, 0, 640, 480),
  426. display_manager()->GetDisplayAt(0).bounds());
  427. // 2nd is right of the primary.
  428. EXPECT_EQ(gfx::Rect(640, 10, 400, 300),
  429. display_manager()->GetDisplayAt(2).bounds());
  430. // 4th is bottom of the primary.
  431. EXPECT_EQ(gfx::Rect(10, 480, 200, 100),
  432. display_manager()->GetDisplayAt(4).bounds());
  433. // 3rd is the left of 4th.
  434. EXPECT_EQ(gfx::Rect(-290, 480, 300, 200),
  435. display_manager()->GetDisplayAt(3).bounds());
  436. // 1st is the bottom of 3rd.
  437. EXPECT_EQ(gfx::Rect(-280, 680, 320, 200),
  438. display_manager()->GetDisplayAt(1).bounds());
  439. }
  440. }
  441. // Makes sure that layouts with overlapped displays are detected and fixed when
  442. // applied.
  443. TEST_F(DisplayManagerTest, NoOverlappedDisplays) {
  444. int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  445. {
  446. // Layout with multiple overlaps and special cases:
  447. //
  448. // +-----+
  449. // +----+-+6 |
  450. // | 5 | | |
  451. // +----+----+ | |
  452. // | 7 | | | |
  453. // +----+----+-+---+---+-+---------+
  454. // | | P | | 2 |
  455. // +------+ | | +----------+
  456. // | | | | 3 |
  457. // | | | | |
  458. // +--+----+-+-+-+-----+--+ |
  459. // | 1 | | 4 | | |
  460. // | | | +--+-------+
  461. // | | | |
  462. // +--------+ +--------+
  463. display::DisplayIdList list =
  464. display::test::CreateDisplayIdListN(primary_id, 8);
  465. display::DisplayLayoutBuilder builder(primary_id);
  466. builder.AddDisplayPlacement(list[1], primary_id,
  467. display::DisplayPlacement::BOTTOM, 50);
  468. builder.AddDisplayPlacement(list[2], list[1],
  469. display::DisplayPlacement::TOP, 300);
  470. builder.AddDisplayPlacement(list[3], list[2],
  471. display::DisplayPlacement::RIGHT, 30);
  472. builder.AddDisplayPlacement(list[4], list[2],
  473. display::DisplayPlacement::BOTTOM, 400);
  474. builder.AddDisplayPlacement(list[5], primary_id,
  475. display::DisplayPlacement::LEFT, -300);
  476. builder.AddDisplayPlacement(list[6], primary_id,
  477. display::DisplayPlacement::TOP, -250);
  478. builder.AddDisplayPlacement(list[7], list[6],
  479. display::DisplayPlacement::LEFT, 250);
  480. display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
  481. list, builder.Build());
  482. UpdateDisplay(
  483. "480x400,480x400,480x400,480x400,480x400,480x400,480x400,530x150");
  484. // The resulting layout after overlaps had been removed:
  485. //
  486. //
  487. // +---------+
  488. // | 7 +-----+
  489. // +-+-------+ 6 |
  490. // | 5 | |
  491. // | | |
  492. // | | |
  493. // | |-+---+----+---------+
  494. // | | | P | 2 |
  495. // +-------+ | | +----------+
  496. // | | | 3 |
  497. // | | | |
  498. // +--+-----+-+-------+ |
  499. // | 1 | | |
  500. // | | +----+---+------+
  501. // | | | 4 |
  502. // +-------+ | |
  503. // | |
  504. // +--------+
  505. EXPECT_EQ(8U, display_manager()->GetNumDisplays());
  506. EXPECT_EQ(gfx::Rect(0, 0, 480, 400),
  507. display_manager()->GetDisplayAt(0).bounds());
  508. EXPECT_EQ(gfx::Rect(50, 400, 480, 400),
  509. display_manager()->GetDisplayAt(1).bounds());
  510. EXPECT_EQ(gfx::Rect(480, 0, 480, 400),
  511. display_manager()->GetDisplayAt(2).bounds());
  512. EXPECT_EQ(gfx::Rect(960, 30, 480, 400),
  513. display_manager()->GetDisplayAt(3).bounds());
  514. EXPECT_EQ(gfx::Rect(730, 430, 480, 400),
  515. display_manager()->GetDisplayAt(4).bounds());
  516. EXPECT_EQ(gfx::Rect(-730, -300, 480, 400),
  517. display_manager()->GetDisplayAt(5).bounds());
  518. EXPECT_EQ(gfx::Rect(-250, -400, 480, 400),
  519. display_manager()->GetDisplayAt(6).bounds());
  520. EXPECT_EQ(gfx::Rect(-780, -450, 530, 150),
  521. display_manager()->GetDisplayAt(7).bounds());
  522. // Expect that the displays have been reparented correctly, such that a
  523. // child is always touching its parent.
  524. display::DisplayLayoutBuilder expected_layout_builder(primary_id);
  525. expected_layout_builder.AddDisplayPlacement(
  526. list[1], primary_id, display::DisplayPlacement::BOTTOM, 50);
  527. expected_layout_builder.AddDisplayPlacement(
  528. list[2], list[1], display::DisplayPlacement::TOP, 430);
  529. expected_layout_builder.AddDisplayPlacement(
  530. list[3], list[2], display::DisplayPlacement::RIGHT, 30);
  531. // [4] became a child of [3] instead of [2] as they no longer touch.
  532. expected_layout_builder.AddDisplayPlacement(
  533. list[4], list[3], display::DisplayPlacement::BOTTOM, -230);
  534. // [5] became a child of [6] instead of [P] as they no longer touch.
  535. expected_layout_builder.AddDisplayPlacement(
  536. list[5], list[6], display::DisplayPlacement::LEFT, 100);
  537. expected_layout_builder.AddDisplayPlacement(
  538. list[6], primary_id, display::DisplayPlacement::TOP, -250);
  539. expected_layout_builder.AddDisplayPlacement(
  540. list[7], list[6], display::DisplayPlacement::LEFT, -50);
  541. const display::DisplayLayout& layout =
  542. display_manager()->GetCurrentResolvedDisplayLayout();
  543. EXPECT_TRUE(
  544. layout.HasSamePlacementList(*(expected_layout_builder.Build())));
  545. }
  546. {
  547. // The following is a special case where a child display is closer to the
  548. // origin than its parent. Test that we can handle it successfully without
  549. // introducing a circular dependency.
  550. //
  551. // +---------+
  552. // | P | +---------+
  553. // | | | 3 |
  554. // | | | |
  555. // | | | |
  556. // +------+--+----+ |
  557. // | 1 | | 2 +---------+
  558. // | | | |
  559. // | | | |
  560. // | | | |
  561. // +------+--+----+
  562. //
  563. display::DisplayIdList list =
  564. display::test::CreateDisplayIdListN(primary_id, 4);
  565. display::DisplayLayoutBuilder builder(primary_id);
  566. builder.AddDisplayPlacement(list[1], primary_id,
  567. display::DisplayPlacement::BOTTOM, 0);
  568. builder.AddDisplayPlacement(list[2], primary_id,
  569. display::DisplayPlacement::BOTTOM, 464);
  570. builder.AddDisplayPlacement(list[3], list[2],
  571. display::DisplayPlacement::RIGHT, -700);
  572. display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
  573. list, builder.Build());
  574. UpdateDisplay("696x800,696x800,300x800,696x800");
  575. // The expected layout should be:
  576. //
  577. // +---------+
  578. // | P | +---------+
  579. // | | | 3 |
  580. // | | | |
  581. // | | | |
  582. // +---------+-------+ |
  583. // | 1 | 2 +---------+
  584. // | | |
  585. // | | |
  586. // | | |
  587. // +---------+-------+
  588. //
  589. //
  590. EXPECT_EQ(4U, display_manager()->GetNumDisplays());
  591. EXPECT_EQ(gfx::Rect(0, 0, 696, 800),
  592. display_manager()->GetDisplayAt(0).bounds());
  593. EXPECT_EQ(gfx::Rect(0, 800, 696, 800),
  594. display_manager()->GetDisplayAt(1).bounds());
  595. EXPECT_EQ(gfx::Rect(696, 800, 300, 800),
  596. display_manager()->GetDisplayAt(2).bounds());
  597. EXPECT_EQ(gfx::Rect(996, 100, 696, 800),
  598. display_manager()->GetDisplayAt(3).bounds());
  599. // This case if not handled correctly might lead to a cyclic dependency.
  600. // Make sure this doesn't happen.
  601. display::DisplayLayoutBuilder expected_layout_builder(primary_id);
  602. expected_layout_builder.AddDisplayPlacement(
  603. list[1], primary_id, display::DisplayPlacement::BOTTOM, 0);
  604. expected_layout_builder.AddDisplayPlacement(
  605. list[2], primary_id, display::DisplayPlacement::BOTTOM, 696);
  606. expected_layout_builder.AddDisplayPlacement(
  607. list[3], list[2], display::DisplayPlacement::RIGHT, -700);
  608. const display::DisplayLayout& layout =
  609. display_manager()->GetCurrentResolvedDisplayLayout();
  610. EXPECT_TRUE(
  611. layout.HasSamePlacementList(*(expected_layout_builder.Build())));
  612. }
  613. {
  614. // The following is a layout with an overlap to the left of the primary
  615. // display.
  616. //
  617. // +---------+---------+
  618. // | 1 | P |
  619. // | | |
  620. // +---------+ |
  621. // | | |
  622. // +---------+---------+
  623. // | 2 |
  624. // | |
  625. // +---------+
  626. display::DisplayIdList list =
  627. display::test::CreateDisplayIdListN(primary_id, 3);
  628. display::DisplayLayoutBuilder builder(primary_id);
  629. builder.AddDisplayPlacement(list[1], primary_id,
  630. display::DisplayPlacement::LEFT, 0);
  631. builder.AddDisplayPlacement(list[2], primary_id,
  632. display::DisplayPlacement::LEFT, 250);
  633. display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
  634. list, builder.Build());
  635. UpdateDisplay("696x500,696x500,696x500");
  636. // The expected layout should be:
  637. //
  638. // +---------+---------+
  639. // | 1 | P |
  640. // | | |
  641. // | | |
  642. // | | |
  643. // +---------+---------+
  644. // | 2 |
  645. // | |
  646. // | |
  647. // | |
  648. // +---------+
  649. EXPECT_EQ(3U, display_manager()->GetNumDisplays());
  650. EXPECT_EQ(gfx::Rect(0, 0, 696, 500),
  651. display_manager()->GetDisplayAt(0).bounds());
  652. EXPECT_EQ(gfx::Rect(-696, 0, 696, 500),
  653. display_manager()->GetDisplayAt(1).bounds());
  654. EXPECT_EQ(gfx::Rect(-696, 500, 696, 500),
  655. display_manager()->GetDisplayAt(2).bounds());
  656. }
  657. {
  658. // The following is a layout with an overlap occurring above the primary
  659. // display.
  660. //
  661. // +------+--+------+
  662. // | 2 | | 1 |
  663. // | | | |
  664. // | | | |
  665. // | | | |
  666. // +------+--+------+
  667. // | P |
  668. // | |
  669. // | |
  670. // | |
  671. // +---------+
  672. //
  673. display::DisplayIdList list =
  674. display::test::CreateDisplayIdListN(primary_id, 3);
  675. display::DisplayLayoutBuilder builder(primary_id);
  676. builder.AddDisplayPlacement(list[1], primary_id,
  677. display::DisplayPlacement::TOP, 0);
  678. builder.AddDisplayPlacement(list[2], primary_id,
  679. display::DisplayPlacement::TOP, -348);
  680. display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
  681. list, builder.Build());
  682. UpdateDisplay("696x500,696x500,696x500");
  683. // The expected layout should be:
  684. //
  685. // +---------+---------+
  686. // | 2 | 1 |
  687. // | | |
  688. // | | |
  689. // | | |
  690. // +---------+---------+
  691. // | P |
  692. // | |
  693. // | |
  694. // | |
  695. // +---------+
  696. //
  697. EXPECT_EQ(3U, display_manager()->GetNumDisplays());
  698. EXPECT_EQ(gfx::Rect(0, 0, 696, 500),
  699. display_manager()->GetDisplayAt(0).bounds());
  700. EXPECT_EQ(gfx::Rect(0, -500, 696, 500),
  701. display_manager()->GetDisplayAt(1).bounds());
  702. EXPECT_EQ(gfx::Rect(-696, -500, 696, 500),
  703. display_manager()->GetDisplayAt(2).bounds());
  704. }
  705. }
  706. TEST_F(DisplayManagerTest, NoOverlappedDisplaysNotFitBetweenTwo) {
  707. // +------+--+----+--+------+
  708. // | 1 | | 2 | | 3 |
  709. // | | | | | |
  710. // | | | | | |
  711. // | | | | | |
  712. // +-+----+--+----+--+---+--+
  713. // | P |
  714. // | |
  715. // | |
  716. // | |
  717. // +-------------------+
  718. //
  719. int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  720. display::DisplayIdList list =
  721. display::test::CreateDisplayIdListN(primary_id, 4);
  722. display::DisplayLayoutBuilder builder(primary_id);
  723. builder.AddDisplayPlacement(list[1], primary_id,
  724. display::DisplayPlacement::TOP, -110);
  725. builder.AddDisplayPlacement(list[2], primary_id,
  726. display::DisplayPlacement::TOP, 300);
  727. builder.AddDisplayPlacement(list[3], primary_id,
  728. display::DisplayPlacement::TOP, 600);
  729. display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
  730. list, builder.Build());
  731. UpdateDisplay("1200x500,600x500,600x500,600x500");
  732. // The expected layout should be:
  733. //
  734. // +---------+---------+---------+
  735. // | 1 | 2 | 3 |
  736. // | | | |
  737. // | | | |
  738. // | | | |
  739. // +-+-------+---------+-+-------+
  740. // | P |
  741. // | |
  742. // | |
  743. // | |
  744. // +-------------------+
  745. //
  746. EXPECT_EQ(4U, display_manager()->GetNumDisplays());
  747. EXPECT_EQ(gfx::Rect(0, 0, 1200, 500),
  748. display_manager()->GetDisplayAt(0).bounds());
  749. EXPECT_EQ(gfx::Rect(-110, -500, 600, 500),
  750. display_manager()->GetDisplayAt(1).bounds());
  751. EXPECT_EQ(gfx::Rect(490, -500, 600, 500),
  752. display_manager()->GetDisplayAt(2).bounds());
  753. EXPECT_EQ(gfx::Rect(1090, -500, 600, 500),
  754. display_manager()->GetDisplayAt(3).bounds());
  755. }
  756. TEST_F(DisplayManagerTest, NoOverlappedDisplaysAfterResolutionChange) {
  757. // Starting with a good layout with no overlaps, test that if the resolution
  758. // of one of the displays is changed, it won't result in any overlaps.
  759. //
  760. // +-------------------+
  761. // | 4 |
  762. // | |
  763. // | |
  764. // | |
  765. // +----+----+---------+----+----+
  766. // | 1 | 2 | 3 |
  767. // | | | |
  768. // | | | |
  769. // | | | |
  770. // +----+----+---------+----+----+
  771. // | p |
  772. // | |
  773. // | |
  774. // | |
  775. // +-------------------+
  776. //
  777. int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  778. display::DisplayIdList list =
  779. display::test::CreateDisplayIdListN(primary_id, 5);
  780. display::DisplayLayoutBuilder builder(primary_id);
  781. builder.AddDisplayPlacement(list[1], primary_id,
  782. display::DisplayPlacement::TOP, -250);
  783. builder.AddDisplayPlacement(list[2], primary_id,
  784. display::DisplayPlacement::TOP, 250);
  785. builder.AddDisplayPlacement(list[3], primary_id,
  786. display::DisplayPlacement::TOP, 750);
  787. builder.AddDisplayPlacement(list[4], list[1], display::DisplayPlacement::TOP,
  788. 250);
  789. display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
  790. list, builder.Build());
  791. UpdateDisplay("1000x500,600x500,600x500,600x500,1000x500");
  792. // There should be no overlap at all.
  793. EXPECT_EQ(5U, display_manager()->GetNumDisplays());
  794. EXPECT_EQ(gfx::Rect(0, 0, 1000, 500),
  795. display_manager()->GetDisplayAt(0).bounds());
  796. EXPECT_EQ(gfx::Rect(-250, -500, 600, 500),
  797. display_manager()->GetDisplayAt(1).bounds());
  798. EXPECT_EQ(gfx::Rect(350, -500, 600, 500),
  799. display_manager()->GetDisplayAt(2).bounds());
  800. EXPECT_EQ(gfx::Rect(950, -500, 600, 500),
  801. display_manager()->GetDisplayAt(3).bounds());
  802. EXPECT_EQ(gfx::Rect(0, -1000, 1000, 500),
  803. display_manager()->GetDisplayAt(4).bounds());
  804. // Change the resolution of display (2) and expect the following layout.
  805. //
  806. // +-------------------+
  807. // | 4 |
  808. // | |
  809. // | |
  810. // | |
  811. // +----+-------------++
  812. // | 2 |
  813. // +---------+ +---------+
  814. // | 1 | | 3 |
  815. // | | | |
  816. // | | | |
  817. // | | | |
  818. // +----+----+-------------++--------+
  819. // | p |
  820. // | |
  821. // | |
  822. // | |
  823. // +-------------------+
  824. //
  825. UpdateDisplay("1000x500,600x500,600x700,600x500,1000x500");
  826. EXPECT_EQ(5U, display_manager()->GetNumDisplays());
  827. EXPECT_EQ(gfx::Rect(0, 0, 1000, 500),
  828. display_manager()->GetDisplayAt(0).bounds());
  829. EXPECT_EQ(gfx::Rect(-250, -500, 600, 500),
  830. display_manager()->GetDisplayAt(1).bounds());
  831. EXPECT_EQ(gfx::Rect(350, -700, 600, 700),
  832. display_manager()->GetDisplayAt(2).bounds());
  833. EXPECT_EQ(gfx::Rect(950, -500, 600, 500),
  834. display_manager()->GetDisplayAt(3).bounds());
  835. EXPECT_EQ(gfx::Rect(0, -1200, 1000, 500),
  836. display_manager()->GetDisplayAt(4).bounds());
  837. }
  838. TEST_F(DisplayManagerTest, NoOverlappedDisplaysWithDetachedDisplays) {
  839. // Detached displays that intersect other non-detached displays.
  840. //
  841. // +---------+---------+---------+
  842. // | 1 | 2 | 3 |
  843. // | | | |
  844. // | | | |
  845. // | | | |
  846. // +----+----+-----+---+----+----+
  847. // | 4, 5 | P |
  848. // | detached | |
  849. // | | |
  850. // +----------+ |
  851. // +-------------------+
  852. //
  853. int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  854. display::DisplayIdList list =
  855. display::test::CreateDisplayIdListN(primary_id, 6);
  856. display::DisplayLayoutBuilder builder(primary_id);
  857. builder.AddDisplayPlacement(list[1], primary_id,
  858. display::DisplayPlacement::TOP, -250);
  859. builder.AddDisplayPlacement(list[2], primary_id,
  860. display::DisplayPlacement::TOP, 250);
  861. builder.AddDisplayPlacement(list[3], primary_id,
  862. display::DisplayPlacement::TOP, 750);
  863. display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
  864. list, builder.Build());
  865. UpdateDisplay("1000x500,600x500,600x500,600x500,500x400,500x400");
  866. // Detached displays will be de-intersected and reparented appropriately.
  867. //
  868. // +---------+---------+---------+
  869. // | 1 | 2 | 3 |
  870. // | | | |
  871. // | | | |
  872. // | | | |
  873. // +----+----+---------+----+----+
  874. // | P |
  875. // | |
  876. // | |
  877. // | |
  878. // +----------+--------+
  879. // | 4 |
  880. // | |
  881. // | |
  882. // +----------+
  883. // | 5 |
  884. // | |
  885. // | |
  886. // +----------+
  887. //
  888. EXPECT_EQ(6U, display_manager()->GetNumDisplays());
  889. EXPECT_EQ(gfx::Rect(0, 0, 1000, 500),
  890. display_manager()->GetDisplayAt(0).bounds());
  891. EXPECT_EQ(gfx::Rect(-250, -500, 600, 500),
  892. display_manager()->GetDisplayAt(1).bounds());
  893. EXPECT_EQ(gfx::Rect(350, -500, 600, 500),
  894. display_manager()->GetDisplayAt(2).bounds());
  895. EXPECT_EQ(gfx::Rect(950, -500, 600, 500),
  896. display_manager()->GetDisplayAt(3).bounds());
  897. EXPECT_EQ(gfx::Rect(0, 500, 500, 400),
  898. display_manager()->GetDisplayAt(4).bounds());
  899. EXPECT_EQ(gfx::Rect(0, 900, 500, 400),
  900. display_manager()->GetDisplayAt(5).bounds());
  901. // This case if not handled correctly might lead to a cyclic dependency.
  902. // Make sure this doesn't happen.
  903. display::DisplayLayoutBuilder expected_layout_builder(primary_id);
  904. expected_layout_builder.AddDisplayPlacement(
  905. list[1], primary_id, display::DisplayPlacement::TOP, -250);
  906. expected_layout_builder.AddDisplayPlacement(
  907. list[2], primary_id, display::DisplayPlacement::TOP, 350);
  908. expected_layout_builder.AddDisplayPlacement(
  909. list[3], primary_id, display::DisplayPlacement::TOP, 950);
  910. expected_layout_builder.AddDisplayPlacement(
  911. list[4], primary_id, display::DisplayPlacement::BOTTOM, 0);
  912. expected_layout_builder.AddDisplayPlacement(
  913. list[5], list[4], display::DisplayPlacement::BOTTOM, 0);
  914. const display::DisplayLayout& layout =
  915. display_manager()->GetCurrentResolvedDisplayLayout();
  916. EXPECT_TRUE(layout.HasSamePlacementList(*(expected_layout_builder.Build())));
  917. }
  918. TEST_F(DisplayManagerTest, OverscanInsetsTest) {
  919. UpdateDisplay("0+0-500x400,0+501-400x300");
  920. reset();
  921. ASSERT_EQ(2u, display_manager()->GetNumDisplays());
  922. const display::ManagedDisplayInfo display_info1 = GetDisplayInfoAt(0);
  923. const display::ManagedDisplayInfo display_info2 = GetDisplayInfoAt(1);
  924. display_manager()->SetOverscanInsets(display_info2.id(),
  925. gfx::Insets::TLBR(13, 12, 11, 10));
  926. std::vector<display::Display> changed_displays = changed();
  927. ASSERT_EQ(1u, changed_displays.size());
  928. EXPECT_EQ(display_info2.id(), changed_displays[0].id());
  929. EXPECT_EQ(gfx::Rect(0, 0, 500, 400), GetDisplayInfoAt(0).bounds_in_native());
  930. display::ManagedDisplayInfo updated_display_info2 = GetDisplayInfoAt(1);
  931. EXPECT_EQ(gfx::Rect(0, 501, 400, 300),
  932. updated_display_info2.bounds_in_native());
  933. EXPECT_EQ(gfx::Size(378, 276), updated_display_info2.size_in_pixel());
  934. EXPECT_EQ(gfx::Insets::TLBR(13, 12, 11, 10),
  935. updated_display_info2.overscan_insets_in_dip());
  936. display::test::DisplayManagerTestApi display_manager_test(display_manager());
  937. EXPECT_EQ(gfx::Rect(500, 0, 378, 276),
  938. display_manager_test.GetSecondaryDisplay().bounds());
  939. // Make sure that SetOverscanInsets() is idempotent.
  940. display_manager()->SetOverscanInsets(display_info1.id(), gfx::Insets());
  941. display_manager()->SetOverscanInsets(display_info2.id(),
  942. gfx::Insets::TLBR(13, 12, 11, 10));
  943. EXPECT_EQ(gfx::Rect(0, 0, 500, 400), GetDisplayInfoAt(0).bounds_in_native());
  944. updated_display_info2 = GetDisplayInfoAt(1);
  945. EXPECT_EQ(gfx::Rect(0, 501, 400, 300),
  946. updated_display_info2.bounds_in_native());
  947. EXPECT_EQ(gfx::Size(378, 276), updated_display_info2.size_in_pixel());
  948. EXPECT_EQ(gfx::Insets::TLBR(13, 12, 11, 10),
  949. updated_display_info2.overscan_insets_in_dip());
  950. display_manager()->SetOverscanInsets(display_info2.id(),
  951. gfx::Insets::TLBR(10, 11, 12, 13));
  952. EXPECT_EQ(gfx::Rect(0, 0, 500, 400), GetDisplayInfoAt(0).bounds_in_native());
  953. EXPECT_EQ(gfx::Size(376, 278), GetDisplayInfoAt(1).size_in_pixel());
  954. EXPECT_EQ(gfx::Insets::TLBR(10, 11, 12, 13),
  955. GetDisplayInfoAt(1).overscan_insets_in_dip());
  956. // Recreate a new 2nd display. It won't apply the overscan inset because the
  957. // new display has a different ID.
  958. UpdateDisplay("0+0-500x400");
  959. UpdateDisplay("0+0-500x400,0+501-400x300");
  960. EXPECT_EQ(gfx::Rect(0, 0, 500, 400), GetDisplayInfoAt(0).bounds_in_native());
  961. EXPECT_EQ(gfx::Rect(0, 501, 400, 300),
  962. GetDisplayInfoAt(1).bounds_in_native());
  963. // Recreate the displays with the same ID. It should apply the overscan
  964. // inset.
  965. UpdateDisplay("0+0-500x400");
  966. std::vector<display::ManagedDisplayInfo> display_info_list;
  967. display_info_list.push_back(display_info1);
  968. display_info_list.push_back(display_info2);
  969. display_manager()->OnNativeDisplaysChanged(display_info_list);
  970. EXPECT_EQ(gfx::Rect(0, 0, 500, 400), GetDisplayInfoAt(0).bounds_in_native());
  971. updated_display_info2 = GetDisplayInfoAt(1);
  972. EXPECT_EQ(gfx::Size(376, 278), updated_display_info2.size_in_pixel());
  973. EXPECT_EQ(gfx::Insets::TLBR(10, 11, 12, 13),
  974. updated_display_info2.overscan_insets_in_dip());
  975. // HiDPI but overscan display. The specified insets size should be doubled.
  976. UpdateDisplay("0+0-500x400,0+501-400x300*2");
  977. display_manager()->SetOverscanInsets(display_manager()->GetDisplayAt(1).id(),
  978. gfx::Insets::TLBR(4, 5, 6, 7));
  979. EXPECT_EQ(gfx::Rect(0, 0, 500, 400), GetDisplayInfoAt(0).bounds_in_native());
  980. updated_display_info2 = GetDisplayInfoAt(1);
  981. EXPECT_EQ(gfx::Rect(0, 501, 400, 300),
  982. updated_display_info2.bounds_in_native());
  983. EXPECT_EQ(gfx::Size(376, 280), updated_display_info2.size_in_pixel());
  984. EXPECT_EQ(gfx::Insets::TLBR(4, 5, 6, 7),
  985. updated_display_info2.overscan_insets_in_dip());
  986. EXPECT_EQ(gfx::Insets::TLBR(8, 10, 12, 14),
  987. updated_display_info2.GetOverscanInsetsInPixel());
  988. // Make sure switching primary display applies the overscan offset only once.
  989. Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
  990. display_manager_test.GetSecondaryDisplay().id());
  991. EXPECT_EQ(gfx::Rect(-500, 0, 500, 400),
  992. display_manager_test.GetSecondaryDisplay().bounds());
  993. EXPECT_EQ(gfx::Rect(0, 0, 500, 400),
  994. GetDisplayInfo(display_manager_test.GetSecondaryDisplay())
  995. .bounds_in_native());
  996. EXPECT_EQ(gfx::Rect(0, 501, 400, 300),
  997. GetDisplayInfo(display::Screen::GetScreen()->GetPrimaryDisplay())
  998. .bounds_in_native());
  999. EXPECT_EQ(gfx::Rect(0, 0, 188, 140),
  1000. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  1001. // Make sure just moving the overscan area should property notify observers.
  1002. UpdateDisplay("0+0-500x400");
  1003. int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  1004. display_manager()->SetOverscanInsets(primary_id,
  1005. gfx::Insets::TLBR(0, 0, 20, 20));
  1006. EXPECT_EQ(gfx::Rect(0, 0, 480, 380),
  1007. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  1008. reset();
  1009. display_manager()->SetOverscanInsets(primary_id, gfx::Insets(10));
  1010. EXPECT_TRUE(changed_metrics() &
  1011. display::DisplayObserver::DISPLAY_METRIC_BOUNDS);
  1012. EXPECT_TRUE(changed_metrics() &
  1013. display::DisplayObserver::DISPLAY_METRIC_WORK_AREA);
  1014. EXPECT_EQ(gfx::Rect(0, 0, 480, 380),
  1015. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  1016. reset();
  1017. display_manager()->SetOverscanInsets(primary_id, gfx::Insets());
  1018. EXPECT_TRUE(changed_metrics() &
  1019. display::DisplayObserver::DISPLAY_METRIC_BOUNDS);
  1020. EXPECT_TRUE(changed_metrics() &
  1021. display::DisplayObserver::DISPLAY_METRIC_WORK_AREA);
  1022. EXPECT_EQ(gfx::Rect(0, 0, 500, 400),
  1023. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  1024. }
  1025. TEST_F(DisplayManagerTest, ZeroOverscanInsets) {
  1026. // Make sure the display change events is emitted for overscan inset changes.
  1027. UpdateDisplay("0+0-500x400,0+501-400x300");
  1028. ASSERT_EQ(2u, display_manager()->GetNumDisplays());
  1029. int64_t display2_id = display_manager()->GetDisplayAt(1).id();
  1030. reset();
  1031. display_manager()->SetOverscanInsets(display2_id, gfx::Insets());
  1032. EXPECT_EQ(0u, changed().size());
  1033. reset();
  1034. display_manager()->SetOverscanInsets(display2_id,
  1035. gfx::Insets::TLBR(1, 0, 0, 0));
  1036. ASSERT_EQ(1u, changed().size());
  1037. EXPECT_EQ(display2_id, changed()[0].id());
  1038. reset();
  1039. display_manager()->SetOverscanInsets(display2_id, gfx::Insets());
  1040. ASSERT_EQ(1u, changed().size());
  1041. EXPECT_EQ(display2_id, changed()[0].id());
  1042. }
  1043. TEST_F(DisplayManagerTest, TouchCalibrationTest) {
  1044. UpdateDisplay("0+0-500x400,0+501-1024x600");
  1045. reset();
  1046. display::TouchDeviceManager* touch_device_manager =
  1047. display_manager()->touch_device_manager();
  1048. display::test::TouchDeviceManagerTestApi tdm_test_api(touch_device_manager);
  1049. const ui::TouchscreenDevice touchdevice(
  1050. 11, ui::InputDeviceType::INPUT_DEVICE_USB,
  1051. std::string("test touch device"), gfx::Size(123, 456), 1);
  1052. ASSERT_EQ(2u, display_manager()->GetNumDisplays());
  1053. const display::ManagedDisplayInfo display_info1 = GetDisplayInfoAt(0);
  1054. const display::ManagedDisplayInfo display_info2 = GetDisplayInfoAt(1);
  1055. EXPECT_FALSE(tdm_test_api.AreAssociated(display_info2, touchdevice));
  1056. const display::TouchCalibrationData::CalibrationPointPairQuad
  1057. point_pair_quad = {
  1058. {std::make_pair(gfx::Point(50, 50), gfx::Point(43, 51)),
  1059. std::make_pair(gfx::Point(950, 50), gfx::Point(975, 45)),
  1060. std::make_pair(gfx::Point(50, 550), gfx::Point(48, 534)),
  1061. std::make_pair(gfx::Point(950, 550), gfx::Point(967, 574))}};
  1062. const gfx::Size bounds_at_calibration(display_info2.size_in_pixel());
  1063. const display::TouchCalibrationData touch_data(point_pair_quad,
  1064. bounds_at_calibration);
  1065. // Set the touch calibration data for the secondary display.
  1066. display_manager()->SetTouchCalibrationData(
  1067. display_info2.id(), point_pair_quad, bounds_at_calibration, touchdevice);
  1068. EXPECT_TRUE(tdm_test_api.AreAssociated(display_info2, touchdevice));
  1069. EXPECT_EQ(touch_data, touch_device_manager->GetCalibrationData(
  1070. touchdevice, display_info2.id()));
  1071. // Clearing touch calibration data from the secondary display.
  1072. touch_device_manager->ClearTouchCalibrationData(touchdevice,
  1073. GetDisplayInfoAt(1).id());
  1074. EXPECT_TRUE(touch_device_manager
  1075. ->GetCalibrationData(touchdevice, GetDisplayInfoAt(1).id())
  1076. .IsEmpty());
  1077. // Make sure that SetTouchCalibrationData() is idempotent.
  1078. display::TouchCalibrationData::CalibrationPointPairQuad point_pair_quad_2 =
  1079. point_pair_quad;
  1080. point_pair_quad_2[1] =
  1081. std::make_pair(gfx::Point(950, 50), gfx::Point(975, 53));
  1082. display::TouchCalibrationData touch_data_2(point_pair_quad_2,
  1083. bounds_at_calibration);
  1084. display_manager()->SetTouchCalibrationData(
  1085. display_info2.id(), point_pair_quad_2, bounds_at_calibration,
  1086. touchdevice);
  1087. EXPECT_EQ(touch_data_2, touch_device_manager->GetCalibrationData(
  1088. touchdevice, GetDisplayInfoAt(1).id()));
  1089. // Recreate a new 2nd display. It won't apply the touhc calibration data
  1090. // because the new display has a different ID.
  1091. UpdateDisplay("0+0-500x400");
  1092. UpdateDisplay("0+0-500x400,0+501-400x300");
  1093. tdm_test_api.ResetTouchDeviceManager();
  1094. // Recreate the displays with the same ID. It should apply the touch
  1095. // calibration associated data.
  1096. UpdateDisplay("0+0-500x400");
  1097. std::vector<display::ManagedDisplayInfo> display_info_list;
  1098. display_info_list.push_back(display_info1);
  1099. display_info_list.push_back(display_info2);
  1100. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1101. // Make sure multiple touch devices works.
  1102. display_manager()->SetTouchCalibrationData(
  1103. display_info2.id(), point_pair_quad, bounds_at_calibration, touchdevice);
  1104. EXPECT_EQ(touch_data, touch_device_manager->GetCalibrationData(
  1105. touchdevice, GetDisplayInfoAt(1).id()));
  1106. const ui::TouchscreenDevice touchdevice_2(
  1107. 12, ui::InputDeviceType::INPUT_DEVICE_USB,
  1108. std::string("test touch device 2"), gfx::Size(234, 567), 1);
  1109. display_manager()->SetTouchCalibrationData(
  1110. display_info2.id(), point_pair_quad_2, bounds_at_calibration,
  1111. touchdevice_2);
  1112. EXPECT_EQ(touch_data_2, touch_device_manager->GetCalibrationData(
  1113. touchdevice_2, GetDisplayInfoAt(1).id()));
  1114. EXPECT_EQ(touch_data, touch_device_manager->GetCalibrationData(
  1115. touchdevice, GetDisplayInfoAt(1).id()));
  1116. }
  1117. TEST_F(DisplayManagerTest, UpdateDisplayZoomTest) {
  1118. // Initialize a display pair.
  1119. UpdateDisplay("1920x1080#1280x720|640x480%60, 600x400*2#600x400");
  1120. reset();
  1121. // The second display has a device scale factor of 2 set.
  1122. constexpr float display_2_dsf = 2.0f;
  1123. ASSERT_EQ(2u, display_manager()->GetNumDisplays());
  1124. const display::ManagedDisplayInfo& info_1 = GetDisplayInfoAt(0);
  1125. // The display should have 2 display modes based on the initialization spec.
  1126. ASSERT_EQ(2u, info_1.display_modes().size());
  1127. const display::ManagedDisplayInfo::ManagedDisplayModeList& modes =
  1128. info_1.display_modes();
  1129. // Set the display mode.
  1130. display::test::SetDisplayResolution(display_manager(), info_1.id(),
  1131. modes[0].size());
  1132. display_manager()->UpdateDisplays();
  1133. // Since no zoom factor or device scale factor has been set on the display,
  1134. // the total/effective device scale factor on the display is 1.
  1135. EXPECT_EQ(
  1136. display_manager()->GetDisplayForId(info_1.id()).device_scale_factor(),
  1137. 1.f);
  1138. float zoom_factor_1 = 2.0f;
  1139. display_manager()->UpdateZoomFactor(info_1.id(), zoom_factor_1);
  1140. EXPECT_EQ(display_manager()->GetDisplayInfo(info_1.id()).zoom_factor(),
  1141. zoom_factor_1);
  1142. // With the zoom factor set for the display. The effective zoom factor
  1143. // returned should have the display zoom taken into consideration.
  1144. EXPECT_EQ(
  1145. display_manager()->GetDisplayForId(info_1.id()).device_scale_factor(),
  1146. zoom_factor_1);
  1147. // Update the zoom factor for a different display mode.
  1148. float zoom_factor_2 = 1.5f;
  1149. display_manager()->UpdateZoomFactor(info_1.id(), zoom_factor_2);
  1150. EXPECT_EQ(display_manager()->GetDisplayInfo(info_1.id()).zoom_factor(),
  1151. zoom_factor_2);
  1152. // Change the display mode of the device.
  1153. display::test::SetDisplayResolution(display_manager(), info_1.id(),
  1154. modes[1].size());
  1155. display_manager()->UpdateDisplays();
  1156. // Since the display mode was changed, the zoom factor for the display is
  1157. // reset to the default of 1.
  1158. EXPECT_EQ(
  1159. display_manager()->GetDisplayForId(info_1.id()).device_scale_factor(),
  1160. 1.f);
  1161. // When setting the display mode back to the old one, the final effective
  1162. // device scale factor should be using the correct zoom factor.
  1163. display::test::SetDisplayResolution(display_manager(), info_1.id(),
  1164. modes[0].size());
  1165. display_manager()->UpdateDisplays();
  1166. // Set the zoom factor back to |zoom_factor_2| for first display.
  1167. display_manager()->UpdateZoomFactor(info_1.id(), zoom_factor_2);
  1168. EXPECT_EQ(display_manager()->GetDisplayInfo(info_1.id()).zoom_factor(),
  1169. zoom_factor_2);
  1170. EXPECT_EQ(
  1171. display_manager()->GetDisplayForId(info_1.id()).device_scale_factor(),
  1172. zoom_factor_2);
  1173. // Update the zoom factor for the second display.
  1174. float zoom_factor_3 = 1.5f;
  1175. const display::ManagedDisplayInfo& info_2 = GetDisplayInfoAt(1);
  1176. display_manager()->UpdateZoomFactor(info_2.id(), zoom_factor_3);
  1177. EXPECT_EQ(display_manager()->GetDisplayInfo(info_2.id()).zoom_factor(),
  1178. zoom_factor_3);
  1179. EXPECT_EQ(
  1180. display_manager()->GetDisplayForId(info_2.id()).device_scale_factor(),
  1181. zoom_factor_3 * display_2_dsf);
  1182. // Modifying zoom factor for a display should not effect zoom factors of
  1183. // other displays.
  1184. EXPECT_EQ(display_manager()->GetDisplayInfo(info_1.id()).zoom_factor(),
  1185. zoom_factor_2);
  1186. // Update the zoom factor for display to see if it gets reflected.
  1187. display_manager()->UpdateZoomFactor(info_1.id(), zoom_factor_3);
  1188. EXPECT_EQ(display_manager()->GetDisplayInfo(info_1.id()).zoom_factor(),
  1189. zoom_factor_3);
  1190. display::test::SetDisplayResolution(display_manager(), info_1.id(),
  1191. modes[0].size());
  1192. display_manager()->UpdateDisplays();
  1193. EXPECT_EQ(
  1194. display_manager()->GetDisplayForId(info_1.id()).device_scale_factor(),
  1195. 1.f);
  1196. EXPECT_EQ(
  1197. display_manager()->GetDisplayForId(info_2.id()).device_scale_factor(),
  1198. zoom_factor_3 * display_2_dsf);
  1199. }
  1200. TEST_F(DisplayManagerTest, ZoomDisplay) {
  1201. // Initialize a display pair.
  1202. UpdateDisplay("1920x1080#1920x1080|1280x720%60, 2560x1440*2#2560x1440");
  1203. reset();
  1204. ASSERT_EQ(2u, display_manager()->GetNumDisplays());
  1205. const display::ManagedDisplayInfo& info_1 = GetDisplayInfoAt(0);
  1206. const display::ManagedDisplayInfo::ManagedDisplayModeList& modes_1 =
  1207. info_1.display_modes();
  1208. const display::ManagedDisplayInfo& info_2 = GetDisplayInfoAt(1);
  1209. const display::ManagedDisplayInfo::ManagedDisplayModeList& modes_2 =
  1210. info_2.display_modes();
  1211. // Set the display mode for each display.
  1212. display::test::SetDisplayResolution(display_manager(), info_1.id(),
  1213. modes_1[0].size());
  1214. display::test::SetDisplayResolution(display_manager(), info_2.id(),
  1215. modes_2[0].size());
  1216. display_manager()->UpdateDisplays();
  1217. // Enumerate the zoom factors for display.
  1218. const std::vector<float> zoom_factors_1 =
  1219. display::GetDisplayZoomFactors(modes_1[0]);
  1220. // Set the zoom factor to one of the enumerated zoom factors for the said
  1221. // display.
  1222. const std::size_t zoom_factor_idx_1 = 0;
  1223. display_manager()->UpdateZoomFactor(info_1.id(),
  1224. zoom_factors_1[zoom_factor_idx_1]);
  1225. // Make sure the chage was successful.
  1226. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(info_1.id()).zoom_factor(),
  1227. zoom_factors_1[zoom_factor_idx_1]);
  1228. // Zoom out the display. This should have no effect, since the display is
  1229. // already at the minimum zoom level.
  1230. display_manager()->ZoomDisplay(info_1.id(), true /* up */);
  1231. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(info_1.id()).zoom_factor(),
  1232. zoom_factors_1[zoom_factor_idx_1]);
  1233. // Ensure that this call did not modify the zoom value for the other display.
  1234. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(info_2.id()).zoom_factor(),
  1235. 1.f);
  1236. // Zoom in the display.
  1237. display_manager()->ZoomDisplay(info_1.id(), false /* up */);
  1238. // The zoom factor for the display should be set to the next zoom factor in
  1239. // list.
  1240. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(info_1.id()).zoom_factor(),
  1241. zoom_factors_1[zoom_factor_idx_1 + 1]);
  1242. // Zoom out the display.
  1243. display_manager()->ZoomDisplay(info_1.id(), true /* up */);
  1244. // The zoom level should decrease from the previous level.
  1245. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(info_1.id()).zoom_factor(),
  1246. zoom_factors_1[zoom_factor_idx_1]);
  1247. // Enumerate the zoom factors for display.
  1248. const std::vector<float> zoom_factors_2 =
  1249. display::GetDisplayZoomFactors(modes_2[0]);
  1250. // Set the zoom factor to one of the enumerated zoom factors for the said
  1251. // display.
  1252. const std::size_t zoom_factor_idx_2 = zoom_factors_2.size() - 1;
  1253. display_manager()->UpdateZoomFactor(info_2.id(),
  1254. zoom_factors_2[zoom_factor_idx_2]);
  1255. // Make sure the chage was successful.
  1256. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(info_2.id()).zoom_factor(),
  1257. zoom_factors_2[zoom_factor_idx_2]);
  1258. // Zoom in the display. This should have no effect since we are already at
  1259. // maximum zoom.
  1260. display_manager()->ZoomDisplay(info_2.id(), false /* up */);
  1261. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(info_2.id()).zoom_factor(),
  1262. zoom_factors_2[zoom_factor_idx_2]);
  1263. // Zoom out the display
  1264. display_manager()->ZoomDisplay(info_2.id(), true /* up */);
  1265. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(info_2.id()).zoom_factor(),
  1266. zoom_factors_2[zoom_factor_idx_2 - 1]);
  1267. // Ensure that this call did not modify the zoom value for the other display.
  1268. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(info_1.id()).zoom_factor(),
  1269. zoom_factors_1[zoom_factor_idx_1]);
  1270. // Reset the zoom value for displays.
  1271. display_manager()->ResetDisplayZoom(info_1.id());
  1272. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(info_1.id()).zoom_factor(),
  1273. 1.f);
  1274. // Resetting the zoom level of one display should not effect the other display
  1275. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(info_2.id()).zoom_factor(),
  1276. zoom_factors_2[zoom_factor_idx_2 - 1]);
  1277. // Now reset the zoom value for other display.
  1278. display_manager()->ResetDisplayZoom(info_2.id());
  1279. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(info_2.id()).zoom_factor(),
  1280. 1.f);
  1281. EXPECT_FLOAT_EQ(display_manager()->GetDisplayInfo(info_1.id()).zoom_factor(),
  1282. 1.f);
  1283. }
  1284. TEST_F(DisplayManagerTest, TestDeviceScaleOnlyChange) {
  1285. UpdateDisplay("1000x600");
  1286. aura::WindowTreeHost* host = Shell::GetPrimaryRootWindow()->GetHost();
  1287. EXPECT_EQ(1, host->compositor()->device_scale_factor());
  1288. EXPECT_EQ(gfx::Size(1000, 600),
  1289. Shell::GetPrimaryRootWindow()->bounds().size());
  1290. EXPECT_EQ("1 0 0 1 1", GetCountSummary());
  1291. UpdateDisplay("1000x600*2");
  1292. EXPECT_EQ(2, host->compositor()->device_scale_factor());
  1293. EXPECT_EQ("2 0 0 2 2", GetCountSummary());
  1294. EXPECT_EQ(gfx::Size(500, 300),
  1295. Shell::GetPrimaryRootWindow()->bounds().size());
  1296. }
  1297. TEST_F(DisplayManagerTest, TestNativeDisplaysChanged) {
  1298. // Disable restoring mirror mode to prevent interference from previous
  1299. // display configuration.
  1300. display_manager()->set_disable_restoring_mirror_mode_for_test(true);
  1301. const int64_t internal_display_id =
  1302. display::test::DisplayManagerTestApi(display_manager())
  1303. .SetFirstDisplayAsInternalDisplay();
  1304. const int external_id = 10;
  1305. const int mirror_id = 11;
  1306. const int64_t invalid_id = display::kInvalidDisplayId;
  1307. const display::ManagedDisplayInfo internal_display_info =
  1308. display::CreateDisplayInfo(internal_display_id,
  1309. gfx::Rect(0, 0, 500, 400));
  1310. const display::ManagedDisplayInfo external_display_info =
  1311. display::CreateDisplayInfo(external_id, gfx::Rect(1, 1, 200, 100));
  1312. const display::ManagedDisplayInfo mirroring_display_info =
  1313. display::CreateDisplayInfo(mirror_id, gfx::Rect(0, 0, 500, 400));
  1314. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  1315. EXPECT_EQ(1U, display_manager()->num_connected_displays());
  1316. gfx::Rect default_bounds = display_manager()->GetDisplayAt(0).bounds();
  1317. std::vector<display::ManagedDisplayInfo> display_info_list;
  1318. // Primary disconnected.
  1319. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1320. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  1321. EXPECT_EQ(default_bounds, display_manager()->GetDisplayAt(0).bounds());
  1322. EXPECT_EQ(1U, display_manager()->num_connected_displays());
  1323. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1324. // External connected while primary was disconnected.
  1325. display_info_list.push_back(external_display_info);
  1326. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1327. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  1328. EXPECT_EQ(invalid_id, GetDisplayForId(internal_display_id).id());
  1329. EXPECT_EQ(gfx::Rect(1, 1, 200, 100),
  1330. GetDisplayInfoForId(external_id).bounds_in_native());
  1331. EXPECT_EQ(1U, display_manager()->num_connected_displays());
  1332. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1333. EXPECT_EQ(external_id,
  1334. display::Screen::GetScreen()->GetPrimaryDisplay().id());
  1335. EXPECT_EQ(internal_display_id, display::Display::InternalDisplayId());
  1336. // Primary connected, with different bounds.
  1337. display_info_list.clear();
  1338. display_info_list.push_back(internal_display_info);
  1339. display_info_list.push_back(external_display_info);
  1340. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1341. EXPECT_EQ(2U, display_manager()->GetNumDisplays());
  1342. EXPECT_EQ(internal_display_id,
  1343. display::Screen::GetScreen()->GetPrimaryDisplay().id());
  1344. // This combinatino is new, so internal display becomes primary.
  1345. EXPECT_EQ(gfx::Rect(0, 0, 500, 400),
  1346. GetDisplayForId(internal_display_id).bounds());
  1347. EXPECT_EQ(gfx::Rect(1, 1, 200, 100),
  1348. GetDisplayInfoForId(10).bounds_in_native());
  1349. EXPECT_EQ(2U, display_manager()->num_connected_displays());
  1350. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1351. EXPECT_EQ(ToDisplayName(internal_display_id),
  1352. display_manager()->GetDisplayNameForId(internal_display_id));
  1353. // Emulate suspend.
  1354. display_info_list.clear();
  1355. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1356. EXPECT_EQ(2U, display_manager()->GetNumDisplays());
  1357. EXPECT_EQ(gfx::Rect(0, 0, 500, 400),
  1358. GetDisplayForId(internal_display_id).bounds());
  1359. EXPECT_EQ(gfx::Rect(1, 1, 200, 100),
  1360. GetDisplayInfoForId(10).bounds_in_native());
  1361. EXPECT_EQ(2U, display_manager()->num_connected_displays());
  1362. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1363. EXPECT_EQ(ToDisplayName(internal_display_id),
  1364. display_manager()->GetDisplayNameForId(internal_display_id));
  1365. // External display has disconnected then resumed.
  1366. display_info_list.push_back(internal_display_info);
  1367. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1368. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  1369. EXPECT_EQ(gfx::Rect(0, 0, 500, 400),
  1370. GetDisplayForId(internal_display_id).bounds());
  1371. EXPECT_EQ(1U, display_manager()->num_connected_displays());
  1372. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1373. // External display was changed during suspend.
  1374. display_info_list.push_back(external_display_info);
  1375. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1376. EXPECT_EQ(2U, display_manager()->GetNumDisplays());
  1377. EXPECT_EQ(2U, display_manager()->num_connected_displays());
  1378. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1379. // suspend...
  1380. display_info_list.clear();
  1381. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1382. EXPECT_EQ(2U, display_manager()->GetNumDisplays());
  1383. EXPECT_EQ(2U, display_manager()->num_connected_displays());
  1384. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1385. // and resume with different external display.
  1386. display_info_list.push_back(internal_display_info);
  1387. display_info_list.push_back(
  1388. display::CreateDisplayInfo(12, gfx::Rect(1, 1, 200, 100)));
  1389. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1390. EXPECT_EQ(2U, display_manager()->GetNumDisplays());
  1391. EXPECT_EQ(2U, display_manager()->num_connected_displays());
  1392. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1393. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1394. // mirrored...
  1395. display_info_list.clear();
  1396. display_info_list.push_back(internal_display_info);
  1397. display_info_list.push_back(mirroring_display_info);
  1398. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1399. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  1400. EXPECT_EQ(gfx::Rect(0, 0, 500, 400),
  1401. GetDisplayForId(internal_display_id).bounds());
  1402. EXPECT_EQ(2U, display_manager()->num_connected_displays());
  1403. EXPECT_EQ(11U, display_manager()->GetMirroringDestinationDisplayIdList()[0]);
  1404. EXPECT_TRUE(display_manager()->IsInMirrorMode());
  1405. // Test display name.
  1406. EXPECT_EQ(ToDisplayName(internal_display_id),
  1407. display_manager()->GetDisplayNameForId(internal_display_id));
  1408. EXPECT_EQ("x-10", display_manager()->GetDisplayNameForId(10));
  1409. EXPECT_EQ("x-11", display_manager()->GetDisplayNameForId(11));
  1410. EXPECT_EQ("x-12", display_manager()->GetDisplayNameForId(12));
  1411. // Default name for the id that doesn't exist.
  1412. EXPECT_EQ("Display 100", display_manager()->GetDisplayNameForId(100));
  1413. // and exit mirroring.
  1414. display_info_list.clear();
  1415. display_info_list.push_back(internal_display_info);
  1416. display_info_list.push_back(external_display_info);
  1417. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1418. EXPECT_EQ(2U, display_manager()->GetNumDisplays());
  1419. EXPECT_EQ(2U, display_manager()->num_connected_displays());
  1420. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1421. EXPECT_EQ(gfx::Rect(0, 0, 500, 400),
  1422. GetDisplayForId(internal_display_id).bounds());
  1423. EXPECT_EQ(gfx::Rect(500, 0, 200, 100), GetDisplayForId(10).bounds());
  1424. // Turn off internal
  1425. display_info_list.clear();
  1426. display_info_list.push_back(external_display_info);
  1427. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1428. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  1429. EXPECT_EQ(invalid_id, GetDisplayForId(internal_display_id).id());
  1430. EXPECT_EQ(gfx::Rect(1, 1, 200, 100),
  1431. GetDisplayInfoForId(external_id).bounds_in_native());
  1432. EXPECT_EQ(1U, display_manager()->num_connected_displays());
  1433. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1434. // Switched to another display
  1435. display_info_list.clear();
  1436. display_info_list.push_back(internal_display_info);
  1437. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1438. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  1439. EXPECT_EQ(gfx::Rect(0, 0, 500, 400),
  1440. GetDisplayInfoForId(internal_display_id).bounds_in_native());
  1441. EXPECT_EQ(1U, display_manager()->num_connected_displays());
  1442. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1443. display_manager()->set_disable_restoring_mirror_mode_for_test(false);
  1444. }
  1445. // Make sure crash does not happen if add and remove happens at the same time.
  1446. // See: crbug.com/414394
  1447. TEST_F(DisplayManagerTest, DisplayAddRemoveAtTheSameTime) {
  1448. UpdateDisplay("100+0-500x400,0+501-400x300");
  1449. display::test::DisplayManagerTestApi display_manager_test(display_manager());
  1450. const int64_t primary_id = WindowTreeHostManager::GetPrimaryDisplayId();
  1451. const int64_t secondary_id = display_manager_test.GetSecondaryDisplay().id();
  1452. display::ManagedDisplayInfo primary_info =
  1453. display_manager()->GetDisplayInfo(primary_id);
  1454. display::ManagedDisplayInfo secondary_info =
  1455. display_manager()->GetDisplayInfo(secondary_id);
  1456. // An id which is different from primary and secondary.
  1457. const int64_t third_id = display::GetNextSynthesizedDisplayId(secondary_id);
  1458. display::ManagedDisplayInfo third_info =
  1459. display::CreateDisplayInfo(third_id, gfx::Rect(0, 0, 600, 500));
  1460. std::vector<display::ManagedDisplayInfo> display_info_list;
  1461. display_info_list.push_back(third_info);
  1462. display_info_list.push_back(secondary_info);
  1463. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1464. // Secondary seconary_id becomes the primary as it has smaller output index.
  1465. EXPECT_EQ(secondary_id, WindowTreeHostManager::GetPrimaryDisplayId());
  1466. EXPECT_EQ(third_id, display_manager_test.GetSecondaryDisplay().id());
  1467. EXPECT_EQ(gfx::Size(600, 500), GetDisplayForId(third_id).size());
  1468. }
  1469. TEST_F(DisplayManagerTest, TestNativeDisplaysChangedNoInternal) {
  1470. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  1471. // Don't change the display info if all displays are disconnected.
  1472. std::vector<display::ManagedDisplayInfo> display_info_list;
  1473. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1474. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  1475. // Connect another display which will become primary.
  1476. const display::ManagedDisplayInfo external_display_info =
  1477. display::CreateDisplayInfo(10, gfx::Rect(1, 1, 200, 100));
  1478. display_info_list.push_back(external_display_info);
  1479. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1480. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  1481. EXPECT_EQ(gfx::Rect(1, 1, 200, 100),
  1482. GetDisplayInfoForId(10).bounds_in_native());
  1483. EXPECT_EQ(
  1484. gfx::Size(200, 100),
  1485. Shell::GetPrimaryRootWindow()->GetHost()->GetBoundsInPixels().size());
  1486. }
  1487. TEST_F(DisplayManagerTest, NativeDisplaysChangedAfterPrimaryChange) {
  1488. const int64_t internal_display_id =
  1489. display::test::DisplayManagerTestApi(display_manager())
  1490. .SetFirstDisplayAsInternalDisplay();
  1491. const display::ManagedDisplayInfo native_display_info =
  1492. display::CreateDisplayInfo(internal_display_id,
  1493. gfx::Rect(0, 0, 500, 400));
  1494. const display::ManagedDisplayInfo secondary_display_info =
  1495. display::CreateDisplayInfo(10, gfx::Rect(1, 1, 200, 100));
  1496. std::vector<display::ManagedDisplayInfo> display_info_list;
  1497. display_info_list.push_back(native_display_info);
  1498. display_info_list.push_back(secondary_display_info);
  1499. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1500. EXPECT_EQ(2U, display_manager()->GetNumDisplays());
  1501. EXPECT_EQ(gfx::Rect(0, 0, 500, 400),
  1502. GetDisplayForId(internal_display_id).bounds());
  1503. EXPECT_EQ(gfx::Rect(500, 0, 200, 100), GetDisplayForId(10).bounds());
  1504. Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
  1505. secondary_display_info.id());
  1506. EXPECT_EQ(gfx::Rect(-500, 0, 500, 400),
  1507. GetDisplayForId(internal_display_id).bounds());
  1508. EXPECT_EQ(gfx::Rect(0, 0, 200, 100), GetDisplayForId(10).bounds());
  1509. // OnNativeDisplaysChanged may change the display bounds. Here makes sure
  1510. // nothing changed if the exactly same displays are specified.
  1511. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1512. EXPECT_EQ(gfx::Rect(-500, 0, 500, 400),
  1513. GetDisplayForId(internal_display_id).bounds());
  1514. EXPECT_EQ(gfx::Rect(0, 0, 200, 100), GetDisplayForId(10).bounds());
  1515. }
  1516. TEST_F(DisplayManagerTest, DontRememberBestResolution) {
  1517. int display_id = 1000;
  1518. display::ManagedDisplayInfo native_display_info =
  1519. display::CreateDisplayInfo(display_id, gfx::Rect(0, 0, 1000, 500));
  1520. display::ManagedDisplayInfo::ManagedDisplayModeList display_modes;
  1521. display_modes.push_back(
  1522. display::ManagedDisplayMode(gfx::Size(1000, 500), 58.0f, false, true));
  1523. display_modes.push_back(
  1524. display::ManagedDisplayMode(gfx::Size(800, 300), 59.0f, false, false));
  1525. display_modes.push_back(
  1526. display::ManagedDisplayMode(gfx::Size(400, 500), 60.0f, false, false));
  1527. native_display_info.SetManagedDisplayModes(display_modes);
  1528. std::vector<display::ManagedDisplayInfo> display_info_list;
  1529. display_info_list.push_back(native_display_info);
  1530. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1531. display::ManagedDisplayMode expected_mode(gfx::Size(1000, 500), 58.0f, false,
  1532. true);
  1533. display::ManagedDisplayMode mode;
  1534. EXPECT_FALSE(
  1535. display_manager()->GetSelectedModeForDisplayId(display_id, &mode));
  1536. display::ManagedDisplayMode active_mode;
  1537. EXPECT_TRUE(
  1538. display_manager()->GetActiveModeForDisplayId(display_id, &active_mode));
  1539. EXPECT_TRUE(expected_mode.IsEquivalent(active_mode));
  1540. // Unsupported resolution.
  1541. display::test::SetDisplayResolution(display_manager(), display_id,
  1542. gfx::Size(800, 4000));
  1543. EXPECT_FALSE(
  1544. display_manager()->GetSelectedModeForDisplayId(display_id, &mode));
  1545. EXPECT_TRUE(
  1546. display_manager()->GetActiveModeForDisplayId(display_id, &active_mode));
  1547. EXPECT_TRUE(expected_mode.IsEquivalent(active_mode));
  1548. // Supported resolution.
  1549. display::test::SetDisplayResolution(display_manager(), display_id,
  1550. gfx::Size(800, 300));
  1551. EXPECT_TRUE(
  1552. display_manager()->GetSelectedModeForDisplayId(display_id, &mode));
  1553. EXPECT_EQ(gfx::Size(800, 300), mode.size());
  1554. EXPECT_EQ(59.0f, mode.refresh_rate());
  1555. EXPECT_FALSE(mode.native());
  1556. expected_mode =
  1557. display::ManagedDisplayMode(gfx::Size(800, 300), 59.0f, false, false);
  1558. EXPECT_TRUE(
  1559. display_manager()->GetActiveModeForDisplayId(display_id, &active_mode));
  1560. EXPECT_TRUE(expected_mode.IsEquivalent(active_mode));
  1561. // Best resolution.
  1562. display::test::SetDisplayResolution(display_manager(), display_id,
  1563. gfx::Size(1000, 500));
  1564. EXPECT_TRUE(
  1565. display_manager()->GetSelectedModeForDisplayId(display_id, &mode));
  1566. EXPECT_EQ(gfx::Size(1000, 500), mode.size());
  1567. EXPECT_EQ(58.0f, mode.refresh_rate());
  1568. EXPECT_TRUE(mode.native());
  1569. expected_mode =
  1570. display::ManagedDisplayMode(gfx::Size(1000, 500), 58.0f, false, true);
  1571. EXPECT_TRUE(
  1572. display_manager()->GetActiveModeForDisplayId(display_id, &active_mode));
  1573. EXPECT_TRUE(expected_mode.IsEquivalent(active_mode));
  1574. }
  1575. TEST_F(DisplayManagerTest, ResolutionFallback) {
  1576. int display_id = 1000;
  1577. display::ManagedDisplayInfo native_display_info =
  1578. display::CreateDisplayInfo(display_id, gfx::Rect(0, 0, 1000, 500));
  1579. display::ManagedDisplayInfo::ManagedDisplayModeList display_modes;
  1580. display_modes.push_back(
  1581. display::ManagedDisplayMode(gfx::Size(1000, 500), 60.0f, false, true));
  1582. display_modes.push_back(
  1583. display::ManagedDisplayMode(gfx::Size(800, 300), 59.0f, false, false));
  1584. display_modes.push_back(
  1585. display::ManagedDisplayMode(gfx::Size(400, 500), 60.0f, false, false));
  1586. display::ManagedDisplayInfo::ManagedDisplayModeList copy = display_modes;
  1587. native_display_info.SetManagedDisplayModes(copy);
  1588. std::vector<display::ManagedDisplayInfo> display_info_list;
  1589. display_info_list.push_back(native_display_info);
  1590. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1591. {
  1592. display::test::SetDisplayResolution(display_manager(), display_id,
  1593. gfx::Size(800, 300));
  1594. display::ManagedDisplayInfo new_native_display_info =
  1595. display::CreateDisplayInfo(display_id, gfx::Rect(0, 0, 400, 500));
  1596. copy = display_modes;
  1597. new_native_display_info.SetManagedDisplayModes(copy);
  1598. std::vector<display::ManagedDisplayInfo> new_display_info_list;
  1599. new_display_info_list.push_back(new_native_display_info);
  1600. display_manager()->OnNativeDisplaysChanged(new_display_info_list);
  1601. display::ManagedDisplayMode mode;
  1602. EXPECT_TRUE(
  1603. display_manager()->GetSelectedModeForDisplayId(display_id, &mode));
  1604. EXPECT_EQ(gfx::Size(400, 500), mode.size());
  1605. EXPECT_EQ(60.0f, mode.refresh_rate());
  1606. EXPECT_FALSE(mode.native());
  1607. }
  1608. {
  1609. // Best resolution should find itself on the resolutions list.
  1610. display::test::SetDisplayResolution(display_manager(), display_id,
  1611. gfx::Size(800, 300));
  1612. display::ManagedDisplayInfo new_native_display_info =
  1613. display::CreateDisplayInfo(display_id, gfx::Rect(0, 0, 1000, 500));
  1614. new_native_display_info.set_native(true);
  1615. display::ManagedDisplayInfo::ManagedDisplayModeList copy = display_modes;
  1616. new_native_display_info.SetManagedDisplayModes(copy);
  1617. std::vector<display::ManagedDisplayInfo> new_display_info_list;
  1618. new_display_info_list.push_back(new_native_display_info);
  1619. display_manager()->OnNativeDisplaysChanged(new_display_info_list);
  1620. display::ManagedDisplayMode mode;
  1621. EXPECT_TRUE(
  1622. display_manager()->GetSelectedModeForDisplayId(display_id, &mode));
  1623. EXPECT_EQ(gfx::Size(1000, 500), mode.size());
  1624. EXPECT_EQ(60.0f, mode.refresh_rate());
  1625. EXPECT_TRUE(mode.native());
  1626. }
  1627. }
  1628. TEST_F(DisplayManagerTest, DisplayRemovedOnlyOnceWhenEnteringDockedMode) {
  1629. // Create two displays, one internal, and one external, such that the full ID
  1630. // of the internal display is *greater* than the full ID of the external
  1631. // display, but the port-index part (least significant 8-bit) of the ID of the
  1632. // internal display is *less* than the port-index part of the external
  1633. // display.
  1634. constexpr int64_t kInternalDisplayId = 0x4D10DBEBF24802LL;
  1635. constexpr int64_t kExternalDisplayId = 0x4CABEF61B95735LL;
  1636. const auto internal_info = display::ManagedDisplayInfo::CreateFromSpecWithID(
  1637. "0+0-400x300", kInternalDisplayId);
  1638. const auto external_info = display::ManagedDisplayInfo::CreateFromSpecWithID(
  1639. "401+0-600x500", kExternalDisplayId);
  1640. vector<display::ManagedDisplayInfo> display_info_list{internal_info,
  1641. external_info};
  1642. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1643. display::test::DisplayManagerTestApi(display_manager())
  1644. .SetFirstDisplayAsInternalDisplay();
  1645. // Switching to docked mode in this configuration should result in only a
  1646. // single display removal, and no new display additions.
  1647. // https://crbug.com/921275.
  1648. reset();
  1649. display_info_list.clear();
  1650. display_info_list.emplace_back(external_info);
  1651. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1652. // There should only be 1 display change, 0 adds, and 1 removal.
  1653. EXPECT_EQ("1 0 1 1 1", GetCountSummary());
  1654. const unsigned int expected_changed_metrics =
  1655. display::DisplayObserver::DISPLAY_METRIC_BOUNDS |
  1656. display::DisplayObserver::DISPLAY_METRIC_WORK_AREA |
  1657. display::DisplayObserver::DISPLAY_METRIC_PRIMARY;
  1658. EXPECT_EQ(expected_changed_metrics, changed_metrics());
  1659. // Exit docked mode by re-adding the internal display again.
  1660. reset();
  1661. display_info_list.clear();
  1662. display_info_list.emplace_back(internal_info);
  1663. display_info_list.emplace_back(external_info);
  1664. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1665. // Expect that we get a "primary" change notification.
  1666. EXPECT_EQ("5 1 0 1 1", GetCountSummary());
  1667. EXPECT_EQ(expected_changed_metrics, changed_metrics());
  1668. }
  1669. TEST_F(DisplayManagerTest, Rotate) {
  1670. UpdateDisplay("100x200/r,300x400/l");
  1671. EXPECT_EQ(gfx::Rect(1, 1, 100, 200), GetDisplayInfoAt(0).bounds_in_native());
  1672. EXPECT_EQ(gfx::Size(200, 100), GetDisplayInfoAt(0).size_in_pixel());
  1673. EXPECT_EQ(gfx::Rect(1, 201, 300, 400),
  1674. GetDisplayInfoAt(1).bounds_in_native());
  1675. EXPECT_EQ(gfx::Size(400, 300), GetDisplayInfoAt(1).size_in_pixel());
  1676. reset();
  1677. UpdateDisplay("100x200/b,300x400");
  1678. EXPECT_EQ("2 0 0 1 1", GetCountSummary());
  1679. reset();
  1680. EXPECT_EQ(gfx::Rect(1, 1, 100, 200), GetDisplayInfoAt(0).bounds_in_native());
  1681. EXPECT_EQ(gfx::Size(100, 200), GetDisplayInfoAt(0).size_in_pixel());
  1682. EXPECT_EQ(gfx::Rect(1, 201, 300, 400),
  1683. GetDisplayInfoAt(1).bounds_in_native());
  1684. EXPECT_EQ(gfx::Size(300, 400), GetDisplayInfoAt(1).size_in_pixel());
  1685. // Just Rotating display will change the bounds on both display.
  1686. UpdateDisplay("100x200/l,300x400");
  1687. EXPECT_EQ("2 0 0 1 1", GetCountSummary());
  1688. reset();
  1689. // Updating to the same configuration should report no changes. A will/did
  1690. // change is still sent.
  1691. UpdateDisplay("100x200/l,300x400");
  1692. EXPECT_EQ("0 0 0 1 1", GetCountSummary());
  1693. reset();
  1694. // Rotating 180 degrees should report one change.
  1695. UpdateDisplay("100x200/r,300x400");
  1696. EXPECT_EQ("1 0 0 1 1", GetCountSummary());
  1697. reset();
  1698. UpdateDisplay("300x200");
  1699. EXPECT_EQ("1 0 1 1 1", GetCountSummary());
  1700. reset();
  1701. // Rotating 180 degrees should report one change.
  1702. UpdateDisplay("300x200/u");
  1703. EXPECT_EQ("1 0 0 1 1", GetCountSummary());
  1704. reset();
  1705. UpdateDisplay("300x200/l");
  1706. EXPECT_EQ("1 0 0 1 1", GetCountSummary());
  1707. // Having the internal display deactivated should restore user rotation. Newly
  1708. // set rotations should be applied.
  1709. UpdateDisplay("300x200, 300x200");
  1710. const int64_t internal_display_id =
  1711. display::test::DisplayManagerTestApi(display_manager())
  1712. .SetFirstDisplayAsInternalDisplay();
  1713. display_manager()->SetDisplayRotation(internal_display_id,
  1714. display::Display::ROTATE_90,
  1715. display::Display::RotationSource::USER);
  1716. display_manager()->SetDisplayRotation(
  1717. internal_display_id, display::Display::ROTATE_0,
  1718. display::Display::RotationSource::ACTIVE);
  1719. const display::ManagedDisplayInfo info =
  1720. GetDisplayInfoForId(internal_display_id);
  1721. EXPECT_EQ(display::Display::ROTATE_0, info.GetActiveRotation());
  1722. // Deactivate internal display to simulate Docked Mode.
  1723. vector<display::ManagedDisplayInfo> secondary_only;
  1724. secondary_only.push_back(GetDisplayInfoAt(1));
  1725. display_manager()->OnNativeDisplaysChanged(secondary_only);
  1726. const display::ManagedDisplayInfo& post_removal_info =
  1727. display::test::DisplayManagerTestApi(display_manager())
  1728. .GetInternalManagedDisplayInfo(internal_display_id);
  1729. EXPECT_NE(info.GetActiveRotation(), post_removal_info.GetActiveRotation());
  1730. EXPECT_EQ(display::Display::ROTATE_90, post_removal_info.GetActiveRotation());
  1731. display_manager()->SetDisplayRotation(
  1732. internal_display_id, display::Display::ROTATE_180,
  1733. display::Display::RotationSource::ACTIVE);
  1734. const display::ManagedDisplayInfo& post_rotation_info =
  1735. display::test::DisplayManagerTestApi(display_manager())
  1736. .GetInternalManagedDisplayInfo(internal_display_id);
  1737. EXPECT_NE(info.GetActiveRotation(), post_rotation_info.GetActiveRotation());
  1738. EXPECT_EQ(display::Display::ROTATE_180,
  1739. post_rotation_info.GetActiveRotation());
  1740. }
  1741. TEST_F(DisplayManagerTest, ResolutionChangeInUnifiedMode) {
  1742. // Don't check root window destruction in unified mode.
  1743. Shell::GetPrimaryRootWindow()->RemoveObserver(this);
  1744. display_manager()->SetUnifiedDesktopEnabled(true);
  1745. UpdateDisplay("300x200, 600x400");
  1746. int64_t unified_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  1747. display::ManagedDisplayInfo info =
  1748. display_manager()->GetDisplayInfo(unified_id);
  1749. ASSERT_EQ(2u, info.display_modes().size());
  1750. EXPECT_EQ(gfx::Size(600, 200), info.display_modes()[0].size());
  1751. EXPECT_TRUE(info.display_modes()[0].native());
  1752. EXPECT_EQ(gfx::Size(1200, 400), info.display_modes()[1].size());
  1753. EXPECT_FALSE(info.display_modes()[1].native());
  1754. EXPECT_EQ(gfx::Size(600, 200),
  1755. display::Screen::GetScreen()->GetPrimaryDisplay().size());
  1756. display::ManagedDisplayMode active_mode;
  1757. EXPECT_TRUE(
  1758. display_manager()->GetActiveModeForDisplayId(unified_id, &active_mode));
  1759. EXPECT_EQ(gfx::Size(600, 200), active_mode.size());
  1760. EXPECT_TRUE(display::test::SetDisplayResolution(display_manager(), unified_id,
  1761. gfx::Size(1200, 400)));
  1762. EXPECT_EQ(gfx::Size(1200, 400),
  1763. display::Screen::GetScreen()->GetPrimaryDisplay().size());
  1764. EXPECT_TRUE(
  1765. display_manager()->GetActiveModeForDisplayId(unified_id, &active_mode));
  1766. EXPECT_EQ(gfx::Size(1200, 400), active_mode.size());
  1767. // resolution change will not persist in unified desktop mode.
  1768. UpdateDisplay("600x400, 300x200");
  1769. EXPECT_EQ(gfx::Size(1200, 400),
  1770. display::Screen::GetScreen()->GetPrimaryDisplay().size());
  1771. EXPECT_TRUE(
  1772. display_manager()->GetActiveModeForDisplayId(unified_id, &active_mode));
  1773. EXPECT_TRUE(active_mode.native());
  1774. EXPECT_EQ(gfx::Size(1200, 400), active_mode.size());
  1775. }
  1776. TEST_F(DisplayManagerTest, RotateExternalDisplayWithNonNativeMode) {
  1777. const int64_t internal_display_id = 5;
  1778. const int64_t external_id = 11;
  1779. const display::ManagedDisplayInfo internal_display_info =
  1780. display::ManagedDisplayInfo::CreateFromSpecWithID(
  1781. "1920x1080#1280x720|640x480%60", internal_display_id);
  1782. // Create an external display with a different origin to avoid triggering HW
  1783. // mirroring.
  1784. display::ManagedDisplayInfo external_display_info =
  1785. display::ManagedDisplayInfo::CreateFromSpecWithID(
  1786. "1+1-1280x720#1280x720|640x480%60", external_id);
  1787. std::vector<display::ManagedDisplayInfo> display_info_list;
  1788. display_info_list.push_back(internal_display_info);
  1789. display_info_list.push_back(external_display_info);
  1790. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1791. display::test::DisplayManagerTestApi(display_manager())
  1792. .SetFirstDisplayAsInternalDisplay();
  1793. EXPECT_EQ(2U, display_manager()->num_connected_displays());
  1794. EXPECT_EQ(internal_display_id,
  1795. display::Screen::GetScreen()->GetPrimaryDisplay().id());
  1796. display::ManagedDisplayMode active_mode;
  1797. EXPECT_TRUE(
  1798. display_manager()->GetActiveModeForDisplayId(external_id, &active_mode));
  1799. EXPECT_TRUE(active_mode.native());
  1800. const auto& modes = external_display_info.display_modes();
  1801. EXPECT_TRUE(display::test::SetDisplayResolution(
  1802. display_manager(), external_id, modes[0].size()));
  1803. display_manager()->UpdateDisplays();
  1804. EXPECT_TRUE(
  1805. display_manager()->GetActiveModeForDisplayId(external_id, &active_mode));
  1806. EXPECT_FALSE(active_mode.native());
  1807. // Rotate the display.
  1808. display_manager()->SetDisplayRotation(
  1809. external_id, display::Display::ROTATE_90,
  1810. display::Display::RotationSource::ACTIVE);
  1811. // Refresh |external_display_info| since we have rotated the display.
  1812. external_display_info = display_manager()->GetDisplayInfo(external_id);
  1813. // Disconnect the external display.
  1814. display_info_list.clear();
  1815. display_info_list.push_back(internal_display_info);
  1816. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1817. EXPECT_EQ(1U, display_manager()->num_connected_displays());
  1818. // Reconnect the external display.
  1819. display_info_list.push_back(external_display_info);
  1820. display_manager()->OnNativeDisplaysChanged(display_info_list);
  1821. EXPECT_EQ(2U, display_manager()->num_connected_displays());
  1822. // Verify the display maintains the rotation.
  1823. auto external_info = display_manager()->GetDisplayInfo(external_id);
  1824. EXPECT_EQ(display::Display::ROTATE_90, external_info.GetActiveRotation());
  1825. }
  1826. TEST_F(DisplayManagerTest, UpdateMouseCursorAfterRotateZoom) {
  1827. // Make sure just rotating will not change native location.
  1828. UpdateDisplay("300x200,200x150");
  1829. aura::Window::Windows root_windows = Shell::GetAllRootWindows();
  1830. aura::Env* env = aura::Env::GetInstance();
  1831. ui::test::EventGenerator generator1(root_windows[0]);
  1832. ui::test::EventGenerator generator2(root_windows[1]);
  1833. // Test on 1st display.
  1834. generator1.MoveMouseToInHost(150, 50);
  1835. EXPECT_EQ(gfx::Point(150, 50), env->last_mouse_location());
  1836. UpdateDisplay("300x200/r,200x150");
  1837. EXPECT_EQ(gfx::Point(50, 150), env->last_mouse_location());
  1838. // Test on 2nd display.
  1839. generator2.MoveMouseToInHost(50, 100);
  1840. EXPECT_EQ(gfx::Point(250, 100), env->last_mouse_location());
  1841. UpdateDisplay("300x200/r,200x150/l");
  1842. EXPECT_EQ(gfx::Point(250, 50), env->last_mouse_location());
  1843. // The native location is now outside, so move to the center
  1844. // of closest display.
  1845. UpdateDisplay("300x200/r,100x50/l");
  1846. EXPECT_EQ(gfx::Point(225, 50), env->last_mouse_location());
  1847. // Make sure just zooming will not change native location.
  1848. UpdateDisplay("600x400*2,400x300");
  1849. // Test on 1st display.
  1850. generator1.MoveMouseToInHost(200, 300);
  1851. EXPECT_EQ(gfx::Point(100, 150), env->last_mouse_location());
  1852. UpdateDisplay("600x400*2@1.5,400x300");
  1853. EXPECT_EQ(gfx::Point(66, 100), env->last_mouse_location());
  1854. // Test on 2nd display.
  1855. UpdateDisplay("600x400,400x300*2");
  1856. generator2.MoveMouseToInHost(200, 250);
  1857. EXPECT_EQ(gfx::Point(700, 125), env->last_mouse_location());
  1858. UpdateDisplay("600x400,400x300*2@1.5");
  1859. EXPECT_EQ(gfx::Point(666, 83), env->last_mouse_location());
  1860. // The native location is now outside, so move to the
  1861. // center of closest display.
  1862. UpdateDisplay("600x400,400x200*2@1.5");
  1863. EXPECT_EQ(gfx::Point(666, 67), env->last_mouse_location());
  1864. }
  1865. class TestDisplayObserver : public display::DisplayObserver {
  1866. public:
  1867. TestDisplayObserver() : changed_(false) {}
  1868. TestDisplayObserver(const TestDisplayObserver&) = delete;
  1869. TestDisplayObserver& operator=(const TestDisplayObserver&) = delete;
  1870. ~TestDisplayObserver() override = default;
  1871. // display::DisplayObserver overrides:
  1872. void OnDisplayMetricsChanged(const display::Display&, uint32_t) override {}
  1873. void OnDisplayAdded(const display::Display& new_display) override {
  1874. // Mirror window should already be delete before restoring
  1875. // the external display.
  1876. EXPECT_TRUE(test_api.GetHosts().empty());
  1877. changed_ = true;
  1878. }
  1879. void OnDisplayRemoved(const display::Display& old_display) override {
  1880. // Mirror window should not be created until the external display
  1881. // is removed.
  1882. EXPECT_TRUE(test_api.GetHosts().empty());
  1883. changed_ = true;
  1884. }
  1885. bool changed_and_reset() {
  1886. bool changed = changed_;
  1887. changed_ = false;
  1888. return changed;
  1889. }
  1890. private:
  1891. MirrorWindowTestApi test_api;
  1892. bool changed_;
  1893. };
  1894. TEST_F(DisplayManagerTest, SoftwareMirroring) {
  1895. UpdateDisplay("300x400,400x500");
  1896. MirrorWindowTestApi test_api;
  1897. EXPECT_TRUE(test_api.GetHosts().empty());
  1898. TestDisplayObserver display_observer;
  1899. display::Screen::GetScreen()->AddObserver(&display_observer);
  1900. display_manager()->SetMultiDisplayMode(display::DisplayManager::MIRRORING);
  1901. display_manager()->UpdateDisplays();
  1902. base::RunLoop().RunUntilIdle();
  1903. EXPECT_TRUE(display_observer.changed_and_reset());
  1904. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  1905. EXPECT_EQ(gfx::Rect(0, 0, 300, 400),
  1906. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  1907. std::vector<aura::WindowTreeHost*> hosts = test_api.GetHosts();
  1908. ASSERT_EQ(1U, hosts.size());
  1909. EXPECT_EQ(gfx::Size(400, 500), hosts[0]->GetBoundsInPixels().size());
  1910. EXPECT_EQ(gfx::Size(300, 400), hosts[0]->window()->bounds().size());
  1911. EXPECT_TRUE(display_manager()->IsInMirrorMode());
  1912. SetSoftwareMirrorMode(false);
  1913. EXPECT_TRUE(display_observer.changed_and_reset());
  1914. EXPECT_TRUE(test_api.GetHosts().empty());
  1915. EXPECT_EQ(2U, display_manager()->GetNumDisplays());
  1916. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  1917. // Make sure the mirror window has the pixel size of the
  1918. // source display.
  1919. SetSoftwareMirrorMode(true);
  1920. EXPECT_TRUE(display_observer.changed_and_reset());
  1921. UpdateDisplay("300x400@0.5,400x500");
  1922. EXPECT_FALSE(display_observer.changed_and_reset());
  1923. EXPECT_EQ(gfx::Size(300, 400),
  1924. test_api.GetHosts()[0]->window()->bounds().size());
  1925. UpdateDisplay("310x410*2,400x500");
  1926. EXPECT_FALSE(display_observer.changed_and_reset());
  1927. EXPECT_EQ(gfx::Size(310, 410),
  1928. test_api.GetHosts()[0]->window()->bounds().size());
  1929. UpdateDisplay("320x420/r,400x500");
  1930. EXPECT_FALSE(display_observer.changed_and_reset());
  1931. EXPECT_EQ(gfx::Size(420, 320),
  1932. test_api.GetHosts()[0]->window()->bounds().size());
  1933. UpdateDisplay("330x440/r,400x500");
  1934. EXPECT_FALSE(display_observer.changed_and_reset());
  1935. EXPECT_EQ(gfx::Size(440, 330),
  1936. test_api.GetHosts()[0]->window()->bounds().size());
  1937. // Overscan insets are ignored.
  1938. UpdateDisplay("400x600/o,600x800/o");
  1939. EXPECT_FALSE(display_observer.changed_and_reset());
  1940. EXPECT_EQ(gfx::Size(400, 600),
  1941. test_api.GetHosts()[0]->window()->bounds().size());
  1942. display::Screen::GetScreen()->RemoveObserver(&display_observer);
  1943. }
  1944. TEST_F(DisplayManagerTest, RotateInSoftwareMirroring) {
  1945. UpdateDisplay("600x400,500x300");
  1946. SetSoftwareMirrorMode(true);
  1947. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  1948. int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  1949. display_manager()->SetDisplayRotation(
  1950. primary_id, display::Display::ROTATE_180,
  1951. display::Display::RotationSource::ACTIVE);
  1952. SetSoftwareMirrorMode(false);
  1953. }
  1954. TEST_F(DisplayManagerTest, InvertLayout) {
  1955. EXPECT_EQ("left, 0",
  1956. display::DisplayPlacement(display::DisplayPlacement::RIGHT, 0)
  1957. .Swap()
  1958. .ToString());
  1959. EXPECT_EQ("left, -100",
  1960. display::DisplayPlacement(display::DisplayPlacement::RIGHT, 100)
  1961. .Swap()
  1962. .ToString());
  1963. EXPECT_EQ("left, 50",
  1964. display::DisplayPlacement(display::DisplayPlacement::RIGHT, -50)
  1965. .Swap()
  1966. .ToString());
  1967. EXPECT_EQ("right, 0",
  1968. display::DisplayPlacement(display::DisplayPlacement::LEFT, 0)
  1969. .Swap()
  1970. .ToString());
  1971. EXPECT_EQ("right, -90",
  1972. display::DisplayPlacement(display::DisplayPlacement::LEFT, 90)
  1973. .Swap()
  1974. .ToString());
  1975. EXPECT_EQ("right, 60",
  1976. display::DisplayPlacement(display::DisplayPlacement::LEFT, -60)
  1977. .Swap()
  1978. .ToString());
  1979. EXPECT_EQ("bottom, 0",
  1980. display::DisplayPlacement(display::DisplayPlacement::TOP, 0)
  1981. .Swap()
  1982. .ToString());
  1983. EXPECT_EQ("bottom, -80",
  1984. display::DisplayPlacement(display::DisplayPlacement::TOP, 80)
  1985. .Swap()
  1986. .ToString());
  1987. EXPECT_EQ("bottom, 70",
  1988. display::DisplayPlacement(display::DisplayPlacement::TOP, -70)
  1989. .Swap()
  1990. .ToString());
  1991. EXPECT_EQ("top, 0",
  1992. display::DisplayPlacement(display::DisplayPlacement::BOTTOM, 0)
  1993. .Swap()
  1994. .ToString());
  1995. EXPECT_EQ("top, -70",
  1996. display::DisplayPlacement(display::DisplayPlacement::BOTTOM, 70)
  1997. .Swap()
  1998. .ToString());
  1999. EXPECT_EQ("top, 80",
  2000. display::DisplayPlacement(display::DisplayPlacement::BOTTOM, -80)
  2001. .Swap()
  2002. .ToString());
  2003. }
  2004. TEST_F(DisplayManagerTest, NotifyPrimaryChange) {
  2005. UpdateDisplay("500x400,500x400");
  2006. SwapPrimaryDisplay();
  2007. reset();
  2008. UpdateDisplay("500x400");
  2009. EXPECT_FALSE(changed_metrics() &
  2010. display::DisplayObserver::DISPLAY_METRIC_BOUNDS);
  2011. EXPECT_FALSE(changed_metrics() &
  2012. display::DisplayObserver::DISPLAY_METRIC_WORK_AREA);
  2013. EXPECT_TRUE(changed_metrics() &
  2014. display::DisplayObserver::DISPLAY_METRIC_PRIMARY);
  2015. UpdateDisplay("500x400,500x400");
  2016. SwapPrimaryDisplay();
  2017. UpdateDisplay("500x400");
  2018. EXPECT_TRUE(changed_metrics() &
  2019. display::DisplayObserver::DISPLAY_METRIC_BOUNDS);
  2020. EXPECT_TRUE(changed_metrics() &
  2021. display::DisplayObserver::DISPLAY_METRIC_WORK_AREA);
  2022. EXPECT_TRUE(changed_metrics() &
  2023. display::DisplayObserver::DISPLAY_METRIC_PRIMARY);
  2024. }
  2025. TEST_F(DisplayManagerTest, NotifyPrimaryChangeUndock) {
  2026. // Assume the default display is an external display, and
  2027. // emulates undocking by switching to another display.
  2028. display::ManagedDisplayInfo another_display_info =
  2029. display::CreateDisplayInfo(1, gfx::Rect(0, 0, 1280, 800));
  2030. std::vector<display::ManagedDisplayInfo> info_list;
  2031. info_list.push_back(another_display_info);
  2032. reset();
  2033. display_manager()->OnNativeDisplaysChanged(info_list);
  2034. EXPECT_TRUE(changed_metrics() &
  2035. display::DisplayObserver::DISPLAY_METRIC_BOUNDS);
  2036. EXPECT_TRUE(changed_metrics() &
  2037. display::DisplayObserver::DISPLAY_METRIC_WORK_AREA);
  2038. EXPECT_TRUE(changed_metrics() &
  2039. display::DisplayObserver::DISPLAY_METRIC_PRIMARY);
  2040. }
  2041. TEST_F(DisplayManagerTest, UpdateDisplayWithHostOrigin) {
  2042. UpdateDisplay("100x200,300x400");
  2043. ASSERT_EQ(2, display::Screen::GetScreen()->GetNumDisplays());
  2044. aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
  2045. ASSERT_EQ(2U, root_windows.size());
  2046. aura::WindowTreeHost* host0 = root_windows[0]->GetHost();
  2047. aura::WindowTreeHost* host1 = root_windows[1]->GetHost();
  2048. EXPECT_EQ(gfx::Point(1, 1), host0->GetBoundsInPixels().origin());
  2049. EXPECT_EQ(gfx::Size(100, 200), host0->GetBoundsInPixels().size());
  2050. // UpdateDisplay set the origin if it's not set.
  2051. EXPECT_NE(gfx::Point(1, 1), host1->GetBoundsInPixels().origin());
  2052. EXPECT_EQ(gfx::Size(300, 400), host1->GetBoundsInPixels().size());
  2053. UpdateDisplay("100x200,200+300-300x400");
  2054. ASSERT_EQ(2, display::Screen::GetScreen()->GetNumDisplays());
  2055. EXPECT_EQ(gfx::Point(0, 0), host0->GetBoundsInPixels().origin());
  2056. EXPECT_EQ(gfx::Size(100, 200), host0->GetBoundsInPixels().size());
  2057. EXPECT_EQ(gfx::Point(200, 300), host1->GetBoundsInPixels().origin());
  2058. EXPECT_EQ(gfx::Size(300, 400), host1->GetBoundsInPixels().size());
  2059. UpdateDisplay("400+500-200x300,300x400");
  2060. ASSERT_EQ(2, display::Screen::GetScreen()->GetNumDisplays());
  2061. EXPECT_EQ(gfx::Point(400, 500), host0->GetBoundsInPixels().origin());
  2062. EXPECT_EQ(gfx::Size(200, 300), host0->GetBoundsInPixels().size());
  2063. EXPECT_EQ(gfx::Point(0, 0), host1->GetBoundsInPixels().origin());
  2064. EXPECT_EQ(gfx::Size(300, 400), host1->GetBoundsInPixels().size());
  2065. UpdateDisplay("100+200-100x200,300+500-200x300");
  2066. ASSERT_EQ(2, display::Screen::GetScreen()->GetNumDisplays());
  2067. EXPECT_EQ(gfx::Point(100, 200), host0->GetBoundsInPixels().origin());
  2068. EXPECT_EQ(gfx::Size(100, 200), host0->GetBoundsInPixels().size());
  2069. EXPECT_EQ(gfx::Point(300, 500), host1->GetBoundsInPixels().origin());
  2070. EXPECT_EQ(gfx::Size(200, 300), host1->GetBoundsInPixels().size());
  2071. }
  2072. TEST_F(DisplayManagerTest, UnifiedDesktopBasic) {
  2073. // Don't check root window destruction in unified mode.
  2074. Shell::GetPrimaryRootWindow()->RemoveObserver(this);
  2075. UpdateDisplay("400x500,300x200");
  2076. // Enable after extended mode.
  2077. display_manager()->SetUnifiedDesktopEnabled(true);
  2078. // Defaults to the unified desktop.
  2079. display::Screen* screen = display::Screen::GetScreen();
  2080. // The 2nd display is scaled so that it has the same height as 1st display.
  2081. // 300 * 500 / 200 + 400 = 1150.
  2082. EXPECT_EQ(gfx::Size(1150, 500), screen->GetPrimaryDisplay().size());
  2083. SetSoftwareMirrorMode(true);
  2084. EXPECT_EQ(gfx::Size(400, 500), screen->GetPrimaryDisplay().size());
  2085. SetSoftwareMirrorMode(false);
  2086. EXPECT_EQ(gfx::Size(1150, 500), screen->GetPrimaryDisplay().size());
  2087. // Switch to single desktop.
  2088. UpdateDisplay("500x300");
  2089. EXPECT_EQ(gfx::Size(500, 300), screen->GetPrimaryDisplay().size());
  2090. // Switch to unified desktop.
  2091. UpdateDisplay("500x300,400x500");
  2092. // 400 * 300 / 500 + 500 ~= 739.
  2093. EXPECT_EQ(gfx::Size(739, 300), screen->GetPrimaryDisplay().size());
  2094. // The default should fit to the internal display.
  2095. std::vector<display::ManagedDisplayInfo> display_info_list;
  2096. display_info_list.push_back(
  2097. display::CreateDisplayInfo(10, gfx::Rect(0, 0, 500, 300)));
  2098. display_info_list.push_back(
  2099. display::CreateDisplayInfo(11, gfx::Rect(500, 0, 400, 500)));
  2100. {
  2101. display::test::ScopedSetInternalDisplayId set_internal(display_manager(),
  2102. 11);
  2103. display_manager()->OnNativeDisplaysChanged(display_info_list);
  2104. // 500 * 500 / 300 + 400 ~= 1233.
  2105. EXPECT_EQ(gfx::Size(1233, 500), screen->GetPrimaryDisplay().size());
  2106. }
  2107. // Switch to 3 displays.
  2108. UpdateDisplay("500x300,400x500,500x300");
  2109. EXPECT_EQ(gfx::Size(1239, 300), screen->GetPrimaryDisplay().size());
  2110. // Switch back to extended desktop.
  2111. display_manager()->SetUnifiedDesktopEnabled(false);
  2112. EXPECT_EQ(gfx::Size(500, 300), screen->GetPrimaryDisplay().size());
  2113. display::test::DisplayManagerTestApi display_manager_test(display_manager());
  2114. EXPECT_EQ(gfx::Size(400, 500),
  2115. display_manager_test.GetSecondaryDisplay().size());
  2116. EXPECT_EQ(gfx::Size(500, 300),
  2117. display_manager()
  2118. ->GetDisplayForId(display::GetNextSynthesizedDisplayId(
  2119. display_manager_test.GetSecondaryDisplay().id()))
  2120. .size());
  2121. }
  2122. TEST_F(DisplayManagerTest, UnifiedDesktopWithHardwareMirroring) {
  2123. // Don't check root window destruction in unified mode.
  2124. Shell::GetPrimaryRootWindow()->RemoveObserver(this);
  2125. // Enter to hardware mirroring.
  2126. display::ManagedDisplayInfo d1(1, "", false);
  2127. d1.SetBounds(gfx::Rect(0, 0, 500, 400));
  2128. display::ManagedDisplayInfo d2(2, "", false);
  2129. d2.SetBounds(gfx::Rect(0, 0, 500, 400));
  2130. std::vector<display::ManagedDisplayInfo> display_info_list;
  2131. display_info_list.push_back(d1);
  2132. display_info_list.push_back(d2);
  2133. display_manager()->OnNativeDisplaysChanged(display_info_list);
  2134. ASSERT_TRUE(display_manager()->IsInHardwareMirrorMode());
  2135. display_manager()->SetUnifiedDesktopEnabled(true);
  2136. EXPECT_TRUE(display_manager()->IsInHardwareMirrorMode());
  2137. // The display manager automatically switches to software mirroring if
  2138. // hardware mirroring is no longer available, because previous mirror mode
  2139. // enforces current display mode to be mirror mode.
  2140. display::DisplayIdList list = display::test::CreateDisplayIdList2(1, 2);
  2141. display::DisplayLayoutBuilder builder(
  2142. display_manager()->layout_store()->GetRegisteredDisplayLayout(list));
  2143. display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
  2144. list, builder.Build());
  2145. d2.SetBounds(gfx::Rect(0, 500, 500, 400));
  2146. display_info_list.clear();
  2147. display_info_list.push_back(d1);
  2148. display_info_list.push_back(d2);
  2149. display_manager()->OnNativeDisplaysChanged(display_info_list);
  2150. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  2151. EXPECT_FALSE(display_manager()->IsInUnifiedMode());
  2152. // Exit software mirroring and enter unified desktop mode after mirror mode is
  2153. // turned off.
  2154. SetSoftwareMirrorMode(false);
  2155. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  2156. EXPECT_TRUE(display_manager()->IsInUnifiedMode());
  2157. }
  2158. TEST_F(DisplayManagerTest, UnifiedDesktopEnabledWithExtended) {
  2159. // Don't check root window destruction in unified mode.
  2160. Shell::GetPrimaryRootWindow()->RemoveObserver(this);
  2161. UpdateDisplay("400x500,300x200");
  2162. display::DisplayIdList list = display_manager()->GetConnectedDisplayIdList();
  2163. display::DisplayLayoutBuilder builder(
  2164. display_manager()->layout_store()->GetRegisteredDisplayLayout(list));
  2165. builder.SetDefaultUnified(false);
  2166. display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
  2167. list, builder.Build());
  2168. display_manager()->SetUnifiedDesktopEnabled(true);
  2169. EXPECT_FALSE(display_manager()->IsInUnifiedMode());
  2170. }
  2171. TEST_F(DisplayManagerTest, UnifiedDesktopWith2xDSF) {
  2172. // Don't check root window destruction in unified mode.
  2173. Shell::GetPrimaryRootWindow()->RemoveObserver(this);
  2174. display_manager()->SetUnifiedDesktopEnabled(true);
  2175. display::Screen* screen = display::Screen::GetScreen();
  2176. // 2nd display is 2x.
  2177. UpdateDisplay("400x500,1000x800*2");
  2178. display::ManagedDisplayInfo info =
  2179. display_manager()->GetDisplayInfo(screen->GetPrimaryDisplay().id());
  2180. ASSERT_EQ(2u, info.display_modes().size());
  2181. EXPECT_EQ(gfx::Size(1640, 800), info.display_modes()[0].size());
  2182. EXPECT_EQ(2.0f, info.display_modes()[0].device_scale_factor());
  2183. EXPECT_EQ(gfx::Size(1025, 500), info.display_modes()[1].size());
  2184. EXPECT_EQ(1.0f, info.display_modes()[1].device_scale_factor());
  2185. // For 1x, 400 + 500 / 800 * 100 = 1025.
  2186. EXPECT_EQ(gfx::Size(1025, 500), screen->GetPrimaryDisplay().size());
  2187. EXPECT_EQ(gfx::Size(1025, 500),
  2188. Shell::GetPrimaryRootWindow()->bounds().size());
  2189. accelerators::ZoomDisplay(false);
  2190. // (800 / 500 * 400 + 500) /2 = 820
  2191. EXPECT_EQ(gfx::Size(820, 400), screen->GetPrimaryDisplay().size());
  2192. EXPECT_EQ(gfx::Size(820, 400),
  2193. Shell::GetPrimaryRootWindow()->bounds().size());
  2194. // 1st display is 2x.
  2195. UpdateDisplay("1200x800*2,1100x1000");
  2196. info = display_manager()->GetDisplayInfo(screen->GetPrimaryDisplay().id());
  2197. ASSERT_EQ(2u, info.display_modes().size());
  2198. EXPECT_EQ(gfx::Size(2080, 800), info.display_modes()[0].size());
  2199. EXPECT_EQ(2.0f, info.display_modes()[0].device_scale_factor());
  2200. EXPECT_EQ(gfx::Size(2600, 1000), info.display_modes()[1].size());
  2201. EXPECT_EQ(1.0f, info.display_modes()[1].device_scale_factor());
  2202. // For 2x, (800 / 1000 * 1100 + 1200) / 2 = 1040
  2203. EXPECT_EQ(gfx::Size(1040, 400), screen->GetPrimaryDisplay().size());
  2204. EXPECT_EQ(gfx::Size(1040, 400),
  2205. Shell::GetPrimaryRootWindow()->bounds().size());
  2206. accelerators::ZoomDisplay(true);
  2207. // 1000 / 800 * 1200 + 1100 = 2600
  2208. EXPECT_EQ(gfx::Size(2600, 1000), screen->GetPrimaryDisplay().size());
  2209. EXPECT_EQ(gfx::Size(2600, 1000),
  2210. Shell::GetPrimaryRootWindow()->bounds().size());
  2211. // Both displays are 2x.
  2212. // 1st display is 2x.
  2213. UpdateDisplay("1200x800*2,1100x1000*2");
  2214. info = display_manager()->GetDisplayInfo(screen->GetPrimaryDisplay().id());
  2215. ASSERT_EQ(2u, info.display_modes().size());
  2216. EXPECT_EQ(gfx::Size(2080, 800), info.display_modes()[0].size());
  2217. EXPECT_EQ(2.0f, info.display_modes()[0].device_scale_factor());
  2218. EXPECT_EQ(gfx::Size(2600, 1000), info.display_modes()[1].size());
  2219. EXPECT_EQ(2.0f, info.display_modes()[1].device_scale_factor());
  2220. EXPECT_EQ(gfx::Size(1040, 400), screen->GetPrimaryDisplay().size());
  2221. EXPECT_EQ(gfx::Size(1040, 400),
  2222. Shell::GetPrimaryRootWindow()->bounds().size());
  2223. accelerators::ZoomDisplay(true);
  2224. EXPECT_EQ(gfx::Size(1300, 500), screen->GetPrimaryDisplay().size());
  2225. EXPECT_EQ(gfx::Size(1300, 500),
  2226. Shell::GetPrimaryRootWindow()->bounds().size());
  2227. // Both displays have the same physical height, with the first display
  2228. // being 2x.
  2229. UpdateDisplay("1000x800*2,300x800");
  2230. info = display_manager()->GetDisplayInfo(screen->GetPrimaryDisplay().id());
  2231. ASSERT_EQ(2u, info.display_modes().size());
  2232. EXPECT_EQ(gfx::Size(1300, 800), info.display_modes()[0].size());
  2233. EXPECT_EQ(2.0f, info.display_modes()[0].device_scale_factor());
  2234. EXPECT_EQ(gfx::Size(1300, 800), info.display_modes()[1].size());
  2235. EXPECT_EQ(1.0f, info.display_modes()[1].device_scale_factor());
  2236. EXPECT_EQ(gfx::Size(650, 400), screen->GetPrimaryDisplay().size());
  2237. EXPECT_EQ(gfx::Size(650, 400),
  2238. Shell::GetPrimaryRootWindow()->bounds().size());
  2239. accelerators::ZoomDisplay(true);
  2240. EXPECT_EQ(gfx::Size(1300, 800), screen->GetPrimaryDisplay().size());
  2241. EXPECT_EQ(gfx::Size(1300, 800),
  2242. Shell::GetPrimaryRootWindow()->bounds().size());
  2243. // Both displays have the same physical height, with the second display
  2244. // being 2x.
  2245. UpdateDisplay("1000x800,300x800*2");
  2246. ASSERT_EQ(2u, info.display_modes().size());
  2247. EXPECT_EQ(gfx::Size(1300, 800), info.display_modes()[0].size());
  2248. EXPECT_EQ(2.0f, info.display_modes()[0].device_scale_factor());
  2249. EXPECT_EQ(gfx::Size(1300, 800), info.display_modes()[1].size());
  2250. EXPECT_EQ(1.0f, info.display_modes()[1].device_scale_factor());
  2251. EXPECT_EQ(gfx::Size(1300, 800), screen->GetPrimaryDisplay().size());
  2252. EXPECT_EQ(gfx::Size(1300, 800),
  2253. Shell::GetPrimaryRootWindow()->bounds().size());
  2254. accelerators::ZoomDisplay(false);
  2255. EXPECT_EQ(gfx::Size(650, 400), screen->GetPrimaryDisplay().size());
  2256. EXPECT_EQ(gfx::Size(650, 400),
  2257. Shell::GetPrimaryRootWindow()->bounds().size());
  2258. }
  2259. // Updating displays again in unified desktop mode should not crash.
  2260. // crbug.com/491094.
  2261. TEST_F(DisplayManagerTest, ConfigureUnifiedTwice) {
  2262. // Don't check root window destruction in unified mode.
  2263. Shell::GetPrimaryRootWindow()->RemoveObserver(this);
  2264. UpdateDisplay("300x200,400x500");
  2265. // Mirror windows are created in a posted task.
  2266. base::RunLoop().RunUntilIdle();
  2267. UpdateDisplay("300x250,400x550");
  2268. base::RunLoop().RunUntilIdle();
  2269. }
  2270. TEST_F(DisplayManagerTest, NoRotateUnifiedDesktop) {
  2271. display_manager()->SetUnifiedDesktopEnabled(true);
  2272. // Don't check root window destruction in unified mode.
  2273. Shell::GetPrimaryRootWindow()->RemoveObserver(this);
  2274. UpdateDisplay("400x500,300x200");
  2275. display::Screen* screen = display::Screen::GetScreen();
  2276. const display::Display& display = screen->GetPrimaryDisplay();
  2277. EXPECT_EQ(gfx::Size(1150, 500), display.size());
  2278. display_manager()->SetDisplayRotation(
  2279. display.id(), display::Display::ROTATE_90,
  2280. display::Display::RotationSource::ACTIVE);
  2281. EXPECT_EQ(gfx::Size(1150, 500), screen->GetPrimaryDisplay().size());
  2282. EXPECT_EQ(display::Display::ROTATE_0,
  2283. screen->GetPrimaryDisplay().panel_rotation());
  2284. display_manager()->SetDisplayRotation(
  2285. display.id(), display::Display::ROTATE_0,
  2286. display::Display::RotationSource::ACTIVE);
  2287. EXPECT_EQ(gfx::Size(1150, 500), screen->GetPrimaryDisplay().size());
  2288. EXPECT_EQ(display::Display::ROTATE_0,
  2289. screen->GetPrimaryDisplay().panel_rotation());
  2290. UpdateDisplay("400x500");
  2291. EXPECT_EQ(gfx::Size(400, 500), screen->GetPrimaryDisplay().size());
  2292. }
  2293. // Validate that setting an invalid matrix will fall back to the default
  2294. // horizontal unified desktop layout.
  2295. TEST_F(DisplayManagerTest, UnifiedDesktopInvalidMatrices) {
  2296. // Don't check root window destruction in unified mode.
  2297. Shell::GetPrimaryRootWindow()->RemoveObserver(this);
  2298. UpdateDisplay("400x500,300x200");
  2299. display_manager()->SetUnifiedDesktopEnabled(true);
  2300. display::Screen* screen = display::Screen::GetScreen();
  2301. display::DisplayIdList list = display_manager()->GetConnectedDisplayIdList();
  2302. ASSERT_EQ(2u, list.size());
  2303. {
  2304. // Create an empty matrix.
  2305. display::UnifiedDesktopLayoutMatrix matrix;
  2306. display_manager()->SetUnifiedDesktopMatrix(matrix);
  2307. // The result is still a valid default horizontal layout.
  2308. EXPECT_EQ(gfx::Size(1150, 500), screen->GetPrimaryDisplay().size());
  2309. // 2 x 1 empty matrix.
  2310. matrix.resize(2u);
  2311. display_manager()->SetUnifiedDesktopMatrix(matrix);
  2312. // The result is still a valid default horizontal layout.
  2313. EXPECT_EQ(gfx::Size(1150, 500), screen->GetPrimaryDisplay().size());
  2314. }
  2315. {
  2316. // 2 x 1 vertical matrix with invalid IDs.
  2317. display::UnifiedDesktopLayoutMatrix matrix;
  2318. matrix.resize(2u);
  2319. matrix[0].emplace_back(list[0]);
  2320. matrix[1].emplace_back(-100);
  2321. display_manager()->SetUnifiedDesktopMatrix(matrix);
  2322. // The result is still a valid default horizontal layout.
  2323. EXPECT_EQ(gfx::Size(1150, 500), screen->GetPrimaryDisplay().size());
  2324. }
  2325. {
  2326. // Matrix with a missing ID.
  2327. display::UnifiedDesktopLayoutMatrix matrix;
  2328. matrix.resize(2u);
  2329. matrix[0].emplace_back(list[0]);
  2330. display_manager()->SetUnifiedDesktopMatrix(matrix);
  2331. // The result is still a valid default horizontal layout.
  2332. EXPECT_EQ(gfx::Size(1150, 500), screen->GetPrimaryDisplay().size());
  2333. }
  2334. // Switch to 3 displays.
  2335. UpdateDisplay("500x300,400x500,500x300");
  2336. list = display_manager()->GetConnectedDisplayIdList();
  2337. ASSERT_EQ(3u, list.size());
  2338. {
  2339. // Create a matrix with unequal rows
  2340. display::UnifiedDesktopLayoutMatrix matrix;
  2341. matrix.resize(3u);
  2342. matrix[0].emplace_back(list[0]);
  2343. matrix[1].emplace_back(list[1]);
  2344. matrix[1].emplace_back(list[2]); // Typo; meant to say matrix[2].
  2345. display_manager()->SetUnifiedDesktopMatrix(matrix);
  2346. // The result is still a valid default horizontal layout.
  2347. EXPECT_EQ(gfx::Size(1239, 300), screen->GetPrimaryDisplay().size());
  2348. }
  2349. {
  2350. // Create a matrix with repeated IDs.
  2351. display::UnifiedDesktopLayoutMatrix matrix;
  2352. matrix.resize(3u);
  2353. matrix[0].emplace_back(list[0]);
  2354. matrix[1].emplace_back(list[1]);
  2355. matrix[2].emplace_back(list[1]); // Typo; meant to say list[2].
  2356. display_manager()->SetUnifiedDesktopMatrix(matrix);
  2357. // The result is still a valid default horizontal layout.
  2358. EXPECT_EQ(gfx::Size(1239, 300), screen->GetPrimaryDisplay().size());
  2359. }
  2360. }
  2361. TEST_F(DisplayManagerTest, UnifiedDesktopVerticalLayout2x1) {
  2362. // Don't check root window destruction in unified mode.
  2363. Shell::GetPrimaryRootWindow()->RemoveObserver(this);
  2364. UpdateDisplay("400x500,300x200");
  2365. display_manager()->SetUnifiedDesktopEnabled(true);
  2366. display::Screen* screen = display::Screen::GetScreen();
  2367. // This is still a horizontal layout.
  2368. EXPECT_EQ(gfx::Size(1150, 500), screen->GetPrimaryDisplay().size());
  2369. display::DisplayIdList list = display_manager()->GetConnectedDisplayIdList();
  2370. ASSERT_EQ(2u, list.size());
  2371. {
  2372. // Create a 2 x 1 vertical layout matrix and set it.
  2373. // [400 x 500]
  2374. // [300 x 200]
  2375. display::UnifiedDesktopLayoutMatrix matrix;
  2376. matrix.resize(2u);
  2377. matrix[0].emplace_back(list[0]);
  2378. matrix[1].emplace_back(list[1]);
  2379. display_manager()->SetUnifiedDesktopMatrix(matrix);
  2380. // 500 + 400 * 200 / 300 ~= 766.
  2381. EXPECT_EQ(gfx::Size(400, 766), screen->GetPrimaryDisplay().size());
  2382. // Default shelf alignment is bottom. Display in bottom-left cell is
  2383. // considered the primary mirroring display.
  2384. EXPECT_EQ(list[1], Shell::Get()
  2385. ->display_configuration_controller()
  2386. ->GetPrimaryMirroringDisplayForUnifiedDesktop()
  2387. .id());
  2388. // Validate display rows and max heights.
  2389. EXPECT_EQ(0, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2390. list[0]));
  2391. EXPECT_EQ(1, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2392. list[1]));
  2393. EXPECT_EQ(500, display_manager()->GetUnifiedDesktopRowMaxHeight(0));
  2394. EXPECT_EQ(400 * 200 / 300,
  2395. display_manager()->GetUnifiedDesktopRowMaxHeight(1));
  2396. EXPECT_FALSE(OverlappingMirroringDisplaysExist());
  2397. }
  2398. {
  2399. // Change the order of the displays such that the [300 x 200] is on top,
  2400. // which should make its bounds used for the default mode.
  2401. // [300 x 200]
  2402. // [400 x 500]
  2403. display::UnifiedDesktopLayoutMatrix matrix;
  2404. matrix.resize(2u);
  2405. matrix[0].emplace_back(list[1]);
  2406. matrix[1].emplace_back(list[0]);
  2407. display_manager()->SetUnifiedDesktopMatrix(matrix);
  2408. // 200 + 300 * 500 / 400 ~= 574 (Note that we actually scale the max unified
  2409. // bounds).
  2410. EXPECT_EQ(gfx::Size(300, 574), screen->GetPrimaryDisplay().size());
  2411. // Display in bottom-left cell is considered primary.
  2412. EXPECT_EQ(list[0], Shell::Get()
  2413. ->display_configuration_controller()
  2414. ->GetPrimaryMirroringDisplayForUnifiedDesktop()
  2415. .id());
  2416. // Validate display rows and max heights.
  2417. EXPECT_EQ(1, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2418. list[0]));
  2419. EXPECT_EQ(0, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2420. list[1]));
  2421. EXPECT_EQ(199, display_manager()->GetUnifiedDesktopRowMaxHeight(0));
  2422. // 300 * 500 / 400.
  2423. EXPECT_EQ(375, display_manager()->GetUnifiedDesktopRowMaxHeight(1));
  2424. EXPECT_FALSE(OverlappingMirroringDisplaysExist());
  2425. }
  2426. {
  2427. // Revert to the first matrix, but mark the [300 x 200] display as internal.
  2428. // [400 x 500]
  2429. // [300 x 200] : Internal
  2430. display::UnifiedDesktopLayoutMatrix matrix;
  2431. matrix.resize(2u);
  2432. matrix[0].emplace_back(list[0]);
  2433. matrix[1].emplace_back(list[1]);
  2434. display_manager()->SetUnifiedDesktopMatrix(matrix);
  2435. std::vector<display::ManagedDisplayInfo> display_info_list;
  2436. display_info_list.emplace_back(
  2437. display::CreateDisplayInfo(list[0], gfx::Rect(0, 0, 400, 500)));
  2438. display_info_list.emplace_back(
  2439. display::CreateDisplayInfo(list[1], gfx::Rect(400, 0, 300, 200)));
  2440. display::test::ScopedSetInternalDisplayId set_internal(display_manager(),
  2441. list[1]);
  2442. display_manager()->OnNativeDisplaysChanged(display_info_list);
  2443. // Run loop to create mirroring displays.
  2444. base::RunLoop().RunUntilIdle();
  2445. EXPECT_EQ(gfx::Size(300, 574), screen->GetPrimaryDisplay().size());
  2446. // Display in bottom-left cell is considered primary.
  2447. EXPECT_EQ(list[1], Shell::Get()
  2448. ->display_configuration_controller()
  2449. ->GetPrimaryMirroringDisplayForUnifiedDesktop()
  2450. .id());
  2451. // Validate display rows and max heights.
  2452. EXPECT_EQ(0, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2453. list[0]));
  2454. EXPECT_EQ(1, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2455. list[1]));
  2456. // 300 * 500 / 400.
  2457. EXPECT_EQ(375, display_manager()->GetUnifiedDesktopRowMaxHeight(0));
  2458. EXPECT_EQ(199, display_manager()->GetUnifiedDesktopRowMaxHeight(1));
  2459. EXPECT_FALSE(OverlappingMirroringDisplaysExist());
  2460. }
  2461. }
  2462. TEST_F(DisplayManagerTest, UnifiedDesktopVerticalLayout3x1) {
  2463. // Don't check root window destruction in unified mode.
  2464. Shell::GetPrimaryRootWindow()->RemoveObserver(this);
  2465. UpdateDisplay("500x300,400x500,500x300");
  2466. display_manager()->SetUnifiedDesktopEnabled(true);
  2467. display::Screen* screen = display::Screen::GetScreen();
  2468. display::DisplayIdList list = display_manager()->GetConnectedDisplayIdList();
  2469. ASSERT_EQ(3u, list.size());
  2470. {
  2471. // Create a 3 x 1 vertical layout matrix and set it.
  2472. // [500 x 300]
  2473. // [400 x 500]
  2474. // [500 x 300]
  2475. display::UnifiedDesktopLayoutMatrix matrix;
  2476. matrix.resize(3u);
  2477. matrix[0].emplace_back(list[0]);
  2478. matrix[1].emplace_back(list[1]);
  2479. matrix[2].emplace_back(list[2]);
  2480. display_manager()->SetUnifiedDesktopMatrix(matrix);
  2481. EXPECT_EQ(gfx::Size(500, 1225), screen->GetPrimaryDisplay().size());
  2482. // Display in bottom-left cell is considered primary.
  2483. EXPECT_EQ(list[2], Shell::Get()
  2484. ->display_configuration_controller()
  2485. ->GetPrimaryMirroringDisplayForUnifiedDesktop()
  2486. .id());
  2487. // Validate display rows and max heights.
  2488. EXPECT_EQ(0, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2489. list[0]));
  2490. EXPECT_EQ(1, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2491. list[1]));
  2492. EXPECT_EQ(2, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2493. list[2]));
  2494. EXPECT_EQ(300, display_manager()->GetUnifiedDesktopRowMaxHeight(0));
  2495. // 500 * 500 / 400 = 625.
  2496. EXPECT_EQ(625, display_manager()->GetUnifiedDesktopRowMaxHeight(1));
  2497. EXPECT_EQ(300, display_manager()->GetUnifiedDesktopRowMaxHeight(2));
  2498. EXPECT_FALSE(OverlappingMirroringDisplaysExist());
  2499. }
  2500. {
  2501. // We can change the order however we want.
  2502. // [400 x 500]
  2503. // [500 x 300]
  2504. // [500 x 300]
  2505. display::UnifiedDesktopLayoutMatrix matrix;
  2506. matrix.resize(3u);
  2507. matrix[0].emplace_back(list[1]);
  2508. matrix[1].emplace_back(list[0]);
  2509. matrix[2].emplace_back(list[2]);
  2510. display_manager()->SetUnifiedDesktopMatrix(matrix);
  2511. EXPECT_EQ(gfx::Size(400, 980), screen->GetPrimaryDisplay().size());
  2512. // Display in bottom-left cell is considered primary.
  2513. EXPECT_EQ(list[2], Shell::Get()
  2514. ->display_configuration_controller()
  2515. ->GetPrimaryMirroringDisplayForUnifiedDesktop()
  2516. .id());
  2517. // Validate display rows and max heights.
  2518. EXPECT_EQ(1, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2519. list[0]));
  2520. EXPECT_EQ(0, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2521. list[1]));
  2522. EXPECT_EQ(2, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2523. list[2]));
  2524. EXPECT_EQ(500, display_manager()->GetUnifiedDesktopRowMaxHeight(0));
  2525. // 400 * 300 / 500 = 240.
  2526. EXPECT_EQ(240, display_manager()->GetUnifiedDesktopRowMaxHeight(1));
  2527. EXPECT_EQ(240, display_manager()->GetUnifiedDesktopRowMaxHeight(2));
  2528. EXPECT_FALSE(OverlappingMirroringDisplaysExist());
  2529. }
  2530. }
  2531. TEST_F(DisplayManagerTest, UnifiedDesktopGridLayout2x2) {
  2532. // Don't check root window destruction in unified mode.
  2533. Shell::GetPrimaryRootWindow()->RemoveObserver(this);
  2534. UpdateDisplay("500x300,400x500,300x600,200x300");
  2535. display_manager()->SetUnifiedDesktopEnabled(true);
  2536. display::Screen* screen = display::Screen::GetScreen();
  2537. display::DisplayIdList list = display_manager()->GetConnectedDisplayIdList();
  2538. ASSERT_EQ(4u, list.size());
  2539. // Create a 2 x 2 vertical layout matrix and set it.
  2540. // [500 x 300] [400 x 500]
  2541. // [300 x 600] [200 x 300]
  2542. display::UnifiedDesktopLayoutMatrix matrix;
  2543. matrix.resize(2u);
  2544. matrix[0].emplace_back(list[0]);
  2545. matrix[0].emplace_back(list[1]);
  2546. matrix[1].emplace_back(list[2]);
  2547. matrix[1].emplace_back(list[3]);
  2548. display_manager()->SetUnifiedDesktopMatrix(matrix);
  2549. EXPECT_EQ(gfx::Size(739, 933), screen->GetPrimaryDisplay().size());
  2550. // Default shelf alignment is bottom.
  2551. Shelf* shelf = Shell::GetPrimaryRootWindowController()->shelf();
  2552. EXPECT_EQ(shelf->alignment(), ShelfAlignment::kBottom);
  2553. // Display in bottom-left cell is considered the primary mirroring display.
  2554. EXPECT_EQ(list[2], Shell::Get()
  2555. ->display_configuration_controller()
  2556. ->GetPrimaryMirroringDisplayForUnifiedDesktop()
  2557. .id());
  2558. // Validate display rows and max heights.
  2559. EXPECT_EQ(0, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2560. list[0]));
  2561. EXPECT_EQ(0, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2562. list[1]));
  2563. EXPECT_EQ(1, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2564. list[2]));
  2565. EXPECT_EQ(1, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2566. list[3]));
  2567. EXPECT_EQ(300, display_manager()->GetUnifiedDesktopRowMaxHeight(0));
  2568. EXPECT_EQ(633, display_manager()->GetUnifiedDesktopRowMaxHeight(1));
  2569. EXPECT_FALSE(OverlappingMirroringDisplaysExist());
  2570. // Change the shelf alignment to left, and expect that the primary mirroring
  2571. // display in the top-left display in the matrix.
  2572. shelf->SetAlignment(ShelfAlignment::kLeft);
  2573. EXPECT_EQ(list[0], Shell::Get()
  2574. ->display_configuration_controller()
  2575. ->GetPrimaryMirroringDisplayForUnifiedDesktop()
  2576. .id());
  2577. // Change the shelf alignment to right, and expect that the primary mirroring
  2578. // display in the top-right display in the matrix.
  2579. shelf->SetAlignment(ShelfAlignment::kRight);
  2580. EXPECT_EQ(list[1], Shell::Get()
  2581. ->display_configuration_controller()
  2582. ->GetPrimaryMirroringDisplayForUnifiedDesktop()
  2583. .id());
  2584. }
  2585. TEST_F(DisplayManagerTest, UnifiedDesktopGridLayout3x2) {
  2586. // Don't check root window destruction in unified mode.
  2587. Shell::GetPrimaryRootWindow()->RemoveObserver(this);
  2588. UpdateDisplay("500x300,400x500,300x600,200x300,700x200,350x480");
  2589. display_manager()->SetUnifiedDesktopEnabled(true);
  2590. display::Screen* screen = display::Screen::GetScreen();
  2591. display::DisplayIdList list = display_manager()->GetConnectedDisplayIdList();
  2592. ASSERT_EQ(6u, list.size());
  2593. // Create a 3 x 2 vertical layout matrix and set it.
  2594. // [500 x 300] [400 x 500]
  2595. // [300 x 600] [200 x 300]
  2596. // [700 x 200] [350 x 480]
  2597. display::UnifiedDesktopLayoutMatrix matrix;
  2598. matrix.resize(3u);
  2599. matrix[0].emplace_back(list[0]);
  2600. matrix[0].emplace_back(list[1]);
  2601. matrix[1].emplace_back(list[2]);
  2602. matrix[1].emplace_back(list[3]);
  2603. matrix[2].emplace_back(list[4]);
  2604. matrix[2].emplace_back(list[5]);
  2605. display_manager()->SetUnifiedDesktopMatrix(matrix);
  2606. EXPECT_EQ(gfx::Size(739, 1108), screen->GetPrimaryDisplay().size());
  2607. // Default shelf alignment is bottom.
  2608. Shelf* shelf = Shell::GetPrimaryRootWindowController()->shelf();
  2609. EXPECT_EQ(shelf->alignment(), ShelfAlignment::kBottom);
  2610. // Display in bottom-left cell is considered the primary mirroring display.
  2611. EXPECT_EQ(list[4], Shell::Get()
  2612. ->display_configuration_controller()
  2613. ->GetPrimaryMirroringDisplayForUnifiedDesktop()
  2614. .id());
  2615. // Validate display rows and max heights.
  2616. EXPECT_EQ(0, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2617. list[0]));
  2618. EXPECT_EQ(0, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2619. list[1]));
  2620. EXPECT_EQ(1, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2621. list[2]));
  2622. EXPECT_EQ(1, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2623. list[3]));
  2624. EXPECT_EQ(2, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2625. list[4]));
  2626. EXPECT_EQ(2, display_manager()->GetMirroringDisplayRowIndexInUnifiedMatrix(
  2627. list[5]));
  2628. EXPECT_EQ(300, display_manager()->GetUnifiedDesktopRowMaxHeight(0));
  2629. EXPECT_EQ(633, display_manager()->GetUnifiedDesktopRowMaxHeight(1));
  2630. EXPECT_EQ(175, display_manager()->GetUnifiedDesktopRowMaxHeight(2));
  2631. EXPECT_FALSE(OverlappingMirroringDisplaysExist());
  2632. // Change the shelf alignment to left, and expect that the primary mirroring
  2633. // display in the top-left display in the matrix.
  2634. shelf->SetAlignment(ShelfAlignment::kLeft);
  2635. EXPECT_EQ(list[0], Shell::Get()
  2636. ->display_configuration_controller()
  2637. ->GetPrimaryMirroringDisplayForUnifiedDesktop()
  2638. .id());
  2639. // Change the shelf alignment to right, and expect that the primary mirroring
  2640. // display in the top-right display in the matrix.
  2641. shelf->SetAlignment(ShelfAlignment::kRight);
  2642. EXPECT_EQ(list[1], Shell::Get()
  2643. ->display_configuration_controller()
  2644. ->GetPrimaryMirroringDisplayForUnifiedDesktop()
  2645. .id());
  2646. }
  2647. TEST_F(DisplayManagerTest, UnifiedDesktopTabletMode) {
  2648. // Don't check root window destruction in unified mode.
  2649. Shell::GetPrimaryRootWindow()->RemoveObserver(this);
  2650. UpdateDisplay("400x300,800x700");
  2651. base::RunLoop().RunUntilIdle();
  2652. // Set the first display as internal display so that the tablet mode can be
  2653. // enabled.
  2654. display::test::DisplayManagerTestApi(display_manager())
  2655. .SetFirstDisplayAsInternalDisplay();
  2656. display_manager()->SetUnifiedDesktopEnabled(true);
  2657. EXPECT_TRUE(display_manager()->IsInUnifiedMode());
  2658. // Turn on tablet mode, expect that we switch to mirror mode without any
  2659. // crashes.
  2660. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
  2661. base::RunLoop().RunUntilIdle();
  2662. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  2663. // The Home Launcher should be created and shown, not dismissed as a result of
  2664. // the destruction of the Unified host when we switched to mirror mode
  2665. // asynchronously.
  2666. auto* app_list_controller = Shell::Get()->app_list_controller();
  2667. auto* tablet_mode_controller = Shell::Get()->tablet_mode_controller();
  2668. EXPECT_TRUE(tablet_mode_controller->InTabletMode());
  2669. EXPECT_TRUE(
  2670. app_list_controller->IsVisible(display_manager()->first_display_id()));
  2671. // Exiting tablet mode should exit mirror mode and return back to Unified
  2672. // mode.
  2673. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
  2674. base::RunLoop().RunUntilIdle();
  2675. EXPECT_FALSE(display_manager()->IsInSoftwareMirrorMode());
  2676. EXPECT_TRUE(display_manager()->IsInUnifiedMode());
  2677. // Home Launcher should be dismissed.
  2678. EXPECT_FALSE(tablet_mode_controller->InTabletMode());
  2679. EXPECT_FALSE(
  2680. app_list_controller->IsVisible(display_manager()->first_display_id()));
  2681. }
  2682. TEST_F(DisplayManagerTest, UnifiedDesktopPrimarySizeWithRotatedDisplays) {
  2683. MirrorWindowTestApi test_api;
  2684. // RootWidow for primary changes during unified desktop transition.
  2685. disable_check_root_window_on_destruction();
  2686. display::test::DisplayManagerTestApi(display_manager())
  2687. .SetFirstDisplayAsInternalDisplay();
  2688. display_manager()->SetUnifiedDesktopEnabled(true);
  2689. UpdateDisplay("1000x700/r");
  2690. EXPECT_EQ(gfx::Size(700, 1000),
  2691. display::Screen::GetScreen()->GetPrimaryDisplay().size());
  2692. UpdateDisplay("1000x700/r,1000x700/r");
  2693. EXPECT_EQ(gfx::Size(1400, 1000),
  2694. display::Screen::GetScreen()->GetPrimaryDisplay().size());
  2695. std::vector<aura::WindowTreeHost*> host_list = test_api.GetHosts();
  2696. std::vector<display::Display> display_list =
  2697. display_manager()->software_mirroring_display_list();
  2698. EXPECT_EQ(gfx::Size(700, 1000), host_list[0]->window()->bounds().size());
  2699. EXPECT_EQ(gfx::OVERLAY_TRANSFORM_ROTATE_90,
  2700. host_list[0]->compositor()->display_transform_hint());
  2701. EXPECT_EQ(display::Display::ROTATE_90, display_list[0].panel_rotation());
  2702. EXPECT_EQ(gfx::Size(700, 1000), host_list[1]->window()->bounds().size());
  2703. EXPECT_EQ(gfx::OVERLAY_TRANSFORM_ROTATE_90,
  2704. host_list[1]->compositor()->display_transform_hint());
  2705. EXPECT_EQ(display::Display::ROTATE_90, display_list[1].panel_rotation());
  2706. // Use custom display offset to ensure rotation is properly updated.
  2707. UpdateDisplay("1000x700/r,1200+100-1000x700/l");
  2708. EXPECT_EQ(gfx::Size(1400, 1000),
  2709. display::Screen::GetScreen()->GetPrimaryDisplay().size());
  2710. host_list = test_api.GetHosts();
  2711. display_list = display_manager()->software_mirroring_display_list();
  2712. EXPECT_EQ(gfx::Size(700, 1000), host_list[0]->window()->bounds().size());
  2713. EXPECT_EQ(gfx::OVERLAY_TRANSFORM_ROTATE_90,
  2714. host_list[0]->compositor()->display_transform_hint());
  2715. EXPECT_EQ(display::Display::ROTATE_90, display_list[0].panel_rotation());
  2716. EXPECT_EQ(gfx::Size(700, 1000), host_list[1]->window()->bounds().size());
  2717. EXPECT_EQ(gfx::OVERLAY_TRANSFORM_ROTATE_270,
  2718. host_list[1]->compositor()->display_transform_hint());
  2719. EXPECT_EQ(display::Display::ROTATE_270, display_list[1].panel_rotation());
  2720. UpdateDisplay("1000x700/r,1000x700");
  2721. // width = 1000 / 700 * 1000 + 700 ~= 2128
  2722. EXPECT_EQ(gfx::Size(2128, 1000),
  2723. display::Screen::GetScreen()->GetPrimaryDisplay().size());
  2724. host_list = test_api.GetHosts();
  2725. display_list = display_manager()->software_mirroring_display_list();
  2726. EXPECT_EQ(gfx::Size(700, 1000), host_list[0]->window()->bounds().size());
  2727. EXPECT_EQ(gfx::OVERLAY_TRANSFORM_ROTATE_90,
  2728. host_list[0]->compositor()->display_transform_hint());
  2729. EXPECT_EQ(display::Display::ROTATE_90, display_list[0].panel_rotation());
  2730. EXPECT_EQ(gfx::Size(1000, 700), host_list[1]->window()->bounds().size());
  2731. EXPECT_EQ(gfx::OVERLAY_TRANSFORM_NONE,
  2732. host_list[1]->compositor()->display_transform_hint());
  2733. EXPECT_EQ(display::Display::ROTATE_0, display_list[1].panel_rotation());
  2734. // Three displays
  2735. UpdateDisplay("1000x700/l,1000x700/r,1000x700/l");
  2736. EXPECT_EQ(gfx::Size(2100, 1000),
  2737. display::Screen::GetScreen()->GetPrimaryDisplay().size());
  2738. host_list = test_api.GetHosts();
  2739. display_list = display_manager()->software_mirroring_display_list();
  2740. EXPECT_EQ(gfx::Size(700, 1000), host_list[0]->window()->bounds().size());
  2741. EXPECT_EQ(gfx::OVERLAY_TRANSFORM_ROTATE_270,
  2742. host_list[0]->compositor()->display_transform_hint());
  2743. EXPECT_EQ(display::Display::ROTATE_270, display_list[0].panel_rotation());
  2744. EXPECT_EQ(gfx::Size(700, 1000), host_list[1]->window()->bounds().size());
  2745. EXPECT_EQ(gfx::OVERLAY_TRANSFORM_ROTATE_90,
  2746. host_list[1]->compositor()->display_transform_hint());
  2747. EXPECT_EQ(display::Display::ROTATE_90, display_list[1].panel_rotation());
  2748. EXPECT_EQ(gfx::Size(700, 1000), host_list[2]->window()->bounds().size());
  2749. EXPECT_EQ(gfx::OVERLAY_TRANSFORM_ROTATE_270,
  2750. host_list[2]->compositor()->display_transform_hint());
  2751. EXPECT_EQ(display::Display::ROTATE_270, display_list[2].panel_rotation());
  2752. }
  2753. TEST_F(DisplayManagerTest, DisplayPrefsAndForcedMirrorMode) {
  2754. UpdateDisplay("400x300,800x700");
  2755. base::RunLoop().RunUntilIdle();
  2756. // Set the first display as internal display so that the tablet mode can be
  2757. // enabled.
  2758. display::test::DisplayManagerTestApi(display_manager())
  2759. .SetFirstDisplayAsInternalDisplay();
  2760. // Initially we can save display prefs ...
  2761. EXPECT_TRUE(Shell::Get()->ShouldSaveDisplaySettings());
  2762. // ... and there are no external displays that are candidates for mirror
  2763. // restore.
  2764. EXPECT_TRUE(display_manager()->external_display_mirror_info().empty());
  2765. // Turn on tablet mode, and expect that it can persist certain
  2766. // display prefs while forced mirror mode is active.
  2767. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
  2768. base::RunLoop().RunUntilIdle();
  2769. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  2770. EXPECT_TRUE(
  2771. display_manager()->layout_store()->forced_mirror_mode_for_tablet());
  2772. EXPECT_TRUE(Shell::Get()->ShouldSaveDisplaySettings());
  2773. // Forced mirror mode does not add external displays as candidates for mirror
  2774. // restore.
  2775. EXPECT_TRUE(display_manager()->external_display_mirror_info().empty());
  2776. // Exit tablet mode and expect everything is back to normal.
  2777. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
  2778. base::RunLoop().RunUntilIdle();
  2779. EXPECT_FALSE(display_manager()->IsInSoftwareMirrorMode());
  2780. EXPECT_FALSE(
  2781. display_manager()->layout_store()->forced_mirror_mode_for_tablet());
  2782. EXPECT_TRUE(Shell::Get()->ShouldSaveDisplaySettings());
  2783. EXPECT_TRUE(display_manager()->external_display_mirror_info().empty());
  2784. }
  2785. TEST_F(DisplayManagerTest, ForcedMirrorModeExited) {
  2786. UpdateDisplay("400x300,800x700");
  2787. base::RunLoop().RunUntilIdle();
  2788. // Set the first display as internal display so that the tablet mode can be
  2789. // enabled.
  2790. display::test::DisplayManagerTestApi(display_manager())
  2791. .SetFirstDisplayAsInternalDisplay();
  2792. // Initially we can save display prefs ...
  2793. EXPECT_TRUE(Shell::Get()->ShouldSaveDisplaySettings());
  2794. // ... and there are no external displays that are candidates for mirror
  2795. // restore.
  2796. EXPECT_TRUE(display_manager()->external_display_mirror_info().empty());
  2797. // Turn on tablet mode, and expect that it can persist certain
  2798. // display prefs while forced mirror mode is active.
  2799. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
  2800. base::RunLoop().RunUntilIdle();
  2801. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  2802. EXPECT_TRUE(
  2803. display_manager()->layout_store()->forced_mirror_mode_for_tablet());
  2804. EXPECT_TRUE(Shell::Get()->ShouldSaveDisplaySettings());
  2805. // Forced mirror mode does not add external displays as candidates for mirror
  2806. // restore.
  2807. EXPECT_TRUE(display_manager()->external_display_mirror_info().empty());
  2808. // Exit mirror mode, and expect that `forced_mirror_mode_for_tablet` is now
  2809. // false.
  2810. SetSoftwareMirrorMode(false);
  2811. EXPECT_FALSE(display_manager()->IsInSoftwareMirrorMode());
  2812. EXPECT_FALSE(
  2813. display_manager()->layout_store()->forced_mirror_mode_for_tablet());
  2814. // Randomly change the external monitor's resolution/refresh rate, and
  2815. // expect that the setting is retained.
  2816. const display::ManagedDisplayInfo& info_1 = GetDisplayInfoAt(0);
  2817. const display::ManagedDisplayInfo::ManagedDisplayModeList& modes =
  2818. info_1.display_modes();
  2819. display::test::SetDisplayResolution(display_manager(), info_1.id(),
  2820. modes[0].size());
  2821. display_manager()->UpdateDisplays();
  2822. EXPECT_EQ(
  2823. display_manager()->GetDisplayForId(info_1.id()).device_scale_factor(),
  2824. 1.f);
  2825. EXPECT_FALSE(display_manager()->IsInSoftwareMirrorMode());
  2826. }
  2827. TEST_F(DisplayManagerTest, DisplayPrefsAndKioskMode) {
  2828. // Login in as kiosk app.
  2829. UserSession session;
  2830. session.session_id = 1u;
  2831. session.user_info.type = user_manager::USER_TYPE_KIOSK_APP;
  2832. session.user_info.account_id = AccountId::FromUserEmail("user1@test.com");
  2833. session.user_info.display_name = "User 1";
  2834. session.user_info.display_email = "user1@test.com";
  2835. Shell::Get()->session_controller()->UpdateUserSession(std::move(session));
  2836. EXPECT_EQ(LoginStatus::KIOSK_APP,
  2837. Shell::Get()->session_controller()->login_status());
  2838. UpdateDisplay("400x300,800x700");
  2839. base::RunLoop().RunUntilIdle();
  2840. EXPECT_TRUE(Shell::Get()->ShouldSaveDisplaySettings());
  2841. }
  2842. TEST_F(DisplayManagerTest, DockMode) {
  2843. const int64_t internal_id = 1;
  2844. const int64_t external_id = 2;
  2845. const display::ManagedDisplayInfo internal_display_info =
  2846. display::CreateDisplayInfo(internal_id, gfx::Rect(0, 0, 500, 400));
  2847. const display::ManagedDisplayInfo external_display_info =
  2848. display::CreateDisplayInfo(external_id, gfx::Rect(1, 1, 200, 100));
  2849. std::vector<display::ManagedDisplayInfo> display_info_list;
  2850. // software mirroring.
  2851. display_info_list.push_back(internal_display_info);
  2852. display_info_list.push_back(external_display_info);
  2853. display_manager()->OnNativeDisplaysChanged(display_info_list);
  2854. const int64_t internal_display_id =
  2855. display::test::DisplayManagerTestApi(display_manager())
  2856. .SetFirstDisplayAsInternalDisplay();
  2857. EXPECT_EQ(internal_id, internal_display_id);
  2858. display_info_list.clear();
  2859. display_info_list.push_back(external_display_info);
  2860. display_manager()->OnNativeDisplaysChanged(display_info_list);
  2861. EXPECT_EQ(1U, display_manager()->active_display_list().size());
  2862. EXPECT_TRUE(display_manager()->IsActiveDisplayId(external_id));
  2863. EXPECT_FALSE(display_manager()->IsActiveDisplayId(internal_id));
  2864. }
  2865. // Make sure that bad layout information is ignored and does not crash.
  2866. TEST_F(DisplayManagerTest, DontRegisterBadConfig) {
  2867. display::DisplayIdList list = display::test::CreateDisplayIdList2(1, 2);
  2868. display::DisplayLayoutBuilder builder(1);
  2869. builder.AddDisplayPlacement(2, 1, display::DisplayPlacement::LEFT, 0);
  2870. builder.AddDisplayPlacement(3, 1, display::DisplayPlacement::BOTTOM, 0);
  2871. display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
  2872. list, builder.Build());
  2873. }
  2874. class ScreenShutdownTest : public AshTestBase {
  2875. public:
  2876. ScreenShutdownTest() = default;
  2877. ScreenShutdownTest(const ScreenShutdownTest&) = delete;
  2878. ScreenShutdownTest& operator=(const ScreenShutdownTest&) = delete;
  2879. ~ScreenShutdownTest() override = default;
  2880. void TearDown() override {
  2881. display::Screen* orig_screen = display::Screen::GetScreen();
  2882. AshTestBase::TearDown();
  2883. display::Screen* screen = display::Screen::GetScreen();
  2884. EXPECT_NE(orig_screen, screen);
  2885. EXPECT_EQ(2, screen->GetNumDisplays());
  2886. EXPECT_EQ(gfx::Size(500, 300), screen->GetPrimaryDisplay().size());
  2887. std::vector<display::Display> all = screen->GetAllDisplays();
  2888. EXPECT_EQ(gfx::Size(500, 300), all[0].size());
  2889. EXPECT_EQ(gfx::Size(800, 400), all[1].size());
  2890. }
  2891. };
  2892. TEST_F(ScreenShutdownTest, ScreenAfterShutdown) {
  2893. UpdateDisplay("500x300,800x400");
  2894. }
  2895. namespace {
  2896. // A helper class that sets the display configuration and starts ash.
  2897. // This is to make sure the font configuration happens during ash
  2898. // initialization process.
  2899. class FontTestHelper : public AshTestBase {
  2900. public:
  2901. enum DisplayType { INTERNAL, EXTERNAL };
  2902. FontTestHelper(float scale, DisplayType display_type) {
  2903. gfx::ClearFontRenderParamsCacheForTest();
  2904. base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
  2905. if (display_type == INTERNAL)
  2906. command_line->AppendSwitch(::switches::kUseFirstDisplayAsInternal);
  2907. command_line->AppendSwitchASCII(::switches::kHostWindowBounds,
  2908. StringPrintf("1000x800*%f", scale));
  2909. SetUp();
  2910. }
  2911. FontTestHelper(const FontTestHelper&) = delete;
  2912. FontTestHelper& operator=(const FontTestHelper&) = delete;
  2913. ~FontTestHelper() override { TearDown(); }
  2914. // AshTestBase:
  2915. void TestBody() override { NOTREACHED(); }
  2916. };
  2917. bool IsTextSubpixelPositioningEnabled() {
  2918. gfx::FontRenderParams params =
  2919. gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), nullptr);
  2920. return params.subpixel_positioning;
  2921. }
  2922. gfx::FontRenderParams::Hinting GetFontHintingParams() {
  2923. gfx::FontRenderParams params =
  2924. gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), nullptr);
  2925. return params.hinting;
  2926. }
  2927. } // namespace
  2928. using DisplayManagerFontTest = testing::Test;
  2929. TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf100Internal) {
  2930. FontTestHelper helper(1.0f, FontTestHelper::INTERNAL);
  2931. ASSERT_DOUBLE_EQ(
  2932. 1.0f,
  2933. display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
  2934. EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
  2935. EXPECT_NE(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
  2936. }
  2937. TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf200Internal) {
  2938. FontTestHelper helper(2.0f, FontTestHelper::INTERNAL);
  2939. ASSERT_DOUBLE_EQ(
  2940. 2.0f,
  2941. display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
  2942. EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
  2943. EXPECT_NE(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
  2944. helper.display_manager()->UpdateZoomFactor(
  2945. display::Screen::GetScreen()->GetPrimaryDisplay().id(), 0.5f);
  2946. ASSERT_DOUBLE_EQ(
  2947. 1.0f,
  2948. display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
  2949. EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
  2950. EXPECT_NE(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
  2951. }
  2952. TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf100External) {
  2953. FontTestHelper helper(1.0f, FontTestHelper::EXTERNAL);
  2954. ASSERT_DOUBLE_EQ(
  2955. 1.0f,
  2956. display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
  2957. EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
  2958. EXPECT_NE(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
  2959. }
  2960. TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf125External) {
  2961. FontTestHelper helper(1.25f, FontTestHelper::EXTERNAL);
  2962. ASSERT_DOUBLE_EQ(
  2963. 1.25f,
  2964. display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
  2965. EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
  2966. EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
  2967. }
  2968. TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf200External) {
  2969. FontTestHelper helper(2.0f, FontTestHelper::EXTERNAL);
  2970. ASSERT_DOUBLE_EQ(
  2971. 2.0f,
  2972. display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
  2973. EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
  2974. EXPECT_NE(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
  2975. }
  2976. TEST_F(DisplayManagerFontTest,
  2977. TextSubpixelPositioningWithDsf125InternalWithScaling) {
  2978. FontTestHelper helper(1.25f, FontTestHelper::INTERNAL);
  2979. ASSERT_DOUBLE_EQ(
  2980. 1.25f,
  2981. display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
  2982. EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
  2983. EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
  2984. helper.display_manager()->UpdateZoomFactor(
  2985. display::Screen::GetScreen()->GetPrimaryDisplay().id(), 0.8f);
  2986. ASSERT_DOUBLE_EQ(
  2987. 1.f,
  2988. display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
  2989. EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
  2990. EXPECT_NE(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
  2991. }
  2992. TEST_F(DisplayManagerTest, CheckInitializationOfRotationProperty) {
  2993. int64_t id = display_manager()->GetDisplayAt(0).id();
  2994. display_manager()->RegisterDisplayProperty(id, display::Display::ROTATE_90,
  2995. nullptr, gfx::Size(), 1.0f, 1.0f,
  2996. 60.f, false);
  2997. const display::ManagedDisplayInfo& info =
  2998. display_manager()->GetDisplayInfo(id);
  2999. EXPECT_EQ(display::Display::ROTATE_90,
  3000. info.GetRotation(display::Display::RotationSource::USER));
  3001. EXPECT_EQ(display::Display::ROTATE_90,
  3002. info.GetRotation(display::Display::RotationSource::ACTIVE));
  3003. }
  3004. TEST_F(DisplayManagerTest, RejectInvalidLayoutData) {
  3005. display::DisplayLayoutStore* layout_store = display_manager()->layout_store();
  3006. int64_t id1 = 10001;
  3007. int64_t id2 = 10002;
  3008. ASSERT_TRUE(display::CompareDisplayIds(id1, id2));
  3009. display::DisplayLayoutBuilder good_builder(id1);
  3010. good_builder.SetSecondaryPlacement(id2, display::DisplayPlacement::LEFT, 0);
  3011. std::unique_ptr<display::DisplayLayout> good(good_builder.Build());
  3012. display::DisplayIdList good_list =
  3013. display::test::CreateDisplayIdList2(id1, id2);
  3014. layout_store->RegisterLayoutForDisplayIdList(good_list, good->Copy());
  3015. display::DisplayLayoutBuilder bad(id1);
  3016. bad.SetSecondaryPlacement(id2, display::DisplayPlacement::BOTTOM, 0);
  3017. display::DisplayIdList bad_list(2);
  3018. bad_list[0] = id2;
  3019. bad_list[1] = id1;
  3020. layout_store->RegisterLayoutForDisplayIdList(bad_list, bad.Build());
  3021. EXPECT_EQ(good->ToString(),
  3022. layout_store->GetRegisteredDisplayLayout(good_list).ToString());
  3023. }
  3024. TEST_F(DisplayManagerTest, GuessDisplayIdFieldsInDisplayLayout) {
  3025. int64_t id1 = 10001;
  3026. int64_t id2 = 10002;
  3027. std::unique_ptr<display::DisplayLayout> old_layout(
  3028. new display::DisplayLayout);
  3029. old_layout->placement_list.emplace_back(display::DisplayPlacement::BOTTOM, 0);
  3030. old_layout->primary_id = id1;
  3031. display::DisplayLayoutStore* layout_store = display_manager()->layout_store();
  3032. display::DisplayIdList list = display::test::CreateDisplayIdList2(id1, id2);
  3033. layout_store->RegisterLayoutForDisplayIdList(list, std::move(old_layout));
  3034. const display::DisplayLayout& stored =
  3035. layout_store->GetRegisteredDisplayLayout(list);
  3036. EXPECT_EQ(id1, stored.placement_list[0].parent_display_id);
  3037. EXPECT_EQ(id2, stored.placement_list[0].display_id);
  3038. }
  3039. TEST_F(DisplayManagerTest, AccelerometerSupport) {
  3040. display::test::DisplayManagerTestApi display_manager_test(display_manager());
  3041. display_manager_test.SetFirstDisplayAsInternalDisplay();
  3042. display::Screen* screen = display::Screen::GetScreen();
  3043. EXPECT_EQ(display::Display::AccelerometerSupport::UNAVAILABLE,
  3044. screen->GetPrimaryDisplay().accelerometer_support());
  3045. display_manager()->set_internal_display_has_accelerometer(true);
  3046. display_manager()->UpdateDisplays();
  3047. EXPECT_EQ(display::Display::AccelerometerSupport::AVAILABLE,
  3048. screen->GetPrimaryDisplay().accelerometer_support());
  3049. UpdateDisplay("1000x9000,800x700");
  3050. EXPECT_EQ(display::Display::AccelerometerSupport::AVAILABLE,
  3051. screen->GetPrimaryDisplay().accelerometer_support());
  3052. EXPECT_EQ(display::Display::AccelerometerSupport::UNAVAILABLE,
  3053. display_manager_test.GetSecondaryDisplay().accelerometer_support());
  3054. // Secondary is now primary and should not have accelerometer support.
  3055. std::vector<display::ManagedDisplayInfo> display_info_list;
  3056. display_info_list.push_back(display::CreateDisplayInfo(
  3057. display_manager_test.GetSecondaryDisplay().id(),
  3058. gfx::Rect(1, 1, 200, 100)));
  3059. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3060. EXPECT_EQ(display::Display::AccelerometerSupport::UNAVAILABLE,
  3061. screen->GetPrimaryDisplay().accelerometer_support());
  3062. // Re-enable internal display.
  3063. display_info_list.clear();
  3064. display_info_list.push_back(display::CreateDisplayInfo(
  3065. display::Display::InternalDisplayId(), gfx::Rect(1, 1, 200, 100)));
  3066. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3067. EXPECT_EQ(display::Display::AccelerometerSupport::AVAILABLE,
  3068. screen->GetPrimaryDisplay().accelerometer_support());
  3069. }
  3070. namespace {
  3071. std::unique_ptr<display::DisplayMode> MakeDisplayMode() {
  3072. return std::make_unique<display::DisplayMode>(gfx::Size(1366, 768), false,
  3073. 60);
  3074. }
  3075. } // namespace
  3076. TEST_F(DisplayManagerTest, DisconnectedInternalDisplayShouldUpdateDisplayInfo) {
  3077. constexpr int64_t external_id = 123;
  3078. const int64_t internal_id =
  3079. display::test::DisplayManagerTestApi(display_manager())
  3080. .SetFirstDisplayAsInternalDisplay();
  3081. display::Screen* screen = display::Screen::GetScreen();
  3082. DCHECK(screen);
  3083. Shell* shell = Shell::Get();
  3084. display::DisplayChangeObserver observer(shell->display_manager());
  3085. display::DisplayConfigurator::DisplayStateList outputs;
  3086. std::unique_ptr<display::DisplaySnapshot> internal_snapshot =
  3087. display::FakeDisplaySnapshot::Builder()
  3088. .SetId(internal_id)
  3089. .SetType(display::DISPLAY_CONNECTION_TYPE_INTERNAL)
  3090. .SetDPI(210) // 1.6f
  3091. .SetNativeMode(MakeDisplayMode())
  3092. .Build();
  3093. EXPECT_FALSE(internal_snapshot->current_mode());
  3094. outputs.push_back(internal_snapshot.get());
  3095. std::unique_ptr<display::DisplaySnapshot> external_snapshot =
  3096. display::FakeDisplaySnapshot::Builder()
  3097. .SetId(external_id)
  3098. .SetNativeMode(MakeDisplayMode())
  3099. .AddMode(MakeDisplayMode())
  3100. .SetOrigin({0, 1000})
  3101. .Build();
  3102. // "Connectd display" has the current mode.
  3103. external_snapshot->set_current_mode(external_snapshot->native_mode());
  3104. outputs.push_back(external_snapshot.get());
  3105. // Update the display manager through DisplayChangeObserver.
  3106. observer.GetStateForDisplayIds(outputs);
  3107. observer.OnDisplayModeChanged(outputs);
  3108. EXPECT_EQ(1u, display_manager()->GetNumDisplays());
  3109. EXPECT_TRUE(display_manager()->IsActiveDisplayId(external_id));
  3110. EXPECT_FALSE(display_manager()->IsActiveDisplayId(internal_id));
  3111. const display::ManagedDisplayInfo& display_info =
  3112. display_manager()->GetDisplayInfo(internal_id);
  3113. EXPECT_EQ(1.6f, display_info.device_scale_factor());
  3114. ASSERT_EQ(1u, display_info.display_modes().size());
  3115. EXPECT_EQ(1.6f, display_info.display_modes()[0].device_scale_factor());
  3116. }
  3117. // TODO(crbug/1262970): Delete when we can read radius from command line.
  3118. TEST_F(DisplayManagerTest, SettingDefaultRoundedCornersOnInternalDisplay) {
  3119. base::test::ScopedFeatureList scoped_feature_list;
  3120. scoped_feature_list.InitAndEnableFeature(display::features::kRoundedDisplay);
  3121. Shell* shell = Shell::Get();
  3122. display::DisplayChangeObserver observer(shell->display_manager());
  3123. const std::unique_ptr<display::DisplaySnapshot> internal_snapshot =
  3124. display::FakeDisplaySnapshot::Builder()
  3125. .SetId(123)
  3126. .SetName("AmazingFakeRoundedDisplay")
  3127. .SetNativeMode(MakeDisplayMode())
  3128. .SetType(
  3129. display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_INTERNAL)
  3130. .Build();
  3131. internal_snapshot->set_current_mode(internal_snapshot->native_mode());
  3132. display::DisplayConfigurator::DisplayStateList outputs;
  3133. outputs.push_back(internal_snapshot.get());
  3134. // Update the display manager through DisplayChangeObserver.
  3135. observer.OnDisplayModeChanged(outputs);
  3136. display::Display primary_display =
  3137. display::Screen::GetScreen()->GetPrimaryDisplay();
  3138. WindowTreeHostManager* window_manager =
  3139. Shell::Get()->window_tree_host_manager();
  3140. aura::Window* primary_root =
  3141. window_manager->GetRootWindowForDisplayId(primary_display.id());
  3142. EXPECT_EQ(gfx::RoundedCornersF(16.0),
  3143. primary_root->layer()->rounded_corner_radii());
  3144. }
  3145. TEST_F(DisplayManagerTest, UpdateInternalDisplayNativeBounds) {
  3146. constexpr int64_t external_id = 123;
  3147. const int64_t internal_id =
  3148. display::test::DisplayManagerTestApi(display_manager())
  3149. .SetFirstDisplayAsInternalDisplay();
  3150. display::Screen* screen = display::Screen::GetScreen();
  3151. DCHECK(screen);
  3152. display::DisplayChangeObserver observer(display_manager());
  3153. display::DisplayConfigurator::DisplayStateList outputs;
  3154. std::unique_ptr<display::DisplaySnapshot> internal_snapshot =
  3155. display::FakeDisplaySnapshot::Builder()
  3156. .SetId(internal_id)
  3157. .SetType(display::DISPLAY_CONNECTION_TYPE_INTERNAL)
  3158. .SetDPI(210) // 1.6f
  3159. .SetNativeMode(MakeDisplayMode())
  3160. .Build();
  3161. internal_snapshot->set_current_mode(internal_snapshot->native_mode());
  3162. outputs.push_back(internal_snapshot.get());
  3163. observer.GetStateForDisplayIds(outputs);
  3164. observer.OnDisplayModeChanged(outputs);
  3165. EXPECT_EQ(1u, display_manager()->GetNumDisplays());
  3166. internal_snapshot->set_origin({0, 1000});
  3167. std::unique_ptr<display::DisplaySnapshot> external_snapshot =
  3168. display::FakeDisplaySnapshot::Builder()
  3169. .SetId(external_id)
  3170. .SetNativeMode(MakeDisplayMode())
  3171. .AddMode(MakeDisplayMode())
  3172. .Build();
  3173. // "Connectd display" has the current mode.
  3174. external_snapshot->set_current_mode(external_snapshot->native_mode());
  3175. outputs.push_back(external_snapshot.get());
  3176. reset();
  3177. observer.GetStateForDisplayIds(outputs);
  3178. observer.OnDisplayModeChanged(outputs);
  3179. EXPECT_EQ(2u, display_manager()->GetNumDisplays());
  3180. EXPECT_TRUE(changed_metrics() &
  3181. display::DisplayObserver::DISPLAY_METRIC_BOUNDS);
  3182. }
  3183. // It's difficult to test with full stack due to crbug.com/771178.
  3184. // Improve the coverage once it is fixed.
  3185. TEST_F(DisplayManagerTest, ForcedMirrorMode) {
  3186. // Disable restoring mirror mode to prevent interference from previous
  3187. // display configuration.
  3188. display_manager()->set_disable_restoring_mirror_mode_for_test(true);
  3189. constexpr int64_t id1 = 1;
  3190. constexpr int64_t id2 = 2;
  3191. display::Screen* screen = display::Screen::GetScreen();
  3192. DCHECK(screen);
  3193. display::DisplayChangeObserver observer(display_manager());
  3194. display::DisplayConfigurator::DisplayStateList outputs;
  3195. std::unique_ptr<display::DisplaySnapshot> snapshot1 =
  3196. display::FakeDisplaySnapshot::Builder()
  3197. .SetId(id1)
  3198. .SetNativeMode(MakeDisplayMode())
  3199. .Build();
  3200. std::unique_ptr<display::DisplaySnapshot> snapshot2 =
  3201. display::FakeDisplaySnapshot::Builder()
  3202. .SetId(id2)
  3203. .SetNativeMode(MakeDisplayMode())
  3204. .SetOrigin({0, 1000})
  3205. .Build();
  3206. snapshot1->set_current_mode(snapshot1->native_mode());
  3207. snapshot2->set_current_mode(snapshot2->native_mode());
  3208. outputs.push_back(snapshot1.get());
  3209. outputs.push_back(snapshot2.get());
  3210. EXPECT_EQ(display::MULTIPLE_DISPLAY_STATE_MULTI_EXTENDED,
  3211. observer.GetStateForDisplayIds(outputs));
  3212. display_manager()->layout_store()->set_forced_mirror_mode_for_tablet(true);
  3213. observer.OnDisplayModeChanged(outputs);
  3214. const display::DisplayIdList current_list =
  3215. display_manager()->GetConnectedDisplayIdList();
  3216. display_manager()->layout_store()->UpdateDefaultUnified(current_list,
  3217. false /* unified */);
  3218. EXPECT_EQ(display::MULTIPLE_DISPLAY_STATE_MULTI_MIRROR,
  3219. observer.GetStateForDisplayIds(outputs));
  3220. display_manager()->layout_store()->set_forced_mirror_mode_for_tablet(false);
  3221. EXPECT_EQ(display::MULTIPLE_DISPLAY_STATE_MULTI_EXTENDED,
  3222. observer.GetStateForDisplayIds(outputs));
  3223. display_manager()->set_disable_restoring_mirror_mode_for_test(false);
  3224. }
  3225. namespace {
  3226. class DisplayManagerOrientationTest : public DisplayManagerTest {
  3227. public:
  3228. DisplayManagerOrientationTest() = default;
  3229. DisplayManagerOrientationTest(const DisplayManagerOrientationTest&) = delete;
  3230. DisplayManagerOrientationTest& operator=(
  3231. const DisplayManagerOrientationTest&) = delete;
  3232. ~DisplayManagerOrientationTest() override = default;
  3233. void SetUp() override {
  3234. DisplayManagerTest::SetUp();
  3235. portrait_primary.Set(ACCELEROMETER_SOURCE_SCREEN, -base::kMeanGravityFloat,
  3236. 0.f, 0.f);
  3237. portrait_secondary.Set(ACCELEROMETER_SOURCE_SCREEN, base::kMeanGravityFloat,
  3238. 0.f, 0.f);
  3239. landscape_primary.Set(ACCELEROMETER_SOURCE_SCREEN, 0,
  3240. -base::kMeanGravityFloat, 0.f);
  3241. }
  3242. protected:
  3243. AccelerometerUpdate portrait_primary;
  3244. AccelerometerUpdate portrait_secondary;
  3245. AccelerometerUpdate landscape_primary;
  3246. };
  3247. class TestObserver : public ScreenOrientationController::Observer {
  3248. public:
  3249. TestObserver() = default;
  3250. ~TestObserver() override = default;
  3251. void OnUserRotationLockChanged() override { count_++; }
  3252. int countAndReset() {
  3253. int tmp = count_;
  3254. count_ = 0;
  3255. return tmp;
  3256. }
  3257. private:
  3258. int count_ = 0;
  3259. };
  3260. } // namespace
  3261. TEST_F(DisplayManagerOrientationTest, SaveRestoreUserRotationLock) {
  3262. Shell* shell = Shell::Get();
  3263. display::DisplayManager* display_manager = shell->display_manager();
  3264. display::test::DisplayManagerTestApi(display_manager)
  3265. .SetFirstDisplayAsInternalDisplay();
  3266. ScreenOrientationController* orientation_controller =
  3267. shell->screen_orientation_controller();
  3268. ScreenOrientationControllerTestApi test_api(orientation_controller);
  3269. TestObserver test_observer;
  3270. orientation_controller->AddObserver(&test_observer);
  3271. // Set up windows with portrait,lanscape and any.
  3272. aura::Window* window_a = CreateTestWindowInShellWithId(0);
  3273. {
  3274. window_a->SetProperty(aura::client::kAppType,
  3275. static_cast<int>(AppType::CHROME_APP));
  3276. orientation_controller->LockOrientationForWindow(
  3277. window_a, chromeos::OrientationType::kAny);
  3278. }
  3279. aura::Window* window_p = CreateTestWindowInShellWithId(0);
  3280. {
  3281. window_p->SetProperty(aura::client::kAppType,
  3282. static_cast<int>(AppType::CHROME_APP));
  3283. orientation_controller->LockOrientationForWindow(
  3284. window_p, chromeos::OrientationType::kPortrait);
  3285. }
  3286. aura::Window* window_l = CreateTestWindowInShellWithId(0);
  3287. {
  3288. window_l->SetProperty(aura::client::kAppType,
  3289. static_cast<int>(AppType::CHROME_APP));
  3290. orientation_controller->LockOrientationForWindow(
  3291. window_l, chromeos::OrientationType::kLandscape);
  3292. }
  3293. DisplayConfigurationController* configuration_controller =
  3294. shell->display_configuration_controller();
  3295. display::Screen* screen = display::Screen::GetScreen();
  3296. // Rotate to portrait in clamshell.
  3297. configuration_controller->SetDisplayRotation(
  3298. screen->GetPrimaryDisplay().id(), display::Display::ROTATE_270,
  3299. display::Display::RotationSource::USER);
  3300. EXPECT_EQ(display::Display::ROTATE_270,
  3301. screen->GetPrimaryDisplay().rotation());
  3302. EXPECT_FALSE(display_manager->registered_internal_display_rotation_lock());
  3303. EXPECT_EQ(0, test_observer.countAndReset());
  3304. // Just enabling will not save the lock.
  3305. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
  3306. EXPECT_EQ(1, test_observer.countAndReset());
  3307. EXPECT_EQ(display::Display::ROTATE_0, screen->GetPrimaryDisplay().rotation());
  3308. EXPECT_FALSE(display_manager->registered_internal_display_rotation_lock());
  3309. EXPECT_EQ(chromeos::OrientationType::kLandscapePrimary,
  3310. test_api.GetCurrentOrientation());
  3311. // Enable lock at 0.
  3312. orientation_controller->ToggleUserRotationLock();
  3313. EXPECT_EQ(1, test_observer.countAndReset());
  3314. EXPECT_TRUE(display_manager->registered_internal_display_rotation_lock());
  3315. EXPECT_EQ(display::Display::ROTATE_0,
  3316. display_manager->registered_internal_display_rotation());
  3317. // Application can overwwrite the locked orientation.
  3318. wm::ActivateWindow(window_p);
  3319. EXPECT_EQ(display::Display::ROTATE_270,
  3320. screen->GetPrimaryDisplay().rotation());
  3321. EXPECT_EQ(display::Display::ROTATE_0,
  3322. display_manager->registered_internal_display_rotation());
  3323. EXPECT_EQ(0, test_observer.countAndReset());
  3324. EXPECT_EQ(chromeos::OrientationType::kPortraitPrimary,
  3325. test_api.GetCurrentOrientation());
  3326. // Any will rotate to the locked rotation.
  3327. wm::ActivateWindow(window_a);
  3328. EXPECT_EQ(display::Display::ROTATE_0, screen->GetPrimaryDisplay().rotation());
  3329. EXPECT_TRUE(display_manager->registered_internal_display_rotation_lock());
  3330. EXPECT_EQ(display::Display::ROTATE_0,
  3331. display_manager->registered_internal_display_rotation());
  3332. EXPECT_EQ(0, test_observer.countAndReset());
  3333. wm::ActivateWindow(window_l);
  3334. EXPECT_EQ(display::Display::ROTATE_0, screen->GetPrimaryDisplay().rotation());
  3335. EXPECT_TRUE(display_manager->registered_internal_display_rotation_lock());
  3336. EXPECT_EQ(display::Display::ROTATE_0,
  3337. display_manager->registered_internal_display_rotation());
  3338. EXPECT_EQ(0, test_observer.countAndReset());
  3339. // Exit tablet mode reset to clamshell's rotation, which is 90.
  3340. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
  3341. EXPECT_EQ(1, test_observer.countAndReset());
  3342. EXPECT_EQ(display::Display::ROTATE_270,
  3343. screen->GetPrimaryDisplay().rotation());
  3344. // Activate Any.
  3345. wm::ActivateWindow(window_a);
  3346. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
  3347. EXPECT_EQ(1, test_observer.countAndReset());
  3348. // Entering with active ANY will lock again to landscape.
  3349. EXPECT_EQ(display::Display::ROTATE_0, screen->GetPrimaryDisplay().rotation());
  3350. wm::ActivateWindow(window_p);
  3351. EXPECT_EQ(display::Display::ROTATE_270,
  3352. screen->GetPrimaryDisplay().rotation());
  3353. EXPECT_EQ(0, test_observer.countAndReset());
  3354. orientation_controller->ToggleUserRotationLock();
  3355. orientation_controller->ToggleUserRotationLock();
  3356. EXPECT_EQ(2, test_observer.countAndReset());
  3357. EXPECT_TRUE(display_manager->registered_internal_display_rotation_lock());
  3358. EXPECT_EQ(display::Display::ROTATE_270,
  3359. display_manager->registered_internal_display_rotation());
  3360. wm::ActivateWindow(window_l);
  3361. EXPECT_EQ(display::Display::ROTATE_0, screen->GetPrimaryDisplay().rotation());
  3362. EXPECT_EQ(display::Display::ROTATE_270,
  3363. display_manager->registered_internal_display_rotation());
  3364. // ANY will rotate to locked ortation.
  3365. wm::ActivateWindow(window_a);
  3366. EXPECT_EQ(display::Display::ROTATE_270,
  3367. screen->GetPrimaryDisplay().rotation());
  3368. orientation_controller->RemoveObserver(&test_observer);
  3369. }
  3370. TEST_F(DisplayManagerOrientationTest, UserRotationLockReverse) {
  3371. Shell* shell = Shell::Get();
  3372. display::DisplayManager* display_manager = shell->display_manager();
  3373. display::test::DisplayManagerTestApi test_api(display_manager);
  3374. test_api.SetFirstDisplayAsInternalDisplay();
  3375. ScreenOrientationController* orientation_controller =
  3376. shell->screen_orientation_controller();
  3377. // Set up windows with portrait,lanscape and any.
  3378. aura::Window* window = CreateTestWindowInShellWithId(0);
  3379. window->SetProperty(aura::client::kAppType,
  3380. static_cast<int>(AppType::CHROME_APP));
  3381. display::Screen* screen = display::Screen::GetScreen();
  3382. // Just enabling will not save the lock.
  3383. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
  3384. orientation_controller->LockOrientationForWindow(
  3385. window, chromeos::OrientationType::kPortrait);
  3386. EXPECT_EQ(display::Display::ROTATE_270,
  3387. screen->GetPrimaryDisplay().rotation());
  3388. orientation_controller->OnAccelerometerUpdated(portrait_secondary);
  3389. EXPECT_EQ(display::Display::ROTATE_90,
  3390. screen->GetPrimaryDisplay().rotation());
  3391. orientation_controller->OnAccelerometerUpdated(portrait_primary);
  3392. EXPECT_EQ(display::Display::ROTATE_270,
  3393. screen->GetPrimaryDisplay().rotation());
  3394. // Enable lock at 270.
  3395. orientation_controller->ToggleUserRotationLock();
  3396. EXPECT_TRUE(display_manager->registered_internal_display_rotation_lock());
  3397. EXPECT_EQ(display::Display::ROTATE_270,
  3398. display_manager->registered_internal_display_rotation());
  3399. orientation_controller->OnAccelerometerUpdated(portrait_secondary);
  3400. EXPECT_EQ(display::Display::ROTATE_270,
  3401. screen->GetPrimaryDisplay().rotation());
  3402. }
  3403. TEST_F(DisplayManagerOrientationTest, LockToSpecificOrientation) {
  3404. Shell* shell = Shell::Get();
  3405. display::DisplayManager* display_manager = shell->display_manager();
  3406. display::test::DisplayManagerTestApi(display_manager)
  3407. .SetFirstDisplayAsInternalDisplay();
  3408. ScreenOrientationController* orientation_controller =
  3409. shell->screen_orientation_controller();
  3410. ScreenOrientationControllerTestApi test_api(orientation_controller);
  3411. aura::Window* window_a = CreateTestWindowInShellWithId(0);
  3412. {
  3413. window_a->SetProperty(aura::client::kAppType,
  3414. static_cast<int>(AppType::CHROME_APP));
  3415. orientation_controller->LockOrientationForWindow(
  3416. window_a, chromeos::OrientationType::kAny);
  3417. }
  3418. wm::ActivateWindow(window_a);
  3419. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
  3420. orientation_controller->OnAccelerometerUpdated(portrait_primary);
  3421. EXPECT_EQ(chromeos::OrientationType::kPortraitPrimary,
  3422. test_api.GetCurrentOrientation());
  3423. orientation_controller->OnAccelerometerUpdated(portrait_secondary);
  3424. aura::Window* window_lsc = CreateTestWindowInShellWithId(1);
  3425. window_lsc->SetProperty(aura::client::kAppType,
  3426. static_cast<int>(AppType::CHROME_APP));
  3427. aura::Window* window_psc = CreateTestWindowInShellWithId(1);
  3428. window_psc->SetProperty(aura::client::kAppType,
  3429. static_cast<int>(AppType::CHROME_APP));
  3430. orientation_controller->LockOrientationForWindow(
  3431. window_psc, chromeos::OrientationType::kPortraitSecondary);
  3432. orientation_controller->LockOrientationForWindow(
  3433. window_psc, chromeos::OrientationType::kCurrent);
  3434. wm::ActivateWindow(window_psc);
  3435. orientation_controller->LockOrientationForWindow(
  3436. window_lsc, chromeos::OrientationType::kLandscapeSecondary);
  3437. orientation_controller->LockOrientationForWindow(
  3438. window_lsc, chromeos::OrientationType::kCurrent);
  3439. EXPECT_EQ(chromeos::OrientationType::kPortraitSecondary,
  3440. test_api.GetCurrentOrientation());
  3441. // The orientation should stay portrait secondary.
  3442. orientation_controller->OnAccelerometerUpdated(portrait_primary);
  3443. EXPECT_EQ(chromeos::OrientationType::kPortraitSecondary,
  3444. test_api.GetCurrentOrientation());
  3445. wm::ActivateWindow(window_lsc);
  3446. EXPECT_EQ(chromeos::OrientationType::kLandscapeSecondary,
  3447. test_api.GetCurrentOrientation());
  3448. // The orientation should stay landscape secondary.
  3449. orientation_controller->OnAccelerometerUpdated(landscape_primary);
  3450. EXPECT_EQ(chromeos::OrientationType::kLandscapeSecondary,
  3451. test_api.GetCurrentOrientation());
  3452. wm::ActivateWindow(window_a);
  3453. orientation_controller->OnAccelerometerUpdated(portrait_primary);
  3454. // Swtching to |window_a| enables rotation.
  3455. EXPECT_EQ(chromeos::OrientationType::kPortraitPrimary,
  3456. test_api.GetCurrentOrientation());
  3457. // The orientation has alraedy been locked to secondary once, so
  3458. // it should swtich back to the portrait secondary.
  3459. wm::ActivateWindow(window_psc);
  3460. EXPECT_EQ(chromeos::OrientationType::kPortraitSecondary,
  3461. test_api.GetCurrentOrientation());
  3462. }
  3463. // crbug.com/734107
  3464. TEST_F(DisplayManagerOrientationTest, DisplayChangeShouldNotSaveUserRotation) {
  3465. Shell* shell = Shell::Get();
  3466. display::DisplayManager* display_manager = shell->display_manager();
  3467. display::test::DisplayManagerTestApi test_api(display_manager);
  3468. test_api.SetFirstDisplayAsInternalDisplay();
  3469. display::Screen* screen = display::Screen::GetScreen();
  3470. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
  3471. // Emulate that Animator is calling this async when animation is completed.
  3472. display_manager->SetDisplayRotation(
  3473. screen->GetPrimaryDisplay().id(), display::Display::ROTATE_90,
  3474. display::Display::RotationSource::ACCELEROMETER);
  3475. EXPECT_EQ(display::Display::ROTATE_90,
  3476. screen->GetPrimaryDisplay().rotation());
  3477. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
  3478. EXPECT_EQ(display::Display::ROTATE_0, screen->GetPrimaryDisplay().rotation());
  3479. }
  3480. TEST_F(DisplayManagerTest, HardwareMirrorMode) {
  3481. // Create three displays with the same origin in frame buffer.
  3482. const int64_t internal_display_id =
  3483. display::test::DisplayManagerTestApi(display_manager())
  3484. .SetFirstDisplayAsInternalDisplay();
  3485. constexpr int64_t first_mirror_id = 11;
  3486. constexpr int64_t second_mirror_id = 12;
  3487. std::vector<display::ManagedDisplayInfo> display_info_list;
  3488. display_info_list.push_back(display::CreateDisplayInfo(
  3489. internal_display_id, gfx::Rect(0, 0, 500, 400)));
  3490. display_info_list.push_back(
  3491. display::CreateDisplayInfo(first_mirror_id, gfx::Rect(0, 0, 500, 400)));
  3492. display_info_list.push_back(
  3493. display::CreateDisplayInfo(second_mirror_id, gfx::Rect(0, 0, 500, 400)));
  3494. // mirrored across 3 displays...
  3495. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3496. base::RunLoop().RunUntilIdle();
  3497. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  3498. EXPECT_EQ(3U, display_manager()->num_connected_displays());
  3499. EXPECT_EQ(internal_display_id, display_manager()->mirroring_source_id());
  3500. EXPECT_EQ(gfx::Rect(0, 0, 500, 400),
  3501. GetDisplayForId(internal_display_id).bounds());
  3502. const display::DisplayIdList id_list =
  3503. display_manager()->GetMirroringDestinationDisplayIdList();
  3504. ASSERT_EQ(2U, id_list.size());
  3505. EXPECT_EQ(11U, id_list[0]);
  3506. EXPECT_EQ(12U, id_list[1]);
  3507. EXPECT_FALSE(display_manager()->IsInSoftwareMirrorMode());
  3508. EXPECT_TRUE(display_manager()->IsInHardwareMirrorMode());
  3509. }
  3510. TEST_F(DisplayManagerTest, SoftwareMirrorModeBasics) {
  3511. UpdateDisplay("300x400,400x500,500x600");
  3512. // There's not mirror window by default.
  3513. MirrorWindowTestApi test_api;
  3514. EXPECT_TRUE(test_api.GetHosts().empty());
  3515. TestDisplayObserver display_observer;
  3516. display::Screen::GetScreen()->AddObserver(&display_observer);
  3517. // Turn on mirror mode.
  3518. SetSoftwareMirrorMode(true);
  3519. EXPECT_TRUE(display_observer.changed_and_reset());
  3520. EXPECT_EQ(1U, display_manager()->GetNumDisplays());
  3521. EXPECT_EQ(gfx::Rect(0, 0, 300, 400),
  3522. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  3523. std::vector<aura::WindowTreeHost*> host_list = test_api.GetHosts();
  3524. ASSERT_EQ(2U, host_list.size());
  3525. EXPECT_EQ(gfx::Size(400, 500), host_list[0]->GetBoundsInPixels().size());
  3526. EXPECT_EQ(gfx::Size(300, 400), host_list[0]->window()->bounds().size());
  3527. EXPECT_EQ(gfx::Size(500, 600), host_list[1]->GetBoundsInPixels().size());
  3528. EXPECT_EQ(gfx::Size(300, 400), host_list[1]->window()->bounds().size());
  3529. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  3530. EXPECT_FALSE(display_manager()->IsInHardwareMirrorMode());
  3531. // Turn off mirror mode.
  3532. SetSoftwareMirrorMode(false);
  3533. EXPECT_TRUE(display_observer.changed_and_reset());
  3534. EXPECT_EQ(3U, display_manager()->GetNumDisplays());
  3535. host_list = test_api.GetHosts();
  3536. EXPECT_TRUE(host_list.empty());
  3537. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  3538. // Make sure the mirror window has the pixel size of the
  3539. // source display.
  3540. SetSoftwareMirrorMode(true);
  3541. EXPECT_TRUE(display_observer.changed_and_reset());
  3542. UpdateDisplay("300x400@0.5,400x500,500x600");
  3543. EXPECT_FALSE(display_observer.changed_and_reset());
  3544. host_list = test_api.GetHosts();
  3545. EXPECT_EQ(gfx::Size(300, 400), host_list[0]->window()->bounds().size());
  3546. EXPECT_EQ(gfx::Size(300, 400), host_list[1]->window()->bounds().size());
  3547. UpdateDisplay("310x410*2,400x500,500x600");
  3548. EXPECT_FALSE(display_observer.changed_and_reset());
  3549. host_list = test_api.GetHosts();
  3550. EXPECT_EQ(gfx::Size(310, 410), host_list[0]->window()->bounds().size());
  3551. EXPECT_EQ(gfx::Size(310, 410), host_list[1]->window()->bounds().size());
  3552. UpdateDisplay("320x420/r,400x500,500x600");
  3553. EXPECT_FALSE(display_observer.changed_and_reset());
  3554. host_list = test_api.GetHosts();
  3555. EXPECT_EQ(gfx::Size(420, 320), host_list[0]->window()->bounds().size());
  3556. EXPECT_EQ(gfx::Size(420, 320), host_list[1]->window()->bounds().size());
  3557. UpdateDisplay("330x440/r,400x500,500x600");
  3558. EXPECT_FALSE(display_observer.changed_and_reset());
  3559. host_list = test_api.GetHosts();
  3560. EXPECT_EQ(gfx::Size(440, 330), host_list[0]->window()->bounds().size());
  3561. EXPECT_EQ(gfx::Size(440, 330), host_list[1]->window()->bounds().size());
  3562. // Overscan insets are ignored.
  3563. UpdateDisplay("400x600/o,600x800/o,500x600/o");
  3564. EXPECT_FALSE(display_observer.changed_and_reset());
  3565. host_list = test_api.GetHosts();
  3566. EXPECT_EQ(gfx::Size(400, 600), host_list[0]->window()->bounds().size());
  3567. EXPECT_EQ(gfx::Size(400, 600), host_list[1]->window()->bounds().size());
  3568. display::Screen::GetScreen()->RemoveObserver(&display_observer);
  3569. }
  3570. TEST_F(DisplayManagerTest, SwitchToAndFromSoftwareMirrorMode) {
  3571. // Don't check root window destruction in unified mode.
  3572. Shell::GetPrimaryRootWindow()->RemoveObserver(this);
  3573. UpdateDisplay("300x400,400x500,500x600");
  3574. // Switch from extended to mirroring.
  3575. SetSoftwareMirrorMode(true);
  3576. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  3577. EXPECT_FALSE(display_manager()->IsInUnifiedMode());
  3578. // Switch from mirroring to extended.
  3579. SetSoftwareMirrorMode(false);
  3580. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  3581. EXPECT_FALSE(display_manager()->IsInUnifiedMode());
  3582. // Switch from mirroring to unified, but it fails.
  3583. SetSoftwareMirrorMode(true);
  3584. display_manager()->SetUnifiedDesktopEnabled(true);
  3585. base::RunLoop().RunUntilIdle();
  3586. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  3587. EXPECT_FALSE(display_manager()->IsInUnifiedMode());
  3588. // Turn off mirroring, it switches to unified.
  3589. SetSoftwareMirrorMode(false);
  3590. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  3591. EXPECT_TRUE(display_manager()->IsInUnifiedMode());
  3592. // Switch from unified to mirroring.
  3593. SetSoftwareMirrorMode(true);
  3594. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  3595. EXPECT_FALSE(display_manager()->IsInUnifiedMode());
  3596. }
  3597. TEST_F(DisplayManagerTest, SourceAndDestinationInSoftwareMirrorMode) {
  3598. constexpr int64_t first_display_id = 10;
  3599. constexpr int64_t second_display_id = 11;
  3600. constexpr int64_t third_display_id = 12;
  3601. std::vector<display::ManagedDisplayInfo> display_info_list;
  3602. display_info_list.emplace_back(
  3603. display::CreateDisplayInfo(first_display_id, gfx::Rect(0, 0, 200, 100)));
  3604. display_info_list.emplace_back(
  3605. display::CreateDisplayInfo(second_display_id, gfx::Rect(1, 1, 500, 400)));
  3606. display_info_list.emplace_back(
  3607. display::CreateDisplayInfo(third_display_id, gfx::Rect(2, 2, 500, 400)));
  3608. // Connect all displays.
  3609. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3610. base::RunLoop().RunUntilIdle();
  3611. EXPECT_EQ(display::kInvalidDisplayId,
  3612. display_manager()->mirroring_source_id());
  3613. EXPECT_TRUE(
  3614. display_manager()->GetMirroringDestinationDisplayIdList().empty());
  3615. // Activate software mirror mode.
  3616. SetSoftwareMirrorMode(true);
  3617. EXPECT_EQ(first_display_id, display_manager()->mirroring_source_id());
  3618. display::DisplayIdList id_list =
  3619. display_manager()->GetMirroringDestinationDisplayIdList();
  3620. EXPECT_EQ(2U, id_list.size());
  3621. EXPECT_EQ(second_display_id, id_list[0]);
  3622. EXPECT_EQ(third_display_id, id_list[1]);
  3623. // Set the second display as internal display.
  3624. SetSoftwareMirrorMode(false);
  3625. display::test::ScopedSetInternalDisplayId set_internal(display_manager(),
  3626. second_display_id);
  3627. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3628. SetSoftwareMirrorMode(true);
  3629. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  3630. EXPECT_EQ(second_display_id, display_manager()->mirroring_source_id());
  3631. id_list = display_manager()->GetMirroringDestinationDisplayIdList();
  3632. EXPECT_EQ(2U, id_list.size());
  3633. EXPECT_EQ(first_display_id, id_list[0]);
  3634. EXPECT_EQ(third_display_id, id_list[1]);
  3635. }
  3636. TEST_F(DisplayManagerTest, CompositingCursorInMultiSoftwareMirroring) {
  3637. const int64_t internal_display_id =
  3638. display::test::DisplayManagerTestApi(display_manager())
  3639. .SetFirstDisplayAsInternalDisplay();
  3640. constexpr int64_t first_mirror_id = 11;
  3641. constexpr int64_t second_mirror_id = 12;
  3642. std::vector<display::ManagedDisplayInfo> display_info_list;
  3643. display_info_list.push_back(display::CreateDisplayInfo(
  3644. internal_display_id, gfx::Rect(0, 0, 200, 100)));
  3645. display_info_list.push_back(
  3646. display::CreateDisplayInfo(first_mirror_id, gfx::Rect(1, 1, 500, 400)));
  3647. display_info_list.push_back(
  3648. display::CreateDisplayInfo(second_mirror_id, gfx::Rect(2, 2, 500, 400)));
  3649. // Connect all displays, cursor compositing is disabled by default.
  3650. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3651. base::RunLoop().RunUntilIdle();
  3652. CursorWindowController* cursor_window_controller =
  3653. Shell::Get()->window_tree_host_manager()->cursor_window_controller();
  3654. EXPECT_FALSE(cursor_window_controller->is_cursor_compositing_enabled());
  3655. MirrorWindowTestApi test_api;
  3656. EXPECT_EQ(nullptr, test_api.GetCursorWindow());
  3657. // Turn on mirror mode, cursor compositing is enabled and cursor window is
  3658. // composited in internal display's root window.
  3659. SetSoftwareMirrorMode(true);
  3660. EXPECT_TRUE(cursor_window_controller->is_cursor_compositing_enabled());
  3661. EXPECT_TRUE(Shell::GetRootWindowForDisplayId(internal_display_id)
  3662. ->Contains(test_api.GetCursorWindow()));
  3663. // Turn off mirror mode, cursor compositing is disabled and cursor window does
  3664. // not exist.
  3665. SetSoftwareMirrorMode(false);
  3666. EXPECT_FALSE(cursor_window_controller->is_cursor_compositing_enabled());
  3667. EXPECT_EQ(nullptr, test_api.GetCursorWindow());
  3668. }
  3669. TEST_F(DisplayManagerTest, MirrorModeRestore) {
  3670. const int64_t internal_display_id =
  3671. display::test::DisplayManagerTestApi(display_manager())
  3672. .SetFirstDisplayAsInternalDisplay();
  3673. constexpr int64_t first_display_id = 210000001;
  3674. constexpr int64_t second_display_id = 220000002;
  3675. const int64_t first_display_masked_id =
  3676. display::GetDisplayIdWithoutOutputIndex(first_display_id);
  3677. const int64_t second_display_masked_id =
  3678. display::GetDisplayIdWithoutOutputIndex(second_display_id);
  3679. display::ManagedDisplayInfo first_mirror_info =
  3680. display::CreateDisplayInfo(first_display_id, gfx::Rect(1, 1, 500, 400));
  3681. display::ManagedDisplayInfo second_mirror_info =
  3682. display::CreateDisplayInfo(second_display_id, gfx::Rect(2, 2, 500, 400));
  3683. std::vector<display::ManagedDisplayInfo> display_info_list;
  3684. // There's no external display now.
  3685. display_info_list.push_back(display::CreateDisplayInfo(
  3686. internal_display_id, gfx::Rect(0, 0, 200, 100)));
  3687. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3688. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  3689. EXPECT_TRUE(display_manager()->external_display_mirror_info().empty());
  3690. // Connect the first external display.
  3691. display_info_list.push_back(first_mirror_info);
  3692. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3693. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  3694. EXPECT_TRUE(display_manager()->external_display_mirror_info().empty());
  3695. // Turn on mirror mode.
  3696. SetSoftwareMirrorMode(true);
  3697. EXPECT_TRUE(display_manager()->IsInMirrorMode());
  3698. EXPECT_EQ(1U, display_manager()->external_display_mirror_info().size());
  3699. EXPECT_TRUE(display_manager()->external_display_mirror_info().count(
  3700. first_display_masked_id));
  3701. // Remove the first external display.
  3702. display_info_list.erase(display_info_list.end() - 1);
  3703. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3704. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  3705. EXPECT_EQ(1U, display_manager()->external_display_mirror_info().size());
  3706. EXPECT_TRUE(display_manager()->external_display_mirror_info().count(
  3707. first_display_masked_id));
  3708. // Reconnect the first external display.
  3709. display_info_list.push_back(first_mirror_info);
  3710. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3711. EXPECT_TRUE(display_manager()->IsInMirrorMode());
  3712. EXPECT_EQ(1U, display_manager()->external_display_mirror_info().size());
  3713. EXPECT_TRUE(display_manager()->external_display_mirror_info().count(
  3714. first_display_masked_id));
  3715. // Remove the first external display.
  3716. display_info_list.erase(display_info_list.end() - 1);
  3717. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3718. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  3719. EXPECT_EQ(1U, display_manager()->external_display_mirror_info().size());
  3720. EXPECT_TRUE(display_manager()->external_display_mirror_info().count(
  3721. first_display_masked_id));
  3722. // Connect the second external display.
  3723. display_info_list.push_back(second_mirror_info);
  3724. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3725. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  3726. EXPECT_EQ(1U, display_manager()->external_display_mirror_info().size());
  3727. EXPECT_TRUE(display_manager()->external_display_mirror_info().count(
  3728. first_display_masked_id));
  3729. // Remove the second external display.
  3730. display_info_list.erase(display_info_list.end() - 1);
  3731. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3732. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  3733. EXPECT_EQ(1U, display_manager()->external_display_mirror_info().size());
  3734. EXPECT_TRUE(display_manager()->external_display_mirror_info().count(
  3735. first_display_masked_id));
  3736. // Add the first and then add the second external display (not mirrored
  3737. // before).
  3738. display_info_list.push_back(first_mirror_info);
  3739. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3740. display_info_list.push_back(second_mirror_info);
  3741. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3742. EXPECT_TRUE(display_manager()->IsInMirrorMode());
  3743. EXPECT_EQ(2U, display_manager()->external_display_mirror_info().size());
  3744. EXPECT_TRUE(display_manager()->external_display_mirror_info().count(
  3745. first_display_masked_id));
  3746. EXPECT_TRUE(display_manager()->external_display_mirror_info().count(
  3747. second_display_masked_id));
  3748. // Remove the second display.
  3749. display_info_list.erase(display_info_list.end() - 1);
  3750. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3751. EXPECT_TRUE(display_manager()->IsInMirrorMode());
  3752. EXPECT_EQ(2U, display_manager()->external_display_mirror_info().size());
  3753. EXPECT_TRUE(display_manager()->external_display_mirror_info().count(
  3754. first_display_masked_id));
  3755. EXPECT_TRUE(display_manager()->external_display_mirror_info().count(
  3756. second_display_masked_id));
  3757. // Remove the first display and then add the second display.
  3758. display_info_list.erase(display_info_list.end() - 1);
  3759. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3760. display_info_list.push_back(second_mirror_info);
  3761. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3762. EXPECT_TRUE(display_manager()->IsInMirrorMode());
  3763. EXPECT_EQ(2U, display_manager()->external_display_mirror_info().size());
  3764. EXPECT_TRUE(display_manager()->external_display_mirror_info().count(
  3765. first_display_masked_id));
  3766. EXPECT_TRUE(display_manager()->external_display_mirror_info().count(
  3767. second_display_masked_id));
  3768. // Turn off mirror mode.
  3769. SetSoftwareMirrorMode(false);
  3770. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  3771. EXPECT_EQ(1U, display_manager()->external_display_mirror_info().size());
  3772. EXPECT_TRUE(display_manager()->external_display_mirror_info().count(
  3773. first_display_masked_id));
  3774. // Add the first display (mirrored before).
  3775. display_info_list.push_back(first_mirror_info);
  3776. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3777. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  3778. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  3779. EXPECT_TRUE(display_manager()->external_display_mirror_info().empty());
  3780. }
  3781. TEST_F(DisplayManagerTest, MixedMirrorModeBasics) {
  3782. UpdateDisplay("300x400,400x500,500x600");
  3783. display::DisplayIdList id_list =
  3784. display_manager()->GetConnectedDisplayIdList();
  3785. // Turn on mixed mirror mode. (Mirror from the first display to the second
  3786. // display)
  3787. display::DisplayIdList dst_ids;
  3788. dst_ids.emplace_back(id_list[1]);
  3789. absl::optional<display::MixedMirrorModeParams> mixed_params(
  3790. absl::in_place, id_list[0], dst_ids);
  3791. display_manager()->SetMirrorMode(display::MirrorMode::kMixed, mixed_params);
  3792. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  3793. EXPECT_EQ(id_list[0], display_manager()->mirroring_source_id());
  3794. display::DisplayIdList destination_ids =
  3795. display_manager()->GetMirroringDestinationDisplayIdList();
  3796. EXPECT_EQ(1U, destination_ids.size());
  3797. EXPECT_EQ(id_list[1], destination_ids[0]);
  3798. EXPECT_TRUE(display_manager()->mixed_mirror_mode_params());
  3799. EXPECT_EQ(gfx::Point(300, 0),
  3800. display_manager()->GetDisplayForId(id_list[2]).bounds().origin());
  3801. // Turn off mirror mode.
  3802. display_manager()->SetMirrorMode(display::MirrorMode::kOff, absl::nullopt);
  3803. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  3804. EXPECT_FALSE(display_manager()->mixed_mirror_mode_params());
  3805. EXPECT_EQ(gfx::Point(300, 0),
  3806. display_manager()->GetDisplayForId(id_list[1]).bounds().origin());
  3807. EXPECT_EQ(gfx::Point(700, 0),
  3808. display_manager()->GetDisplayForId(id_list[2]).bounds().origin());
  3809. }
  3810. TEST_F(DisplayManagerTest, MixedMirrorModeToMirrorMode) {
  3811. UpdateDisplay("300x400,400x500,500x600");
  3812. display::DisplayIdList id_list =
  3813. display_manager()->GetConnectedDisplayIdList();
  3814. // Turn on mixed mirror mode. (Mirror from the first display to the second
  3815. // display)
  3816. display::DisplayIdList dst_ids;
  3817. dst_ids.emplace_back(id_list[1]);
  3818. absl::optional<display::MixedMirrorModeParams> mixed_params(
  3819. absl::in_place, id_list[0], dst_ids);
  3820. display_manager()->SetMirrorMode(display::MirrorMode::kMixed, mixed_params);
  3821. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  3822. EXPECT_EQ(id_list[0], display_manager()->mirroring_source_id());
  3823. display::DisplayIdList destination_ids =
  3824. display_manager()->GetMirroringDestinationDisplayIdList();
  3825. EXPECT_EQ(1U, destination_ids.size());
  3826. EXPECT_EQ(id_list[1], destination_ids[0]);
  3827. EXPECT_TRUE(display_manager()->mixed_mirror_mode_params());
  3828. // Overwrite mixed mirror mode with default mirror mode (Mirror all
  3829. // displays).
  3830. display_manager()->SetMirrorMode(display::MirrorMode::kNormal, absl::nullopt);
  3831. EXPECT_TRUE(display_manager()->IsInMirrorMode());
  3832. EXPECT_EQ(id_list[0], display_manager()->mirroring_source_id());
  3833. destination_ids = display_manager()->GetMirroringDestinationDisplayIdList();
  3834. EXPECT_EQ(2U, destination_ids.size());
  3835. EXPECT_EQ(id_list[1], destination_ids[0]);
  3836. EXPECT_EQ(id_list[2], destination_ids[1]);
  3837. EXPECT_FALSE(display_manager()->mixed_mirror_mode_params());
  3838. }
  3839. TEST_F(DisplayManagerTest, MirrorModeToMixedMirrorMode) {
  3840. UpdateDisplay("300x400,400x500,500x600");
  3841. display::DisplayIdList id_list =
  3842. display_manager()->GetConnectedDisplayIdList();
  3843. // Turn on mirror mode.
  3844. display_manager()->SetMirrorMode(display::MirrorMode::kNormal, absl::nullopt);
  3845. EXPECT_TRUE(display_manager()->IsInMirrorMode());
  3846. EXPECT_EQ(id_list[0], display_manager()->mirroring_source_id());
  3847. display::DisplayIdList destination_ids =
  3848. display_manager()->GetMirroringDestinationDisplayIdList();
  3849. EXPECT_EQ(2U, destination_ids.size());
  3850. EXPECT_EQ(id_list[1], destination_ids[0]);
  3851. EXPECT_EQ(id_list[2], destination_ids[1]);
  3852. EXPECT_FALSE(display_manager()->mixed_mirror_mode_params());
  3853. // Overwrite default mirror mode with mixed mirror mode. (Mirror from the
  3854. // first display to the second display)
  3855. display::DisplayIdList dst_ids;
  3856. dst_ids.emplace_back(id_list[1]);
  3857. absl::optional<display::MixedMirrorModeParams> mixed_params(
  3858. absl::in_place, id_list[0], dst_ids);
  3859. display_manager()->SetMirrorMode(display::MirrorMode::kMixed, mixed_params);
  3860. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  3861. EXPECT_EQ(id_list[0], display_manager()->mirroring_source_id());
  3862. destination_ids = display_manager()->GetMirroringDestinationDisplayIdList();
  3863. EXPECT_EQ(1U, destination_ids.size());
  3864. EXPECT_EQ(id_list[1], destination_ids[0]);
  3865. EXPECT_TRUE(display_manager()->mixed_mirror_mode_params());
  3866. }
  3867. TEST_F(DisplayManagerTest, MixedMirrorModeRestore) {
  3868. const int64_t internal_display_id =
  3869. display::test::DisplayManagerTestApi(display_manager())
  3870. .SetFirstDisplayAsInternalDisplay();
  3871. constexpr int64_t first_display_id = 210000001;
  3872. constexpr int64_t second_display_id = 220000002;
  3873. display::ManagedDisplayInfo first_mirror_info =
  3874. display::CreateDisplayInfo(first_display_id, gfx::Rect(1, 1, 500, 400));
  3875. display::ManagedDisplayInfo second_mirror_info =
  3876. display::CreateDisplayInfo(second_display_id, gfx::Rect(2, 2, 500, 400));
  3877. std::vector<display::ManagedDisplayInfo> display_info_list;
  3878. // Connect the first and second displays.
  3879. display_info_list.push_back(display::CreateDisplayInfo(
  3880. internal_display_id, gfx::Rect(0, 0, 200, 100)));
  3881. display_info_list.push_back(first_mirror_info);
  3882. display_info_list.push_back(second_mirror_info);
  3883. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3884. // Turn on mixed mirror mode. (Mirror from the internal display to the
  3885. // first display)
  3886. display::DisplayIdList dst_ids;
  3887. dst_ids.emplace_back(first_display_id);
  3888. absl::optional<display::MixedMirrorModeParams> mixed_params(
  3889. absl::in_place, internal_display_id, dst_ids);
  3890. display_manager()->SetMirrorMode(display::MirrorMode::kMixed, mixed_params);
  3891. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  3892. EXPECT_EQ(internal_display_id, display_manager()->mirroring_source_id());
  3893. display::DisplayIdList destination_ids =
  3894. display_manager()->GetMirroringDestinationDisplayIdList();
  3895. EXPECT_EQ(1U, destination_ids.size());
  3896. EXPECT_EQ(first_display_id, destination_ids[0]);
  3897. // Remove the second display. Mirroring is not changed.
  3898. display_info_list.erase(display_info_list.end() - 1);
  3899. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3900. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  3901. EXPECT_EQ(internal_display_id, display_manager()->mirroring_source_id());
  3902. destination_ids = display_manager()->GetMirroringDestinationDisplayIdList();
  3903. EXPECT_EQ(1U, destination_ids.size());
  3904. EXPECT_EQ(first_display_id, destination_ids[0]);
  3905. // Add the second display. Mirroring is not changed.
  3906. display_info_list.push_back(second_mirror_info);
  3907. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3908. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  3909. EXPECT_EQ(internal_display_id, display_manager()->mirroring_source_id());
  3910. destination_ids = display_manager()->GetMirroringDestinationDisplayIdList();
  3911. EXPECT_EQ(1U, destination_ids.size());
  3912. EXPECT_EQ(first_display_id, destination_ids[0]);
  3913. // Remove the first display. Mirroring ends.
  3914. display_info_list.erase(display_info_list.end() - 2);
  3915. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3916. EXPECT_FALSE(display_manager()->IsInMirrorMode());
  3917. // Add the first display. Mirroring is restored.
  3918. display_info_list.push_back(first_mirror_info);
  3919. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3920. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  3921. EXPECT_EQ(internal_display_id, display_manager()->mirroring_source_id());
  3922. destination_ids = display_manager()->GetMirroringDestinationDisplayIdList();
  3923. EXPECT_EQ(1U, destination_ids.size());
  3924. EXPECT_EQ(first_display_id, destination_ids[0]);
  3925. }
  3926. TEST_F(DisplayManagerTest, MirrorModeRestoreAfterResume) {
  3927. const int64_t internal_display_id =
  3928. display::test::DisplayManagerTestApi(display_manager())
  3929. .SetFirstDisplayAsInternalDisplay();
  3930. constexpr int64_t external_display_id = 210000001;
  3931. std::vector<display::ManagedDisplayInfo> display_info_list;
  3932. display_info_list.emplace_back(display::CreateDisplayInfo(
  3933. internal_display_id, gfx::Rect(0, 0, 200, 100)));
  3934. display_info_list.emplace_back(display::CreateDisplayInfo(
  3935. external_display_id, gfx::Rect(1, 1, 500, 400)));
  3936. // Turn on mirror mode.
  3937. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3938. display_manager()->SetMirrorMode(display::MirrorMode::kNormal, absl::nullopt);
  3939. EXPECT_TRUE(display_manager()->IsInMirrorMode());
  3940. // Suspend.
  3941. display_manager()->SetMultiDisplayMode(display::DisplayManager::MIRRORING);
  3942. display_manager()->OnNativeDisplaysChanged(
  3943. std::vector<display::ManagedDisplayInfo>());
  3944. EXPECT_TRUE(display_manager()->IsInMirrorMode());
  3945. // Resume.
  3946. display_manager()->SetMultiDisplayMode(display::DisplayManager::MIRRORING);
  3947. display_manager()->OnNativeDisplaysChanged(display_info_list);
  3948. EXPECT_TRUE(display_manager()->IsInMirrorMode());
  3949. }
  3950. TEST_F(DisplayManagerTest, SoftwareMirrorRotationForTablet) {
  3951. enum Scenario {
  3952. // Auto mirror mode set when entering tablet mode.
  3953. kForcedMirror,
  3954. // Manual mirror mode with device is in physical tablet mode.
  3955. kPhysicalTablet,
  3956. };
  3957. // Set the first display as internal display so that the tablet mode can be
  3958. // enabled.
  3959. display::test::DisplayManagerTestApi(display_manager())
  3960. .SetFirstDisplayAsInternalDisplay();
  3961. auto* tablet_mode_controller = Shell::Get()->tablet_mode_controller();
  3962. auto tablet_mode_test_api = std::make_unique<TabletModeControllerTestApi>();
  3963. for (auto sc : {kForcedMirror, kPhysicalTablet}) {
  3964. SCOPED_TRACE(testing::Message() << "Scenario: " << sc);
  3965. UpdateDisplay("400x300,800x700");
  3966. switch (sc) {
  3967. case kForcedMirror: {
  3968. // Simulate turning on mirror mode triggered by tablet mode on.
  3969. tablet_mode_controller->SetEnabledForTest(true);
  3970. base::RunLoop().RunUntilIdle();
  3971. break;
  3972. }
  3973. case kPhysicalTablet: {
  3974. // Simulate physical tablet mode with clamshell ui.
  3975. tablet_mode_controller->SetEnabledForTest(true);
  3976. tablet_mode_test_api->AttachExternalMouse();
  3977. base::RunLoop().RunUntilIdle();
  3978. // Manual mirror mode.
  3979. SetSoftwareMirrorMode(true);
  3980. ASSERT_TRUE(tablet_mode_controller->is_in_tablet_physical_state());
  3981. ASSERT_FALSE(tablet_mode_controller->IsInTabletMode());
  3982. break;
  3983. }
  3984. }
  3985. ASSERT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  3986. EXPECT_EQ(gfx::Rect(0, 0, 400, 300),
  3987. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  3988. MirrorWindowTestApi test_api;
  3989. std::vector<aura::WindowTreeHost*> host_list = test_api.GetHosts();
  3990. ASSERT_EQ(1U, host_list.size());
  3991. EXPECT_EQ(gfx::Size(800, 700), host_list[0]->GetBoundsInPixels().size());
  3992. EXPECT_EQ(gfx::Size(400, 300), host_list[0]->window()->bounds().size());
  3993. // Test the target display's bounds after the transforms are applied.
  3994. gfx::RectF transformed_rect1(
  3995. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  3996. Shell::Get()->GetPrimaryRootWindow()->transform().TransformRect(
  3997. &transformed_rect1);
  3998. host_list[0]->window()->transform().TransformRect(&transformed_rect1);
  3999. EXPECT_EQ(gfx::RectF(0.0f, 50.0f, 800.0f, 600.0f), transformed_rect1);
  4000. // Rotate the source display by 90 degrees.
  4001. UpdateDisplay("400x300/r,800x700");
  4002. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  4003. EXPECT_EQ(gfx::Rect(0, 0, 300, 400),
  4004. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  4005. host_list = test_api.GetHosts();
  4006. ASSERT_EQ(1U, host_list.size());
  4007. EXPECT_EQ(gfx::Size(800, 700), host_list[0]->GetBoundsInPixels().size());
  4008. EXPECT_EQ(gfx::Size(300, 400), host_list[0]->window()->bounds().size());
  4009. // Test the target display's bounds after the transforms are applied.
  4010. gfx::RectF transformed_rect2(
  4011. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  4012. Shell::Get()->GetPrimaryRootWindow()->transform().TransformRect(
  4013. &transformed_rect2);
  4014. host_list[0]->window()->transform().TransformRect(&transformed_rect2);
  4015. // Use gfx::EncolosingRect because `transformed_rect2` has rounding errors:
  4016. // 137.000000,0.000000 524.999939x699.999939
  4017. EXPECT_EQ(gfx::Rect(137.0f, 0.0f, 525.0f, 700.0f),
  4018. gfx::ToEnclosingRect(transformed_rect2));
  4019. // Change the bounds of the source display and rotate the source display by
  4020. // 90 degrees.
  4021. UpdateDisplay("300x400/r,800x700");
  4022. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  4023. EXPECT_EQ(gfx::Rect(0, 0, 400, 300),
  4024. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  4025. host_list = test_api.GetHosts();
  4026. ASSERT_EQ(1U, host_list.size());
  4027. EXPECT_EQ(gfx::Size(800, 700), host_list[0]->GetBoundsInPixels().size());
  4028. EXPECT_EQ(gfx::Size(400, 300), host_list[0]->window()->bounds().size());
  4029. // Test the target display's bounds after the transforms are applied.
  4030. gfx::RectF transformed_rect3(
  4031. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  4032. Shell::Get()->GetPrimaryRootWindow()->transform().TransformRect(
  4033. &transformed_rect3);
  4034. host_list[0]->window()->transform().TransformRect(&transformed_rect3);
  4035. EXPECT_EQ(gfx::RectF(0.0f, 50.0f, 800.0f, 600.0f), transformed_rect3);
  4036. }
  4037. }
  4038. TEST_F(DisplayManagerTest, SoftwareMirrorRotationForNonTablet) {
  4039. MirrorWindowTestApi test_api;
  4040. UpdateDisplay("400x300,800x700");
  4041. // Simulate turning on mirror mode not triggered by tablet mode.
  4042. SetSoftwareMirrorMode(true);
  4043. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  4044. EXPECT_EQ(gfx::Rect(0, 0, 400, 300),
  4045. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  4046. std::vector<aura::WindowTreeHost*> host_list = test_api.GetHosts();
  4047. ASSERT_EQ(1U, host_list.size());
  4048. EXPECT_EQ(gfx::Size(800, 700), host_list[0]->GetBoundsInPixels().size());
  4049. EXPECT_EQ(gfx::Size(400, 300), host_list[0]->window()->bounds().size());
  4050. // Test the target display's bounds after the transforms are applied.
  4051. gfx::RectF transformed_rect1(
  4052. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  4053. Shell::Get()->GetPrimaryRootWindow()->transform().TransformRect(
  4054. &transformed_rect1);
  4055. host_list[0]->window()->transform().TransformRect(&transformed_rect1);
  4056. EXPECT_EQ(gfx::RectF(0.0f, 50.0f, 800.0f, 600.0f), transformed_rect1);
  4057. // Rotate the source display by 90 degrees.
  4058. UpdateDisplay("400x300/r,800x700");
  4059. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  4060. EXPECT_EQ(gfx::Rect(0, 0, 300, 400),
  4061. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  4062. host_list = test_api.GetHosts();
  4063. ASSERT_EQ(1U, host_list.size());
  4064. EXPECT_EQ(gfx::Size(800, 700), host_list[0]->GetBoundsInPixels().size());
  4065. EXPECT_EQ(gfx::Size(300, 400), host_list[0]->window()->bounds().size());
  4066. // Test the target display's bounds after the transforms are applied.
  4067. gfx::RectF transformed_rect2(
  4068. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  4069. Shell::Get()->GetPrimaryRootWindow()->transform().TransformRect(
  4070. &transformed_rect2);
  4071. host_list[0]->window()->transform().TransformRect(&transformed_rect2);
  4072. EXPECT_EQ(gfx::RectF(50.0f, 0.0f, 600.0f, 800.0f), transformed_rect2);
  4073. // Change the bounds of the source display and rotate the source display by 90
  4074. // degrees.
  4075. UpdateDisplay("300x400/r,800x700");
  4076. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  4077. EXPECT_EQ(gfx::Rect(0, 0, 400, 300),
  4078. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  4079. host_list = test_api.GetHosts();
  4080. ASSERT_EQ(1U, host_list.size());
  4081. EXPECT_EQ(gfx::Size(800, 700), host_list[0]->GetBoundsInPixels().size());
  4082. EXPECT_EQ(gfx::Size(400, 300), host_list[0]->window()->bounds().size());
  4083. // Test the target display's bounds after the transforms are applied.
  4084. gfx::RectF transformed_rect3(
  4085. display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
  4086. Shell::Get()->GetPrimaryRootWindow()->transform().TransformRect(
  4087. &transformed_rect3);
  4088. host_list[0]->window()->transform().TransformRect(&transformed_rect3);
  4089. // Use gfx::EncolosingRect because `transformed_rect3` has rounding errors.
  4090. EXPECT_EQ(gfx::Rect(0.0f, 137.0f, 700.0f, 525.0f),
  4091. gfx::ToEnclosingRect(transformed_rect3));
  4092. }
  4093. TEST_F(DisplayManagerTest, DPSizeTest) {
  4094. display::test::DisplayManagerTestApi(display_manager())
  4095. .SetFirstDisplayAsInternalDisplay();
  4096. UpdateDisplay(base::StringPrintf("3840x2160*%s", display::kDsfStr_2_666));
  4097. {
  4098. gfx::Size expected(1440, 810);
  4099. EXPECT_EQ(expected,
  4100. display::Screen::GetScreen()->GetPrimaryDisplay().size());
  4101. EXPECT_EQ(expected, Shell::GetPrimaryRootWindow()->bounds().size());
  4102. }
  4103. UpdateDisplay(base::StringPrintf("1920x1200*%s", display::kDsfStr_1_777));
  4104. {
  4105. gfx::Size expected(1080, 675);
  4106. EXPECT_EQ(expected,
  4107. display::Screen::GetScreen()->GetPrimaryDisplay().size());
  4108. EXPECT_EQ(expected, Shell::GetPrimaryRootWindow()->bounds().size());
  4109. }
  4110. UpdateDisplay(base::StringPrintf("3000x2000*%s", display::kDsfStr_2_252));
  4111. {
  4112. gfx::Size expected(1332, 888);
  4113. EXPECT_EQ(expected,
  4114. display::Screen::GetScreen()->GetPrimaryDisplay().size());
  4115. EXPECT_EQ(expected, Shell::GetPrimaryRootWindow()->bounds().size());
  4116. }
  4117. UpdateDisplay(base::StringPrintf("2160x1440*%s", display::kDsfStr_1_8));
  4118. {
  4119. gfx::Size expected(1200, 800);
  4120. EXPECT_EQ(expected,
  4121. display::Screen::GetScreen()->GetPrimaryDisplay().size());
  4122. EXPECT_EQ(expected, Shell::GetPrimaryRootWindow()->bounds().size());
  4123. }
  4124. }
  4125. TEST_F(DisplayManagerTest, PanelOrientation) {
  4126. int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
  4127. display::test::ScopedSetInternalDisplayId set_internal(display_manager(),
  4128. display_id);
  4129. // The panel is portrait but its orientation is landscape.
  4130. display::ManagedDisplayInfo native_display_info =
  4131. display::CreateDisplayInfo(display_id, gfx::Rect(0, 0, 1920, 1080));
  4132. native_display_info.set_panel_orientation(
  4133. display::PanelOrientation::kRightUp);
  4134. const display::ManagedDisplayMode base_mode(gfx::Size(1920, 1080), 60.0f,
  4135. false, false);
  4136. display::ManagedDisplayInfo::ManagedDisplayModeList mode_list =
  4137. CreateInternalManagedDisplayModeList(base_mode);
  4138. native_display_info.SetManagedDisplayModes(mode_list);
  4139. std::vector<display::ManagedDisplayInfo> display_info_list;
  4140. display_info_list.push_back(native_display_info);
  4141. display_manager()->OnNativeDisplaysChanged(display_info_list);
  4142. // Check display is landscape at ROTATE_0.
  4143. EXPECT_EQ(gfx::Size(1080, 1920),
  4144. display::Screen::GetScreen()->GetPrimaryDisplay().GetSizeInPixel());
  4145. EXPECT_EQ(display::Display::ROTATE_0,
  4146. display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
  4147. // Check the orientation controller reports correct orientation.
  4148. auto* screen_orientation_controller =
  4149. Shell::Get()->screen_orientation_controller();
  4150. EXPECT_EQ(chromeos::OrientationType::kLandscape,
  4151. screen_orientation_controller->natural_orientation());
  4152. EXPECT_EQ(chromeos::OrientationType::kLandscapePrimary,
  4153. screen_orientation_controller->GetCurrentOrientation());
  4154. // Test if changing rotation works as if it's landscape panel.
  4155. DisplayConfigurationController::DisableAnimatorForTest();
  4156. ScreenOrientationControllerTestApi(screen_orientation_controller)
  4157. .SetDisplayRotation(display::Display::ROTATE_270,
  4158. display::Display::RotationSource::USER);
  4159. EXPECT_EQ(gfx::Size(1920, 1080),
  4160. display::Screen::GetScreen()->GetPrimaryDisplay().GetSizeInPixel());
  4161. EXPECT_EQ(display::Display::ROTATE_270,
  4162. display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
  4163. EXPECT_EQ(chromeos::OrientationType::kPortraitPrimary,
  4164. screen_orientation_controller->GetCurrentOrientation());
  4165. }
  4166. TEST_F(DisplayManagerTest, UpdateRootWindowForNewWindows) {
  4167. Shell::GetPrimaryRootWindow()->RemoveObserver(this);
  4168. // Sets display configuration with three displays, sets the "root window for
  4169. // new windows" to the one at index before, removes the one at index 2, and
  4170. // checks that the "root window for new windows" is the one at index after.
  4171. const auto test_removing_secondary = [this](size_t before, size_t after) {
  4172. UpdateDisplay("800x600,800x600,800x600");
  4173. aura::Window::Windows root_windows = Shell::GetAllRootWindows();
  4174. Shell::SetRootWindowForNewWindows(root_windows[before]);
  4175. UpdateDisplay("800x600,800x600");
  4176. EXPECT_EQ(root_windows[after], Shell::GetRootWindowForNewWindows());
  4177. };
  4178. test_removing_secondary(0u, 0u);
  4179. test_removing_secondary(1u, 1u);
  4180. test_removing_secondary(2u, 0u);
  4181. // Each iteration sets display configuration with three displays, sets the
  4182. // "root window for new windows" to the one at index before, enters unified
  4183. // desktop mode, and checks that the "root window for new windows" is the
  4184. // primary one.
  4185. for (size_t before = 0u; before < 3u; ++before) {
  4186. UpdateDisplay("800x600,800x600,800x600");
  4187. Shell::SetRootWindowForNewWindows(Shell::GetAllRootWindows()[before]);
  4188. display_manager()->SetUnifiedDesktopEnabled(true);
  4189. EXPECT_EQ(Shell::GetPrimaryRootWindow(),
  4190. Shell::GetRootWindowForNewWindows());
  4191. display_manager()->SetUnifiedDesktopEnabled(false);
  4192. }
  4193. }
  4194. // Test that exiting mirror mode in tablet mode with a fullscreen window
  4195. // does not cause a crash (crbug.com/1021662).
  4196. TEST_F(DisplayManagerTest, ExitMirrorModeInTabletMode) {
  4197. // Simulate a tablet with and external display connected.
  4198. display::test::DisplayManagerTestApi(display_manager())
  4199. .SetFirstDisplayAsInternalDisplay();
  4200. UpdateDisplay("800x600,800x600");
  4201. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
  4202. base::RunLoop().RunUntilIdle();
  4203. EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
  4204. // Create a window to force in-app shelf.
  4205. std::unique_ptr<aura::Window> window = CreateTestWindow();
  4206. // Exit mirror mode.
  4207. display_manager()->SetMirrorMode(display::MirrorMode::kOff, absl::nullopt);
  4208. base::RunLoop().RunUntilIdle();
  4209. EXPECT_FALSE(display_manager()->IsInSoftwareMirrorMode());
  4210. }
  4211. } // namespace ash