Test fixes; update for changes in spec

This commit is contained in:
Manish Goregaokar 2016-06-06 18:58:50 +05:30
parent f4e3e8e38e
commit fd6f9bd411
22 changed files with 320 additions and 269 deletions

View file

@ -14,7 +14,7 @@ use hyper::server::{Request as HyperRequest, Response as HyperResponse};
use hyper::status::StatusCode;
use hyper::uri::RequestUri;
use net::fetch::cors_cache::CORSCache;
use net::fetch::methods::{fetch, fetch_with_cors_cache};
use net::fetch::methods::{FetchContext, fetch, fetch_with_cors_cache};
use net::http_loader::HttpState;
use net_traits::FetchTaskTarget;
use net_traits::request::{Origin, RedirectMode, Referer, Request, RequestMode};
@ -22,10 +22,10 @@ use net_traits::response::{CacheState, Response, ResponseBody, ResponseType};
use std::fs::File;
use std::io::Read;
use std::rc::Rc;
use std::thread;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::mpsc::{Sender, channel};
use std::sync::{Arc, Mutex};
use std::thread;
use time::{self, Duration};
use unicase::UniCase;
use url::{Origin as UrlOrigin, Url};
@ -37,6 +37,12 @@ struct FetchResponseCollector {
sender: Sender<Response>,
}
fn new_fetch_context() -> FetchContext {
FetchContext {
state: HttpState::new(),
user_agent: "Such Browser. Very Layout. Wow.".into(),
}
}
impl FetchTaskTarget for FetchResponseCollector {
fn process_request_body(&mut self, _: &Request) {}
fn process_request_eof(&mut self, _: &Request) {}
@ -50,7 +56,7 @@ impl FetchTaskTarget for FetchResponseCollector {
fn fetch_async(request: Request, target: Box<FetchTaskTarget + Send>) {
thread::spawn(move || {
fetch(Rc::new(request), &mut Some(target), HttpState::new());
fetch(Rc::new(request), &mut Some(target), new_fetch_context());
});
}
@ -77,7 +83,7 @@ fn test_fetch_response_is_not_network_error() {
*request.referer.borrow_mut() = Referer::NoReferer;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
if fetch_response.is_network_error() {
@ -98,7 +104,7 @@ fn test_fetch_response_body_matches_const_message() {
*request.referer.borrow_mut() = Referer::NoReferer;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
assert!(!fetch_response.is_network_error());
@ -120,7 +126,7 @@ fn test_fetch_aboutblank() {
*request.referer.borrow_mut() = Referer::NoReferer;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
assert!(!fetch_response.is_network_error());
assert!(*fetch_response.body.lock().unwrap() == ResponseBody::Done(vec![]));
}
@ -132,7 +138,7 @@ fn test_fetch_data() {
let request = Request::new(url, Some(origin), false);
request.same_origin_data.set(true);
let expected_resp_body = "<p>Servo</p>".to_owned();
let fetch_response = fetch(Rc::new(request), &mut None, HttpState::new());
let fetch_response = fetch(Rc::new(request), &mut None, new_fetch_context());
assert!(!fetch_response.is_network_error());
assert_eq!(fetch_response.headers.len(), 1);
@ -161,7 +167,7 @@ fn test_fetch_file() {
let request = Request::new(url, Some(origin), false);
request.same_origin_data.set(true);
let fetch_response = fetch(Rc::new(request), &mut None, HttpState::new());
let fetch_response = fetch(Rc::new(request), &mut None, new_fetch_context());
assert!(!fetch_response.is_network_error());
assert_eq!(fetch_response.headers.len(), 1);
let content_type: &ContentType = fetch_response.headers.get().unwrap();
@ -205,7 +211,7 @@ fn test_cors_preflight_fetch() {
request.mode = RequestMode::CORSMode;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
assert!(!fetch_response.is_network_error());
@ -245,8 +251,8 @@ fn test_cors_preflight_cache_fetch() {
let wrapped_request0 = Rc::new(request.clone());
let wrapped_request1 = Rc::new(request);
let fetch_response0 = fetch_with_cors_cache(wrapped_request0.clone(), &mut cache, &mut None, HttpState::new());
let fetch_response1 = fetch_with_cors_cache(wrapped_request1.clone(), &mut cache, &mut None, HttpState::new());
let fetch_response0 = fetch_with_cors_cache(wrapped_request0.clone(), &mut cache, &mut None, new_fetch_context());
let fetch_response1 = fetch_with_cors_cache(wrapped_request1.clone(), &mut cache, &mut None, new_fetch_context());
let _ = server.close();
assert!(!fetch_response0.is_network_error() && !fetch_response1.is_network_error());
@ -294,7 +300,7 @@ fn test_cors_preflight_fetch_network_error() {
request.mode = RequestMode::CORSMode;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
assert!(fetch_response.is_network_error());
@ -317,7 +323,7 @@ fn test_fetch_response_is_basic_filtered() {
*request.referer.borrow_mut() = Referer::NoReferer;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
assert!(!fetch_response.is_network_error());
@ -365,7 +371,7 @@ fn test_fetch_response_is_cors_filtered() {
request.mode = RequestMode::CORSMode;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
assert!(!fetch_response.is_network_error());
@ -398,7 +404,7 @@ fn test_fetch_response_is_opaque_filtered() {
*request.referer.borrow_mut() = Referer::NoReferer;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
assert!(!fetch_response.is_network_error());
@ -448,7 +454,7 @@ fn test_fetch_response_is_opaque_redirect_filtered() {
request.redirect_mode.set(RedirectMode::Manual);
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
assert!(!fetch_response.is_network_error());
@ -486,7 +492,7 @@ fn test_fetch_with_local_urls_only() {
request.local_urls_only = true;
let wrapped_request = Rc::new(request);
fetch(wrapped_request, &mut None, HttpState::new())
fetch(wrapped_request, &mut None, new_fetch_context())
};
let local_url = Url::parse("about:blank").unwrap();
@ -525,7 +531,7 @@ fn setup_server_and_fetch(message: &'static [u8], redirect_cap: u32) -> Response
*request.referer.borrow_mut() = Referer::NoReferer;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
fetch_response
}
@ -611,7 +617,7 @@ fn test_fetch_redirect_updates_method_runner(tx: Sender<bool>, status_code: Stat
*request.method.borrow_mut() = method;
let wrapped_request = Rc::new(request);
let _ = fetch(wrapped_request, &mut None, HttpState::new());
let _ = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
}

View file

@ -1,5 +0,0 @@
[send-authentication-basic-setrequestheader-existing-session.htm]
type: testharness
[XMLHttpRequest: send() - "Basic" authenticated request using setRequestHeader() when there is an existing session]
expected: FAIL

View file

@ -1,5 +0,0 @@
[send-authentication-basic.htm]
type: testharness
[XMLHttpRequest: send() - "Basic" authenticated requests with user name and password passed to open()]
expected: FAIL

View file

@ -0,0 +1,8 @@
[send-conditional.htm]
type: testharness
[XMLHttpRequest: send() - conditional requests (tag)]
expected: FAIL
[XMLHttpRequest: send() - conditional requests (date)]
expected: FAIL

View file

@ -15,9 +15,12 @@
[charset given but wrong, fix it (known MIME, bogus charset)]
expected: FAIL
[charset given but wrong, fix it (known MIME, actual charset)]
expected: FAIL
[If multiple charset parameters are given, all should be rewritten]
expected: FAIL
[Correct text/plain MIME with charset]
expected: FAIL
[charset given but wrong, fix it (known MIME, actual charset)]
expected: FAIL

View file

@ -1,5 +0,0 @@
[send-entity-body-get-head.htm]
type: testharness
[XMLHttpRequest: send() - non-empty data argument and GET/HEAD (HEAD)]
expected: FAIL

View file

@ -0,0 +1,14 @@
[send-redirect-to-cors.htm]
type: testharness
[XMLHttpRequest: send() - Redirect to CORS-enabled resource (301)]
expected: FAIL
[XMLHttpRequest: send() - Redirect to CORS-enabled resource (302)]
expected: FAIL
[XMLHttpRequest: send() - Redirect to CORS-enabled resource (303)]
expected: FAIL
[XMLHttpRequest: send() - Redirect to CORS-enabled resource (307)]
expected: FAIL

View file

@ -1,14 +0,0 @@
[send-redirect-to-non-cors.htm]
type: testharness
[XMLHttpRequest: send() - Redirect to cross-origin resource, not CORS-enabled (301)]
expected: FAIL
[XMLHttpRequest: send() - Redirect to cross-origin resource, not CORS-enabled (302)]
expected: FAIL
[XMLHttpRequest: send() - Redirect to cross-origin resource, not CORS-enabled (303)]
expected: FAIL
[XMLHttpRequest: send() - Redirect to cross-origin resource, not CORS-enabled (307)]
expected: FAIL

View file

@ -33,6 +33,3 @@
[Allow origin: [tab\]http://web-platform.test:8000]
expected: FAIL
[Disallow origin: http://web-platform.test:8000/]
expected: FAIL

View file

@ -33,12 +33,3 @@
[Allow origin: [tab\]http://web-platform.test:8000]
expected: FAIL
[Disallow origin: http://web-platform.test:8000/]
expected: FAIL
[Disallow multiple headers (, *)]
expected: FAIL
[Disallow multiple headers (*, )]
expected: FAIL

View file

@ -1,17 +1,8 @@
[preflight-cache.htm]
type: testharness
[Test preflight]
expected: FAIL
[preflight for x-print should be cached]
expected: FAIL
[age = 0, should not be cached]
expected: FAIL
[age = -1, should not be cached]
expected: FAIL
[preflight first request, second from cache, wait, third should preflight again]
expected: FAIL

View file

@ -62,24 +62,12 @@
[local (*) to remote (http://web-platform.test:8000), expect origin=http://web-platform.test:8000]
expected: FAIL
[local (*) to remote (null), expect to fail]
expected: FAIL
[local (*) to remote (none), expect to fail]
expected: FAIL
[local (http://web-platform.test:8000) to remote (*), expect origin=http://web-platform.test:8000]
expected: FAIL
[local (http://web-platform.test:8000) to remote (http://web-platform.test:8000), expect origin=http://web-platform.test:8000]
expected: FAIL
[local (http://web-platform.test:8000) to remote (null), expect to fail]
expected: FAIL
[local (http://web-platform.test:8000) to remote (none), expect to fail]
expected: FAIL
[local (null) to remote (*), expect origin=http://web-platform.test:8000]
expected: FAIL
@ -110,27 +98,3 @@
[remote (http://web-platform.test:8000) to remote2 (null), expect origin=null]
expected: FAIL
[remote (http://www1.web-platform.test:8000) to remote (*), expect to fail]
expected: FAIL
[remote (null) to remote2 (*), expect to fail]
expected: FAIL
[remote (none) to remote2 (*), expect to fail]
expected: FAIL
[remote (none) to remote2 (*), expect to fail]
expected: FAIL
[remote (null) to remote (*), expect to fail]
expected: FAIL
[remote (none) to remote (*), expect to fail]
expected: FAIL
[remote (none) to local (*), expect to fail]
expected: FAIL
[remote (null) to local (*), expect to fail]
expected: FAIL

View file

@ -1,8 +0,0 @@
[redirect-preflight-2.htm]
type: testharness
[Same-origin custom-header request, redirect to cross-origin succeeds after doing a preflight]
expected: FAIL
[Same-origin custom-header request, redirect to cross-origin fails after doing a non-successful preflight]
expected: FAIL

View file

@ -9,6 +9,3 @@
[getResponse: don't expose x-nonexposed]
expected: FAIL
[getAllResponseHeaders: don't expose x-nonexposed]
expected: FAIL