Skip to content

Commit

Permalink
Fullscreen: give trusted_click and trusted_click the test for step_func
Browse files Browse the repository at this point in the history
The element.requestFullscreen() is wrapped in an arrow function, which
together with the other changes should make failures more obvious.
  • Loading branch information
foolip committed Jan 4, 2017
1 parent a3a0201 commit 5e1a3b8
Show file tree
Hide file tree
Showing 32 changed files with 55 additions and 56 deletions.
2 changes: 1 addition & 1 deletion fullscreen/api/document-exit-fullscreen-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script>
async_test(function(t)
{
trusted_request(document.querySelector("div"));
trusted_request(t, document.querySelector("div"));

document.addEventListener("fullscreenchange", t.step_func(function(event)
{
Expand Down
2 changes: 1 addition & 1 deletion fullscreen/api/document-exit-fullscreen-timing-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script>
async_test(t => {
const div = document.querySelector('div');
trusted_request(div);
trusted_request(t, div);

document.onfullscreenchange = t.step_func(() => {
// We are now in fullscreen. Exit again.
Expand Down
2 changes: 1 addition & 1 deletion fullscreen/api/document-exit-fullscreen-twice-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
});
document.onfullscreenerror = t.unreached_func("fullscreenerror event");

trusted_request(div);
trusted_request(t, div);
});
</script>
4 changes: 2 additions & 2 deletions fullscreen/api/document-fullscreen-element-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
});
});

trusted_click(t.step_func(function()
trusted_click(t, function()
{
assert_equals(document.fullscreenElement, null, "fullscreenElement before requestFullscreen()");
div.requestFullscreen();
assert_equals(document.fullscreenElement, null, "fullscreenElement after requestFullscreen()");
}), document.body);
}, document.body);
});
</script>
2 changes: 1 addition & 1 deletion fullscreen/api/document-onfullscreenchange-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
var div = document.querySelector("div");
assert_equals(document.onfullscreenchange, null, "initial onfullscreenchange");
document.onfullscreenchange = t.step_func_done();
trusted_request(div);
trusted_request(t, div);
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
async_test(function(t)
{
var iframes = document.getElementsByTagName("iframe");
trusted_request(iframes[0].contentDocument.body, document.body);
trusted_request(t, iframes[0].contentDocument.body, document.body);
iframes[0].contentDocument.onfullscreenchange = t.step_func(function()
{
trusted_request(iframes[1].contentDocument.body, iframes[0].contentDocument.body);
trusted_request(t, iframes[1].contentDocument.body, iframes[0].contentDocument.body);
iframes[1].contentDocument.onfullscreenchange = t.unreached_func("fullscreenchange event");
iframes[1].contentDocument.onfullscreenerror = t.step_func_done();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
iframe.contentDocument.onfullscreenchange = t.unreached_func("iframe fullscreenchange event");
iframe.contentDocument.onfullscreenerror = t.step_func_done();
assert_false(iframe.contentDocument.fullscreenEnabled, "fullscreen enabled flag");
trusted_request(iframe.contentDocument.body, document.body);
trusted_request(t, iframe.contentDocument.body, document.body);
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
document.onfullscreenchange = t.step_func(function()
{
assert_equals(document.fullscreenElement, a, "fullscreen element");
trusted_request(b, a);
trusted_request(t, b, a);
document.onfullscreenchange = t.unreached_func("second fullscreenchange event");
document.onfullscreenerror = t.step_func_done();
});
trusted_request(a);
trusted_request(t, a);
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
});
document.onfullscreenerror = t.unreached_func("fullscreenerror event");

trusted_request(div, iframe.contentDocument.body);
trusted_request(t, div, iframe.contentDocument.body);
});

trusted_request(iframe);
trusted_request(t, iframe);
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
});
document.onfullscreenerror = t.unreached_func("fullscreenerror event");

trusted_request(div, document.body);
trusted_request(t, div, document.body);
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
var div = document.createElement("div");
document.onfullscreenchange = t.unreached_func("fullscreenchange event");
document.onfullscreenerror = t.step_func_done();
trusted_request(div, document.body);
trusted_request(t, div, document.body);
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
document.onfullscreenerror = t.unreached_func('fullscreenerror event');
iframeDoc.onfullscreenerror = t.unreached_func('iframe fullscreenerror event');

