Skip to content

Commit

Permalink
Merge pull request #5 from w3c/master
Browse files Browse the repository at this point in the history
Catch up to W3C master
  • Loading branch information
engelke authored Jun 15, 2016
2 parents 9645ea5 + 63bcabe commit f9542e0
Show file tree
Hide file tree
Showing 83 changed files with 5,575 additions and 118 deletions.
17 changes: 10 additions & 7 deletions WebCryptoAPI/encrypt_decrypt/aes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

function run_test() {
var subtle = crypto.subtle; // Change to test prefixed implementations
var subtle = self.crypto.subtle; // Change to test prefixed implementations

// When are all these tests really done? When all the promises they use have resolved.
var all_promises = [];
Expand Down Expand Up @@ -123,7 +123,7 @@ function run_test() {
.then(function(result) {
assert_unreached("should have thrown exception for test " + vector.name);
}, function(err) {
assert_equals(err.name, "InvalidAccessError", "Should throw an InvalidAccessError")
assert_equals(err.name, "InvalidAccessError", "Should throw an InvalidAccessError instead of " + err.message)
});
}, vector.name + " without encrypt usage");
}, function(err) {
Expand All @@ -142,8 +142,11 @@ function run_test() {
var algorithm = Object.assign({}, vector.algorithm);
if (algorithm.name === "AES-CBC") {
algorithm.name = "AES-CTR";
algorithm.counter = new Uint8Array(16);
algorithm.length = 64;
} else {
algorithm.name = "AES-CBC";
algorithm.iv = new Uint8Array(16); // Need syntactically valid parameter to get to error being checked.
}

var promise = importVectorKey(vector, ["encrypt", "decrypt"])
Expand All @@ -153,7 +156,7 @@ function run_test() {
.then(function(result) {
assert_unreached("encrypt succeeded despite mismatch " + vector.name + ": " + err.message);
}, function(err) {
assert_equals(err.name, "InvalidAccessError", "Mismatch should cause InvalidAccessError");
assert_equals(err.name, "InvalidAccessError", "Mismatch should cause InvalidAccessError instead of " + err.message);
});
}, vector.name + " with mismatched key and algorithm");
}, function(err) {
Expand All @@ -180,7 +183,7 @@ function run_test() {
.then(function(result) {
assert_unreached("should have thrown exception for test " + vector.name);
}, function(err) {
assert_equals(err.name, "InvalidAccessError", "Should throw an InvalidAccessError")
assert_equals(err.name, "InvalidAccessError", "Should throw an InvalidAccessError instead of " + err.message)
});
}, vector.name + " without decrypt usage");
}, function(err) {
Expand All @@ -203,7 +206,7 @@ function run_test() {
.then(function(result) {
assert_unreached("should have thrown exception for test " + vector.name);
}, function(err) {
assert_equals(err.name, "OperationError", "Should throw an OperationError")
assert_equals(err.name, "OperationError", "Should throw an OperationError instead of " + err.message)
});
}, vector.name);
}, function(err) {
Expand All @@ -226,7 +229,7 @@ function run_test() {
.then(function(result) {
assert_unreached("should have thrown exception for test " + vector.name);
}, function(err) {
assert_equals(err.name, "OperationError", "Should throw an OperationError")
assert_equals(err.name, "OperationError", "Should throw an OperationError instead of " + err.message)
});
}, vector.name + " decryption");
}, function(err) {
Expand All @@ -250,7 +253,7 @@ function run_test() {
.then(function(result) {
assert_unreached("should have thrown exception for test " + vector.name);
}, function(err) {
assert_equals(err.name, "OperationError", "Should throw an OperationError")
assert_equals(err.name, "OperationError", "Should throw an OperationError instead of " + err.message)
});
}, vector.name);
}, function(err) {
Expand Down
6 changes: 4 additions & 2 deletions WebCryptoAPI/encrypt_decrypt/aes_cbc_vectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ function getTestVectors() {
keyBuffer: keyBytes[keyLength],
key: null,
algorithm: {name: "AES-CBC", iv: shortIv},
plaintext: plaintext
plaintext: plaintext,
result: ciphertext[keyLength]
});

var longIv = new Uint8Array(24);
Expand All @@ -232,7 +233,8 @@ function getTestVectors() {
keyBuffer: keyBytes[keyLength],
key: null,
algorithm: {name: "AES-CBC", iv: longIv},
plaintext: plaintext
plaintext: plaintext,
result: ciphertext[keyLength]
});
});

