summaryrefslogtreecommitdiffstats
path: root/dom/plugins/test/mochitest/test_plugin_fallback_focus.html
blob: e89abb44df8a8703ac272675952973b9fcf71839 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test that plugins reject focus</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<div id="content">
	<object id="obj_elt" type="application/x-shockwave-flash"></object>
	<object tabindex='0' id="obj_elt_with_idx" type="application/x-shockwave-flash"></object>
	<embed id="embed_elt" type="application/x-shockwave-flash"></embed>
</div>
<script type="application/javascript">
var objElt = document.getElementById('obj_elt');
var objEltWithIdx = document.getElementById('obj_elt_with_idx');
var embedElt = document.getElementById('embed_elt');

function checkHasFocus(expected, typeOfElts, elt) {
	ok((document.activeElement == elt) == expected,
		typeOfElts + " element should " + (expected ? "" : "not ") + "accept focus");
}

function checkNoneHasFocus(typeOfElts) {
	checkHasFocus(false, typeOfElts + " <object>", objElt);
	checkHasFocus(false, typeOfElts + " <object> with tabindex", objEltWithIdx);
	checkHasFocus(false, typeOfElts + " <embed>", embedElt);
}

function checkFocusable(expected, typeOfElts, elt) {
	elt.focus();
	checkHasFocus(expected, typeOfElts, elt);
}

// As plugins, object and embed elements are not given focus
ok(objElt != null, "object element should exist");
ok(objEltWithIdx != null, "object element with tabindex should exist");
ok(embedElt != null, "embed element should exist");

// As plugins, obj/embed_elt can not take focus
checkNoneHasFocus("plugin");

// Switch obj/embed_elt attributes from plugin to image
objElt.data = "large-pic.jpg";
objElt.width = 100;
objElt.height = 100;
objElt.type = "image/jpg";
objEltWithIdx.data = "large-pic.jpg";
objEltWithIdx.width = 100;
objEltWithIdx.height = 100;
objEltWithIdx.type = "image/jpg";
embedElt.src = "large-pic.jpg";
embedElt.width = 100;
embedElt.height = 100;
embedElt.type = "image/jpg";

// As images, obj/embed_elt can take focus as image
// object image elements require a tabindex to accept focus. 
// embed elements must be reparented before new type is recognized.
checkFocusable(false, "<object> image", objElt);
checkFocusable(true, "<object> image with tabindex", objEltWithIdx);
checkFocusable(false, "<embed> plugin with image attribs before reparenting", embedElt);
embedElt.parentNode.appendChild(embedElt);
checkFocusable(true, "<embed> image", embedElt);

// Switch obj/embed_elt attributes from image to plugin
objElt.type = "application/x-shockwave-flash";
embedElt.type = "application/x-shockwave-flash";

// embed elements must be reparented before new type is recognized.
checkFocusable(true, "<embed> image with plugin attribs", embedElt);
embedElt.parentNode.appendChild(embedElt);
checkNoneHasFocus("plugin");
</script>
</body>
</html>