Skip to content

Commit

Permalink
[wdspec] Add tests for file protocol.
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D20488

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1495513
gecko-commit: be197c4fadf05f3d838d8c22c0e5ad041156cc60
gecko-integration-branch: central
gecko-reviewers: ato
  • Loading branch information
whimboo authored and moz-wptsync-bot committed Feb 25, 2019
1 parent 67e1c4c commit 38bd28f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 27 deletions.
57 changes: 30 additions & 27 deletions webdriver/tests/get_current_url/get.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import json
import pytest
import types

from tests.support import platform_name
from tests.support.inline import inline
from tests.support.asserts import assert_error, assert_success
from tests.support.sync import Poll
Expand All @@ -25,33 +22,36 @@ def test_no_browsing_context(session, closed_window):
def test_get_current_url_matches_location(session):
url = session.execute_script("return window.location.href")

result = get_current_url(session)
assert_success(result, url)
response = get_current_url(session)
assert_success(response, url)


def test_get_current_url_payload(session):
session.start()

result = get_current_url(session)
assert result.status == 200
assert isinstance(result.body["value"], basestring)
response = get_current_url(session)
assert response.status == 200
assert isinstance(response.body["value"], basestring)


def test_get_current_url_special_pages(session):
session.url = "about:blank"

result = get_current_url(session)
assert_success(result, "about:blank")
response = get_current_url(session)
assert_success(response, "about:blank")


# TODO(ato): This test requires modification to pass on Windows
def test_get_current_url_file_protocol(session):
def test_get_current_url_file_protocol(session, server_config):
# tests that the browsing context remains the same
# when navigated privileged documents
session.url = "file:///"
path = server_config["doc_root"]
if platform_name == "windows":
path = path.replace("\\", "/")
url = u"file:///{}".format(path)
session.url = url

result = get_current_url(session)
assert_success(result, "file:///")
response = get_current_url(session)
assert_success(response, url)


# TODO(ato): Test for http:// and https:// protocols.
Expand All @@ -60,27 +60,30 @@ def test_get_current_url_file_protocol(session):


def test_set_malformed_url(session):
result = session.transport.send("POST",
"session/%s/url" % session.session_id,
{"url": "foo"})
response = session.transport.send(
"POST",
"session/%s/url" % session.session_id, {"url": "foo"})

assert_error(response, "invalid argument")

assert_error(result, "invalid argument")

def test_get_current_url_after_modified_location(session):
start = get_current_url(session)
session.execute_script("window.location.href = 'about:blank#wd_test_modification'")
Poll(session, message="URL did not change").until(
lambda s: get_current_url(s).body["value"] != start.body["value"])
lambda s: get_current_url(s).body["value"] != start.body["value"])

response = get_current_url(session)
assert_success(response, "about:blank#wd_test_modification")

result = get_current_url(session)
assert_success(result, "about:blank#wd_test_modification")

def test_get_current_url_nested_browsing_context(session, create_frame):
session.url = "about:blank#wd_from_within_frame"
session.switch_frame(create_frame())

result = get_current_url(session)
assert_success(result, "about:blank#wd_from_within_frame")
response = get_current_url(session)
assert_success(response, "about:blank#wd_from_within_frame")


def test_get_current_url_nested_browsing_contexts(session):
session.url = two_frames_doc
Expand All @@ -92,5 +95,5 @@ def test_get_current_url_nested_browsing_contexts(session):
inner_frame = session.find.css("iframe", all=False)
session.switch_frame(inner_frame)

result = get_current_url(session)
assert_success(result, top_level_url)
response = get_current_url(session)
assert_success(response, top_level_url)
15 changes: 15 additions & 0 deletions webdriver/tests/navigate_to/navigate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from tests.support import platform_name
from webdriver.transport import Response

from tests.support.asserts import assert_error, assert_success
Expand Down Expand Up @@ -25,3 +26,17 @@ def test_null_response_value(session):
def test_no_browsing_context(session, closed_window):
response = navigate_to(session, "foo")
assert_error(response, "no such window")


def test_file_protocol(session, server_config):
# tests that the browsing context remains the same
# when navigated privileged documents
path = server_config["doc_root"]
if platform_name == "windows":
path = path.replace("\\", "/")
url = u"file:///{}".format(path)

response = navigate_to(session, url)
assert_success(response)

assert session.url == url

0 comments on commit 38bd28f

Please sign in to comment.