Skip to content

Commit

Permalink
Merge pull request #693 from xiaojunwu/submission/xiaojunwu/window-le…
Browse files Browse the repository at this point in the history
…ngth

Tests for the window's length attribute
  • Loading branch information
zcorpan committed Mar 4, 2014
2 parents ebd00c6 + a59ad82 commit 71680a2
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Test: the browsing contexts must be sorted in the order that their containers were inserted into the Document</title>
<link rel="author" title="Intel" href="http://www.intel.com/" />
<link rel="help" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#accessing-other-browsing-contexts" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>

var t1 = async_test("The window's length must return the number of child browsing contexts(in iframe)");
function on_load1(fr) {
t1.step(function () {
var doc = fr.contentDocument;
var fr3 = doc.createElement("iframe");
fr3.setAttribute("id", "fr3");
doc.body.insertBefore(fr3, doc.getElementById("tbl"));

assert_equals(fr.contentWindow.length, 3, "The window.length should be 3.");
assert_array_equals([fr.contentWindow[0].frameElement, fr.contentWindow[1].frameElement, fr.contentWindow[2].frameElement],
[fr.contentDocument.getElementById("fr4"), fr.contentDocument.getElementById("fr5"), fr.contentDocument.getElementById("fr3")],
"The child browsing contexts must be sorted in the order that their containers were inserted into the Document.");
});
t1.done();
}

var t2 = async_test("The window's length must return zero if it has no child browsing context");
function on_load2(fr) {
t2.step(function () {
assert_equals(fr.contentWindow.length, 0, "The window.length should be 0.");
});
t2.done();
}

</script>
<iframe id="fr1" src="test1.html" style="display:none" onload="on_load1(this)"></iframe>
<iframe id="fr2" src="test2.html" style="display:none" onload="on_load2(this)"></iframe>
<script>

test(function () {
assert_equals(window.length, 2, "The window.length should be 2.");
assert_array_equals([window[0].frameElement, window[1].frameElement],
[document.getElementById("fr1"), document.getElementById("fr2")],
"The child browsing contexts must be sorted in the tree order.");
}, "The window's length must return the number of child browsing contexts");

</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>HTML Test: the browsing contexts created by various container elements</title>
<link rel="author" title="Intel" href="http://www.intel.com/" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>

var t1 = async_test("Accessing child browsing contexts 1");
var t2 = async_test("Accessing child browsing contexts 2");
var t3 = async_test("Accessing child browsing contexts 3");
function on_load() {
//Child browsing contexts created by iframe, object and embed elements.
t1.step(function () {
assert_equals(window.length, 3, "The top browsing context should have 3 child browsing contexts.");
});
t1.step(function () {
assert_equals(window[0].name, "win1", "The browsing context name should be 'win1'.");
assert_equals(window[1].name, "win2", "The browsing context name should be 'win2'.");
assert_equals(window[2].name, "win3", "The browsing context name should be 'win3'.");
});
t1.done();

//Child browsing contexts created by frame elements.
t2.step(function () {
assert_equals(document.getElementById("fr").contentWindow.length, 2,
"The child browsing context created by the iframe element should have 2 child browsing contexts.");
});
t2.step(function () {
assert_equals(document.getElementById("fr").contentWindow[0].name, "win4",
"The browsing context name should be 'win4'.");
assert_equals(document.getElementById("fr").contentWindow[1].name, "win5",
"The browsing context name should be 'win5'.");
});
t2.done();

//The child browsing context will be removed if the data attribute of the associated object element is removed.
t3.step(function () {
document.getElementById("obj").removeAttribute("type");
assert_equals(window.length, 3, "The top browsing context should have 3 child browsing contexts.");
document.getElementById("obj").removeAttribute("data");
assert_equals(window.length, 3, "The top browsing context should have 3 child browsing contexts.");

setTimeout(function () {
assert_equals(window.length, 2, "The top browsing context should have 2 child browsing contexts.");
}, 1);
});
t3.done();
}

</script>
</head>
<body onload="on_load()">
<div id="log"></div>
<div style="display:none">
<iframe id="fr" name="win1" src="test3.html"></iframe>
<object id="obj" name="win2" type="text/html" data="about:blank"></object>
<object type="image/png" src="/images/green.png"></object>
<embed id="emb" name="win3" type="image/svg+xml" src="/images/green.svg"></embed>
</div>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>HTML Test: indexed property of a Window object</title>
<link rel="author" title="Intel" href="http://www.intel.com/" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>

var t1 = async_test("Indexed child browsing contexts");
function on_load() {
t1.step(function () {
assert_equals(window[0], document.getElementsByTagName("object")[0].contentWindow,
"The first child browsing context's container should be the object element.");
assert_equals(window[1], document.getElementsByTagName("iframe")[0].contentWindow,
"The second child browsing context's container should be the iframe element.");
});
t1.done();
}

</script>
</head>
<body onload="on_load()">
<div id="log"></div>
<div style="display:none">
<div id="0"></div>
<object name="0" type="text/html" data="test2.html"></object>
<iframe name="0" src="about:blank"></iframe>
</div>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Test: child browsing contexts created by iframe elements</title>
<link rel="author" title="Intel" href="http://www.intel.com/" />
<table id="tbl">
<tr>
<td>
<iframe id="fr4" src=""></iframe>
</td>
</tr>
<iframe id="fr5" src="about:blank"></iframe>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Test: child browsing contexts created by object and embed elements</title>
<link rel="author" title="Intel" href="http://www.intel.com/" />
<object type="image/png" src="/images/green.png"></object>
<embed type="image/png" src="/images/green.png"></embed>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Test: child browsing contexts created by frame elements</title>
<link rel="author" title="Intel" href="http://www.intel.com/" />
<frameset>
<frame name="win4"></frame>
<frame name="win5"></frame>
</frameset>

0 comments on commit 71680a2

Please sign in to comment.