Skip to content

Commit

Permalink
Change XHRContext and resource timing information to use request URL …
Browse files Browse the repository at this point in the history
…instead of XHR's global URL r?@jdm
  • Loading branch information
sreeise committed May 24, 2019
1 parent 2181872 commit e169278
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
7 changes: 3 additions & 4 deletions components/script/dom/xmlhttprequest.rs
Expand Up @@ -98,6 +98,7 @@ struct XHRContext {
gen_id: GenerationId,
sync_status: DomRefCell<Option<ErrorResult>>,
resource_timing: ResourceFetchTiming,
url: ServoUrl,
}

#[derive(Clone)]
Expand Down Expand Up @@ -284,10 +285,7 @@ impl XMLHttpRequest {

impl ResourceTimingListener for XHRContext {
fn resource_timing_information(&self) -> (InitiatorType, ServoUrl) {
(
InitiatorType::XMLHttpRequest,
self.resource_timing_global().get_url().clone(),
)
(InitiatorType::XMLHttpRequest, self.url.clone())
}

fn resource_timing_global(&self) -> DomRoot<GlobalScope> {
Expand Down Expand Up @@ -1466,6 +1464,7 @@ impl XMLHttpRequest {
gen_id: self.generation_id.get(),
sync_status: DomRefCell::new(None),
resource_timing: ResourceFetchTiming::new(ResourceTimingType::Resource),
url: init.url.clone(),
}));

let (task_source, script_port) = if self.sync.get() {
Expand Down
34 changes: 31 additions & 3 deletions tests/wpt/mozilla/meta/MANIFEST.json
@@ -1,5 +1,11 @@
{
"items": {
"conformancechecker": {
"mozilla/xmlhttprequest_url.html": []
},
"manual": {
"mozilla/xmlhttprequest_url.html": []
},
"reftest": {
"css/abs-overflow-stackingcontext.html": [
[
Expand Down Expand Up @@ -7624,7 +7630,8 @@
],
{}
]
]
],
"mozilla/xmlhttprequest_url.html": []
},
"reftest_node": {
"css/border_black_groove.html": [
Expand All @@ -7638,7 +7645,11 @@
],
{}
]
]
],
"mozilla/xmlhttprequest_url.html": []
},
"stub": {
"mozilla/xmlhttprequest_url.html": []
},
"support": {
".gitignore": [
Expand Down Expand Up @@ -11210,7 +11221,8 @@
[
{}
]
]
],
"mozilla/xmlhttprequest_url.html": []
},
"testharness": {
"bluetooth/advertisingEvent/watchAdvertisements-succeeds.html": [
Expand Down Expand Up @@ -13909,7 +13921,19 @@
"mozilla/worklets/test_worklet.html",
{}
]
],
"mozilla/xmlhttprequest_url.html": [
[
"mozilla/xmlhttprequest_url.html",
{}
]
]
},
"visual": {
"mozilla/xmlhttprequest_url.html": []
},
"wdspec": {
"mozilla/xmlhttprequest_url.html": []
}
},
"paths": {
Expand Down Expand Up @@ -21084,6 +21108,10 @@
"mozilla/worklets/throw_exception.js": [
"6ca4f80fc2728c00848bb4474b62fa3596ed2f18",
"support"
],
"mozilla/xmlhttprequest_url.html": [
"e5d10f27c06e1febd3bb70f8f128194fc3f63861",
"testharness"
]
},
"url_base": "/_mozilla/",
Expand Down
26 changes: 26 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/xmlhttprequest_url.html
@@ -0,0 +1,26 @@
<!doctype html>
<meta charset="utf-8">
<title>XMLHttpRequest Origin</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
function resolve(path) {
let a = document.createElement("a");
a.href = path;
return a.href;
}

async_test(function(t) {
let href = window.location.href;
let request = new XMLHttpRequest();
let url = resolve("./test.txt");
request.open('GET', url, true);
request.send();

request.onload = t.step_func_done(function() {
let entries = window.performance.getEntriesByType("resource");
assert_equals(entries.length, 1);
assert_equals(entries[0].name, href);
});
}, "Performance entries should contain the URL where the XMLHttpRequest originated");
</script>

0 comments on commit e169278

Please sign in to comment.