Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
svgeesus committed Jan 30, 2018
2 parents 4e5bfe4 + 7174d3e commit 63c87e5
Show file tree
Hide file tree
Showing 595 changed files with 12,371 additions and 3,342 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,29 @@ function makeVideo() {
});
}

function makeImage() {
return new Promise(resolve => {
var img = new Image();
img.onload = function() {
resolve(img);
};
img.src = "/images/pattern.png";
});
function makeMakeHTMLImage(src) {
return function() {
return new Promise(resolve => {
var img = new Image();
img.onload = function() {
resolve(img);
};
img.src = src;
});
}
}

function makeMakeSVGImage(src) {
return function() {
return new Promise((resolve, reject) => {
var image = document.createElementNS(NAMESPACES.svg, "image");
image.onload = () => resolve(image);
image.onerror = reject;
image.setAttribute("externalResourcesRequired", "true");
image.setAttributeNS(NAMESPACES.xlink, 'xlink:href', src);
document.body.appendChild(image);
});
}
}

function makeImageData() {
Expand Down Expand Up @@ -100,7 +115,10 @@ function makeBlob() {
var imageSourceTypes = [
{ name: 'an HTMLCanvasElement', factory: makeCanvas },
{ name: 'an HTMLVideoElement', factory: makeVideo },
{ name: 'an HTMLImageElement', factory: makeImage },
{ name: 'a bitmap HTMLImageElement', factory: makeMakeHTMLImage("/images/pattern.png") },
{ name: 'a vector HTMLImageElement', factory: makeMakeHTMLImage("/images/pattern.svg") },
{ name: 'a bitmap SVGImageElement', factory: makeMakeSVGImage("/images/pattern.png") },
{ name: 'a vector SVGImageElement', factory: makeMakeSVGImage("/images/pattern.svg") },
{ name: 'an OffscreenCanvas', factory: makeOffscreenCanvas },
{ name: 'an ImageData', factory: makeImageData },
{ name: 'an ImageBitmap', factory: makeImageBitmap },
Expand Down
3 changes: 2 additions & 1 deletion 2dcontext/imagebitmap/createImageBitmap-drawImage.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<script src="/resources/testharnessreport.js"></script>
<script src="/common/canvas-tests.js"></script>
<script src="/common/media.js"></script>
<script src="common.js"></script>
<script src="/common/namespaces.js"></script>
<script src="common.sub.js"></script>
<link rel="stylesheet" href="/common/canvas-tests.css">
<body>
<script>
Expand Down
46 changes: 41 additions & 5 deletions 2dcontext/imagebitmap/createImageBitmap-invalid-args.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/media.js"></script>
<script src="common.js"></script>
<script src="/common/namespaces.js"></script>
<script src="common.sub.js"></script>
<script>

function makeOversizedCanvas() {
Expand All @@ -29,17 +30,18 @@
}

function makeBrokenImage() {
return new Promise(resolve => {
return new Promise((resolve, reject) => {
const image = new Image();
image.src = "data:,x";
image.onload = reject;
image.onerror = () => resolve(image);
});
}

function makeAvailableButBrokenImage() {
function makeAvailableButBrokenImage(path) {
return new Promise((resolve, reject) => {
const image = new Image();
image.src = "/images/broken.png";
image.src = path;
image.onload = () => resolve(image);
image.onerror = reject;
});
Expand Down Expand Up @@ -99,6 +101,26 @@
return promise_rejects(t, new TypeError(), createImageBitmap(null));
}, "createImageBitmap with null image source.");

promise_test( t => {
var context = document.createElement("canvas").getContext("2d");
return promise_rejects(t, new TypeError(), createImageBitmap(context));
}, "createImageBitmap with CanvasRenderingContext2D image source.");

promise_test( t => {
var context = document.createElement("canvas").getContext("webgl");
return promise_rejects(t, new TypeError(), createImageBitmap(context));
}, "createImageBitmap with WebGLRenderingContext image source.");

promise_test( t => {
var buffer = new Uint8Array();
return promise_rejects(t, new TypeError(), createImageBitmap(buffer));
}, "createImageBitmap with Uint8Array image source.");

promise_test( t => {
var buffer = new ArrayBuffer(8);
return promise_rejects(t, new TypeError(), createImageBitmap(buffer));
}, "createImageBitmap with ArrayBuffer image source.");

promise_test( t => {
return promise_rejects(t, "InvalidStateError",
createImageBitmap(new Image()));
Expand Down Expand Up @@ -138,12 +160,26 @@
}, "createImageBitmap with a broken image source.");

promise_test( t => {
return makeAvailableButBrokenImage().then(image => {
return makeAvailableButBrokenImage("/images/broken.png").then(image => {
return promise_rejects(t, "InvalidStateError",
createImageBitmap(image));
});
}, "createImageBitmap with an available but undecodable image source.");

promise_test( t => {
return makeAvailableButBrokenImage("/images/red-zeroheight.svg").then(image => {
return promise_rejects(t, "InvalidStateError",
createImageBitmap(image));
});
}, "createImageBitmap with an available but zero height image source.");

promise_test( t => {
return makeAvailableButBrokenImage("/images/red-zerowidth.svg").then(image => {
return promise_rejects(t, "InvalidStateError",
createImageBitmap(image));
});
}, "createImageBitmap with an available but zero width image source.");

promise_test( t => {
return makeImageBitmap().then(bitmap => {
bitmap.close()
Expand Down
86 changes: 86 additions & 0 deletions 2dcontext/imagebitmap/createImageBitmap-origin.sub.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>createImageBitmap: origin-clean flag</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/media.js"></script>
<script src="/common/namespaces.js"></script>
<div id=log></div>
<script>
const crossOriginImageUrl = "http://{{domains[www1]}}:{{ports[http][0]}}/images/red.png";

function assert_origin_unclean(bitmap) {
const context = document.createElement("canvas").getContext("2d");
context.drawImage(bitmap, 0, 0);
assert_throws("SecurityError", () => {
context.getImageData(0, 0, 1, 1);
});
}

function makeImage() {
return new Promise((resolve, reject) => {
const image = new Image();
image.onload = () => resolve(image);
image.onerror = reject;
image.src = crossOriginImageUrl;
});
}

const arguments = [
{
name: "cross-origin HTMLImageElement",
factory: makeImage,
},

{
name: "cross-origin SVGImageElement",
factory: () => {
return new Promise((resolve, reject) => {
const image = document.createElementNS(NAMESPACES.svg, "image");
image.onload = () => resolve(image);
image.onerror = reject;
image.setAttribute("externalResourcesRequired", "true");
image.setAttributeNS(NAMESPACES.xlink, 'xlink:href', crossOriginImageUrl);
document.body.appendChild(image);
});
},
},

{
name: "cross-origin HTMLVideoElement",
factory: () => {
return new Promise((resolve, reject) => {
const video = document.createElement("video");
video.oncanplaythrough = () => resolve(video);
video.onerror = reject;
video.src = getVideoURI("http://{{domains[www1]}}:{{ports[http][0]}}/media/movie_300");
});
},
},

{
name: "unclean HTMLCanvasElement",
factory: () => {
return makeImage().then(image => {
const canvas = document.createElement("canvas");
const context = canvas.getContext("2d");
context.drawImage(image, 0, 0);
return canvas;
});
},
},

{
name: "unclean ImageBitmap",
factory: () => {
return makeImage().then(createImageBitmap);
},
},
];

for (let { name, factory } of arguments) {
promise_test(function() {
return factory().then(createImageBitmap).then(assert_origin_unclean);
}, name);
}
</script>
27 changes: 27 additions & 0 deletions acid/acid3/numbered-tests.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!doctype html>
<title>Acid3 numbered tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
var tests = undefined;

function gotMessage(e) {
var m = e.data;
if (tests === undefined && "num_tests" in m) {
tests = [];
for (var i = 0; i < m.num_tests; i++) {
tests.push(async_test("Test " + i));
}
} else if ("result" in m) {
var test = m.test;
var passed = m.result === "pass";
var message = m.message;
tests[test].step(function() {
assert_true(passed, message);
});
tests[test].done();
}
}
window.addEventListener("message", gotMessage, false);
</script>
<iframe src="test.html"></iframe>
3 changes: 3 additions & 0 deletions acid/acid3/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -3419,6 +3419,7 @@
}

];
window.parent.postMessage({num_tests: tests.length}, "*");
var log = '';
var delay = 10;
var score = 0, index = 0, retry = 0, errors = 0;
Expand Down Expand Up @@ -3456,6 +3457,7 @@
} else {
fail("no error message");
}
window.parent.postMessage({test: index, result: "pass"}, "*");
} catch (e) {
var s;
if (e.message)
Expand All @@ -3464,6 +3466,7 @@
s = e;
errors += 1;
log += "Test " + zeroPaddedIndex + " failed: " + s + "\n";
window.parent.postMessage({test: index, result: "fail", message: s}, "*");
};
retry = 0;
index += 1;
Expand Down
27 changes: 18 additions & 9 deletions beacon/beacon-error.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,25 @@ test(function() {
}, "Verify calling 'navigator.sendBeacon()' with a URL that is not a http(s) scheme throws an exception.");

// We'll validate that we can send one beacon that uses our entire Quota and then fail to send one that is just one char.
test(function () {
var destinationURL = "/fetch/api/resources/trickle.py?count=1&ms=1000";

var firstSuccess = navigator.sendBeacon(destinationURL, maxPayload);
assert_true(firstSuccess, "calling 'navigator.sendBeacon()' with our max payload size should succeed.");
promise_test(async () => {
function wait(ms) {
return new Promise(res => step_timeout(res, ms));
}
const url = '/fetch/api/resources/trickle.py?count=1&ms=0';
assert_true(navigator.sendBeacon(url, maxPayload),
"calling 'navigator.sendBeacon()' with our max payload size should succeed.");

// Now we'll send just one character.
var secondSuccess = navigator.sendBeacon(destinationURL, "1");
assert_false(secondSuccess, "calling 'navigator.sendBeacon()' with just one char should fail while our Quota is used up.");

}, "Verify calling 'navigator.sendBeacon()' with a small payload fails while Quota is completely utilized.");
assert_false(navigator.sendBeacon(url, '1'),
"calling 'navigator.sendBeacon()' with just one char should fail while our Quota is used up.");

for (let i = 0; i < 20; ++i) {
await wait(100);
if (navigator.sendBeacon(url, maxPayload)) {
return;
}
}
assert_unreached('The quota should recover after fetching.');
}, "Verify the behavior after the quota is exhausted.");

done();
15 changes: 14 additions & 1 deletion bluetooth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ the API to be loaded as needed.
The Chromium implementation is provided by
`../resources/chromium/web-bluetooth-test.js`.

The Chromium implementation is not included in stable Chrome builds since it
would add too much to the binary size. On Chromium infrastructure, it is run
using the `content_shell` executable.

In the future, Chromium `src/device/bluetooth` may be refactored into a Mojo
service. At this point, it would be possible to add the necessary testing hooks
into stable Chrome without substantially increasing the binary size, similar to
WebUSB.

These bluetooth tests are upstreamed here because other browsers can reuse them
by implementing the [Web Bluetooth Testing API], even if only on their internal
infrastructure.

[Web Bluetooth Testing API]: https://docs.google.com/document/d/1Nhv_oVDCodd1pEH_jj9k8gF4rPGb_84VYaZ9IG8M_WY/

# Generated gen-* files from generator.py
Expand Down Expand Up @@ -45,4 +58,4 @@ Usage:
$ python generate.py
```

More details documented in `generate.py`.
More details documented in `generate.py`.
25 changes: 25 additions & 0 deletions bluetooth/requestDevice/blocklisted-service-in-filter.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/bluetooth/resources/bluetooth-helpers.js"></script>
<script>
'use strict';
const test_desc = 'Reject with SecurityError if requesting a blocklisted ' +
'service.';
const expected = new DOMException(
'requestDevice() called with a filter containing a blocklisted UUID. ' +
'https://goo.gl/4NeimX',
'SecurityError');

bluetooth_test(() => setUpPreconnectedDevice({
knownServiceUUIDs: ['human_interface_device']
})
.then(() => assert_promise_rejects_with_message(
requestDeviceWithTrustedClick({
filters: [{services: ['human_interface_device']}]
}),
expected, 'Requesting blocklisted service rejects.')),
test_desc);
</script>
Loading

0 comments on commit 63c87e5

Please sign in to comment.