Skip to content

Commit

Permalink
Merge r225213 - Unreviewed. Update W3C WebDriver imported tests.
Browse files Browse the repository at this point in the history
* imported/w3c/importer.json:
* imported/w3c/tools/webdriver/webdriver/client.py:
* imported/w3c/tools/webdriver/webdriver/error.py:
* imported/w3c/tools/wptrunner/docs/conf.py:
* imported/w3c/tools/wptrunner/wptrunner/browsers/ie.py:
* imported/w3c/tools/wptrunner/wptrunner/executors/base.py:
* imported/w3c/tools/wptrunner/wptrunner/executors/pytestrunner/runner.py:
* imported/w3c/tools/wptrunner/wptrunner/stability.py:
* imported/w3c/tools/wptrunner/wptrunner/testdriver-vendor.js: Added.
* imported/w3c/tools/wptrunner/wptrunner/update/sync.py:
* imported/w3c/tools/wptrunner/wptrunner/wptcommandline.py:
* imported/w3c/webdriver/interface/interface.html:
* imported/w3c/webdriver/tests/document_handling/page_source.py: Added.
* imported/w3c/webdriver/tests/element_click/bubbling.py: Added.
* imported/w3c/webdriver/tests/element_retrieval/get_active_element.py:
* imported/w3c/webdriver/tests/execute_async_script/user_prompts.py: Added.
* imported/w3c/webdriver/tests/execute_script/user_prompts.py: Added.
* imported/w3c/webdriver/tests/sessions/status.py: Added.
* imported/w3c/webdriver/tests/status.py: Removed.
* imported/w3c/webdriver/tests/support/fixtures.py:
* imported/w3c/webdriver/tests/support/wait.py:
* imported/w3c/webdriver/tests/user_prompts/accept_alert.py:
* imported/w3c/webdriver/tests/user_prompts/dismiss_alert.py:
* imported/w3c/webdriver/tests/user_prompts/get_alert_text.py:
* imported/w3c/webdriver/tests/user_prompts/send_alert_text.py:
  • Loading branch information
carlosgcampos committed Dec 18, 2017
1 parent 4358961 commit 2cbb72e
Show file tree
Hide file tree
Showing 26 changed files with 517 additions and 109 deletions.
30 changes: 30 additions & 0 deletions WebDriverTests/ChangeLog
@@ -1,3 +1,33 @@
2017-11-28 Carlos Garcia Campos <cgarcia@igalia.com>

Unreviewed. Update W3C WebDriver imported tests.

* imported/w3c/importer.json:
* imported/w3c/tools/webdriver/webdriver/client.py:
* imported/w3c/tools/webdriver/webdriver/error.py:
* imported/w3c/tools/wptrunner/docs/conf.py:
* imported/w3c/tools/wptrunner/wptrunner/browsers/ie.py:
* imported/w3c/tools/wptrunner/wptrunner/executors/base.py:
* imported/w3c/tools/wptrunner/wptrunner/executors/pytestrunner/runner.py:
* imported/w3c/tools/wptrunner/wptrunner/stability.py:
* imported/w3c/tools/wptrunner/wptrunner/testdriver-vendor.js: Added.
* imported/w3c/tools/wptrunner/wptrunner/update/sync.py:
* imported/w3c/tools/wptrunner/wptrunner/wptcommandline.py:
* imported/w3c/webdriver/interface/interface.html:
* imported/w3c/webdriver/tests/document_handling/page_source.py: Added.
* imported/w3c/webdriver/tests/element_click/bubbling.py: Added.
* imported/w3c/webdriver/tests/element_retrieval/get_active_element.py:
* imported/w3c/webdriver/tests/execute_async_script/user_prompts.py: Added.
* imported/w3c/webdriver/tests/execute_script/user_prompts.py: Added.
* imported/w3c/webdriver/tests/sessions/status.py: Added.
* imported/w3c/webdriver/tests/status.py: Removed.
* imported/w3c/webdriver/tests/support/fixtures.py:
* imported/w3c/webdriver/tests/support/wait.py:
* imported/w3c/webdriver/tests/user_prompts/accept_alert.py:
* imported/w3c/webdriver/tests/user_prompts/dismiss_alert.py:
* imported/w3c/webdriver/tests/user_prompts/get_alert_text.py:
* imported/w3c/webdriver/tests/user_prompts/send_alert_text.py:

