1
1
<?php
2
2
3
+ /**
4
+ * @noinspection PhpUnhandledExceptionInspection
5
+ * @noinspection PhpRedundantOptionalArgumentInspection
6
+ */
7
+
3
8
namespace Behat \Mink \Tests \Driver \Js ;
4
9
5
10
use Behat \Mink \Tests \Driver \TestCase ;
6
11
7
12
final class WindowTest extends TestCase
8
13
{
9
- public function testWindow ()
14
+ public function testWindow (): void
10
15
{
11
16
$ this ->getSession ()->visit ($ this ->pathTo ('/window.html ' ));
12
17
$ session = $ this ->getSession ();
@@ -35,7 +40,7 @@ public function testWindow()
35
40
$ this ->assertSame ('Main window div text ' , $ el ->getText ());
36
41
}
37
42
38
- public function testGetWindowNames ()
43
+ public function testGetWindowNames (): void
39
44
{
40
45
$ this ->getSession ()->visit ($ this ->pathTo ('/window.html ' ));
41
46
$ session = $ this ->getSession ();
@@ -55,7 +60,7 @@ public function testGetWindowNames()
55
60
$ this ->assertNotNull ($ windowNames [2 ]);
56
61
}
57
62
58
- public function testResizeWindow ()
63
+ public function testResizeWindow (): void
59
64
{
60
65
$ this ->getSession ()->visit ($ this ->pathTo ('/index.html ' ));
61
66
$ session = $ this ->getSession ();
@@ -82,17 +87,33 @@ public function testResizeWindow()
82
87
$ this ->assertTrue ($ session ->evaluateScript ($ jsWindowSizeScript ));
83
88
}
84
89
85
- public function testWindowMaximize ()
90
+ public function testWindowMaximize (): void
86
91
{
87
92
$ this ->getSession ()->visit ($ this ->pathTo ('/index.html ' ));
88
93
$ session = $ this ->getSession ();
89
-
90
- $ session ->maximizeWindow ();
91
- $ session ->wait (1000 , 'false ' );
92
-
93
- $ unusedWidth = $ session ->evaluateScript ('screen.availWidth - window.outerWidth ' );
94
- $ unusedHeight = $ session ->evaluateScript ('screen.availHeight - window.outerHeight ' );
95
- $ this ->assertLessThanOrEqual (0 , $ unusedWidth );
96
- $ this ->assertLessThanOrEqual (0 , $ unusedHeight );
94
+ $ popupName = 'testPopup ' ;
95
+ $ createWindowJs = "window.open('about:blank', ' $ popupName', 'left=20,top=40,width=300,height=200') " ;
96
+ $ getWindowPosJs = '
97
+ return {
98
+ top: window.screenY,
99
+ left: window.screenX,
100
+ right: window.screenX + window.innerWidth,
101
+ bottom: window.screenX + window.innerHeight
102
+ }
103
+ ' ;
104
+ $ session ->executeScript ($ createWindowJs );
105
+ $ session ->switchToWindow ($ popupName );
106
+ $ oldDim = (array )$ session ->evaluateScript ($ getWindowPosJs );
107
+
108
+ $ session ->maximizeWindow ($ popupName );
109
+ $ newDim = (array )$ session ->evaluateScript ($ getWindowPosJs );
110
+
111
+ foreach (array_keys ($ oldDim ) as $ name ) {
112
+ $ this ->assertNotEquals (
113
+ $ oldDim [$ name ],
114
+ $ newDim [$ name ],
115
+ "The popup's $ name position should not be the same after maximizing "
116
+ );
117
+ }
97
118
}
98
119
}
0 commit comments