Bug 1388365 - Return window to normal state. r?whimboo draft
authorAndreas Tolfsen <ato@sny.no>
Tue, 08 Aug 2017 14:57:24 +0100
changeset 642715 f195c5b537e23ae3ff71831d7d4bfcbd40d4148c
parent 642586 ebd53f599da19432c4e8f1c86a2d91e9900497a0
child 642716 5b069b674c29368eead868fa3f5ca70df1275f67
push id72846
push userbmo:ato@sny.no
push dateTue, 08 Aug 2017 17:43:46 +0000
reviewerswhimboo
bugs1388365
milestone57.0a1
Bug 1388365 - Return window to normal state. r?whimboo If a test leaves the window in maximized, minimized, or fullscreen state it should be returned to the normal state the next time a session is requested. MozReview-Commit-ID: IALlITFVz1w
testing/web-platform/tests/webdriver/tests/support/fixtures.py
--- a/testing/web-platform/tests/webdriver/tests/support/fixtures.py
+++ b/testing/web-platform/tests/webdriver/tests/support/fixtures.py
@@ -8,17 +8,20 @@ import webdriver
 from tests.support.asserts import assert_error
 from tests.support.http_request import HTTPRequest
 from tests.support import merge_dictionaries
 
 default_host = "http://127.0.0.1"
 default_port = "4444"
 
 def _ensure_valid_window(session):
-    """If current window is not open anymore, ensure to have a valid one selected."""
+    """If current window is not open anymore, ensure to have a valid
+    one selected.
+
+    """
     try:
         session.window_handle
     except webdriver.NoSuchWindowException:
         session.window_handle = session.handles[0]
 
 
 def _dismiss_user_prompts(session):
     """Dismisses any open user prompts in windows."""
@@ -29,16 +32,30 @@ def _dismiss_user_prompts(session):
         try:
             session.alert.dismiss()
         except webdriver.NoSuchAlertException:
             pass
 
     session.window_handle = current_window
 
 
+def _restore_normal_window_state(session):
+    """If the window is maximized, minimized, or fullscreened it will
+    be returned to normal state.
+
+    """
+    state = session.window.state
+    if state == "maximized":
+        session.window.maximize()
+    elif state == "minimized":
+        session.window.minimize()
+    elif state == "fullscreen":
+        session.window.fullscreen()
+
+
 def _restore_windows(session):
     """Closes superfluous windows opened by the test without ending
     the session implicitly by closing the last window.
     """
     current_window = session.window_handle
 
     for window in _windows(session, exclude=[current_window]):
         session.window_handle = window
@@ -130,16 +147,17 @@ def session(configuration, request):
         _current_session.start()
     except webdriver.errors.SessionNotCreatedException:
         if not _current_session.session_id:
             raise
 
     # finalisers are popped off a stack,
     # making their ordering reverse
     request.addfinalizer(lambda: _switch_to_top_level_browsing_context(_current_session))
+    request.addfinalizer(lambda: _restore_normal_window_state(_current_session))
     request.addfinalizer(lambda: _restore_windows(_current_session))
     request.addfinalizer(lambda: _dismiss_user_prompts(_current_session))
     request.addfinalizer(lambda: _ensure_valid_window(_current_session))
 
     return _current_session
 
 
 def new_session(configuration, request):