Expand Down
6 changes: 4 additions & 2 deletions WebCryptoAPI/encrypt_decrypt/aes_ctr_vectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,17 @@ function getTestVectors() {
keyBuffer: keyBytes[keyLength],
key: null,
algorithm: {name: "AES-CTR", counter: counter, length: 0},
plaintext: plaintext
plaintext: plaintext,
result: ciphertext[keyLength]
});

failing.push({
name: "AES-CTR " + keyLength.toString() + "-bit key, 129-bit counter",
keyBuffer: keyBytes[keyLength],
key: null,
algorithm: {name: "AES-CTR", counter: counter, length: 129},
plaintext: plaintext
plaintext: plaintext,
result: ciphertext[keyLength]
});
});

Expand Down
3 changes: 2 additions & 1 deletion WebCryptoAPI/encrypt_decrypt/aes_gcm_vectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ function getTestVectors() {
keyBuffer: keyBytes[keyLength],
key: null,
algorithm: {name: "AES-GCM", iv: iv, additionalData: additionalData, tagLength: badTagLength},
plaintext: plaintext
plaintext: plaintext,
result: ciphertext[keyLength]
});
});
});
Expand Down
12 changes: 6 additions & 6 deletions WebCryptoAPI/encrypt_decrypt/rsa.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

function run_test() {
var subtle = crypto.subtle; // Change to test prefixed implementations
var subtle = self.crypto.subtle; // Change to test prefixed implementations

// When are all these tests really done? When all the promises they use have resolved.
var all_promises = [];
Expand Down Expand Up @@ -81,7 +81,7 @@ function run_test() {
.then(function(plaintext) {
assert_unreached("Should have thrown error for using publicKey to decrypt in " + vector.name + ": " + err.message + "'");
}, function(err) {
assert_equals(err.name, "InvalidAccessError", "Should throw InvalidAccessError");
assert_equals(err.name, "InvalidAccessError", "Should throw InvalidAccessError instead of " + err.message);
});
}, vector.name + " using publicKey to decrypt");

Expand Down Expand Up @@ -109,7 +109,7 @@ function run_test() {
.then(function(plaintext) {
assert_unreached("Should have thrown error for no decrypt usage in " + vector.name + ": " + err.message + "'");
}, function(err) {
assert_equals(err.name, "InvalidAccessError", "Should throw InvalidAccessError");
assert_equals(err.name, "InvalidAccessError", "Should throw InvalidAccessError instead of " + err.message);
});
}, vector.name + " no decrypt usage");

Expand Down Expand Up @@ -225,7 +225,7 @@ function run_test() {
.then(function(ciphertext) {
assert_unreached("Should have thrown error for too long plaintext in " + vector.name + ": " + err.message + "'");
}, function(err) {
assert_equals(err.name, "OperationError", "Should throw OperationError");
assert_equals(err.name, "OperationError", "Should throw OperationError instead of " + err.message);
});
}, vector.name + " too long plaintext");

Expand All @@ -250,7 +250,7 @@ function run_test() {
.then(function(ciphertext) {
assert_unreached("Should have thrown error for using privateKey to encrypt in " + vector.name + ": " + err.message + "'");
}, function(err) {
assert_equals(err.name, "InvalidAccessError", "Should throw InvalidAccessError");
assert_equals(err.name, "InvalidAccessError", "Should throw InvalidAccessError instead of " + err.message);
});
}, vector.name + " using privateKey to encrypt");

Expand Down Expand Up @@ -278,7 +278,7 @@ function run_test() {
.then(function(ciphertext) {
assert_unreached("Should have thrown error for no encrypt usage in " + vector.name + ": " + err.message + "'");
}, function(err) {
assert_equals(err.name, "InvalidAccessError", "Should throw InvalidAccessError");
assert_equals(err.name, "InvalidAccessError", "Should throw InvalidAccessError instead of " + err.message);
});
}, vector.name + " no encrypt usage");

Expand Down
49 changes: 29 additions & 20 deletions XMLHttpRequest/send-usp.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const NUM_TESTS = 128;

