Skip to content

Commit

Permalink
Auto merge of #11196 - fduraffourg:master, r=jdm
Browse files Browse the repository at this point in the history
Add unit tests for cookies handling

Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data:
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #9965

Either:
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

Add unit tests for the `net` component about cookies. The tests are generated
with a new `mach update-net-cookies` command from this repo: https://github.com/abarth/http-state.

This PR also includes two trivial bug fixes about cookie handling.

From all the tests included, the following ones are currently failing:

- cookie_http_state::test_0003
- cookie_http_state::test_0006
- cookie_http_state::test_attribute0004
- cookie_http_state::test_attribute0005
- cookie_http_state::test_attribute0007
- cookie_http_state::test_attribute0008
- cookie_http_state::test_domain0017
- cookie_http_state::test_mozilla0001
- cookie_http_state::test_mozilla0002
- cookie_http_state::test_mozilla0003
- cookie_http_state::test_mozilla0005
- cookie_http_state::test_mozilla0007
- cookie_http_state::test_mozilla0009
- cookie_http_state::test_mozilla0010
- cookie_http_state::test_mozilla0013

`test_000[36]` and `test_mozilla*` are failing because there is currently no
method to clean a `net::cookie_storage` from expired cookies.

`test_attribute000[4578]` are failing because hyper does not parse the `Secure`
attribute correctly. I will open an issue on the upstream project.

`test_domain0017` fails because the TLD .org is not on the PUB_DOMAINS list.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11196)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed May 17, 2016
2 parents 6c08ad8 + 4fb53c8 commit c519739
Show file tree
Hide file tree
Showing 5 changed files with 2,125 additions and 5 deletions.
6 changes: 1 addition & 5 deletions components/net/cookie_storage.rs
Expand Up @@ -57,10 +57,6 @@ impl CookieStorage {
return;
}

if cookie.cookie.value.is_empty() {
return;
}

// Step 11
if let Some(old_cookie) = old_cookie.unwrap() {
// Step 11.3
Expand Down Expand Up @@ -107,7 +103,7 @@ impl CookieStorage {
// Step 4
(match acc.len() {
0 => acc,
_ => acc + ";"
_ => acc + "; "
}) + &c.cookie.name + "=" + &c.cookie.value
};
let result = url_cookies.iter_mut().fold("".to_owned(), reducer);
Expand Down
12 changes: 12 additions & 0 deletions python/servo/testing_commands.py
Expand Up @@ -664,3 +664,15 @@ def run_create(self, **kwargs):

if editor:
proc.wait()

@Command('update-net-cookies',
description='Update the net unit tests with cookie tests from http-state',
category='testing')
def update_net_cookies(self):
cache_dir = path.join(self.config["tools"]["cache-dir"], "tests")
run_file = path.abspath(path.join(PROJECT_TOPLEVEL_PATH,
"tests", "unit", "net",
"cookie_http_state_utils.py"))
run_globals = {"__file__": run_file}
execfile(run_file, run_globals)
return run_globals["update_test_file"](cache_dir)

0 comments on commit c519739

Please sign in to comment.