/* Ċ Ġ* ĠCopyright Ġ( C ) Ġ 2 0 1 6 ĠThe ĠAndroid ĠOpen ĠSource ĠProject Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ package Ġcom . android . tools . idea . app inspection . inspect ors . network . view Ċ Ċ import Ġcom . android . tools . adt ui . model . Fake Timer Ċ import Ġcom . android . tools . adt ui . model . Range Ċ import Ġcom . android . tools . adt ui . std ui . Tooltip Layer ed Pane Ċ import Ġcom . android . tools . idea . app inspection . inspect ors . network . model . Code Navigation Provider Ċ import Ġcom . android . tools . idea . app inspection . inspect ors . network . model . Fake Network Inspector DataSource Ċ import Ġcom . android . tools . idea . app inspection . inspect ors . network . model . Network Inspector Model Ċ import Ġcom . android . tools . idea . app inspection . inspect ors . network . model . Network Inspector Services Ċ import Ġcom . android . tools . idea . app inspection . inspect ors . network . model . http data . FA KE _ CONTENT _ TYPE Ċ import Ġcom . android . tools . idea . app inspection . inspect ors . network . model . http data . FA KE _ RESPONSE _ CODE Ċ import Ġcom . android . tools . idea . app inspection . inspect ors . network . model . http data . Http Data Ċ import Ġcom . android . tools . idea . app inspection . inspect ors . network . model . http data . Http DataModel Ċ import Ġcom . android . tools . idea . app inspection . inspect ors . network . model . http data . create Fake Http Data Ċ import Ġcom . android . tools . idea . app inspection . inspect ors . network . model . http data . fake Response Fields Ċ import Ġcom . android . tools . inspect ors . common . api . stack trace . Code Location Ċ import Ġcom . android . tools . inspect ors . common . api . stack trace . Code Navigator Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġcom . google . common . util . concurrent . More Executors Ċ import Ġcom . intellij . test Framework . Ed t Rule Ċ import Ġcom . intellij . test Framework . Runs In Ed t Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġjava . awt . Color Ċ import Ġjava . util . concurrent . Count DownLatch Ċ import Ġjava . util . concurrent . TimeUnit Ċ import Ġjavax . swing . JPanel Ċ import Ġjavax . swing . J Table Ċ Ċ private Ġval ĠFA KE _ DATA Ġ= ĠlistOf ( ĊĠ Ġcreate Fake Http Data ( 1 , Ġ 1 , Ġ 2 ), ĊĠ Ġcreate Fake Http Data ( 2 , Ġ 3 , Ġ 5 ), ĊĠ Ġcreate Fake Http Data ( 3 , Ġ 8 , Ġ 1 3 ), ĊĠ Ġcreate Fake Http Data ( 4 , Ġ 2 1 , Ġ 3 4 ). copy ( response Fields Ġ= Ġfake Response Fields ( 4 , Ġ" bmp ")) Ċ ) Ċ Ċ @ Runs In Ed t Ċ class ĠConnection s View Test Ġ{ ĊĠ Ġ@ get : Rule ĊĠ Ġval Ġed t Rule Ġ= ĠE dt Rule () ĊĊĠ Ġprivate Ġlateinit Ġvar Ġmodel : ĠNetwork Inspector Model ĊĠ Ġprivate Ġlateinit Ġvar Ġinspector View : ĠNetwork Inspector View ĊĊĠ Ġprivate Ġval Ġtimer Ġ= ĠFake Timer () ĊĊĠ Ġ/** ĊĠĠ Ġ* ĠThe Ġunderlying Ġtable Ġin ĠConnection s View Ġis Ġintention ally Ġnot Ġexposed Ġto Ġregular Ġusers Ġof Ġthe ĊĠĠ Ġ* Ġclass . ĠHowever , Ġfor Ġtests , Ġit Ġis Ġuseful Ġto Ġinspect Ġthe Ġcontents Ġof Ġthe Ġtable Ġto Ġverify Ġit Ġwas ĊĠĠ Ġ* Ġupdated . ĊĠĠ Ġ*/ ĊĠ Ġprivate Ġfun Ġget Connections Table ( view : ĠConnection s View ): ĠJ Table Ġ{ ĊĠĠĠ Ġreturn Ġview . component Ġas ĠJ Table ĊĠ Ġ} ĊĊĊĠ Ġ@ Before ĊĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠ Ġval Ġcode Navigation Provider Ġ= Ġobject Ġ: ĠCode Navigation Provider Ġ{ ĊĠĠĠĠĠ Ġoverride Ġval Ġcode Navigator Ġ= Ġobject Ġ: ĠCode Navigator () Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġis Navig atable ( location : ĠCode Location ) Ġ= Ġtrue ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġhandle Navigate ( location : ĠCode Location ) Ġ= ĠUnit ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġservices Ġ= ĠNetwork Inspector Services ( code Navigation Provider , Ġ 0 , Ġtimer , ĠMore Executors . direct Executor ()) ĊĠĠĠ Ġmodel Ġ= ĠNetwork Inspector Model ( services , ĠFake Network Inspector DataSource (), Ġobject Ġ: ĠHttp DataModel Ġ{ ĊĠĠĠĠĠ Ġprivate Ġval Ġdata List Ġ= ĠFA KE _ DATA ĊĠĠĠĠĠ Ġoverride Ġfun ĠgetData ( time Current Range Us : ĠRange ): ĠList < Http Data > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġdata List . filter Ġ{ Ġit . request StartTime Us Ġ>= Ġtime Current Range Us . min Ġ&& Ġit . request StartTime Us Ġ<= Ġtime Current Range Us . max Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠĠĠ Ġval Ġparent Panel Ġ= ĠJPanel () ĊĠĠĠ Ġval Ġcomponent Ġ= ĠTooltip Layer ed Pane ( parent Panel ) ĊĠĠĠ Ġinspector View Ġ= ĠNetwork Inspector View ( model , ĠFake Ui Components Provider (), Ġcomponent ) ĊĠĠĠ Ġparent Panel . add ( inspector View . component ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġlogic To Extract Column Values From Data Works () Ġ{ ĊĠĠĠ Ġval Ġdata Ġ= ĠFA KE _ DATA [ 2 ] Ġ// ĠRequest : Ġid Ġ= Ġ 3 , Ġtime Ġ= Ġ 8 -> 1 3 ĊĠĠĠ ĠassertThat ( data . id ). isEqualTo ( 3 ) ĊĊĠĠĠ Ġ// ĠID Ġis Ġset Ġas Ġthe ĠURL Ġname , Ġe . g . Ġexample . com /{ id }, Ġby ĠTest Http Data ĊĠĠĠ ĠassertThat ( Connections View . Column . NAME . getValue From ( data )). isEqualTo ( data . id . toString ()) ĊĠĠĠ ĠassertThat ( Connections View . Column . SIZE . getValue From ( data )). isEqualTo ( 8 ) ĊĠĠĠ ĠassertThat ( FA KE _ CONTENT _ TYPE ). endsWith ( Connections View . Column . TYPE . getValue From ( data ) Ġas ĠString ) ĊĠĠĠ ĠassertThat ( Connections View . Column . STATUS . getValue From ( data )). isEqualTo ( FA KE _ RESPONSE _ CODE ) ĊĠĠĠ ĠassertThat ( Connections View . Column . TIME . getValue From ( data )). isEqualTo ( TimeUnit . SECONDS . to Micro s ( 5 )) ĊĠĠĠ ĠassertThat ( Connections View . Column . TIME LINE . getValue From ( data )). isEqualTo ( TimeUnit . SECONDS . to Micro s ( 8 )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠmimeType Containing Multiple Components Is Truncated () Ġ{ ĊĠĠĠ Ġval Ġdata Ġ= ĠFA KE _ DATA [ 0 ] Ġ// ĠRequest : Ġid Ġ= Ġ 1 ĊĠĠĠ ĠassertThat ( data . id ). isEqualTo ( 1 ) ĊĠĠĠ ĠassertThat ( FA KE _ CONTENT _ TYPE ). endsWith ( Connections View . Column . TYPE . getValue From ( data ) Ġas ĠString ) ĊĠĠĠ ĠassertThat ( FA KE _ CONTENT _ TYPE ). isNot EqualTo ( Connections View . Column . TYPE . getValue From ( data ) Ġas ĠString ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġsimple MimeType Is Correct ly Displayed () Ġ{ ĊĠĠĠ Ġval Ġdata Ġ= ĠFA KE _ DATA [ 3 ] Ġ// ĠRequest : Ġid Ġ= Ġ 4 ĊĠĠĠ ĠassertThat ( data . id ). isEqualTo ( 4 ) ĊĠĠĠ ĠassertThat (" bmp "). isEqualTo ( Connections View . Column . TYPE . getValue From ( data ) Ġas ĠString ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġdata Range Controls Visible Connections () Ġ{ ĊĠĠĠ Ġval Ġview Ġ= Ġinspector View . connections View ĊĠĠĠ Ġval Ġtable Ġ= Ġget Connections Table ( view ) ĊĠĠĠ ĠassertThat ( table . rowCount ). isEqualTo ( 0 ) ĊĠĠĠ Ġmodel . timeline . selection Range . set ( TimeUnit . SECONDS . to Micro s ( 3 ). toDouble (), ĠTimeUnit . SECONDS . to Micro s ( 1 0 ). toDouble ()) ĊĠĠĠ ĠassertThat ( table . rowCount ). isEqualTo ( 2 ) ĊĠĠĠ Ġmodel . timeline . selection Range . set ( 0 . 0 , Ġ 0 . 0 ) ĊĠĠĠ ĠassertThat ( table . rowCount ). isEqualTo ( 0 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġactive Connection Is Auto Focused By Table () Ġ{ ĊĠĠĠ Ġval Ġview Ġ= Ġinspector View . connections View ĊĠĠĠ Ġval Ġtable Ġ= Ġget Connections Table ( view ) ĊĠĠĠ Ġvar Ġselected Row Ġ= Ġ- 1 ĊĊĠĠĠ Ġ// ĠWe Ġar bitr arily Ġselect Ġone Ġof Ġthe Ġfake Ġdata Ġinstances Ġand Ġsanity Ġcheck Ġthat Ġthe Ġtable ĊĠĠĠ Ġ// Ġauto - select s Ġit , Ġwhich Ġis Ġchecked Ġfor Ġbelow . ĊĠĠĠ Ġval Ġarbitrary Index Ġ= Ġ 1 ĊĠĠĠ Ġval Ġactive Data Ġ= ĠFA KE _ DATA [ ar bitrary Index ] ĊĠĠĠ Ġmodel . setSelected Connection ( active Data ) ĊĠĠĠ Ġval Ġl atch Selected Ġ= ĠCount DownLatch ( 1 ) ĊĠĠĠ Ġtable . selection Model . add List Selection Listener Ġ{ Ġe Ġ-> ĊĠĠĠĠĠ Ġselected Row Ġ= Ġe . first Index ĊĠĠĠĠĠ Ġl atch Selected . count Down () ĊĠĠĠ Ġ} ĊĠĠĠ Ġmodel . timeline . selection Range . set ( 0 . 0 , ĠTimeUnit . SECONDS . to Micro s ( 1 0 0 ). toDouble ()) ĊĠĠĠ Ġl atch Selected . await () ĊĠĠĠ ĠassertThat ( selected Row ). isEqualTo ( ar bitrary Index ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtable Can Be Sorted () Ġ{ ĊĠĠĠ Ġmodel . timeline . selection Range . set ( 0 . 0 , ĠTimeUnit . SECONDS . to Micro s ( 1 0 0 ). toDouble ()) ĊĠĠĠ Ġval Ġview Ġ= Ġinspector View . connections View ĊĠĠĠ Ġval Ġtable Ġ= Ġget Connections Table ( view ) ĊĊĠĠĠ Ġ// ĠTimes : Ġ 1 , Ġ 2 , Ġ 5 , Ġ 1 3 . ĠShould Ġsort Ġnumeric ally , Ġnot Ġalphabet ically Ġ( e . g . Ġnot Ġ 1 , Ġ 1 3 , Ġ 2 , Ġ 5 ) ĊĠĠĠ Ġ// ĠToggle Ġonce Ġfor Ġascending , Ġtwice Ġfor Ġdescending ĊĠĠĠ Ġtable . row Sorter . toggle SortOrder ( Connections View . Column . TIME . ordinal ) ĊĠĠĠ Ġtable . row Sorter . toggle SortOrder ( Connections View . Column . TIME . ordinal ) ĊĊĠĠĠ Ġ// ĠAfter Ġreverse Ġsorting , Ġdata Ġshould Ġbe Ġbackwards ĊĠĠĠ ĠassertThat ( table . rowCount ). isEqualTo ( 4 ) ĊĠĠĠ ĠassertThat ( table . convert RowIndex To View ( 0 )). isEqualTo ( 3 ) ĊĠĠĠ ĠassertThat ( table . convert RowIndex To View ( 1 )). isEqualTo ( 2 ) ĊĠĠĠ ĠassertThat ( table . convert RowIndex To View ( 2 )). isEqualTo ( 1 ) ĊĠĠĠ ĠassertThat ( table . convert RowIndex To View ( 3 )). isEqualTo ( 0 ) ĊĊĠĠĠ Ġmodel . timeline . selection Range . set ( 0 . 0 , Ġ 0 . 0 ) ĊĠĠĠ ĠassertThat ( table . rowCount ). isEqualTo ( 0 ) ĊĊĠĠĠ Ġ// ĠInclude Ġmiddle Ġtwo Ġrequests : Ġ 3 -> 5 Ġ( time Ġ= Ġ 2 ), Ġand Ġ 8 -> 1 3 Ġ( time = 5 ) ĊĠĠĠ Ġ// ĠThis Ġshould Ġstill Ġbe Ġshown Ġin Ġreverse Ġsorted Ġover ĊĠĠĠ Ġmodel . timeline . selection Range . set ( TimeUnit . SECONDS . to Micro s ( 3 ). toDouble (), ĠTimeUnit . SECONDS . to Micro s ( 1 0 ). toDouble ()) ĊĠĠĠ ĠassertThat ( table . rowCount ). isEqualTo ( 2 ) ĊĠĠĠ ĠassertThat ( table . convert RowIndex To View ( 0 )). isEqualTo ( 1 ) ĊĠĠĠ ĠassertThat ( table . convert RowIndex To View ( 1 )). isEqualTo ( 0 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest TableRow Highlight () Ġ{ ĊĠĠĠ Ġmodel . timeline . selection Range . set ( 0 . 0 , ĠTimeUnit . SECONDS . to Micro s ( 1 0 0 ). toDouble ()) ĊĠĠĠ Ġval Ġview Ġ= Ġinspector View . connections View ĊĠĠĠ Ġval Ġtimeline Column Ġ= ĠConnection s View . Column . TIME LINE . ordinal ĊĠĠĠ Ġval Ġtable Ġ= Ġget Connections Table ( view ) ĊĠĠĠ Ġval ĠbackgroundColor Ġ= ĠColor . YELLOW ĊĠĠĠ Ġval Ġselection Color Ġ= ĠColor . BLUE ĊĠĠĠ Ġtable . background Ġ= ĠbackgroundColor ĊĠĠĠ Ġtable . selection Background Ġ= Ġselection Color ĊĠĠĠ Ġval Ġrenderer Ġ= Ġtable . getCell Renderer ( 1 , Ġtimeline Column ) ĊĠĠĠ ĠassertThat ( table . prepare Renderer ( renderer , Ġ 1 , Ġtimeline Column ). background ). isEqualTo ( backgroundColor ) ĊĠĠĠ Ġtable . set Row Selection Interval ( 1 , Ġ 1 ) ĊĠĠĠ ĠassertThat ( table . prepare Renderer ( renderer , Ġ 1 , Ġtimeline Column ). background ). isEqualTo ( selection Color ) ĊĠ Ġ} Ċ }