Skip to content

Commit

Permalink
Extract Location object tests from query-encoding/
Browse files Browse the repository at this point in the history
Helps with #4934.
  • Loading branch information
annevk committed May 9, 2018
1 parent 9ca0d55 commit 42006d1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!doctype html>
<meta charset={{GET[encoding]}}> <!-- ends up as <meta charset> by default which is windows-1252 -->
<meta name=variant content="?encoding=x-cp1251">
<meta name=variant content="?encoding=utf8">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
<script>
function expected(encoding) {
return "?" + {
"UTF-8": "%C3%BF",
"windows-1251": "&%23255;",
"windows-1252": "%FF"
}[encoding];
}

[
[(win, input) => { win.location = input; }, "location [PutForwards]"],
[(win, input) => { win.location.assign(input); }, "location.assign()"],
[(win, input) => { win.location.replace(input); }, "location.replace()"],
[(win, input) => { win.location.href = input; }, "location.href"]
].forEach(([callback, desc]) => {
async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe")),
actualEncoding = document.characterSet
callback(frame.contentWindow, "/common/blank.html?\u00FF");
frame.onload = t.step_func_done(() => {
assert_equals(frame.contentWindow.location.search, expected(actualEncoding));
});
}, desc);
});

async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe")),
actualEncoding = document.characterSet;
frame.src = "/common/blank.html";
frame.onload = t.step_func(() => {
frame.contentWindow.location.search = "\u00FF";
frame.onload = t.step_func_done(() => {
assert_equals(frame.contentWindow.location.search, expected(actualEncoding));
});
});
}, "location.search");
</script>
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// NOTE: this file needs to be split up rather than expanded. See ../location.sub.html for some
// extracted tests. Tracked by https://github.com/w3c/web-platform-tests/issues/4934.

setup({explicit_done:true});
onload = function() {
var encoding = '{{GET[encoding]}}';
Expand Down Expand Up @@ -35,15 +38,15 @@ onload = function() {
// page and the test timing out
test_obj.force_timeout();
}
step_timeout(poll, 200);
test_obj.step_timeout(poll, 200);
} else {
assert_equals(xhr.response, expected);
test_obj.done();
}
});
xhr.send();
})
step_timeout(poll, 200);
test_obj.step_timeout(poll, 200);
}

// background attribute, check with getComputedStyle
Expand Down Expand Up @@ -505,55 +508,6 @@ onload = function() {
}, 'window.open()',
{help:'https://html.spec.whatwg.org/multipage/#dom-open'});

// location
function test_location(func, desc) {
async_test(function() {
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
this.add_cleanup(function() {
document.body.removeChild(iframe);
});
func(iframe.contentWindow, input_url_html);
iframe.onload = this.step_func(function() {
var got = iframe.contentDocument.body.textContent;
if (got != '') {
assert_equals(got, expected_current);
this.done();
}
});
}, desc,
{help:'https://html.spec.whatwg.org/multipage/#the-location-interface'});
}
[[function(win, input) { win.location = input; }, "location [PutForwards]"],
[function(win, input) { win.location.assign(input); }, "location.assign()"],
[function(win, input) { win.location.replace(input); }, "location.replace()"],
[function(win, input) { win.location.href = input; }, "location.href"]].forEach(function(arr) {
test_location(arr[0], arr[1]);
});

// location.search
async_test(function() {
var iframe = document.createElement('iframe');
iframe.src = input_url_html;
document.body.appendChild(iframe);
this.add_cleanup(function() {
document.body.removeChild(iframe);
});
var i = 0;
iframe.onload = this.step_func(function() {
i++;
if (i == 1) {
iframe.contentWindow.location.search = '?' + input_url_html.split('?')[1] + '&other=foobar';
} else {
var got = iframe.contentDocument.body.textContent;
assert_equals(got, expected_current);
this.done();
}
});
}, 'location.search',
{help:['https://html.spec.whatwg.org/multipage/#the-location-interface',
'http://url.spec.whatwg.org/#dom-url-search']});

// a.search, area.search
function test_hyperlink_search(tag) {
test(function() {
Expand Down

0 comments on commit 42006d1

Please sign in to comment.