Пример #1
0
  /** Tests createFocusEvent(). */
  public void testTriggerFocusEvent() {
    NonBubbleAssertingEventListener listener =
        new NonBubbleAssertingEventListener("focus") {
          @Override
          public void onBrowserEvent(Event event) {
            if (cancelled) {
              return;
            }
            super.onBrowserEvent(event);
            assertEquals("focus", event.getType());
          }
        };
    Event.setEventListener(parent, listener);
    Event.setEventListener(child, listener);

    child.dispatchEvent(Document.get().createFocusEvent());
    listener.cancel();

    assertTrue("Expected child to receive event", listener.childReceived);
  }
Пример #2
0
  /**
   * Tests createKeyPressEvent().
   *
   * <p>Failed in all modes due to HtmlUnit bug:
   */
  @DoNotRunWith({Platform.HtmlUnitBug})
  public void testTriggerScrollEvent() {
    NonBubbleAssertingEventListener listener =
        new NonBubbleAssertingEventListener("scroll") {
          @Override
          public void onBrowserEvent(Event event) {
            if (cancelled) {
              return;
            }
            super.onBrowserEvent(event);
            assertEquals("scroll", event.getType());
          }
        };
    Event.setEventListener(parent, listener);
    Event.setEventListener(child, listener);

    child.dispatchEvent(Document.get().createScrollEvent());
    listener.cancel();

    assertTrue("Expected child to receive event", listener.childReceived);
  }
Пример #3
0
  /** Tests NativeEvent.stopPropagation(). */
  public void testStopPropagation() {
    NonBubbleAssertingEventListener listener =
        new NonBubbleAssertingEventListener("click") {
          @Override
          public void onBrowserEvent(Event event) {
            super.onBrowserEvent(event);
            if (event.getCurrentEventTarget().equals(child)) {
              event.stopPropagation();
            }
          }
        };
    Event.setEventListener(parent, listener);
    Event.setEventListener(child, listener);

    child.dispatchEvent(
        Document.get()
            .createClickEvent(
                MOUSE_DETAIL, SCREEN_X, SCREEN_Y, CLIENT_X, CLIENT_Y, true, true, true, true));
    listener.cancel();

    assertTrue("Expected child to receive event", listener.childReceived);
  }