@@ -57,13 +57,59 @@ public function testSetUserAgent()
5757 $ pageFooBar ->setUserAgent ('foobar ' )->await ();
5858 $ pageBarBaz ->setUserAgent ('barbaz ' )->await ();
5959
60- $ pageFooBar ->navigate (' http://requestbin.fullcontact.com/uhunfhuh ' )->waitForNavigation ();
61- $ pageBarBaz ->navigate (' http://requestbin.fullcontact.com/uhunfhuh ' )->waitForNavigation ();
60+ $ pageFooBar ->navigate ($ this -> sitePath ( ' a.html ' ) )->waitForNavigation ();
61+ $ pageBarBaz ->navigate ($ this -> sitePath ( ' a.html ' ) )->waitForNavigation ();
6262
6363 $ value1 = $ pageFooBar ->evaluate ('navigator.userAgent ' )->getReturnValue ();
6464 $ value2 = $ pageBarBaz ->evaluate ('navigator.userAgent ' )->getReturnValue ();
6565
6666 $ this ->assertEquals ('foobar ' , $ value1 );
6767 $ this ->assertEquals ('barbaz ' , $ value2 );
6868 }
69+
70+
71+ public function testPreScriptOption ()
72+ {
73+ $ factory = new BrowserFactory ();
74+
75+ $ browser = $ factory ->createBrowser ();
76+
77+ $ preScript1 =
78+ "if(!('foo' in navigator)) {
79+ navigator.foo = 0
80+ }
81+ navigator.foo++; " ;
82+
83+ $ preScript2 =
84+ "if(!('bar' in navigator)) {
85+ navigator.bar = 10
86+ }
87+ navigator.bar++; " ;
88+
89+ $ page = $ browser ->createPage ();
90+ $ page2 = $ browser ->createPage ();
91+ $ page ->addPreScript ($ preScript1 );
92+ $ page ->addPreScript ($ preScript2 );
93+
94+ // make sure prescript evaluates
95+ $ page ->navigate ($ this ->sitePath ('a.html ' ))->waitForNavigation ();
96+ $ fooValue = $ page ->evaluate ('navigator.foo ' )->getReturnValue ();
97+ $ barValue = $ page ->evaluate ('navigator.bar ' )->getReturnValue ();
98+ $ this ->assertEquals (1 , $ fooValue );
99+ $ this ->assertEquals (11 , $ barValue );
100+
101+ // make sure prescript is not adding again and again on every requests
102+ $ page ->navigate ($ this ->sitePath ('b.html ' ))->waitForNavigation ();
103+ $ fooValue = $ page ->evaluate ('navigator.foo ' )->getReturnValue ();
104+ $ barValue = $ page ->evaluate ('navigator.bar ' )->getReturnValue ();
105+ $ this ->assertEquals (1 , $ fooValue );
106+ $ this ->assertEquals (11 , $ barValue );
107+
108+ // make sure prescript did not pollute other pages
109+ $ page2 ->navigate ($ this ->sitePath ('b.html ' ))->waitForNavigation ();
110+ $ fooValue = $ page2 ->evaluate ('navigator.foo ' )->getReturnValue ();
111+ $ barValue = $ page2 ->evaluate ('navigator.bar ' )->getReturnValue ();
112+ $ this ->assertEquals (null , $ fooValue );
113+ $ this ->assertEquals (null , $ barValue );
114+ }
69115}
0 commit comments