Exemple #1
0
  @Test
  public void clone_Deep() {
    // Arrange
    AnchorElement child = Document.get().createAnchorElement();
    child.setInnerText("child inner text");
    child.getStyle().setBackgroundColor("black");
    n.appendChild(child);

    // Act
    DivElement newNode = n.cloneNode(true).cast();

    // Assert
    assertEquals(Node.ELEMENT_NODE, newNode.getNodeType());
    DivElement source = n.cast();
    assertEquals(source.getInnerText(), newNode.getInnerText());
    assertEquals(source.getInnerHTML(), newNode.getInnerHTML());
    assertEquals(source.toString(), newNode.toString());

    assertNull(newNode.getParentNode());
    assertEquals(n.getChildNodes().getLength(), newNode.getChildNodes().getLength());

    assertEquals(Node.ELEMENT_NODE, newNode.getChildNodes().getItem(0).getNodeType());
    AnchorElement childElement = newNode.getChildNodes().getItem(0).cast();
    assertEquals("child inner text", childElement.getInnerText());

    Style newStyle = childElement.getStyle();
    assertTrue(newStyle != child.getStyle());
    assertEquals("black", newStyle.getBackgroundColor());
  }
Exemple #2
0
  private void initPostion() {
    if (pns == null) {
      pns = new ArrayList<PositionNav>();
    }
    NodeList<Node> nodes = content.getChildNodes();
    for (int i = 1; i < nodes.getLength(); i = i + 2) {
      Element elm = nodes.getItem(i).<Element>cast();

      final int absoluteTop = elm.getAbsoluteTop() - OFFSET;

      LIElement li = Document.get().createLIElement().cast();
      li.setInnerHTML(elm.getId());
      EventGenerator.onClick(
          li,
          new Function() {
            @Override
            public void f(Event e) {
              root.getElement().setScrollTop(absoluteTop);
            }
          });
      ul.appendChild(li);

      pns.add(new PositionNav(absoluteTop, li));
    }
    currentli = pns.get(0).getElm();
    currentli.addClassName(style.active());
  }
Exemple #3
0
  @Test
  public void clone_NotDeep() {
    // Arrange
    Element e = n.cast();
    e.setInnerText("text");
    e.getStyle().setBackgroundColor("black");

    AnchorElement child = Document.get().createAnchorElement();
    child.setInnerText("child inner text");
    n.appendChild(child);

    // Act
    DivElement newNode = n.cloneNode(false).cast();

    // Assert
    assertEquals(Node.ELEMENT_NODE, newNode.getNodeType());
    assertTrue(e.getStyle() != newNode.getStyle());
    assertEquals("black", newNode.getStyle().getBackgroundColor());
    assertEquals("text", newNode.getInnerText());
    assertNull(newNode.getParentNode());
    assertEquals(2, n.getChildNodes().getLength());
    assertEquals(1, newNode.getChildNodes().getLength());
  }