Skip to content
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

Merged
merged 17 commits into from
Apr 27, 2018
Merged

Conversation

yutakahirano
Copy link
Contributor

@yutakahirano yutakahirano commented Mar 27, 2018

This is for w3c/ServiceWorker#1167.

@yutakahirano
Copy link
Contributor Author

@ghost
Copy link

ghost commented Mar 27, 2018

Build PASSED

Started: 2018-04-03 03:16:23
Finished: 2018-04-03 03:22:30

View more information about this build on:

@annevk
Copy link
Member

annevk commented Mar 29, 2018

I think we should have more tests:

  • history.go(0)
  • A manual test you have to reload yourself
  • A POSTed navigation followed by a reload
  • History traversal followed by a reload.

@yutakahirano
Copy link
Contributor Author

I think we should have more tests:

  • history.go(0)
  • A manual test you have to reload yourself
  • A POSTed navigation followed by a reload
  • History traversal followed by a reload.

Done.

@yutakahirano
Copy link
Contributor Author

@annevk, are you happy with this change?

Copy link
Member

@annevk annevk left a 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');
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@annevk
Copy link
Member

annevk commented Apr 10, 2018

Why does this only test this property btw? Don't we need tests for the other two properties two and their combinations?

@yutakahirano
Copy link
Contributor Author

@matto @wanderview can you take a look at SW related tests?

@yutakahirano
Copy link
Contributor Author

Why does this only test this property btw? Don't we need tests for the other two properties two and their combinations?

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);
Copy link
Member

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)

Copy link
Contributor Author

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);
Copy link
Member

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();
Copy link
Member

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.

Copy link
Contributor Author

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))');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

history

Copy link
Contributor Author

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);
Copy link
Member

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?

Copy link
Contributor Author

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))');
Copy link
Member

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)"

Copy link
Contributor Author

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)');
Copy link
Member

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..."

Copy link
Contributor Author

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)');
Copy link
Member

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."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@mfalken mfalken left a 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));
Copy link
Member

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?

Copy link
Contributor Author

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())');
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't

Copy link
Contributor Author

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.
Copy link
Member

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 .

Copy link
Contributor Author

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");
Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@annevk
Copy link
Member

annevk commented Apr 24, 2018

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.

@wanderview
Copy link
Member

The Cache API spec just stores the Request in a conceptual map, so it implies it should persist. It most likely does need code changes in actual implementations to persist through whatever disk schema is used.

@yutakahirano
Copy link
Contributor Author

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.

Copy link
Member

@inexorabletash inexorabletash left a 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) {
Copy link
Member

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?

Copy link
Contributor Author

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*)/)
Copy link
Member

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');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@yutakahirano
Copy link
Contributor Author

Thanks, comments are addressed.

@annevk annevk merged commit 58ee169 into master Apr 27, 2018
@annevk annevk deleted the yhirano/reload-navigation-type branch April 27, 2018 07:17
annevk pushed a commit to whatwg/fetch that referenced this pull request Apr 27, 2018
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.
annevk pushed a commit to whatwg/html that referenced this pull request Apr 27, 2018
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.
alice pushed a commit to alice/html that referenced this pull request Jan 8, 2019
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants