Beispiel #1
0
  /** Test an event that supports shift keys by testing each shift key individually. */
  private void testTriggerEventWithShiftKeys(
      BubbleAssertingEventListener listener, EventCreator creator) {
    Event.setEventListener(parent, listener);
    Event.setEventListener(child, listener);

    listener.setExpectedShiftKeys(true, true, true, true);
    child.dispatchEvent(creator.createEvent(true, true, true, true));
    listener.assertReceived();

    listener.setExpectedShiftKeys(true, false, false, false);
    child.dispatchEvent(creator.createEvent(true, false, false, false));
    listener.assertReceived();

    listener.setExpectedShiftKeys(false, true, false, false);
    child.dispatchEvent(creator.createEvent(false, true, false, false));
    listener.assertReceived();

    listener.setExpectedShiftKeys(false, false, true, false);
    child.dispatchEvent(creator.createEvent(false, false, true, false));
    listener.assertReceived();

    listener.setExpectedShiftKeys(false, false, false, true);
    child.dispatchEvent(creator.createEvent(false, false, false, true));
    listener.assertReceived();
  }
Beispiel #2
0
  /** Tests createDblClickEvent(). */
  public void testTriggerDblClickEvent() {
    BubbleAssertingEventListener listener =
        new BubbleAssertingEventListener("dblclick", true) {
          @Override
          public void onBrowserEvent(Event event) {
            if (cancelled) {
              return;
            }
            if (event.getTypeInt() == Event.ONCLICK) {
              // Some browsers (IE, I'm looking at you) synthesize an extra click
              // event when a double-click is triggered. This synthesized click
              // will *not* have the same properties as the dblclick, so we will
              // not try to assert them here.
              return;
            }

            super.onBrowserEvent(event);
            assertMouseCoordinates(event);
          }
        };
    Event.setEventListener(parent, listener);
    Event.setEventListener(child, listener);

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

    assertTrue("Expected child to receive event", listener.childReceived);
    assertTrue("Expected parent to receive event", listener.parentReceived);
  }
  @Override
  public void setCampaignList(List<Campaign> campaignList) {
    int i = 0;
    TableSectionElement tbody = campaignTable.getTBodies().getItem(0);
    for (final Campaign cam : campaignList) {
      TableRowElement tr = tbody.insertRow(i);
      tr.setAttribute("class", "items");

      TableCellElement tdName = tr.insertCell(0);
      tdName.setInnerText(cam.getTitle());

      TableCellElement tdCat = tr.insertCell(1);
      tdCat.setAttribute("class", "text-right color-success");
      tdCat.setInnerText(cam.getTags().get(0));

      TableCellElement tcDate = tr.insertCell(2);
      tcDate.setInnerText(cam.getDate());

      TableCellElement tcOp = tr.insertCell(3);
      tcOp.setClassName("text-center");

      AnchorElement aEdit = Document.get().createAnchorElement();
      aEdit.setClassName("label label-default");
      aEdit.setInnerHTML("<i class=\"fa fa-pencil\"></i>");

      AnchorElement aDel = Document.get().createAnchorElement();
      aDel.setClassName("label label-danger");
      aDel.setInnerHTML("<i class=\"fa fa-times\"></i>");

      tcOp.appendChild(aEdit);
      tcOp.appendChild(aDel);

      Event.sinkEvents(aEdit, Event.ONCLICK);
      Event.setEventListener(
          aEdit,
          new EventListener() {
            @Override
            public void onBrowserEvent(Event event) {
              System.out.println("ok");
              if (Event.ONCLICK == event.getTypeInt()) {
                listener.goTo(new EditCampaignPlace("", cam));
              }
            }
          });

      Event.sinkEvents(aDel, Event.ONCLICK);
      Event.setEventListener(
          aDel,
          new EventListener() {
            @Override
            public void onBrowserEvent(Event event) {
              if (Event.ONCLICK == event.getTypeInt()) {
                Window.alert("Borrar " + cam.getTitle());
              }
            }
          });
      i++;
    }
  }
Beispiel #4
0
  /** Tests createLoadEvent(). */
  public void testTriggerLoadEvent() {
    ImgEventListener listener = new ImgEventListener("load");
    Event.setEventListener(parent, listener);
    Event.setEventListener(img, listener);

    img.dispatchEvent(Document.get().createLoadEvent());

    assertTrue("Expected img to receive event", listener.imgReceived);
  }
Beispiel #5
0
  /**
   * Tests createErrorEvent().
   *
   * <p>Failed in all modes due to HtmlUnit bug: https://sourceforge.net/tracker/?func
   * =detail&aid=2888342&group_id=47038&atid=448266
   */
  @DoNotRunWith({Platform.HtmlUnitBug})
  public void testTriggerErrorEvent() {
    ImgEventListener listener = new ImgEventListener("error");
    Event.setEventListener(parent, listener);
    Event.setEventListener(img, listener);

    img.dispatchEvent(Document.get().createErrorEvent());

    assertTrue("Expected child to receive event", listener.imgReceived);
  }
Beispiel #6
0
  /** Tests createChangeEvent(). */
  public void testTriggerChangeEvent() {
    BubbleAssertingEventListener listener = new BubbleAssertingEventListener("change", false);
    Event.setEventListener(parent, listener);
    Event.setEventListener(child, listener);

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

    assertTrue("Expected child to receive event", listener.childReceived);
  }
  @Override
  public void sinkEvents() {
    Element dashBoardView = DOM.getElementById("dashBoardView");
    Event.sinkEvents(dashBoardView, Event.ONCLICK);
    Event.setEventListener(
        dashBoardView,
        new EventListener() {
          @Override
          public void onBrowserEvent(Event event) {
            if (Event.ONCLICK == event.getTypeInt()) {
              listener.goTo(new DashBoardPlace(""));
            }
          }
        });

    Element beaconsView = DOM.getElementById("beaconsView");
    Event.sinkEvents(beaconsView, Event.ONCLICK);
    Event.setEventListener(
        beaconsView,
        new EventListener() {
          @Override
          public void onBrowserEvent(Event event) {
            if (Event.ONCLICK == event.getTypeInt()) {
              listener.goTo(new BeaconsPlace(""));
            }
          }
        });

    Element campaignView = DOM.getElementById("campaignView");
    Event.sinkEvents(campaignView, Event.ONCLICK);
    Event.setEventListener(
        campaignView,
        new EventListener() {
          @Override
          public void onBrowserEvent(Event event) {
            if (Event.ONCLICK == event.getTypeInt()) {
              listener.goTo(new CampaignPlace(""));
            }
          }
        });

    Element beacon = DOM.getElementById("beacon");
    Event.sinkEvents(beacon, Event.ONCLICK);
    Event.setEventListener(
        beacon,
        new EventListener() {
          @Override
          public void onBrowserEvent(Event event) {
            if (Event.ONCLICK == event.getTypeInt()) {
              listener.goTo(new BeaconsPlace(""));
            }
          }
        });
  }
Beispiel #8
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);
  }
Beispiel #9
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);
  }
Beispiel #10
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);
  }
Beispiel #11
0
  /** Tests that {@link Event#getCurrentEvent()} returns the right value for synthesized events. */
  public void testGetCurrentEvent() {
    CurrentEventListener listener = new CurrentEventListener();
    Event.setEventListener(child, listener);

    // Test all three major event types.
    child.dispatchEvent(Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false));
    child.dispatchEvent(Document.get().createKeyPressEvent(false, false, false, false, 65));
    child.dispatchEvent(Document.get().createFocusEvent());

    assertTrue("Expecting click as current event", listener.gotClick);
    assertTrue("Expecting keypress as current event", listener.gotKeyPress);
    assertTrue("Expecting focus as current event", listener.gotFocus);
  }
Beispiel #12
0
  /** Tests createClickEvent(). */
  public void testTriggerClickEvent() {
    BubbleAssertingEventListener listener =
        new BubbleAssertingEventListener("click", true) {
          @Override
          public void onBrowserEvent(Event event) {
            if (cancelled) {
              return;
            }
            super.onBrowserEvent(event);
            assertMouseCoordinates(event);
          }
        };
    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);
    assertTrue("Expected parent to receive event", listener.parentReceived);
  }
Beispiel #13
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;
  }
Beispiel #14
0
  public EventListener acquireLockOnDemand(final Element element) {
    Event.sinkEvents(element, lockDemandDetector.getLockDemandEventTypes());

    EventListener lockDemandListener =
        new EventListener() {

          @Override
          public void onBrowserEvent(Event event) {
            if (isLockedByCurrentUser()) {
              return;
            }

            if (lockDemandDetector.isLockRequired(event)) {
              acquireLock();
            }
          }
        };

    Event.setEventListener(element, lockDemandListener);

    return lockDemandListener;
  }