Skip to content

Commit

Permalink
Add tests for the object element
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaojunwu committed Mar 12, 2014
1 parent d682079 commit e546ac5
Show file tree
Hide file tree
Showing 14 changed files with 257 additions and 0 deletions.
6 changes: 6 additions & 0 deletions html/semantics/embedded-content/the-object-element/blue.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Blue Page</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<body style="background-color:blue">
</body>
6 changes: 6 additions & 0 deletions html/semantics/embedded-content/the-object-element/green.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Green Page</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<body style="background-color:green">
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Test: object - attributes</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body onload="on_load()">
<div id="log"></div>
<form>
<object id="obj1" data="blue.html" name="o" height="50" width="100"></object>
<object id="obj2" data="/images/blue.png" name="p" type="image/png"></object>
</form>
<script>
var obj1;
var obj2;
var t1 = async_test("object.contentWindow");
var t2 = async_test("object.form");
var t3 = async_test("object.width");
var t4 = async_test("object.height");

setup(function() {
obj1 = document.getElementById("obj1");
obj2 = document.getElementById("obj2");
});

function on_load () {
t1.step(function() {
assert_equals(obj1.contentWindow.name, "o", "The contentWindow's name of the object element should be 'o'.");
assert_equals(obj2.contentWindow, null, "The contentWindow of the object element should be null when it type attribute starts with 'image/'.");
obj1.setAttribute("name", "o1");
assert_equals(obj1.name, "o1", "The name of the object element should be 'o1'.");
assert_equals(obj1.contentWindow.name, "o1", "The contentWindow's name of the object element should be 'o1'.");
obj1.removeAttribute("name");
assert_equals(obj1.name, "", "The name of the object element should be empty string.");
assert_equals(obj1.contentWindow.name, "", "The contentWindow's name of the object element should be empty string.");
});
t1.done()

t2.step(function() {
assert_equals(obj1.form, document.forms[0], "The form attribute is incorrect.");
});
t2.done();

t3.step(function() {
assert_equals(getComputedStyle(obj1, null)["width"], "100px", "The width should be 100px.");
});
t3.done();

t4.step(function() {
assert_equals(getComputedStyle(obj1, null)["height"], "50px", "The height should be 50px.");
});
t4.done();
}
</script>

</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Test: object-events</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>

var t1 = async_test("error event");
var t2 = async_test("load event");
var t3 = async_test("load event of about:blank");

setup(function () {
var obj1 = document.createElement("object");
var obj2 = document.createElement("object");
var obj3 = document.createElement("object");
obj1.data = "test.html";
obj2.data = "/images/blue.png";
obj3.data = "about:blank";

obj1.onerror = t1.step_func_done(function (e) {
assert_true(e.isTrusted, "The error event should be a truested event.");
assert_false(e.cancelable, "The error event should not be a cancelable event.");
assert_false(e.bubbles, "The error event should not be a bubble event.");
assert_equals(e.target, obj1, "The error event target should be the corresponding object element.");
assert_true(e instanceof Event, "The load event should be an instance of Event interface.");
});

obj2.onload = t2.step_func_done(function (e) {
assert_true(e.isTrusted, "The load event should be a truested event.");
assert_false(e.cancelable, "The load event should not be a cancelable event.");
assert_false(e.bubbles, "The load event should not be a bubble event.");
assert_equals(e.target, obj2, "The load event target should be the corresponding object element.");
assert_true(e instanceof Event, "The load event should be an instance of Event interface.");
});

obj3.onload = t3.step_func_done(function (e) {
assert_true(e.isTrusted, "The laod event should be a truested event.");
assert_false(e.cancelable, "The load event should not be a cancelable event.");
assert_false(e.bubbles, "The load event should not be a bubble event.");
assert_equals(e.target, obj3, "The load event target should be the corresponding object element.");
assert_true(e instanceof Event, "The load event should be an instance of Event interface.");
});

document.body.appendChild(obj1);
document.body.appendChild(obj2);
document.body.appendChild(obj3);
});

