Bug 1529156 [wpt PR 15305] - Add testdriver support for generate_test_report WebDriver command., a=testonly

Automatic update from web-platform-tests
Add testdriver support for generate_test_report WebDriver command.

Also adds Reporting API tests which utilize this command.

--
fix lint errors

--
Add comments to tests

--

wpt-commits: 5109698f5a9b61797c86fda8000baeb0e701f3f1, 49f474206a2374f3da136f3ddb62cb85ea5c5532, c0a12dae123c560ef835c19e166a253e44275c80
wpt-pr: 15305
This commit is contained in:
Paul Meyer 2019-03-06 12:31:01 +00:00 коммит произвёл James Graham
Родитель 7ddf314514
Коммит b32867bb02
10 изменённых файлов: 217 добавлений и 3 удалений

Просмотреть файл

@ -0,0 +1,29 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Reporting: Buffer size</title>
<link rel="author" title="Paul Meyer" href="paulmeyer@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script>
// Test the buffer size (100) of ReportingObserver.
async_test(async function(test) {
for (i = 0; i != 110; ++i)
await test_driver.generate_test_report("" + i);
var observer = new ReportingObserver(function(reports) {
test.step(function() {
// Only (the most recent) 100 reports should be observed, even though
// 110 were buffered.
assert_equals(reports.length, 100);
for(i = 0; i != 100; ++i) {
assert_equals(reports[i].body.message, "" + (i + 10));
}
});
test.done();
}, {buffered: true});
observer.observe();
}, "Buffer size");
</script>

Просмотреть файл

@ -0,0 +1,25 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Reporting: Disconnect</title>
<link rel="author" title="Paul Meyer" href="paulmeyer@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script>
async_test(async function(test) {
var observer = new ReportingObserver(function(reports, observer) {
test.step(function() {
assert_equals(reports.length, 1);
assert_equals(reports[0].body.message, "Test message.");
});
test.done();
});
observer.observe();
// The observer should still receive this report even though disconnect()
// is called immediately afterwards.
await test_driver.generate_test_report("Test message.");
observer.disconnect();
}, "Disconnect");
</script>

Просмотреть файл

@ -0,0 +1,27 @@
<!DOCTYPE html>
<meta charset="utf-8" />
<title>Reporting: Generate Test Report</title>
<link rel="author" title="Paul Meyer" href="paulmeyer@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script>
// Test that the "generate_test_report" API works.
async_test(function(test) {
var observer = new ReportingObserver(function(reports) {
test.step(function() {
assert_equals(reports.length, 1);
// Ensure that the contents of the report are valid.
assert_equals(reports[0].type, "test");
assert_true(reports[0].url.endsWith("reporting/generateTestReport.html"));
assert_equals(reports[0].body.message, "Test message.");
});
test.done();
});
observer.observe();
// This should result in a "test" type report being generated and observed.
test_driver.generate_test_report("Test message.");
}, "Generate Test Report");
</script>

Просмотреть файл

@ -0,0 +1,30 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Reporting: Nested report</title>
<link rel="author" title="Paul Meyer" href="paulmeyer@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script>
// Test that reports can be generated within a ReportingObserver
// callback. These reports should be received by the same observer.
async_test(function(test) {
var step = 0;
var observer = new ReportingObserver(async function(reports, observer) {
test.step(function() {
assert_equals(reports.length, 1);
assert_equals(reports[0].body.message, "" + step);
});
++step;
if (step == 3)
test.done();
test_driver.generate_test_report("" + step);
});
observer.observe();
test_driver.generate_test_report("0");
}, "Nested report");
</script>

Просмотреть файл

@ -0,0 +1,32 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Reporting: Order</title>
<link rel="author" title="Paul Meyer" href="paulmeyer@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<p id="error">No error</p>
<script>
var count = 0;
async_test(function(test) {
var observer = new ReportingObserver(function(reports) {
test.step(function() {
// Reports should be received in the same order that they were
// generated.
for(i in reports) {
assert_equals(reports[i].body.message, "" + count++);
}
});
if (count == 10)
test.done();
});
observer.observe();
for (i = 0; i != 10; ++i)
test_driver.generate_test_report("" + i);
}, "Order");
</script>
</body>
</html>

Просмотреть файл