trusted_request(iframeBody, document.body);
trusted_request(t, iframeBody, document.body);
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
});
document.onfullscreenerror = t.unreached_func("fullscreenchange event");

trusted_click(t.step_func(() => {
trusted_click(t, () => {
target.requestFullscreen();
moveTo.appendChild(target);
}), document.body);
}, document.body);
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
assert_equals(iframeDoc.fullscreenElement, null);
});

trusted_click(t.step_func(() => {
trusted_click(t, () => {
target.requestFullscreen();
iframeDoc.body.appendChild(target);
}), document.body);
}, document.body);
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
iframeDocument.onfullscreenchange = t.unreached_func("iframe fullscreenchange event");
iframeDocument.onfullscreenerror = t.unreached_func("iframe fullscreenerror event");

trusted_click(t.step_func(() => {
trusted_click(t, () => {
iframeDocument.body.requestFullscreen();
iframe.remove();
// No events will be fired, end test after 100ms.
setTimeout(t.step_func_done(() => {
assert_equals(document.fullscreenElement, null);
assert_equals(iframeDocument.fullscreenElement, null);
}), 100);
}), document.body);
}, document.body);
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
assert_equals(document.fullscreenElement, null);
});

trusted_click(t.step_func(() => {
trusted_click(t, () => {
target.requestFullscreen();
target.remove();
}), document.body);
}, document.body);
});
</script>
2 changes: 1 addition & 1 deletion fullscreen/api/element-request-fullscreen-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
t.done();
}));

trusted_request(div);
trusted_request(t, div);
});
</script>
6 changes: 3 additions & 3 deletions fullscreen/api/element-request-fullscreen-non-top-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
async_test(function(t)
{
var first = document.getElementById("first");
trusted_request(first);
trusted_request(t, first);
document.onfullscreenchange = t.step_func(function()
{
assert_equals(document.fullscreenElement, first);
var last = document.getElementById("last");
trusted_request(last);
trusted_request(t, last);
document.onfullscreenchange = t.step_func(function()
{
assert_equals(document.fullscreenElement, last);
trusted_request(first, last);
trusted_request(t, first, last);
document.onfullscreenerror = t.step_func_done();
});
});
Expand Down
6 changes: 3 additions & 3 deletions fullscreen/api/element-request-fullscreen-same-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
// doc's fullscreen element, terminate these subsubsteps."
document.onfullscreenchange = t.unreached_func("fullscreenchange event");

trusted_click(t.step_func(() => {
trusted_click(t, () => {
target.requestFullscreen();

// Wait until after the next animation frame.
requestAnimationFrame(t.step_func_done());
}), target);
}, target);
});
document.onfullscreenerror = t.unreached_func("fullscreenerror event");

trusted_request(target);
trusted_request(t, target);
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
var rect = document.querySelector("rect");
assert_true(rect instanceof SVGRectElement);
trusted_request(rect, document.body);
trusted_request(t, rect, document.body);
document.onfullscreenchange = t.unreached_func("fullscreenerror event");
document.onfullscreenerror = t.step_func_done();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
var svg = document.querySelector("svg");
assert_true(svg instanceof SVGSVGElement);
trusted_request(svg, document.body);
trusted_request(t, svg, document.body);
document.onfullscreenchange = t.step_func_done();
document.onfullscreenerror = t.unreached_func("fullscreenerror event");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div id="log"></div>
<script>
async_test(t => {
trusted_request(document.querySelector('div'));
trusted_request(t, document.querySelector('div'));

// If fullscreenchange is an animation frame event, then animation frame
// callbacks should be run after it is fired, before the timer callback.
Expand Down
6 changes: 3 additions & 3 deletions fullscreen/api/element-request-fullscreen-top-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
async_test(function(t)
{
var top = document.getElementById("top");
trusted_request(top);
trusted_request(t, top);
document.onfullscreenchange = t.step_func(function()
{
assert_equals(document.fullscreenElement, top);
document.onfullscreenchange = t.unreached_func("fullscreenchange event");
trusted_click(t.step_func(function()
trusted_click(t, function()
{
top.requestFullscreen();
// A fullscreenerror event would be fired after an async section
Expand All @@ -23,7 +23,7 @@
{
requestAnimationFrame(t.step_func_done());
}, 0);
}), top);
}, top);
});
document.onfullscreenerror = t.unreached_func("fullscreenerror event");
});
Expand Down
4 changes: 2 additions & 2 deletions fullscreen/api/element-request-fullscreen-twice-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
});
document.onfullscreenerror = t.unreached_func("fullscreenerror event");

trusted_click(t.step_func(() => {
trusted_click(t, () => {
// Request fullscreen twice.
div.requestFullscreen();
assert_equals(document.fullscreenElement, null, "fullscreenElement after first requestFullscreen()");
div.requestFullscreen();
assert_equals(document.fullscreenElement, null, "fullscreenElement after second requestFullscreen()");
}), document.body);
}, document.body);
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
});
document.onfullscreenerror = t.unreached_func('fullscreenerror event');

trusted_click(t.step_func(() => {
trusted_click(t, () => {
b.requestFullscreen();
a.requestFullscreen();
}), document.body);
}, document.body);
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
});
document.onfullscreenerror = t.unreached_func('fullscreenerror event');

trusted_click(t.step_func(() => {
trusted_click(t, () => {
b.contentDocument.body.requestFullscreen();
a.contentDocument.body.requestFullscreen();
}), document.body);
}, document.body);
});
</script>
2 changes: 1 addition & 1 deletion fullscreen/model/remove-child-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
async_test(function(t)
{
var parent = document.getElementById("parent");
trusted_request(parent);
trusted_request(t, parent);
document.onfullscreenchange = t.step_func(function()
{
assert_equals(document.fullscreenElement, parent);
Expand Down
4 changes: 2 additions & 2 deletions fullscreen/model/remove-first-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
async_test(function(t)
{
var first = document.getElementById("first");
trusted_request(first);
trusted_request(t, first);
document.onfullscreenchange = t.step_func(function()
{
assert_equals(document.fullscreenElement, first);
var last = document.getElementById("last");
trusted_request(last);
trusted_request(t, last);
document.onfullscreenchange = t.step_func(function()
{
assert_equals(document.fullscreenElement, last);
Expand Down
4 changes: 2 additions & 2 deletions fullscreen/model/remove-last-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
async_test(function(t)
{
var first = document.getElementById("first");
trusted_request(first);
trusted_request(t, first);
document.onfullscreenchange = t.step_func(function()
{
assert_equals(document.fullscreenElement, first);
var last = document.getElementById("last");
trusted_request(last);
trusted_request(t, last);
document.onfullscreenchange = t.step_func(function()
{
assert_equals(document.fullscreenElement, last);
Expand Down
2 changes: 1 addition & 1 deletion fullscreen/model/remove-parent-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
async_test(function(t)
{
var child = document.getElementById("child");
trusted_request(child);
trusted_request(t, child);
document.onfullscreenchange = t.step_func(function()
{
assert_equals(document.fullscreenElement, child);
Expand Down
2 changes: 1 addition & 1 deletion fullscreen/model/remove-single-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
t.done();
});
});
trusted_request(single);
trusted_request(t, single);
});
</script>
11 changes: 5 additions & 6 deletions fullscreen/trusted-click.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
// Invokes callback from a trusted click event, to satisfy
// https://html.spec.whatwg.org/#triggered-by-user-activation
function trusted_click(callback, container)
function trusted_click(test, callback, container)
{
var document = container.ownerDocument;
var button = document.createElement("button");
button.textContent = "click to continue test";
button.style.display = "block";
button.style.fontSize = "20px";
button.style.padding = "10px";
button.onclick = function()
button.onclick = test.step_func(function()
{
callback();
container.removeChild(button);
};
});
container.appendChild(button);
}

// Invokes element.requestFullscreen() from a trusted click.
function trusted_request(element, container)
function trusted_request(test, element, container)
{
var request = element.requestFullscreen.bind(element);
trusted_click(request, container || element.parentNode);
trusted_click(test, () => element.requestFullscreen(), container || element.parentNode);
}

0 comments on commit 5e1a3b8

Please sign in to comment.