</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Test: display fallback content</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<meta name="flag" content="interact"></meta>
<meta name="assert" content="The object element will not display when its type attribute does not match the source specified by data attribute">
<p>Test passes if there is <strong>no blue</strong>, and 'PASS' is displayed.</p>
<object data="/images/blue.png" type="text/plain" typemustmatch>
<p>PASS</p>
</object>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Test: object - handler</title>
<link rel="author" title="Intel" href="http://www.intel.com" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<object id="test" data="test0.html" type="text/html"></object>
<div id="result" style="display:none"></div>
<script>

var result;
var t1 = async_test("The nested browsing context must be navigated to the resource specified by the data attribute.");
var t2 = async_test("The object.data must not be updated if the browsing context gets further navigated.");
var testEle;

setup(function() {
testEle = document.getElementById("test");
result = document.getElementById("result");
window.addEventListener("message", callback, false);
});

function callback(e) {
if (e.data == "test0 loaded") {
t1.step(function() {
assert_true(testEle.data.indexOf("test0.html") != -1, "The value of attribute data should not be updated.");
assert_equals(result.innerHTML, "1", "The soruce specified by data attribute of object element is not loaded.");
});
t1.done();
} else if (e.data == "test1 loaded") {
t2.step(function() {
assert_true(testEle.contentDocument.location.href.indexOf("test1.html") != -1, "The bowser context should be navigated to test1.html.");
assert_true(testEle.data.indexOf("test0.html") != -1, "The value of attribute data should not be updated.");
});
t2.done();
}
}

</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Test: object-usemap-effect</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("usemap attribute");
function on_load() {
t1.step(function () {
assert_true(frames[1].location.href.indexOf("white.html") > 0, "A white area should be displayed.");
assert_true(frames[2].location.href.indexOf("red.html") > 0, "A red area should be displayed.");
assert_true(frames[3].location.href.indexOf("green.html") > 0, "A green area should be displayed.");
assert_true(frames[4].location.href.indexOf("blue.html") > 0, "A blue area should be displayed.");
assert_true(frames[5].location.href.indexOf("yellow.html") > 0, "A yellow area should be displayed.");
})
t1.done();
}

</script>
<body onload="on_load()">
<div id="log"></div>
<iframe src="test2.html"></iframe>
<iframe src="" name="frame1"></iframe>
<iframe src="" name="frame2"></iframe>
<iframe src="" name="frame3"></iframe>
<iframe src="" name="frame4"></iframe>
<iframe src="" name="frame5"></iframe>
</body>
6 changes: 6 additions & 0 deletions html/semantics/embedded-content/the-object-element/red.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Red Page</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<body style="background-color:red">
</body>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions html/semantics/embedded-content/the-object-element/test0.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Test</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<script>

parent.document.getElementById("result").innerHTML = "1";
parent.postMessage("test0 loaded", "*");
document.location.href = "test1.html";

</script>
9 changes: 9 additions & 0 deletions html/semantics/embedded-content/the-object-element/test1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Test</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<script>

parent.window.postMessage("test1 loaded", "*");

</script>
21 changes: 21 additions & 0 deletions html/semantics/embedded-content/the-object-element/test2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Test</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<object data="sample-usemap.png" usemap="#shapes"></object>
<map name="shapes">
<area id="a1" shape="rect" coords="50,50,100,100" href="white.html" alt="White box" target="frame1"><!-- the hole in the red box -->
<area id="a2" shape="rect" coords="25,25,125,125" href="red.html" alt="Red box" target="frame2">
<area id="a3" shape="circle" coords="200,75,50" href="green.html" alt="Green circle" target="frame3">
<area id="a4" shape="poly" coords="325,25,262,125,388,125" href="blue.html" alt="Blue triangle" target="frame4">
<area id="a5" shape="poly" coords="450,25,435,60,400,75,435,90,450,125,465,90,500,75,465,60" href="yellow.html" alt="Yellow star" target="frame5">
</map>
<script>

document.getElementById("a1").click();
document.getElementById("a2").click();
document.getElementById("a3").click();
document.getElementById("a4").click();
document.getElementById("a5").click();

</script>
6 changes: 6 additions & 0 deletions html/semantics/embedded-content/the-object-element/white.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>White Page</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<body style="background-color:white">
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Yellow Page</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<body style="background-color:yellow">
</body>

0 comments on commit e546ac5

Please sign in to comment.