Ejemplo n.º 1
0
  public void testMouseDown() {
    delayTestFinish(5000);
    final Element elem = Document.get().getElementById(id);
    Document.get().createClickEvent(0, 10, 10, 10, 10, false, false, false, false);

    NativeEvent evt;

    evt = Document.get().createMouseDownEvent(0, 10, 10, 10, 10, false, false, false, false, 1);

    assertEquals(
        "<input style=\"opacity: 0; height: 1px; width: 1px; z-index: -1; overflow: hidden; position: absolute;\" tabindex=\"-1\" type=\"text\"><div class=\"gwt-Label\">box1</div>",
        elem.getInnerHTML());
    assertEquals(
        "background-color: red; width: 100px; height: 100px; position: absolute; left: 125px; top: 0px;",
        elem.getAttribute("style"));
    assertEquals("dragdrop-draggable dragdrop-handle", elem.getAttribute("class"));

    elem.dispatchEvent(evt);

    assertEquals(
        "<input style=\"opacity: 0; height: 1px; width: 1px; z-index: -1; overflow: hidden; position: absolute;\" tabindex=\"-1\" type=\"text\"><div class=\"gwt-Label\">box1</div>",
        elem.getInnerHTML());
    assertEquals(
        "background-color: red; width: 100px; height: 100px; margin: 0px; position: absolute; left: 0px; top: 0px;",
        elem.getAttribute("style"));
    assertEquals(
        "dragdrop-draggable dragdrop-handle dragdrop-dragging", elem.getAttribute("class"));
  }
Ejemplo n.º 2
0
  public void testSimpleDrag() {
    delayTestFinish(5000);
    final Element elem = Document.get().getElementById(id);
    Document.get().createClickEvent(0, 10, 10, 10, 10, false, false, false, false);

    NativeEvent evt;

    final int oldX = elem.getAbsoluteLeft();
    final int oldY = elem.getAbsoluteTop();

    evt = Document.get().createMouseDownEvent(0, 10, 10, 10, 10, false, false, false, false, 1);
    elem.dispatchEvent(evt);

    assertEquals("draggable x after mouse down", oldX, elem.getAbsoluteLeft());
    assertEquals("draggabel y after mouse down", oldY, elem.getAbsoluteTop());

    new Step() {
      @Override
      void run() {
        NativeEvent evt =
            Document.get().createMouseMoveEvent(0, 20, 20, 200, 200, false, false, false, false, 1);
        elem.dispatchEvent(evt);

        assertEquals("draggable x after mouse move", oldX + 190, elem.getAbsoluteLeft());
        assertEquals("draggabel y after mouse move", oldY + 190, elem.getAbsoluteTop());
      }
    };

    new Step() {
      @Override
      void run() {
        NativeEvent evt =
            Document.get().createMouseUpEvent(0, 20, 20, 100, 100, false, false, false, false, 1);
        elem.dispatchEvent(evt);

        assertEquals("draggable x after mouse up", oldX + 90, elem.getAbsoluteLeft());
        assertEquals("draggable y after mouse up", oldY + 90, elem.getAbsoluteTop());
      }
    };

    new Step() {
      @Override
      void run() {
        finishTest();
      }
    };
  }
Ejemplo n.º 3
0
  /**
   * Test {@link Cell#onBrowserEvent(Element, Object, Object, NativeEvent, ValueUpdater)} with the
   * specified conditions.
   *
   * @param cell the cell to use
   * @param startHtml the innerHTML of the cell before the test starts
   * @param event the event to fire
   * @param value the cell value
   * @param expectedValue the expected value passed to the value updater, or null if none expected
   * @param dispatchToFirstChild true to dispatch to the first child of the rendered parent element,
   *     if one is available
   * @return the parent element
   */
  protected Element testOnBrowserEvent(
      final Cell<T> cell,
      String startHtml,
      NativeEvent event,
      final T value,
      T expectedValue,
      boolean dispatchToFirstChild) {
    // Setup the parent element.
    final Element parent = Document.get().createDivElement();
    parent.setInnerHTML(startHtml);
    Document.get().getBody().appendChild(parent);

    // If the element has a child, use it as the event target.
    Element target = parent;
    if (dispatchToFirstChild) {
      Element child = parent.getFirstChildElement();
      target = (child == null) ? parent : child;
    }

    // Pass the event to the cell.
    final MockValueUpdater valueUpdater = new MockValueUpdater();
    Event.setEventListener(
        parent,
        new EventListener() {
          public void onBrowserEvent(Event event) {
            try {
              DOM.setEventListener(parent, null);
              Context context = new Context(0, 0, DEFAULT_KEY);
              cell.onBrowserEvent(context, parent, value, event, valueUpdater);
              parent.removeFromParent();
            } catch (Exception e) {
              // We are in an event loop, so events may not propagate out to JUnit.
              fail("An exception occured while handling the event: " + e.getMessage());
            }
          }
        });
    Event.sinkEvents(target, Event.getTypeInt(event.getType()));
    target.dispatchEvent(event);
    assertNull(DOM.getEventListener(parent));

    // Check the expected value and view data.
    valueUpdater.assertLastValue(expectedValue);
    return parent;
  }