/* Ċ Ġ* ĠCopyright Ġ( c ) Ġ 2 0 2 1 ĠD uck Duck Go Ċ Ġ* Ċ Ġ* Ġ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 . duck duck go . app . browser . http auth Ċ Ċ import Ġandroid . webkit . WebView Ċ import Ġandroid . webkit . WebView Database Ċ import Ġandroidx . test . filters . Sdk Suppress Ċ import Ġandroidx . test . platform . app . Instrumentation Registry Ċ import Ġcom . duck duck go . app . Coroutine Test Rule Ċ import Ġcom . duck duck go . app . fire . Auth Database Locator Ċ import Ġcom . duck duck go . app . fire . Database Clean er Ċ import Ġcom . duck duck go . app . run Blocking Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . mock Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . never Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ Ċ @ Experimental Cor outines Api Ċ class ĠWebView Http Auth Store Test Ġ{ ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġcoroutine Rule Ġ= ĠCor outine Test Rule () ĊĊĠĠĠ Ġprivate Ġval Ġcontext Ġ= ĠInstrument ation Registry . get Instrumentation (). target Context ĊĠĠĠ Ġprivate Ġval ĠwebView Database : ĠWebView Database Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval Ġmock Database Clean er : ĠDatabase Clean er Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval ĠwebView : ĠWebView Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval Ġdatabase Locator Ġ= ĠAuth Database Locator ( context ) ĊĊĠĠĠ Ġprivate Ġval ĠwebView Http Auth Store Ġ= ĠReal WebView Http Auth Store ( web View Database , Ġmock Database Clean er , Ġdatabase Locator , Ġcoroutine Rule . test Dispatcher Provider ) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Sdk Suppress ( min Sdk Version Ġ= Ġandroid . os . Build . VERSION _ CODES . O ) ĊĠĠĠ Ġfun Ġwhen Set Http Auth Username Password Api 2 6 And Above Then Insert Http Auth Entity () Ġ{ ĊĠĠĠĠĠĠĠ ĠwebView Http Auth Store . set Http Auth Username Password ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠwebView Ġ= ĠwebView , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhost Ġ= Ġ" host ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrealm Ġ= Ġ" realm ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" name ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpassword Ġ= Ġ" pass ", ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġverify ( web View Database ). set Http Auth Username Password (" host ", Ġ" realm ", Ġ" name ", Ġ" pass ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Sdk Suppress ( min Sdk Version Ġ= Ġandroid . os . Build . VERSION _ CODES . O ) ĊĠĠĠ Ġfun Ġwhen Get Http Auth Username Password Api 2 6 And Above Then Return WebView Http Auth Credentials () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( web View Database . get Http Auth Username Password (" host ", Ġ" realm ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. thenReturn ( array Of (" name ", Ġ" pass ")) ĊĠĠĠĠĠĠĠ Ġval Ġcredentials Ġ= ĠwebView Http Auth Store . get Http Auth Username Password ( web View , Ġ" host ", Ġ" realm ") ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( WebView Http Auth Credentials (" name ", Ġ" pass "), Ġcredentials ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Sdk Suppress ( max Sdk Version Ġ= Ġandroid . os . Build . VERSION _ CODES . N _ MR 1 ) ĊĠĠĠ Ġ@ Suppress (" DE PREC ATION ") ĊĠĠĠ Ġfun Ġwhen Set Http Auth Username Password Api Below 2 6 Then Insert Http Auth Entity () Ġ{ ĊĠĠĠĠĠĠĠ ĠwebView Http Auth Store . set Http Auth Username Password ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠwebView Ġ= ĠwebView , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhost Ġ= Ġ" host ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrealm Ġ= Ġ" realm ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġusername Ġ= Ġ" name ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpassword Ġ= Ġ" pass ", ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġverify ( web View ). set Http Auth Username Password (" host ", Ġ" realm ", Ġ" name ", Ġ" pass ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Sdk Suppress ( max Sdk Version Ġ= Ġandroid . os . Build . VERSION _ CODES . N _ MR 1 ) ĊĠĠĠ Ġ@ Suppress (" DE PREC ATION ") ĊĠĠĠ Ġfun Ġwhen Get Http Auth Username Password Api Below 2 6 Then Return WebView Http Auth Credentials () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( web View . get Http Auth Username Password (" host ", Ġ" realm ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. thenReturn ( array Of (" name ", Ġ" pass ")) ĊĠĠĠĠĠĠĠ Ġval Ġcredentials Ġ= ĠwebView Http Auth Store . get Http Auth Username Password ( web View , Ġ" host ", Ġ" realm ") ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( WebView Http Auth Credentials (" name ", Ġ" pass "), Ġcredentials ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġwhen Clean Http Auth Database Then Clean Database Called () Ġ= Ġcoroutine Rule . run Blocking Ġ{ ĊĠĠĠĠĠĠĠ ĠwebView Http Auth Store . clean Http Auth Database () ĊĠĠĠĠĠĠĠ Ġverify ( mock Database Clean er ). clean Database ( database Locator . get Database Path ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Sdk Suppress ( min Sdk Version Ġ= Ġandroid . os . Build . VERSION _ CODES . LO L LI POP , Ġmax Sdk Version Ġ= Ġandroid . os . Build . VERSION _ CODES . O _ MR 1 ) ĊĠĠĠ Ġfun Ġwhen App Created And Api Between 2 1 And 2 7 Then Journal Mode Changed ToDelete () Ġ= Ġcoroutine Rule . run Blocking Ġ{ ĊĠĠĠĠĠĠĠ ĠwebView Http Auth Store . on App Created () ĊĠĠĠĠĠĠĠ Ġverify ( mock Database Clean er ). change Journal Mode ToDelete ( database Locator . get Database Path ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Sdk Suppress ( min Sdk Version Ġ= Ġandroid . os . Build . VERSION _ CODES . Q ) ĊĠĠĠ Ġfun Ġwhen App Created And Api GreaterThan 2 8 Then Journal Mode Changed ToDelete () Ġ= Ġcoroutine Rule . run Blocking Ġ{ ĊĠĠĠĠĠĠĠ ĠwebView Http Auth Store . on App Created () ĊĠĠĠĠĠĠĠ Ġverify ( mock Database Clean er ). change Journal Mode ToDelete ( database Locator . get Database Path ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Sdk Suppress ( min Sdk Version Ġ= Ġandroid . os . Build . VERSION _ CODES . P , Ġmax Sdk Version Ġ= Ġandroid . os . Build . VERSION _ CODES . P ) ĊĠĠĠ Ġfun Ġwhen App Created And Api Is 2 8 Then Journal Mode Changed ToDelete Not Called () Ġ= Ġcoroutine Rule . run Blocking Ġ{ ĊĠĠĠĠĠĠĠ ĠwebView Http Auth Store . on App Created () ĊĠĠĠĠĠĠĠ Ġverify ( mock Database Clean er , Ġnever ()). change Journal Mode ToDelete ( database Locator . get Database Path ()) ĊĠĠĠ Ġ} Ċ } Ċ