-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove vendor prefix for printing with webdriver
This removes the vendor prefix for printing to PDF as it has landed in the WebDriver specification[1]. It moves the wpt to the main test suite. [1] https://w3c.github.io/webdriver/#print Differential Revision: https://phabricator.services.mozilla.com/D76294 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1639230 gecko-commit: c55864fc7a4ac6a1c3d3d6d2697f19d1ac485661 gecko-integration-branch: autoland gecko-reviewers: jgraham, webdriver-reviewers
- Loading branch information
1 parent
be4a903
commit b577b1f
Showing
3 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import base64 | ||
|
||
import pytest | ||
|
||
from tests.support.asserts import assert_error, assert_success | ||
from tests.support.inline import inline | ||
|
||
|
||
def do_print(session, options): | ||
return session.transport.send( | ||
"POST", "session/{session_id}/print".format(**vars(session)), | ||
options) | ||
|
||
|
||
def assert_pdf(data): | ||
assert data.startswith("%PDF-"), "Decoded data starts with the PDF signature" | ||
assert data.endswith("%%EOF\n"), "Decoded data ends with the EOF flag" | ||
|
||
|
||
def test_no_browsing_context(session, closed_window): | ||
response = do_print(session, {}) | ||
assert_error(response, "no such window") | ||
|
||
|
||
def test_html_document(session): | ||
session.url = inline("Test") | ||
|
||
response = do_print(session, {}) | ||
value = assert_success(response) | ||
pdf = base64.decodestring(value) | ||
# TODO: Test that the output is reasonable | ||
assert_pdf(pdf) | ||
|
||
|
||
@pytest.mark.parametrize("options", [{"orientation": 0}, | ||
{"orientation": "foo"}, | ||
{"scale": "1"}, | ||
{"scale": 3}, | ||
{"scale": 0.01}, | ||
{"margin": {"top": "1"}}, | ||
{"margin": {"bottom": -1}}, | ||
{"page": {"height": False}}, | ||
{"shrinkToFit": "false"}]) | ||
def test_invalid(session, options): | ||
response = do_print(session, options) | ||
assert_error(response, "invalid argument") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# META: timeout=long | ||
import base64 | ||
|
||
import pytest | ||
|
||
from tests.support.asserts import assert_dialog_handled, assert_error, assert_success | ||
from tests.support.inline import inline | ||
from printcmd import do_print, assert_pdf | ||
|
||
|
||
@pytest.fixture | ||
def check_user_prompt_closed_without_exception(session, create_dialog): | ||
def check_user_prompt_closed_without_exception(dialog_type, retval): | ||
session.url = inline("<input/>") | ||
|
||
create_dialog(dialog_type, text=dialog_type) | ||
|
||
response = do_print(session, {}) | ||
value = assert_success(response) | ||
|
||
pdf = base64.decodestring(value) | ||
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval) | ||
|
||
assert_pdf(pdf) | ||
|
||
return check_user_prompt_closed_without_exception | ||
|
||
|
||
@pytest.fixture | ||
def check_user_prompt_closed_with_exception(session, create_dialog): | ||
def check_user_prompt_closed_with_exception(dialog_type, retval): | ||
session.url = inline("<input/>") | ||
|
||
create_dialog(dialog_type, text=dialog_type) | ||
|
||
response = do_print(session, {}) | ||
assert_error(response, "unexpected alert open") | ||
|
||
assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval) | ||
|
||
return check_user_prompt_closed_with_exception | ||
|
||
|
||
@pytest.fixture | ||
def check_user_prompt_not_closed_but_exception(session, create_dialog): | ||
def check_user_prompt_not_closed_but_exception(dialog_type): | ||
session.url = inline("<input/>") | ||
|
||
create_dialog(dialog_type, text=dialog_type) | ||
|
||
response = do_print(session, {}) | ||
assert_error(response, "unexpected alert open") | ||
|
||
assert session.alert.text == dialog_type | ||
session.alert.dismiss() | ||
|
||
return check_user_prompt_not_closed_but_exception | ||
|
||
|
||
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"}) | ||
@pytest.mark.parametrize("dialog_type, retval", [ | ||
("alert", None), | ||
("confirm", True), | ||
("prompt", ""), | ||
]) | ||
def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval): | ||
check_user_prompt_closed_without_exception(dialog_type, retval) | ||
|
||
|
||
@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"}) | ||
@pytest.mark.parametrize("dialog_type, retval", [ | ||
("alert", None), | ||
("confirm", True), | ||
("prompt", ""), | ||
]) | ||
def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval): | ||
check_user_prompt_closed_with_exception(dialog_type, retval) | ||
|
||
|
||
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"}) | ||
@pytest.mark.parametrize("dialog_type, retval", [ | ||
("alert", None), | ||
("confirm", False), | ||
("prompt", None), | ||
]) | ||
def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval): | ||
check_user_prompt_closed_without_exception(dialog_type, retval) | ||
|
||
|
||
@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"}) | ||
@pytest.mark.parametrize("dialog_type, retval", [ | ||
("alert", None), | ||
("confirm", False), | ||
("prompt", None), | ||
]) | ||
def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval): | ||
check_user_prompt_closed_with_exception(dialog_type, retval) | ||
|
||
|
||
@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"}) | ||
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"]) | ||
def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type): | ||
check_user_prompt_not_closed_but_exception(dialog_type) | ||
|
||
|
||
@pytest.mark.parametrize("dialog_type, retval", [ | ||
("alert", None), | ||
("confirm", False), | ||
("prompt", None), | ||
]) | ||
def test_default(check_user_prompt_closed_with_exception, dialog_type, retval): | ||
check_user_prompt_closed_with_exception(dialog_type, retval) |