Esempio n. 1
0
TEST_F(CustomElementRegistryTest, lookupCustomElementDefinition) {
  NonThrowableExceptionState shouldNotThrow;
  TestCustomElementDefinitionBuilder builder;
  CustomElementDefinition* definitionA = registry().define(
      "a-a", builder, ElementDefinitionOptions(), shouldNotThrow);
  ElementDefinitionOptions options;
  options.setExtends("div");
  CustomElementDefinition* definitionB =
      registry().define("b-b", builder, options, shouldNotThrow);
  // look up defined autonomous custom element
  CustomElementDefinition* definition = registry().definitionFor(
      CustomElementDescriptor(CustomElementDescriptor("a-a", "a-a")));
  EXPECT_NE(nullptr, definition) << "a-a, a-a should be registered";
  EXPECT_EQ(definitionA, definition);
  // look up undefined autonomous custom element
  definition = registry().definitionFor(CustomElementDescriptor("a-a", "div"));
  EXPECT_EQ(nullptr, definition) << "a-a, div should not be registered";
  // look up defined customized built-in element
  definition = registry().definitionFor(CustomElementDescriptor("b-b", "div"));
  EXPECT_NE(nullptr, definition) << "b-b, div should be registered";
  EXPECT_EQ(definitionB, definition);
  // look up undefined customized built-in element
  definition = registry().definitionFor(CustomElementDescriptor("a-a", "div"));
  EXPECT_EQ(nullptr, definition) << "a-a, div should not be registered";
}
TEST(CustomElementDescriptorTest, hashable)
{
    HashSet<CustomElementDescriptor> descriptors;
    descriptors.add(CustomElementDescriptor("foo-bar", "foo-bar"));
    EXPECT_TRUE(
        descriptors.contains(CustomElementDescriptor("foo-bar", "foo-bar")))
        << "the identical descriptor should be found in the hash set";
    EXPECT_FALSE(descriptors.contains(CustomElementDescriptor(
        "bad-poetry",
        "blockquote")))
        << "an unrelated descriptor should not be found in the hash set";
}
Esempio n. 3
0
TEST_F(CustomElementRegistryTest, collectCandidates_oneCandidate) {
  Element* element = CreateElement("a-a").inDocument(&document());
  registry().addCandidate(element);
  document().documentElement()->appendChild(element);

  HeapVector<Member<Element>> elements;
  collectCandidates(CustomElementDescriptor("a-a", "a-a"), &elements);

  EXPECT_EQ(1u, elements.size())
      << "exactly one candidate should have been found";
  EXPECT_TRUE(elements.contains(element))
      << "the candidate should be the element that was added";
}
Esempio n. 4
0
TEST_F(CustomElementRegistryTest,
       collectCandidates_shouldNotIncludeElementsRemovedFromDocument) {
  Element* element = CreateElement("a-a").inDocument(&document());
  registry().addCandidate(element);

  HeapVector<Member<Element>> elements;
  collectCandidates(CustomElementDescriptor("a-a", "a-a"), &elements);

  EXPECT_TRUE(elements.isEmpty())
      << "no candidates should have been found, but we have "
      << elements.size();
  EXPECT_FALSE(elements.contains(element))
      << "the out-of-document candidate should not have been found";
}
Esempio n. 5
0
TEST_F(CustomElementRegistryTest,
       collectCandidates_shouldNotIncludeElementsInDifferentDocument) {
  Element* element = CreateElement("a-a").inDocument(&document());
  registry().addCandidate(element);

  Document* otherDocument = HTMLDocument::create();
  otherDocument->appendChild(element);
  EXPECT_EQ(otherDocument, element->ownerDocument())
      << "sanity: another document should have adopted an element on append";

  HeapVector<Member<Element>> elements;
  collectCandidates(CustomElementDescriptor("a-a", "a-a"), &elements);

  EXPECT_TRUE(elements.isEmpty())
      << "no candidates should have been found, but we have "
      << elements.size();
  EXPECT_FALSE(elements.contains(element))
      << "the adopted-away candidate should not have been found";
}
Esempio n. 6
0
TEST_F(CustomElementRegistryTest, collectCandidates_shouldBeInDocumentOrder) {
  CreateElement factory = CreateElement("a-a");
  factory.inDocument(&document());
  Element* elementA = factory.withId("a");
  Element* elementB = factory.withId("b");
  Element* elementC = factory.withId("c");

  registry().addCandidate(elementB);
  registry().addCandidate(elementA);
  registry().addCandidate(elementC);

  document().documentElement()->appendChild(elementA);
  elementA->appendChild(elementB);
  document().documentElement()->appendChild(elementC);

  HeapVector<Member<Element>> elements;
  collectCandidates(CustomElementDescriptor("a-a", "a-a"), &elements);

  EXPECT_EQ(elementA, elements[0].get());
  EXPECT_EQ(elementB, elements[1].get());
  EXPECT_EQ(elementC, elements[2].get());
}