Skip to content

Commit

Permalink
Working with the new chromedriver
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankYFTang committed Dec 15, 2020
1 parent 06752c3 commit 361b97a
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 73 deletions.
16 changes: 8 additions & 8 deletions docs/writing-tests/testdriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,21 @@ await test_driver.set_permission({ name: "background-fetch" }, "denied");
await test_driver.set_permission({ name: "push", userVisibleOnly: true }, "granted", true);
```

### set_timezone
### set_time_zone

Usage: `test_driver.set_timezone(timezone)`
* _timezone_: a
Usage: `test_driver.set_time_zone(time_zone)`
* _timezone_: a string matching one of the
[Zone or Link names of the IANA Time Zone Database](https://www.iana.org/time-zones)

This function set the host default timezone to the given timezone ID.
It returns a promise that resolves after the timezone has
been set to be overridden with _state_.
This function set the host default time zone to the given time zone ID.
It returns a promise that resolves after the time zone has
been set to be overridden with _time_zone_.

Example:

``` js
await test_driver.set_timezone("Asia/Taipei");
await test_driver.set_timezone("Asia/Hong_Kong");
await test_driver.set_time_zone("Asia/Taipei");
await test_driver.set_time_zone("Asia/Hong_Kong");
```

## Using testdriver in Other Browsing Contexts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[set_timezone.html]
[TestDriver set_timezone method]
[TestDriver set_time_zone method]
expected:
if product == "firefox" or product == "safari" or product == "epiphany" or product == "webkit": FAIL
12 changes: 6 additions & 6 deletions infrastructure/testdriver/set_timezone.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>TestDriver set_timezone method</title>
<title>TestDriver set_time_zone method</title>
<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>
function defaultTimezone() {
function defaultTimeZone() {
return (new Intl.DateTimeFormat()).resolvedOptions().timeZone;
}
async_test(t => {
let timezone = "Asia/Taipei";
let timeZone = "Asia/Taipei";
test_driver
.set_timezone(timezone)
.set_time_zone(timeZone)
.then(() => {
assert_equals(defaultTimezone(), timezone);
assert_equals(defaultTimeZone(), timeZone);
t.done()
})
.catch(() => assert_unreached("set_timezone failed"));
.catch(() => assert_unreached("set_time_zone failed"));
});
</script>
23 changes: 12 additions & 11 deletions resources/testdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,22 +439,23 @@
},

/**
* Set timezone.
* Set time zone.
*
* The set_timezone function set the host default timezone to a new
* timezone id.
* The set_time_zone function sets the host default time zone to a new
* time zone id.
*
* This matches the behavior of the {@link
* https://docs.google.com/document/d/12vdPTH_Vlkt4pxwlWzR1CjKtLE6y2Z-Qs-GPi_hWXqc
* Set Timezone command}.
* https://github.com/whatwg/html/pull/3047
* Set Time Zone command}.
*
* @param {String} timezone - IANA Timezone ID.
* @param {String} time_zone - IANA Timezone ID.
*
* @returns {Promise} fulfilled after the timezone is set, or
* rejected if the set of timezone fails
* @returns {Promise} fulfilled after the time zone is set, or
* rejected if the set of time zone fails
*/
set_timezone: function(timezone) {
return window.test_driver_internal.set_timezone(timezone);
set_time_zone: function(time_zone) {
console.log("set_time_zone " + time_zone);
return window.test_driver_internal.set_time_zone(time_zone);
},

};
Expand Down Expand Up @@ -559,7 +560,7 @@
return Promise.reject(new Error("unimplemented"));
},

set_timezone: function(timezone) {
set_time_zone: function(time_zone) {
return Promise.reject(new Error("unimplemented"));
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
promise_test(async t => {
const oldTimeZone = "Pacific/Fakaofo";
const newTimeZone = "Asia/Taipei";
// First, we set to a fixed timezone.
await window.test_driver.set_timezone(oldTimeZone);
// First, we set to a fixed time zone.
await window.test_driver.set_time_zone(oldTimeZone);
assert_equals(defaultTimeZone(), oldTimeZone);

const script = 'resources/service-worker-timezonechange.js';
Expand All @@ -40,8 +40,8 @@
assert_equals(e.data, 'READY:' + oldTimeZone);
return new Promise(async resolve => {
port.onmessage = resolve;
// Change the timezone once the service worker is ready.
await window.test_driver.set_timezone(newTimeZone);
// Change the time zone once the service worker is ready.
await window.test_driver.set_time_zone(newTimeZone);
});
})
.then(e => {
Expand Down
6 changes: 3 additions & 3 deletions timezonechange/addeventlistener-timezonechange-fired.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
promise_test(async t => {
const oldTimeZone = "Pacific/Fakaofo";
const newTimeZone = "Asia/Taipei";
// First, setup the timezone in a fixed place.
await window.test_driver.set_timezone(oldTimeZone);
// First, setup the time zone in a fixed place.
await window.test_driver.set_time_zone(oldTimeZone);
assert_equals(defaultTimeZone(), oldTimeZone);
return new Promise(r => {
window.addEventListener('timezonechange', r);
window.test_driver.set_timezone(newTimeZone);
window.test_driver.set_time_zone(newTimeZone);
}).then(e => {
assert_equals(defaultTimeZone(), newTimeZone);
});
Expand Down
6 changes: 3 additions & 3 deletions timezonechange/ontimezonechange-event-property.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
promise_test(async t => {
const oldTimeZone = "Pacific/Fakaofo";
const newTimeZone = "Asia/Taipei";
// First, setup the timezone in a fixed place.
await window.test_driver.set_timezone(oldTimeZone);
// First, setup the time zone in a fixed place.
await window.test_driver.set_time_zone(oldTimeZone);
assert_equals(defaultTimeZone(), oldTimeZone);
return new Promise(async r => {
window.addEventListener('timezonechange', r);
await window.test_driver.set_timezone(newTimeZone);
await window.test_driver.set_time_zone(newTimeZone);
}).then(e => {
assert_false(e.cancelable);
assert_false(e.bubbles);
Expand Down
6 changes: 3 additions & 3 deletions timezonechange/ontimezonechange-over-setattribute.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
promise_test(async t => {
const oldTimeZone = "Pacific/Fakaofo";
const newTimeZone = "Asia/Taipei";
// First, setup the timezone in a fixed place.
await window.test_driver.set_timezone(oldTimeZone);
// First, setup the time_zone in a fixed place.
await window.test_driver.set_time_zone(oldTimeZone);
assert_equals(defaultTimeZone(), oldTimeZone);
window.received = 0; // We need a global variable here.
var fromWindowHandler = false;
document.body.setAttribute('ontimezonechange', 'window.received++;');

return new Promise(async r => {
window.ontimezonechange = r;
await window.test_driver.set_timezone(newTimeZone);
await window.test_driver.set_time_zone(newTimeZone);
}).then(evt => {
received++;
assert_equals(window.received, 1);
Expand Down
6 changes: 3 additions & 3 deletions timezonechange/setattribute-over-ontimezonechange.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
promise_test(async t => {
const oldTimeZone = "Pacific/Fakaofo";
const newTimeZone = "Asia/Taipei";
// First, setup the timezone in a fixed place.
await window.test_driver.set_timezone(oldTimeZone);
// First, setup the time zone in a fixed place.
await window.test_driver.set_time_zone(oldTimeZone);
assert_equals(defaultTimeZone(), oldTimeZone);
window.received = 0; // We need a global variable here.
window.ontimezonechange = () => received++;
Expand All @@ -22,7 +22,7 @@
assert_equals(window.received, 1);
assert_equals(defaultTimeZone(), newTimeZone);
});
await window.test_driver.set_timezone(newTimeZone);
await window.test_driver.set_time_zone(newTimeZone);
}, "Test that the timezonechange event fires on body ontimezonechange attribute but not window.ontimezonechange");
</script>
</body>
Expand Down
6 changes: 3 additions & 3 deletions timezonechange/setattribute.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
promise_test(async t => {
const oldTimeZone = "Pacific/Fakaofo";
const newTimeZone = "Asia/Taipei";
// First, setup the timezone in a fixed place.
await window.test_driver.set_timezone(oldTimeZone);
// First, setup the time zone in a fixed place.
await window.test_driver.set_time_zone(oldTimeZone);
assert_equals(defaultTimeZone(), oldTimeZone);
window.received = false; // We need a global variable here.
document.body.setAttribute('ontimezonechange', 'window.received = true;');

await window.test_driver.set_timezone(newTimeZone);
await window.test_driver.set_time_zone(newTimeZone);
assert_true(window.received);
assert_equals(defaultTimeZone(), newTimeZone);
}, "Test that the timezonechange event fires on body ontimezonechange attribute");
Expand Down
8 changes: 4 additions & 4 deletions timezonechange/shared-worker-timezonechange.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
promise_test(async t => {
const oldTimeZone = "Pacific/Fakaofo";
const newTimeZone = "Asia/Taipei";
// First we set the timezone to a fixed timezone.
await window.test_driver.set_timezone(oldTimeZone);
// First we set the time zone to a fixed time zone.
await window.test_driver.set_time_zone(oldTimeZone);
const worker = new SharedWorker('resources/shared-worker-timezonechange.js', 'name');
return new Promise(r => { worker.port.onmessage = r; })
.then(e => {
// Once we know the worker is ready, we change the timezone.
// Once we know the worker is ready, we change the time zone.
assert_equals(e.data, "READY:" + oldTimeZone);
return new Promise(async r => {
worker.port.onmessage = r;
await window.test_driver.set_timezone(newTimeZone);
await window.test_driver.set_time_zone(newTimeZone);
}).then(e => {
assert_equals(e.data, "SUCCESS:" + newTimeZone);
})
Expand Down
6 changes: 3 additions & 3 deletions timezonechange/window-ontimezonechange-fired.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
promise_test(async t => {
const oldTimeZone = "Pacific/Fakaofo";
const newTimeZone = "Asia/Taipei";
// First, setup the timezone in a fixed place.
await window.test_driver.set_timezone(oldTimeZone);
// First, setup the time zone in a fixed place.
await window.test_driver.set_time_zone(oldTimeZone);
assert_equals(defaultTimeZone(), oldTimeZone);
return new Promise(async r => {
window.ontimezonechange = r;
await window.test_driver.set_timezone(newTimeZone);
await window.test_driver.set_time_zone(newTimeZone);
}).then(e => {
assert_equals(defaultTimeZone(), newTimeZone);
});
Expand Down
6 changes: 3 additions & 3 deletions timezonechange/worker-timezonechange.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
promise_test(async t => {
const oldTimeZone = "Pacific/Fakaofo";
const newTimeZone = "Asia/Taipei";
// First we set the timezone to a fixed timezone.
await window.test_driver.set_timezone(oldTimeZone);
// First we set the time zone to a fixed time zone.
await window.test_driver.set_time_zone(oldTimeZone);
const worker = new Worker('resources/worker-timezonechange.js');
return new Promise(r => { worker.onmessage = r; })
.then(e => {
// Once we know the worker is ready, we change the timezone.
assert_equals(e.data, "READY:" + oldTimeZone);
return new Promise(async r => {
worker.onmessage = r;
await window.test_driver.set_timezone(newTimeZone);
await window.test_driver.set_time_zone(newTimeZone);
}).then(e => {
assert_equals(e.data, "SUCCESS:" + newTimeZone);
})
Expand Down
14 changes: 8 additions & 6 deletions tools/wptrunner/wptrunner/executors/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,19 @@ def __call__(self, payload):
"Setting user verified flag on authenticator %s to %s" % (authenticator_id, uv["isUserVerified"]))
return self.protocol.virtual_authenticator.set_user_verified(authenticator_id, uv)

class SetTimezoneAction(object):
name = "set_timezone"
class SetTimeZoneAction(object):
name = "set_time_zone"

def __init__(self, logger, protocol):
self.logger = logger
self.protocol = protocol

def __call__(self, payload):
timezone = payload["timezone"]
self.logger.debug("Setting timezone to %s" % timezone)
self.protocol.set_timezone.set_timezone(timezone)
print("SetTimeZoneAction ")
time_zone = payload["time_zone"]
print("SetTimeZoneAction " + time_zone)
self.logger.debug("Setting time_zone to %s" % time_zone)
self.protocol.set_time_zone.set_time_zone(time_zone)


actions = [ClickAction,
Expand All @@ -194,4 +196,4 @@ def __call__(self, payload):
RemoveCredentialAction,
RemoveAllCredentialsAction,
SetUserVerifiedAction,
SetTimezoneAction]
SetTimeZoneAction]
11 changes: 6 additions & 5 deletions tools/wptrunner/wptrunner/executors/executorwebdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
GenerateTestReportProtocolPart,
SetPermissionProtocolPart,
VirtualAuthenticatorProtocolPart,
SetTimezoneProtocolPart)
SetTimeZoneProtocolPart)
from ..testrunner import Stop

import webdriver as client
Expand Down Expand Up @@ -284,12 +284,13 @@ def set_user_verified(self, authenticator_id, uv):
return self.webdriver.send_session_command("POST", "webauthn/authenticator/%s/uv" % authenticator_id, uv)


class WebDriverSetTimezoneProtocolPart(SetTimezoneProtocolPart):
class WebDriverSetTimeZoneProtocolPart(SetTimeZoneProtocolPart):
def setup(self):
self.webdriver = self.parent.webdriver

def set_timezone(self, timezone):
return self.webdriver.send_session_command("POST", "timezone", {"timezone": timezone})
def set_time_zone(self, time_zone):
print("WebDriverSetTimeZoneProtocolPart " + time_zone)
return self.webdriver.send_session_command("POST", "time_zone", {"time_zone": time_zone})


class WebDriverProtocol(Protocol):
Expand All @@ -303,7 +304,7 @@ class WebDriverProtocol(Protocol):
WebDriverGenerateTestReportProtocolPart,
WebDriverSetPermissionProtocolPart,
WebDriverVirtualAuthenticatorProtocolPart,
WebDriverSetTimezoneProtocolPart]
WebDriverSetTimeZoneProtocolPart]

def __init__(self, executor, browser, capabilities, **kwargs):
super(WebDriverProtocol, self).__init__(executor, browser)
Expand Down
11 changes: 6 additions & 5 deletions tools/wptrunner/wptrunner/executors/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,14 +504,15 @@ def render_as_pdf(self, width, height):
"""Output document as PDF"""
pass

class SetTimezoneProtocolPart(ProtocolPart):
"""Protocol part for setting timezone"""
class SetTimeZoneProtocolPart(ProtocolPart):
"""Protocol part for setting time zone"""
__metaclass__ = ABCMeta

name = "set_timezone"
name = "set_time_zone"

@abstractmethod
def set_timezone(self, timezone):
"""Set timezone as default timezone."""
def set_time_zone(self, time_zone):
"""Set time_zone as default time zone."""
print("SetTimeZoneProtocolPart" + time_zone)
pass

5 changes: 3 additions & 2 deletions tools/wptrunner/wptrunner/testdriver-extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@
return create_action("set_user_verified", {authenticator_id, uv, context});
};

window.test_driver_internal.set_timezone = function(timezone) {
return create_action("set_timezone", {timezone});
window.test_driver_internal.set_time_zone = function(time_zone) {
console.log("Internal set_time_zone " + time_zone);
return create_action("set_time_zone", {time_zone});
};
})();

0 comments on commit 361b97a

Please sign in to comment.