Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make WebDriver:MaximizeWindow idempotent. #7108

Merged
merged 1 commit into from
Aug 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 44 additions & 24 deletions webdriver/tests/contexts/maximize_window.py
@@ -1,31 +1,39 @@
from tests.support.inline import inline
from tests.support.asserts import assert_error, assert_success


alert_doc = inline("<script>window.alert()</script>")


def maximize(session):
return session.transport.send("POST", "session/%s/window/maximize" % session.session_id)


# 10.7.3 Maximize Window
def test_maximize_no_browsing_context(session, create_window):
# Step 1


def test_no_browsing_context(session, create_window):
# step 1
session.window_handle = create_window()
session.close()
result = session.transport.send("POST", "session/%s/window/maximize" % session.session_id)
assert_error(result, "no such window")
response = maximize(session)
assert_error(response, "no such window")


def test_handle_user_prompt(session):
# Step 2
# step 2
session.url = alert_doc
result = session.transport.send("POST", "session/%s/window/maximize" % session.session_id)
assert_error(result, "unexpected alert open")
response = maximize(session)
assert_error(response, "unexpected alert open")


def test_maximize(session):
before_size = session.window.size
assert session.window.state == "normal"

# step 4
result = session.transport.send("POST", "session/%s/window/maximize" % session.session_id)
assert_success(result)
response = maximize(session)
assert_success(response)

assert before_size != session.window.size
assert session.window.state == "maximized"
Expand All @@ -35,28 +43,40 @@ def test_payload(session):
before_size = session.window.size
assert session.window.state == "normal"

result = session.transport.send("POST", "session/%s/window/maximize" % session.session_id)
response = maximize(session)

# step 5
assert result.status == 200
assert isinstance(result.body["value"], dict)

rect = result.body["value"]
assert "width" in rect
assert "height" in rect
assert "x" in rect
assert "y" in rect
assert "state" in rect
assert isinstance(rect["width"], (int, float))
assert isinstance(rect["height"], (int, float))
assert isinstance(rect["x"], (int, float))
assert isinstance(rect["y"], (int, float))
assert isinstance(rect["state"], basestring)
assert response.status == 200
assert isinstance(response.body["value"], dict)

value = response.body["value"]
assert "width" in value
assert "height" in value
assert "x" in value
assert "y" in value
assert "state" in value
assert isinstance(value["width"], (int, float))
assert isinstance(value["height"], (int, float))
assert isinstance(value["x"], (int, float))
assert isinstance(value["y"], (int, float))
assert isinstance(value["state"], basestring)

assert before_size != session.window.size
assert session.window.state == "maximized"


def test_maximize_twice_is_idempotent(session):
assert session.window.state == "normal"

first_response = maximize(session)
assert_success(first_response)
assert session.window.state == "maximized"

second_response = maximize(session)
assert_success(second_response)
assert session.window.state == "maximized"


def test_maximize_when_resized_to_max_size(session):
# Determine the largest available window size by first maximising
# the window and getting the window rect dimensions.
Expand Down
82 changes: 67 additions & 15 deletions webdriver/tests/set_window_rect.py
Expand Up @@ -87,27 +87,79 @@ def test_invalid_params(session, data):
assert_error(response, "invalid argument")


def test_fullscreened(session):
# step 10
def test_fully_exit_fullscreen(session):
"""
10. Fully exit fullscreen.

[...]

To fully exit fullscreen a document document, run these steps:

1. If document's fullscreen element is null, terminate these steps.

2. Unfullscreen elements whose fullscreen flag is set, within
document's top layer, except for document's fullscreen element.

3. Exit fullscreen document.

"""

session.window.fullscreen()
assert session.window.state == "fullscreen"
assert session.execute_script("return window.fullScreen") is True

response = set_window_rect(session, {"width": 400, "height": 400})
assert_success(response)
assert rect["width"] == 400
assert rect["height"] == 400
assert rect["state"] == "normal"
value = assert_success(response)
assert value["width"] == 400
assert value["height"] == 400
assert value["state"] == "normal"


def test_restore_window_from_minimized(session):
"""
11. Restore the window.

[...]

To restore the window, given an operating system level window with an
associated top-level browsing context, run implementation-specific
steps to restore or unhide the window to the visible screen. Do not
return from this operation until the visibility state of the top-level
browsing context's active document has reached the visible state,
or until the operation times out.
"""

def test_minimized(session):
# step 11
session.window.minimize()
assert session.window.state == "minimized"
assert session.execute_script("return document.hidden") is True

response = set_window_rect(session, {"width": 400, "height": 400})
rect = assert_success(response)
assert rect["width"] == 400
assert rect["height"] == 400
assert rect["state"] == "normal"
response = set_window_rect(session, {"width": 450, "height": 450})
value = assert_success(response)
assert value["width"] == 450
assert value["height"] == 450
assert value["state"] == "normal"


def test_restore_window_from_maximized(session):
"""
11. Restore the window.

[...]

To restore the window, given an operating system level window with an
associated top-level browsing context, run implementation-specific
steps to restore or unhide the window to the visible screen. Do not
return from this operation until the visibility state of the top-level
browsing context’s active document has reached the visible state,
or until the operation times out.
"""

session.window.maximize()
assert session.window.state == "maximized"

response = set_window_rect(session, {"width": 500, "height": 500})
value = assert_success(response)
assert value["width"] == 500
assert value["height"] == 500
assert value["state"] == "normal"


def test_height_width(session):
Expand Down