function encode(n) {
if (n === 0x20) {
return "\x2B";
Expand All @@ -13,27 +15,34 @@ function encode(n) {
return "%" + (s.length === 2 ? s : '0' + s);
}

function do_test(n) {
async_test(function() {
var x = new XMLHttpRequest();
x.onload = this.step_func_done(function(e) {
assert_equals(x.response, "a=" + encode(n))
});
x.onerror = this.unreached_func();
x.open("POST", "resources/content.py");
var usp = new URLSearchParams();
usp.append("a", String.fromCharCode(n));
x.send(usp)
}, "XMLHttpRequest.send(URLSearchParams) (" + n + ")");
}

function run_test() {
var i = 0;
add_result_callback(function() {
if (++i === 128) {
return;
var tests = [];
var overall_test = async_test("Overall fetch with URLSearchParams");
for (var i = 0; i < NUM_TESTS; i++) {
// Multiple subtests so that failures can be fine-grained
tests[i] = async_test("XMLHttpRequest.send(URLSearchParams) (" + i + ")");
}

// We use a single XHR since this test tends to time out
// with 128 consecutive fetches when run in parallel
// with many other WPT tests.
var x = new XMLHttpRequest();
x.onload = overall_test.step_func(function() {
var response_split = x.response.split("&");
overall_test.done();
for (var i = 0; i < NUM_TESTS; i++) {
tests[i].step(function() {
assert_equals(response_split[i], "a" + i + "="+encode(i));
tests[i].done();
});
}
do_test(i);
});
do_test(i);
x.onerror = overall_test.unreached_func();

x.open("POST", "resources/content.py");
var usp = new URLSearchParams();
for (var i = 0; i < NUM_TESTS; i++) {
usp.append("a" + i, String.fromCharCode(i));
}
x.send(usp)
}
81 changes: 81 additions & 0 deletions battery-status/battery-promise-iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Battery Test: iframe has a different Navigator object</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
iframe {
display: none;
}
</style>
<div id="log"></div>
<iframe id="blank" src="about:blank"></iframe>
<iframe id="frame" src="support-iframe-initial.html"></iframe>
<script>
promise_test(function(t) {
var iframe = document.querySelector('#blank');
var originalPromise = navigator.getBattery();

return originalPromise.then(function(originalManager) {
var promise = iframe.contentWindow.navigator.getBattery();

assert_true(originalManager instanceof BatteryManager);
assert_not_equals(iframe.contentWindow.navigator,
navigator,
'navigator objects shall be different');
assert_not_equals(promise,
originalPromise,
'battery promises in different navigators shall be different');
assert_equals(iframe.contentWindow.navigator.getBattery(),
promise,
'battery promises in same navigator shall be same');

return promise;
}).then(function(manager) {
assert_equals(manager.__proto__,
iframe.contentWindow.BatteryManager.prototype);
assert_true(manager instanceof iframe.contentWindow.BatteryManager);
});

}, 'iframe has a different Navigator object thus getting another battery promise');

async_test(function (t) {
var iframe = document.querySelector('#blank');
var originalNavigator = iframe.contentWindow.navigator;
var originalPromise = iframe.contentWindow.navigator.getBattery();

iframe.onload = t.step_func(function() {
assert_equals(iframe.contentWindow.navigator,
originalNavigator,
'navigator objects shall be same');
assert_equals(iframe.contentWindow.navigator.getBattery(),
originalPromise,
'battery status promises shall be same');
t.done();
});

iframe.src = 'support-iframe.html';
}, 'setting src of an iframe with initial about:blank makes same Navigator object and battery promise');

async_test(function (t) {
window.onmessage = t.step_func(function(e) {
var iframe = document.querySelector('#frame');
var originalNavigator = iframe.contentWindow.navigator;
var originalPromise = iframe.contentWindow.navigator.getBattery();

assert_equals(e.data, 'loaded');

iframe.onload = t.step_func(function() {
assert_not_equals(iframe.contentWindow.navigator,
originalNavigator,
'navigator objects shall be changed');
assert_not_equals(iframe.contentWindow.navigator.getBattery(),
originalPromise,
'battery status promises shall be different');
t.done();
});

iframe.src = 'support-iframe.html';
});
}, 'setting src of an iframe with initial frame makes its Navigator object vary thus getting another battery promise');
</script>
28 changes: 28 additions & 0 deletions battery-status/battery-promise-window.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Battery Test: window.open() makes a different Navigator object</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
#note {
background-color: #fef1b5;
border: solid 1px #cdab2d;
padding: 5px;
margin: 15px;
display: block;
}
</style>
<div id="note">
Allow pop-up windows before running the tests.
</div>
<div id="log"></div>
<script>
async_test(function (t) {
var win = window.open('support-window-open.html');
window.onmessage = t.step_func(function(e) {
assert_array_equals(e.data, [false, false, true]);
win.close();
t.done();
});
}, 'window.open() makes a different Navigator object thus getting another battery promise');
</script>
Loading

0 comments on commit f9542e0

Please sign in to comment.