-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exposing vendor specific API for testing (e.g. terminateServiceWorker) #6866
Comments
@makotoshimazu Are there existing manual tests that require this? |
Sorry, can I ask you what's the manual tests? In chromium, we have tests which requires vendor specific APIs in a separated directory, and it runs on chrome specific test runner. |
Test runner APIs are being used in Chrome (and probably WebKit in the future) to directly implement what is done otherwise with WebDriver. This is used for manual tests in cases like triggering a user click on a button. WebKit is close in terms of model to Chrome, so it would be probably fine (and useful) to share such test runner based tests. I am not sure how well that would apply to Gecko and Edge. There would also be a need to specify somewhere such test runner API. |
Chromium has --expose-internals-for-testing flag to expose the terminateServiceWorker API. // in a JS file in WPT
DefaultVendorSpecificAPI = function() {}
DefaultVendorSpecificAPI.prototype.terminateServiceWorker = function() {
throw SomeSpecialError();
} and implement them for each browser, and use it as follows. if (IsChromium()) {
VendorSpecificAPI = new ChromiumVendorSpecificAPI();
} else if (...) {
...
} else {
VendorSpecificAPI = new DefaultVendorSpecificAPI();
} Some tests using not implemented APIs would fail with SomeSpecialError(), so we would be able to distinguish them. |
@makotoshimazu, I see that there are 9 tests in Chromium that use terminateServiceWorker. How valuable do you think these tests would be to other implementers, how likely are they to reveal interop problems for example? (Trying to decide on what priority label to give this.) We now have a mechanism on which testing API like this can be built: However, it's currently only for wrapping WebDriver APIs, and it's not widely used and battle tested yet. @JKereliuk, can you work with @makotoshimazu to see if this would make sense as a WebDriver API, or if something else is needed? |
Tentatively calling it roadmap, but if this issue comes up in the infra issue triage and there doesn't seem to be that much value in sharing these tests, we should downgrade to backlog. |
I see, testdriver.js looks good place to do that:) Restarting workers would reveal issues around headers attached to the response of the installed service worker. For example, we can test if CSP header or referrer header is working well even after the script is loaded from a storage. |
I would prefer keeping it separate. That would mean these tests will probably always fail for Safari in https://wpt.fyi.
Sharing such tests look promising. |
@youennf, sounds like regardless of the shape of the testing mechanism, the tests would be failing in Safari, right? Given that, wouldn't it be OK to put it in testdriver.js if at least on WebDriver implementation has some API for this? |
WebKit is starting to implement a terminateServiceWorker testRunner API. I am unsure whether a WebDriver "terminate service worker" API makes sense. |
The current Chrome implementation is just wrong: it doesn't wait for the worker to terminate. So the tests are probably not always testing what's intended. We should probably change it to be Promise-based. I'm not familiar with WebDriver and testdriver.js. Chrome's tests in question are not manual tests, just tests that want to terminate a service worker and test something after starting it up again. I agree these tests are probably useful for all implementors. [edit: "I'm familiar" -> "I'm not familiar"] |
Is it the case that this API would make no sense from the outside (WebDriver) because there's no handle for the thing to terminate, or would it be weird even given such a handle? |
This API is currently given a ServiceWorker object, a web page can get access to all its related service workers through getRegistrations. I guess web driver could get access to this list and request termination of any of these. |
It's been a while since there was last updated. Is there still interest in adding this feature to WebDriver, and should this still be priority:roadmap? |
@makotoshimazu, what ended up happening with the tests in questions? Are they simply Blink-specific for now? |
Yes these are Blink-specific for now as they're using the internals API. Incidentally, @bashi is looking into making Chrome's terminateServiceWorker API return a promise. |
I wonder what shape of a solution would be most preferable to all implementers here? Can this API be sensibly be expressed as a WebDriver API? How would the |
I probably lack some context, but I would image it wouldn't be too difficult to specify this as an extension in the Service Worker spec. Maybe something like this with the details filled in.
This could look like :sessionId/serviceworker/register and return an ID for the worker
:sessionId/serviceworker/:id/terminate, terminate the worker with the ID returned from registering it
:sessionId/serviceworker/:id/fetch |
Update: @bashi changed Chrome's internals.terminateServiceWorker() to return a promise now: https://bugs.chromium.org/p/chromium/issues/detail?id=816328#c2. I'm probably also missing context... but ideally these tests could register() and run fetch as normal instead of going through a special API just in order to get the ability to do terminateServiceWorker(). |
If I understand the context correctly, the difficulty of adding service workers to the WebDriver API may be how to identify a service worker. |
@makotoshimazu Sorry this slipped through my notifications :( but no excuses.
WebDriver can execute scripts, so I think we should be able to get a handle to a given service worker with WebDriver that way if its possible with the regular js API, but correct me if I'm making an incorrect assumption here :) |
Since we didn't actually assign an owner for this in Q2 and though there were more serious infra/automation issues to tackle first, downgrading the priority to be transparent about that. @kereliuk, I wonder if adding testdriver.js API that isn't backed by WebDriver is something we'd ever consider? It would mean that the semantics would have to be defined in some other way, and maybe there wouldn't be a default implementation, but I wonder if we'll have a gray area (including this case) where the overhead of a WebDriver API and the plumbing is such that in practice people just won't do it? |
It sounds from off-issue discussions like it would be possible to define a WebDriver endpoint that takes a Perhaps it could be as simple as |
I'm now trying to add a test like the following steps:
For chromium, we have a testing API (internals.terminateServiceWorker()) for stopping the worker so we can make the test as a chromium specific test, but I think it's worth considering how to get the test in the web platform tests.
I also realized we don't have any tests in which service workers get launched by events.
The flow of current tests is like (1) registration (and it creates the worker thread), (2) install/activate events on the worker's thread, (3) run some tests (on the worker and the page), and we don't have any tests for stopped but installed service workers though usually the path to get the installed worker's scripts is different from the path to load the worker's scripts from the network.
Is it possible to have an unified way to expose some internals API for testing to WPT?
The text was updated successfully, but these errors were encountered: