Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for Page Visibility #180

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions pagevisibility/idlharness.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>idlharness test</title>
<link rel="author" title="W3C" href="http://www.w3.org/" />
<link rel="help" href="http://www.w3.org/TR/page-visibility/#sec-document-interface"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/webidl2.js/lib/webidl2.js"></script>
<script src="/resources/idlharness.js"></script>
</head>
<body>
<h1>idlharness test</h1>
<p>This test validates the WebIDL included in the Page Visibility specification.</p>

<pre id='untested_idl' style='display:none'>
interface Document {
};
</pre>

<pre id='idl'>
enum VisibilityState { "hidden", "visible", "prerender", "unloaded" };

partial interface Document {
readonly attribute boolean hidden;
readonly attribute VisibilityState visibilityState;
};
</pre>

<script>

(function() {
var idl_array = new IdlArray();

idl_array.add_untested_idls(document.getElementById("untested_idl").textContent);
idl_array.add_idls(document.getElementById("idl").textContent);

idl_array.add_objects({Document: ["window.document"]});

idl_array.test();
})();

</script>

<div id="log"></div>

</body>
</html>
10 changes: 10 additions & 0 deletions pagevisibility/resources/blank_page_green.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE HTML>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Green Test Page</title>
</head>
<body style="background-color:#00FF00;">
<h1>Placeholder</h1>
</body>
</html>
121 changes: 121 additions & 0 deletions pagevisibility/resources/pagevistestharness.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
Distributed under both the W3C Test Suite License [1] and the W3C
3-clause BSD License [2]. To contribute to a W3C Test Suite, see the
policies and contribution forms [3].

