Bug 887836 - patch 2 - URLQuery in workers, r=khuey

This commit is contained in:
Andrea Marchesini 2013-12-12 19:30:20 +00:00
parent f3f5a6c47c
commit 1e4cd05d99
4 changed files with 180 additions and 0 deletions

View File

@ -26,6 +26,7 @@
#include "mozilla/dom/XMLHttpRequestBinding.h"
#include "mozilla/dom/XMLHttpRequestUploadBinding.h"
#include "mozilla/dom/URLBinding.h"
#include "mozilla/dom/URLSearchParamsBinding.h"
#include "mozilla/dom/WorkerBinding.h"
#include "mozilla/dom/WorkerLocationBinding.h"
#include "mozilla/dom/WorkerNavigatorBinding.h"
@ -70,6 +71,7 @@ WorkerPrivate::RegisterBindings(JSContext* aCx, JS::Handle<JSObject*> aGlobal)
!XMLHttpRequestBinding_workers::GetConstructorObject(aCx, aGlobal) ||
!XMLHttpRequestUploadBinding_workers::GetConstructorObject(aCx, aGlobal) ||
!URLBinding_workers::GetConstructorObject(aCx, aGlobal) ||
!URLSearchParamsBinding::GetConstructorObject(aCx, global) ||
!WorkerBinding::GetConstructorObject(aCx, aGlobal) ||
!WorkerLocationBinding_workers::GetConstructorObject(aCx, aGlobal) ||
!WorkerNavigatorBinding_workers::GetConstructorObject(aCx, aGlobal)) {

View File

@ -57,6 +57,7 @@ support-files =
xhr_worker.js
url_exceptions_worker.js
jsversion_worker.js
urlSearchParams_worker.js
[test_404.html]
[test_atob.html]
@ -114,4 +115,5 @@ support-files =
[test_xhr_system.html]
[test_xhr_system.js]
[test_url_exceptions.html]
[test_urlSearchParams.html]
[test_jsversion.html]

View File

@ -0,0 +1,43 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Test for URLSearchParams object in workers</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<script class="testbody" type="text/javascript">
var worker = new Worker("urlSearchParams_worker.js");
worker.onmessage = function(event) {
is(event.target, worker);
if (event.data.type == 'finish') {
SimpleTest.finish();
} else if (event.data.type == 'status') {
ok(event.data.status, event.data.msg);
}
};
worker.onerror = function(event) {
is(event.target, worker);
ok(false, "Worker had an error: " + event.data);
SimpleTest.finish();
};
worker.postMessage(true);
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,133 @@
function ok(a, msg) {
dump("OK: " + !!a + " => " + a + " " + msg + "\n");
postMessage({type: 'status', status: !!a, msg: a + ": " + msg });
}
function is(a, b, msg) {
dump("IS: " + (a===b) + " => " + a + " | " + b + " " + msg + "\n");
postMessage({type: 'status', status: a === b, msg: a + " === " + b + ": " + msg });
}
onmessage = function() {
status = false;
try {
if ((URLSearchParams instanceof Object)) {
status = true;
}
} catch(e) {
}
ok(status, "URLSearchParams in workers \\o/");
function testSimpleURLSearchParams() {
var u = new URLSearchParams();
ok(u, "URLSearchParams created");
is(u.has('foo'), false, 'URLSearchParams.has(foo)');
is(u.get('foo'), '', 'URLSearchParams.get(foo)');
is(u.getAll('foo').length, 0, 'URLSearchParams.getAll(foo)');
is(u.size, 0, 'URLSearchParams.size()');
u.append('foo', 'bar');
is(u.has('foo'), true, 'URLSearchParams.has(foo)');
is(u.get('foo'), 'bar', 'URLSearchParams.get(foo)');
is(u.getAll('foo').length, 1, 'URLSearchParams.getAll(foo)');
is(u.size, 1, 'URLSearchParams.size()');
u.set('foo', 'bar2');
is(u.get('foo'), 'bar2', 'URLSearchParams.get(foo)');
is(u.getAll('foo').length, 1, 'URLSearchParams.getAll(foo)');
is(u.size, 1, 'URLSearchParams.size()');
u.delete('foo');
is(u.size, 0, 'URLSearchParams.size()');
runTest();
}
function testCopyURLSearchParams() {
var u = new URLSearchParams();
ok(u, "URLSearchParams created");
u.append('foo', 'bar');
is(u.size, 1, "u.size()");
var uu = new URLSearchParams(u);
is(uu.size, 1, "uu.size()");
is(uu.get('foo'), 'bar', 'uu.get()');
u.append('foo', 'bar2');
is(u.getAll('foo').length, 2, "u.getAll()");
is(uu.getAll('foo').length, 1, "uu.getAll()");
runTest();
}
function testParserURLSearchParams() {
var checks = [
{ input: '', data: {} },
{ input: 'a', data: { 'a' : [''] } },
{ input: 'a=b', data: { 'a' : ['b'] } },
{ input: 'a=', data: { 'a' : [''] } },
{ input: '=b', data: { '' : ['b'] } },
{ input: '&', data: {} },
{ input: '&a', data: { 'a' : [''] } },
{ input: 'a&', data: { 'a' : [''] } },
{ input: 'a&a', data: { 'a' : ['', ''] } },
{ input: 'a&b&c', data: { 'a' : [''], 'b' : [''], 'c' : [''] } },
{ input: 'a=b&c=d', data: { 'a' : ['b'], 'c' : ['d'] } },
{ input: 'a=b&c=d&', data: { 'a' : ['b'], 'c' : ['d'] } },
{ input: '&&&a=b&&&&c=d&', data: { 'a' : ['b'], 'c' : ['d'] } },
{ input: 'a=a&a=b&a=c', data: { 'a' : ['a', 'b', 'c'] } },
{ input: 'a==a', data: { 'a' : ['=a'] } },
{ input: 'a=a+b+c+d', data: { 'a' : ['a b c d'] } },
{ input: '%=a', data: { '%' : ['a'] } },
{ input: '%a=a', data: { '%a' : ['a'] } },
{ input: '%a_=a', data: { '%a_' : ['a'] } },
{ input: '%61=a', data: { 'a' : ['a'] } },
{ input: '%=a', data: { '%' : ['a'] } },
{ input: '%a=a', data: { '%a' : ['a'] } },
{ input: '%a_=a', data: { '%a_' : ['a'] } },
{ input: '%61=a', data: { 'a' : ['a'] } },
{ input: '%61+%4d%4D=', data: { 'a MM' : [''] } },
];
for (var i = 0; i < checks.length; ++i) {
var u = new URLSearchParams(checks[i].input);
var count = 0;
for (var key in checks[i].data) {
++count;
ok(u.has(key), "key " + key + " found");
var all = u.getAll(key);
is(all.length, checks[i].data[key].length, "same number of elements");
for (var k = 0; k < all.length; ++k) {
is(all[k], checks[i].data[key][k], "value matches");
}
}
is(u.size, count, "size matches");
}
runTest();
}
var tests = [
testSimpleURLSearchParams,
testCopyURLSearchParams,
testParserURLSearchParams
];
function runTest() {
if (!tests.length) {
postMessage({type: 'finish' });
return;
}
var test = tests.shift();
test();
}
runTest();
}