2017-11-28 Carlos Garcia Campos <cgarcia@igalia.com>

WebDriver: add timeout option to run-webdriver-tests script
Expand Down
2 changes: 1 addition & 1 deletion WebDriverTests/imported/w3c/importer.json
@@ -1,6 +1,6 @@
{
"repository": "https://github.com/w3c/web-platform-tests.git",
"revision": "448984b0e1c5bad4af20abeaf84eb8b5e8e81478",
"revision": "2b50389ee72d89dd0be12bc6ca54a6e95c98d163",
"paths_to_import": [
"tools/pytest",
"tools/webdriver",
Expand Down
Expand Up @@ -507,6 +507,11 @@ def refresh(self):
def title(self):
return self.send_session_command("GET", "title")

@property
@command
def source(self):
return self.send_session_command("GET", "source")

@property
@command
def window_handle(self):
Expand Down
Expand Up @@ -11,16 +11,21 @@ def __init__(self, message, stacktrace=None):
self.stacktrace = stacktrace

def __repr__(self):
return "<%s http_status=%d>" % (self.__class__.__name__, self.http_status)
return "<%s http_status=%s>" % (self.__class__.__name__, self.http_status)

def __str__(self):
return ("%s (%d)\n"
return ("%s (%s)\n"
"\n"
"Remote-end stacktrace:\n"
"\n"
"%s" % (self.status_code, self.http_status, self.stacktrace))


class ElementClickInterceptedException(WebDriverException):
http_status = 400
status_code = "element click intercepted"


class ElementNotSelectableException(WebDriverException):
http_status = 400
status_code = "element not selectable"
Expand Down
2 changes: 1 addition & 1 deletion WebDriverTests/imported/w3c/tools/wptrunner/docs/conf.py
Expand Up @@ -264,4 +264,4 @@

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'python': ('http://docs.python.org/', None),
'mozlog': ('http://mozbase.readthedocs.org/en/latest/', None)}
'mozlog': ('https://firefox-source-docs.mozilla.org/', None)}
Expand Up @@ -31,8 +31,6 @@ def executor_kwargs(test_type, server_config, cache_manager, run_info_data,
ieOptions = {}
ieOptions["requireWindowFocus"] = True
capabilities = {}
capabilities["browserName"] = "internet explorer"
capabilities["platformName"] = "windows"
capabilities["se:ieOptions"] = ieOptions
executor_kwargs = base_executor_kwargs(test_type, server_config,
cache_manager, **kwargs)
Expand Down
Expand Up @@ -357,12 +357,10 @@ def do_test(self, test):
return (test.result_cls(*data), [])

def do_wdspec(self, session_config, path, timeout):
harness_result = ("OK", None)
subtest_results = pytestrunner.run(path,
self.server_config,
session_config,
timeout=timeout)
return (harness_result, subtest_results)
return pytestrunner.run(path,
self.server_config,
session_config,
timeout=timeout)

def do_delayed_imports(self):
global pytestrunner
Expand Down
@@ -1,4 +1,5 @@
"""Provides interface to deal with pytest.
"""
Provides interface to deal with pytest.
Usage::
Expand All @@ -24,7 +25,8 @@ def do_delayed_imports():


def run(path, server_config, session_config, timeout=0):
"""Run Python test at ``path`` in pytest. The provided ``session``
"""
Run Python test at ``path`` in pytest. The provided ``session``
is exposed as a fixture available in the scope of the test functions.
:param path: Path to the test file.
Expand All @@ -33,36 +35,51 @@ def run(path, server_config, session_config, timeout=0):
:param timeout: Duration before interrupting potentially hanging
tests. If 0, there is no timeout.
:returns: List of subtest results, which are tuples of (test id,
status, message, stacktrace).
:returns: (<harness result>, [<subtest result>, ...]),
where <subtest result> is (test id, status, message, stacktrace).
"""

if pytest is None:
do_delayed_imports()

recorder = SubtestResultRecorder()

os.environ["WD_HOST"] = session_config["host"]
os.environ["WD_PORT"] = str(session_config["port"])
os.environ["WD_CAPABILITIES"] = json.dumps(session_config["capabilities"])
os.environ["WD_SERVER_CONFIG"] = json.dumps(server_config)

plugins = [recorder]

# TODO(ato): Deal with timeouts
harness = HarnessResultRecorder()
subtests = SubtestResultRecorder()

with TemporaryDirectory() as cache:
pytest.main(["--strict", # turn warnings into errors
"--verbose", # show each individual subtest
"--capture", "no", # enable stdout/stderr from tests
"--basetemp", cache, # temporary directory
"--showlocals", # display contents of variables in local scope
"-p", "no:mozlog", # use the WPT result recorder
"-p", "no:cacheprovider", # disable state preservation across invocations
path],
plugins=plugins)

return recorder.results
try:
pytest.main(["--strict", # turn warnings into errors
"--verbose", # show each individual subtest
"--capture", "no", # enable stdout/stderr from tests
"--basetemp", cache, # temporary directory
"--showlocals", # display contents of variables in local scope
"-p", "no:mozlog", # use the WPT result recorder
"-p", "no:cacheprovider", # disable state preservation across invocations
path],
plugins=[harness, subtests])
except Exception as e:
harness.outcome = ("ERROR", str(e))

return (harness.outcome, subtests.results)


class HarnessResultRecorder(object):
outcomes = {
"failed": "ERROR",
"passed": "OK",
"skipped": "SKIP",
}

def __init__(self):
# we are ok unless told otherwise
self.outcome = ("OK", None)

def pytest_collectreport(self, report):
harness_result = self.outcomes[report.outcome]
self.outcome = (harness_result, None)


class SubtestResultRecorder(object):
Expand Down
42 changes: 21 additions & 21 deletions WebDriverTests/imported/w3c/tools/wptrunner/wptrunner/stability.py
@@ -1,14 +1,14 @@
import copy
import functools
import imp
import io
import os
import sys
from collections import OrderedDict, defaultdict
from datetime import datetime

from mozlog import reader
from mozlog.formatters import JSONFormatter, TbplFormatter
from mozlog.handlers import BaseHandler, LogLevelFilter, StreamHandler
from mozlog.formatters import JSONFormatter
from mozlog.handlers import BaseHandler, StreamHandler, LogLevelFilter

here = os.path.dirname(__file__)
localpaths = imp.load_source("localpaths", os.path.abspath(os.path.join(here, os.pardir, os.pardir, "localpaths.py")))
Expand Down Expand Up @@ -86,6 +86,8 @@ def test_end(self, data):

def is_inconsistent(results_dict, iterations):
"""Return whether or not a single test is inconsistent."""
if 'SKIP' in results_dict:
return False
return len(results_dict) > 1 or sum(results_dict.values()) != iterations


Expand Down Expand Up @@ -178,31 +180,29 @@ def run_step(logger, iterations, restart_after_iteration, kwargs_extras, **kwarg
kwargs["pause_after_test"] = False
kwargs.update(kwargs_extras)

handler = LogActionFilter(
LogLevelFilter(
StreamHandler(
sys.stdout,
TbplFormatter()
),
"WARNING"),
["log", "process_output"])
def wrap_handler(x):
x = LogLevelFilter(x, "WARNING")
if not kwargs["verify_log_full"]:
x = LogActionFilter(x, ["log", "process_output"])
return x

# There is a public API for this in the next mozlog
initial_handlers = logger._state.handlers
logger._state.handlers = []
logger._state.handlers = [wrap_handler(handler)
for handler in initial_handlers]

with open("raw.log", "wb") as log:
# Setup logging for wptrunner that keeps process output and
# warning+ level logs only
logger.add_handler(handler)
logger.add_handler(StreamHandler(log, JSONFormatter()))
log = io.BytesIO()
# Setup logging for wptrunner that keeps process output and
# warning+ level logs only
logger.add_handler(StreamHandler(log, JSONFormatter()))

wptrunner.run_tests(**kwargs)
wptrunner.run_tests(**kwargs)

logger._state.handlers = initial_handlers
logger._state.running_tests = set()
logger._state.suite_started = False

with open("raw.log", "rb") as log:
results, inconsistent = process_results(log, iterations)
log.seek(0)
results, inconsistent = process_results(log, iterations)
return results, inconsistent, iterations


Expand Down
@@ -0,0 +1 @@
// This file intentionally left blank
Expand Up @@ -81,7 +81,6 @@ def copy_wpt_tree(tree, dest, excludes=None, includes=None):
shutil.copy2(source_path, dest_path)

for source, destination in [("testharness_runner.html", ""),
("testharnessreport.js", "resources/"),
("testdriver-vendor.js", "resources/")]:
source_path = os.path.join(here, os.pardir, source)
dest_path = os.path.join(dest, destination, os.path.split(source)[1])
Expand Down
Expand Up @@ -79,6 +79,9 @@ def create_parser(product_choices=None):
mode_group.add_argument("--verify", action="store_true",
default=False,
help="Run a stability check on the selected tests")
mode_group.add_argument("--verify-log-full", action="store_true",
default=False,
help="Output per-iteration test results when running verify")

test_selection_group = parser.add_argument_group("Test Selection")
test_selection_group.add_argument("--test-types", action="store",
Expand Down
47 changes: 33 additions & 14 deletions WebDriverTests/imported/w3c/webdriver/interface/interface.html
Expand Up @@ -2,20 +2,39 @@
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src=/resources/WebIDLParser.js></script>
<script src=/resources/idlharness.js></script>
<script type=text/plain class=untested>
[Exposed=Window]
interface Navigator {
// objects implementing this interface also implement the interfaces given below
};
</script>
<script type=text/plain>
Navigator implements NavigatorAutomationInformation;

[NoInterfaceObject,
Exposed=(Window)]
interface NavigatorAutomationInformation {
readonly attribute boolean webdriver;
// always returns true
};
</script>
<script>
"use strict";

test(function() {
if ("webdriver" in navigator) {
var descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(navigator), "webdriver");
assert_true(descriptor !== undefined);
assert_true(descriptor.configurable);
assert_true(descriptor.enumerable);
assert_true(descriptor.set === undefined);
assert_true(navigator.webdriver);
} else {
assert_true(navigator.webdriver === undefined);
}
}, "Test that the navigator.webdriver descriptor has expected properties or doesn't exist at all");
if ("webdriver" in navigator) {
test(() => assert_true(navigator.webdriver), "navigator.webdriver is always true");
var idlArray = new IdlArray();
[].forEach.call(document.querySelectorAll("script[type=text\\/plain]"), function(node) {
if (node.className == "untested") {
idlArray.add_untested_idls(node.textContent);
} else {
idlArray.add_idls(node.textContent);
}
});
idlArray.test();
} else {
done();
}
</script>
</body>
</html>
@@ -0,0 +1,14 @@
import pytest

from tests.support.inline import inline


# 15.1.3 "Let source be the result returned from the outerHTML IDL attribute
# of the document element"
def test_source_matches_outer_html(session):
session.url = inline("<html><head><title>Cheese</title><body>Peas")
expected_source = session.execute_script(
"return document.documentElement.outerHTML")

assert session.source == expected_source

0 comments on commit 2cbb72e

Please sign in to comment.