[1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license
[2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license
[3] http://www.w3.org/2004/10/27-testcases
*/

//
// Helper Functions for PageVisibility W3C tests
//
var VISIBILITY_STATES =
{
HIDDEN: "hidden",
VISIBLE: "visible"
};

var feature_check = false;

//
// All test() functions in the WebPerf PageVis test suite should use pv_test() instead.
//
// pv_test() validates the document.hidden and document.visibilityState attributes
// exist prior to running tests and immediately shows a failure if they do not.
//

function pv_test(func, msg, doc)
{
if (!doc)
{
doc = document;
}

// only run the feature check once, unless func == null, in which case,
// this call is intended as a feature check
if (!feature_check)
{
feature_check = true;

var hiddenVal = doc.hidden;
var visStateVal = doc.visibilityState;

// show a single error that the Page Visibility feature is undefined
test(function()
{
assert_true(hiddenVal !== undefined && hiddenVal != null,
"document.hidden is defined and not null.");},
"document.hidden is defined and not null.");

test(function()
{
assert_true(visStateVal !== undefined && hiddenVal != null,
"document.visibilityState is defined and not null.");},
"document.visibilityState is defined and not null.");

}

if (func)
{
test(func, msg);
}
}


function test_feature_exists(doc, msg)
{
if (!msg)
{
msg = "";
}
var hiddenMsg = "document.hidden is defined" + msg + ".";
var stateMsg = "document.visibilityState is defined" + msg + ".";
pv_test(function(){assert_true(document.hidden !== undefined, hiddenMsg);}, hiddenMsg, doc);
pv_test(function(){assert_true(document.visibilityState !== undefined, stateMsg);}, stateMsg, doc);
}

//
// Common helper functions
//

function test_true(value, msg)
{
pv_test(function() { assert_true(value, msg); }, msg);
}

function test_equals(value, equals, msg)
{
pv_test(function() { assert_equals(value, equals, msg); }, msg);
}

//
// asynchronous test helper functions
//

function add_async_result(test_obj, pass_state)
{
// add assertion to manual test for the pass state
test_obj.step(function() { assert_true(pass_state) });

// end manual test
test_obj.done();
}

function add_async_result_assert(test_obj, func)
{
// add assertion to manual test for the pass state
test_obj.step(func);

// end manual test
test_obj.done();
}

var open_link;
function TabSwitch()
{
//var open_link = window.open("http://www.bing.com");
open_link = window.open('', '_blank');
setTimeout(function() { open_link.close(); }, 2000);
}
21 changes: 21 additions & 0 deletions pagevisibility/test_attributes_exist.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Page Visibility API Definition</title>

<script type="text/javascript" src="/resources/testharness.js"></script>
<script type="text/javascript" src="resources/pagevistestharness.js"></script>
</head>
<body>
<h1>Description</h1>
<p>This test validates that all of the attributes associated with the Page Visibility feature exist
(but does not validate that their values are correct).</p>

<div id="log"></div>

<script type="text/javascript" >
test_feature_exists();
</script>
</body>
</html>
93 changes: 93 additions & 0 deletions pagevisibility/test_child_document.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Page Visibility API Child Document Test</title>

<script type="text/javascript" src="/resources/testharness.js"></script>
<script type="text/javascript" src="resources/pagevistestharness.js"></script>

<style type="text/css">
iframe
{
width:250px;
height:250px;
margin-left:5px;
}

div.docs
{
position:relative;
float:left;
text-align:center;
margin:10px;
border:solid 1px black;
padding:3px;
}
</style>

<script type="text/javascript" >
setup({explicit_done: true});

function onload_test()
{
pv_test();

var frames = document.getElementsByTagName("iframe");
var doc, doc_name;

for (var i = 0; i < frames.length; i++)
{
doc = frames[i].contentDocument;
doc_name = "IFrame with " + frames[i].id;

pv_test(function()
{
test_feature_exists(doc, " for frame with " + frames[i].id);
});

test_equals(doc.visibilityState, VISIBILITY_STATES.VISIBLE,
"document.visibilityState for frame with " +
frames[i].id + " == " +
VISIBILITY_STATES.VISIBLE);
}

done();
}
</script>
</head>
<body onload="onload_test()">
<h1>Description</h1>
<p>This test validates that, within child documents, all of the Page Visibility API attributes exist,
are read-only, and match the value of the attributes within the parent document.</p>

<div id="log"></div>

<br/>

<div class="docs">
IFrame with no style attribute
<br/>
<iframe id="no style attribute" src="resources/blank_page_green.html">
iframes unsupported
</iframe>
</div>

<div class="docs">
IFrame with "display:none" style<br/>
<iframe id="'display:none' style" style="display:none"
src="resources/blank_page_green.html">
iframes unsupported
</iframe>
</div>

<div class="docs">
IFrame with "visibility:hidden" style
<br/>
<iframe id="'visibility:hidden' style" style="visibility:hidden"
src="resources/blank_page_green.html">
iframes unsupported
</iframe>
</div>
</body>
</html>
42 changes: 42 additions & 0 deletions pagevisibility/test_default_view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Page Visibility Null Default View Test</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com/" />

<script type="text/javascript" src="/resources/testharness.js"></script>
<script type="text/javascript" src="resources/pagevistestharness.js"></script>

<script type="text/javascript" >
setup({explicit_done: true});

function onload_test()
{
// inject a windowless subdocument as a child of the root document <html> element
var subDoc = document.implementation.createDocument('resources/blank_page_green.html', 'html', null);

// Test precondition: ensure subdocument has a null default view
test_true(subDoc.defaultView == null, "windowless subdocument generated for test has a null default view");

// check that feature exists within subdocument
test_feature_exists(subDoc, 'windowless subdocument');

// check that the subdocument has a hidden visibility state
test_true(subDoc.hidden,
"hidden == true for windowless subdocuments with a null default view");
test_equals(subDoc.visibilityState, VISIBILITY_STATES.HIDDEN,
"visibilityState == " + VISIBILITY_STATES.HIDDEN +
" for windowless subdocuments with a null default view");

done();
}
</script>
</head>
<body onload="onload_test()">
<h1>Description</h1>
<p>This test validates that document.hidden == false and
document.visibilityState == "visible" for windowless subdocuments.</p>
<div id="log"></div>
</body>
</html>
Loading