<!DOCTYPE html>
<meta charset=utf-8>
<title>Named items: embeds</title>
<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-document-nameditem">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<div id="test">
<embed name=test1></embed>

<embed name=test2></embed>
<embed name=test2></embed>

<embed id=test3></embed>

<embed id=test4></embed>
<embed id=test4></embed>

<embed name=test5></embed>
<embed id=test5></embed>

<embed id=test6></embed>
<embed name=test6></embed>

<embed id=test7 name=fail></embed>

<embed name=test8 id=fail></embed>
</div>
<script>
test(function() {
  var embed = document.getElementsByTagName("embed")[0];
  assert_equals(embed.name, "test1");

  assert_true("test1" in document, '"test1" in document should be true');
  assert_equals(document.test1, embed);
}, "If there is one embed, it should be returned (name)");

test(function() {
  var embed1 = document.getElementsByTagName("embed")[1];
  assert_equals(embed1.name, "test2");
  var embed2 = document.getElementsByTagName("embed")[2];
  assert_equals(embed2.name, "test2");

  assert_true("test2" in document, '"test2" in document should be true');
  var collection = document.test2;
  assert_class_string(collection, "HTMLCollection", "collection should be an HTMLCollection");
  assert_array_equals(collection, [embed1, embed2]);
}, "If there are two embeds, a collection should be returned. (name)");

test(function() {
  var embed = document.getElementsByTagName("embed")[3];
  assert_equals(embed.id, "test3");

  assert_false("test3" in document, '"test3" in document should be false');
  assert_equals(document.test3, undefined);
}, "If there is one embed, it should not be returned (id)");

test(function() {
  var embed1 = document.getElementsByTagName("embed")[4];
  assert_equals(embed1.id, "test4");
  var embed2 = document.getElementsByTagName("embed")[5];
  assert_equals(embed2.id, "test4");

  assert_false("test4" in document, '"test4" in document should be false');
  assert_equals(document.test4, undefined);
}, "If there are two embeds, nothing should be returned. (id)");

test(function() {
  var embed1 = document.getElementsByTagName("embed")[6];
  assert_equals(embed1.name, "test5");
  var embed2 = document.getElementsByTagName("embed")[7];
  assert_equals(embed2.id, "test5");

  assert_true("test5" in document, '"test5" in document should be true');
  assert_equals(document.test5, embed1);
}, "If there are two embeds, a collection should be returned. (name and id)");

test(function() {
  var embed1 = document.getElementsByTagName("embed")[8];
  assert_equals(embed1.id, "test6");
  var embed2 = document.getElementsByTagName("embed")[9];
  assert_equals(embed2.name, "test6");

  assert_true("test6" in document, '"test6" in document should be true');
  assert_equals(document.test6, embed2);
}, "If there are two embeds, a collection should be returned. (id and name)");

test(function() {
  var embed = document.getElementsByTagName("embed")[10];
  assert_equals(embed.id, "test7");

  assert_false("test7" in document, '"test7" in document should be false');
  assert_equals(document.test7, undefined);
}, "A name shouldn't affect getting an embed by id");

test(function() {
  var embed = document.getElementsByTagName("embed")[11];
  assert_equals(embed.name, "test8");

  assert_true("test8" in document, '"test8" in document should be true');
  assert_equals(document.test8, embed);
}, "An id shouldn't affect getting an embed by name");
</script>