@ -194,6 +194,20 @@
*/
action_sequence: function(actions) {
return window.test_driver_internal.action_sequence(actions);
},
/**
* Generates a test report on the current page
*
* The generate_test_report function generates a report (to be observed
* by ReportingObserver) for testing purposes, as described in
* {@link https://w3c.github.io/reporting/#generate-test-report-command}
*
* @returns {Promise} fulfilled after the report is generated, or
* rejected if the report generation fails
*/
generate_test_report: function(message) {
return window.test_driver_internal.generate_test_report(message);
}
};
@ -281,6 +295,17 @@
*/
action_sequence: function(actions) {
return Promise.reject(new Error("unimplemented"));
},
/**
* Generates a test report on the current page
*
* @param {String} message - the message to be contained in the report
* @returns {Promise} fulfilled after the report is generated, or
* rejected if the report generation fails
*/
generate_test_report: function(message) {
return Promise.reject(new Error("unimplemented"));
}
};
})();

Просмотреть файл

@ -509,7 +509,8 @@ class CallbackHandler(object):
self.actions = {
"click": ClickAction(self.logger, self.protocol),
"send_keys": SendKeysAction(self.logger, self.protocol),
"action_sequence": ActionSequenceAction(self.logger, self.protocol)
"action_sequence": ActionSequenceAction(self.logger, self.protocol),
"generate_test_report": GenerateTestReportAction(self.logger, self.protocol)
}
def __call__(self, result):
@ -593,3 +594,13 @@ class ActionSequenceAction(object):
def get_element(self, selector):
element = self.protocol.select.element_by_selector(selector)
return element
class GenerateTestReportAction(object):
def __init__(self, logger, protocol):
self.logger = logger
self.protocol = protocol
def __call__(self, payload):
message = payload["message"]
self.logger.debug("Generating test report: %s" % message)
self.protocol.generate_test_report.generate_test_report(message)

Просмотреть файл

@ -20,7 +20,8 @@ from .protocol import (BaseProtocolPart,
ClickProtocolPart,
SendKeysProtocolPart,
ActionSequenceProtocolPart,
TestDriverProtocolPart)
TestDriverProtocolPart,
GenerateTestReportProtocolPart)
from ..testrunner import Stop
import webdriver as client
@ -188,6 +189,15 @@ class WebDriverTestDriverProtocolPart(TestDriverProtocolPart):
self.webdriver.execute_script("window.postMessage(%s, '*')" % json.dumps(obj))
class WebDriverGenerateTestReportProtocolPart(GenerateTestReportProtocolPart):
def setup(self):
self.webdriver = self.parent.webdriver
def generate_test_report(self, message):
json_message = {"message": message}
self.webdriver.send_session_command("POST", "reporting/generate_test_report", json_message)
class WebDriverProtocol(Protocol):
implements = [WebDriverBaseProtocolPart,
WebDriverTestharnessProtocolPart,
@ -195,7 +205,8 @@ class WebDriverProtocol(Protocol):
WebDriverClickProtocolPart,
WebDriverSendKeysProtocolPart,
WebDriverActionSequenceProtocolPart,
WebDriverTestDriverProtocolPart]
WebDriverTestDriverProtocolPart,
WebDriverGenerateTestReportProtocolPart]
def __init__(self, executor, browser, capabilities, **kwargs):
super(WebDriverProtocol, self).__init__(executor, browser)

Просмотреть файл

@ -265,6 +265,7 @@ class ClickProtocolPart(ProtocolPart):
:param element: A protocol-specific handle to an element."""
pass
class SendKeysProtocolPart(ProtocolPart):
"""Protocol part for performing trusted clicks"""
__metaclass__ = ABCMeta
@ -280,6 +281,20 @@ class SendKeysProtocolPart(ProtocolPart):
pass
class GenerateTestReportProtocolPart(ProtocolPart):
"""Protocol part for generating test reports"""
__metaclass__ = ABCMeta
name = "generate_test_report"
@abstractmethod
def generate_test_report(self, message):
"""Generate a test report.
:param message: The message to be contained in the report."""
pass
class ActionSequenceProtocolPart(ProtocolPart):
"""Protocol part for performing trusted clicks"""
__metaclass__ = ABCMeta

Просмотреть файл

@ -90,4 +90,13 @@
window.__wptrunner_message_queue.push({"type": "action", "action": "action_sequence", "actions": actions});
return pending_promise;
};
window.test_driver_internal.generate_test_report = function(message) {
const pending_promise = new Promise(function(resolve, reject) {
pending_resolve = resolve;
pending_reject = reject;
});
window.__wptrunner_message_queue.push({"type": "action", "action": "generate_test_report", "message": message});
return pending_promise;
};
})();