-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Add tests for Request.isReloadNavigation #10192
Conversation
Build PASSEDStarted: 2018-04-03 03:16:23 View more information about this build on: |
I think we should have more tests:
|
Done. |
@annevk, are you happy with this change? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I'm the right person to review the service worker bits. Probably best to ask someone else.
<script> | ||
test(() => { | ||
assert_false(new Request('/').isReloadNavigation, 'isReloadNavigation'); | ||
}, 'default values for navigation type attributes'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we merge this in somewhere else that checks default values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Why does this only test this property btw? Don't we need tests for the other two properties two and their combinations? |
@matto @wanderview can you take a look at SW related tests? |
I like small changes and I would like to focus on one attribute at a time. I can leave whatwg/fetch#685 open until we land tests for other attributes, if you like. |
assert_equals(frame.contentDocument.body.textContent, | ||
'method = GET, isReloadNavigation = true'); | ||
frame.remove(); | ||
await service_worker_unregister_and_done(t, scope); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can just call reg.unregister()
instead (not sure it matters if you await or return it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
if (frame) { | ||
frame.remove(); | ||
} | ||
await service_worker_unregister(t, scope); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
}); | ||
assert_equals(frame.contentDocument.body.textContent, | ||
'method = GET, isReloadNavigation = true'); | ||
frame.remove(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nice to test the normal case of a top-level navigation also, which should be possible since this is a manual case, but I imagine that can be convoluted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
await service_worker_unregister(t, scope); | ||
} | ||
}, 'Service Worker responds to fetch event with the correct isReloadNavigation value (historg.go(0))'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
history
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
assert_equals(frame.contentDocument.body.textContent, | ||
'method = GET, isReloadNavigation = false'); | ||
// Wait a while for the history entry creation. | ||
await wait(10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems likely to be flaky on at least some browsers. Is it something needed for Chrome? If the spec says this creation should be synchronous, we could possibly remove the delay and have Chrome flakily fail the test (and move it to another file so not all of fetch-event.https.html is flaky).
If the spec allows async, could we instead poll for the change with a delay between turns of the loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for Blink and WebKit, and there is not flakiness. I added some comments.
} | ||
await service_worker_unregister(t, scope); | ||
} | ||
}, 'Service Worker responds to fetch event with the correct isReloadNavigation value (historg.go(0))'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the "Service Worker responds..." part is really needed but I know existing tests have this. Maybe just call it:
'FetchEvent#request.isReloadNavigation is true for history.go(0)"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
await service_worker_unregister(t, scope); | ||
} | ||
}, 'Service Worker responds to fetch event with the correct isReloadNavigation value (with history traversal)'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar about "Service Worker responds..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
'method = GET, isReloadNavigation = true'); | ||
frame.remove(); | ||
await service_worker_unregister_and_done(t, scope); | ||
}, 'Service Worker responds to fetch event with the correct isReloadNavigation value (manual reload)'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the "Service Worker responds to..." is really needed. Maybe just "FetchEvent#request.isReloadNavigation is true for manual reload."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@@ -6,6 +6,9 @@ | |||
<body> | |||
<script> | |||
var worker = 'resources/fetch-event-test-worker.js'; | |||
function wait(ms) { | |||
return new Promise(resolve => step_timeout(resolve, ms)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it ok to call step_timeout without a test object, like test.step_timeout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, it's exposed explicitly.
await reg.unregister(); | ||
} | ||
} | ||
}, 'Service Worker responds to fetch event with the correct isReloadNavigation value (location.reload())'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FetchEvent#request.isReloadNavigation is correct (location.reload())
frame = await with_iframe(scope); | ||
assert_equals(frame.contentDocument.body.textContent, | ||
'method = GET, isReloadNavigation = false'); | ||
// Blink and WebKit doesn't create a history entry for a navigation requested here, so |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the word as suggested below.
assert_equals(frame.contentDocument.body.textContent, | ||
'method = GET, isReloadNavigation = false'); | ||
// Blink and WebKit doesn't create a history entry for a navigation requested here, so | ||
// we need to use setTimeout to avoid that. See https://bugs.webkit.org/show_bug.cgi?id=42861. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe more direct as: Use setTimeout(0) to ensure the history entry is created for Blink and WebKit. See .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
frame.addEventListener('load', resolve); | ||
frame.src = anotherUrl; | ||
}); | ||
assert_equals(frame.contentDocument.body.textContent, "Here\'s a simple html file.\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can remove the '' when using double-quotes (same comment throughout)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
I think the one thing that isn't tested here yet is whether this survives the Cache API. @wanderview suggested that it should. I don't know if that requires changes to the Cache API specification or not. |
The Cache API spec just stores the |
I'm not sure if we need Cache API tests (IIUC no test tests that for any attributes), but here it is. see service-workers/cache-storage files. @wanderview, @inexorabletash, can you take a look? We don't need Cache API spec changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cache-storage/ changes LGTM, with a couple optional suggestions.
@@ -0,0 +1,23 @@ | |||
self.addEventListener('fetch', function(event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why not arrow function (=>
) here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
if (url.endsWith('?ignore')) { | ||
return; | ||
} | ||
const match = url.match(/\?name=(\w*)/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the URL type to simplify parsing? e.g.
const params = new URL(event.request.url).searchParams;
if (params.has('ignore')) ...
if (!params.has('name')) ...
const name = params.get('name');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Thanks, comments are addressed. |
And also a member on the request concept (reload-navigation flag) to support this API. See w3c/ServiceWorker#1167 for the discussion that led to this. Tests: web-platform-tests/wpt#10192. Corresponding HTML change: whatwg/html#3592.
See w3c/ServiceWorker#1167 for the discussion that led to this change and whatwg/fetch#685 for the infrastructure in Fetch this builds upon. Tests: web-platform-tests/wpt#10192.
See w3c/ServiceWorker#1167 for the discussion that led to this change and whatwg/fetch#685 for the infrastructure in Fetch this builds upon. Tests: web-platform-tests/wpt#10192.
This is for w3c/ServiceWorker#1167.