a ze)@sBddlZddlZddlZddlZddlZddlmZddlmZdZdZ Gdddej Z Gdd d Z Gd d d e ej ZGd d d e ej ZGddde ej ZGddde ej ZGddde ej ZGddde ej ZGddde ej ZGddde ej ZGdddej ZGdddej Zedkr>edS)N)mock)supportzhttp://www.example.comtestc@seZdZddZdddZdS) PopenMockcCsdSNrselfrrH/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_webbrowser.pypollszPopenMock.pollNcCsdSrr)r Zsecondsrrr waitszPopenMock.wait)N)__name__ __module__ __qualname__r r rrrr rsrc@seZdZegidddZdS)CommandTestMixin)argskwc Cst}t|td||jtd}t|||i|tjjdd}| |dt| d|D] } | | || | | qd| ||dS)ajGiven a web browser instance method name along with arguments and keywords for same (which defaults to the single argument URL), creates a browser instance from the class pointed to by self.browser, calls the indicated instance method with the indicated arguments, and compares the resulting options and arguments passed to Popen by the browser instance against the 'options' and 'args' lists. Options are compared in a position independent fashion, and the arguments are compared in sequence order to whatever is left over after removing the options. Popen)namerN) rrZpatch subprocess browser_classCMD_NAMEgetattrrZ call_args assertEqualpopassertInindex) r methrroptions argumentspopenbrowserZ popen_argsoptionrrr _tests    zCommandTestMixin._testN)r rrURLr#rrrr rsrc@seZdZejZddZdS)GenericBrowserCommandTestcCs|jdgtgddSNopenrrr#r$rrrr test_open5sz#GenericBrowserCommandTest.test_openN)r rr webbrowserGenericBrowserrr*rrrr r%1sr%c@seZdZejZddZdS)BackgroundBrowserCommandTestcCs|jdgtgddSr&r)rrrr r*?sz&BackgroundBrowserCommandTest.test_openN)r rrr+ZBackgroundBrowserrr*rrrr r-;sr-c@s2eZdZejZddZddZddZddZ d S) ChromeCommandTestcCs|jdgtgddSr&r)rrrr r*IszChromeCommandTest.test_opencCs|jdtddgtgddSNr'FZ autoraiserrrr#dictr$rrrr test_open_with_autoraise_falseNsz0ChromeCommandTest.test_open_with_autoraise_falsecCs|jddgtgddSNopen_newz --new-windowr(r)rrrr test_open_newSszChromeCommandTest.test_open_newcCs|jdgtgddSN open_new_tabr(r)rrrr test_open_new_tabXsz#ChromeCommandTest.test_open_new_tabN) r rrr+ZChromerr*r4r7r:rrrr r.Es r.c@s2eZdZejZddZddZddZddZ d S) MozillaCommandTestcCs|jdgtgddSr&r)rrrr r*bszMozillaCommandTest.test_opencCs|jdtddgtgddSr/r2rrrr r4gsz1MozillaCommandTest.test_open_with_autoraise_falsecCs|jdgdtgddS)Nr6z -new-windowr(r)rrrr r7lsz MozillaCommandTest.test_open_newcCs|jdgdtgddS)Nr9z-new-tabr(r)rrrr r:qsz$MozillaCommandTest.test_open_new_tabN) r rrr+ZMozillarr*r4r7r:rrrr r;^s r;c@s2eZdZejZddZddZddZddZ d S) NetscapeCommandTestcCs |jdddgdtgddS)Nr'-raise-remote openURL({})r(r#formatr$rrrr r*{s zNetscapeCommandTest.test_opencCs(|jdtddddgdtgddS)Nr'Fr0-noraiser>r?r1)r#r3rAr$rrrr r4s z2NetscapeCommandTest.test_open_with_autoraise_falsecCs |jdddgdtgddS)Nr6r=r>openURL({},new-window)r(r@rrrr r7s z!NetscapeCommandTest.test_open_newcCs |jdddgdtgddS)Nr9r=r>openURL({},new-tab)r(r@rrrr r:s z%NetscapeCommandTest.test_open_new_tabN) r rrr+ZNetscaperr*r4r7r:rrrr r<ws r<c@s2eZdZejZddZddZddZddZ d S) GaleonCommandTestcCs|jddgtgddS)Nr'-nr(r)rrrr r*szGaleonCommandTest.test_opencCs"|jdtddddgtgddS)Nr'Fr0rBrFr1r2rrrr r4sz0GaleonCommandTest.test_open_with_autoraise_falsecCs|jddgtgddS)Nr6-wr(r)rrrr r7szGaleonCommandTest.test_open_newcCs|jddgtgddS)Nr9rGr(r)rrrr r:sz#GaleonCommandTest.test_open_new_tabN) r rrr+ZGaleonrr*r4r7r:rrrr rEs rEc@s2eZdZejZddZddZddZddZ d S) OperaCommandTestcCs|jdgtgddSr&r)rrrr r*szOperaCommandTest.test_opencCs|jdtddgtgddSr/r2rrrr r4sz/OperaCommandTest.test_open_with_autoraise_falsecCs|jddgtgddSr5r)rrrr r7szOperaCommandTest.test_open_newcCs|jdgtgddSr8r)rrrr r:sz"OperaCommandTest.test_open_new_tabN) r rrr+ZOperarr*r4r7r:rrrr rHs rHc@s2eZdZejZddZddZddZddZ d S) ELinksCommandTestcCs|jddgdtgddSNr'r>r?r(r@rrrr r*s  zELinksCommandTest.test_opencCs|jddgdtgddSrJr@rrrr r4s z0ELinksCommandTest.test_open_with_autoraise_falsecCs|jddgdtgddS)Nr6r>rCr(r@rrrr r7s zELinksCommandTest.test_open_newcCs|jddgdtgddS)Nr9r>rDr(r@rrrr r:s z#ELinksCommandTest.test_open_new_tabN) r rrr+ZElinksrr*r4r7r:rrrr rIs rIc@s<eZdZddZddZddZddZd d Zd d Zd S)BrowserRegistrationTestcCs tj|_gt_tj|_it_dSN)r+ _tryorder_saved_tryorder _browsers_saved_browsersrrrr setUpszBrowserRegistrationTest.setUpcCs|jt_|jt_dSrL)rNr+rMrPrOrrrr tearDownsz BrowserRegistrationTest.tearDowncCsGddd}g}i}|tj||tj|td|dg}|dg|d<|tj||tj||}|durtjd|||dntd|||rddg}nddg}||g|d<|tj||tj|dS)Nc@s eZdZdS)zCBrowserRegistrationTest._check_registration..ExampleBrowserNr rrrrrr ExampleBrowsersrTExample1example1Zexample2 preferred)rr+rMrOregister)r rXrTZexpected_tryorderZexpected_browsersinstancerrr _check_registrations,     z+BrowserRegistrationTest._check_registrationcCs|jdddS)NFrWr[rrrr test_registersz%BrowserRegistrationTest.test_registercCs|jdddS)NrWr\rrrr test_register_defaultsz-BrowserRegistrationTest.test_register_defaultcCs|jdddS)NTrWr\rrrr test_register_preferred sz/BrowserRegistrationTest.test_register_preferredN) r rrrQrRr[r]r^r_rrrr rKs rKc@s4eZdZddZddZddZddZd d Zd S) ImportTestcCstd}||j||jGddd}|d|||j||jdd||j| d|j||jd|dgdS)Nr+c@s eZdZdS)z0ImportTest.test_register..ExampleBrowserNrSrrrr rTsrTrUrV) rimport_fresh_module assertIsNonerM assertFalserOrYZ assertTruerr)r r+rTrrr r]s      zImportTest.test_registercCshtd}||j||j||j|dWdn1sN0Y| |jdS)Nr+Z fakebrowser) rrbrcrMrdrOZ assertRaisesErrorgetZassertIsNotNone)r r+rrr test_gets    (zImportTest.test_getcCs@td}tjtj}||d| || tjdS)Nr+) rrbospathbasenamesys executablelowerrYr,rf)r r+rrrr test_synthesize's zImportTest.test_synthesizec Cstd}z|j}Wn8|jtfyP}z|t|WYd}~n d}~00t*}||d<td}|Wdn1s0YdS)Nr+BROWSER) rrbrfrreAttributeErrorskipTeststrEnvironmentVarGuard)r r+r!errenvrrr test_environment-s $  zImportTest.test_environmentc Cstd}z|||jdj}Wn:|jttfyb}z|t |WYd}~n d}~00t 4}||d<td}| |j|Wdn1s0Yt 8}t j |d<td}| |jt j Wdn1s0YdS)Nr+raro)rrbrfrMrrerp IndexErrorrqrrrsrrkrl)r r+Zleast_preferred_browserrtrurrr test_environment_preferred8s $  0   z%ImportTest.test_environment_preferredN)r rrr]rgrnrvrxrrrr r`s   r`__main__)r+Zunittestrhrkrrrrr$rZ MagicMockrrZTestCaser%r-r.r;r<rErHrIrKr`r mainrrrr s,     5<