@Test
  public void testFireFocusEventBeforeMouseEvent() {
    final java.util.List<TypedEvent> eventLog = new ArrayList<TypedEvent>();
    Button button = new Button(shell, SWT.PUSH);
    getRemoteObject(button).setHandler(new ButtonOperationHandler(button));
    Fixture.markInitialized(button);
    button.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseDown(MouseEvent event) {
            eventLog.add(event);
          }
        });
    button.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusGained(FocusEvent event) {
            eventLog.add(event);
          }
        });
    Fixture.fakeNewRequest();
    fakeMouseDownRequest(button, 1, 2);
    Fixture.fakeSetProperty(getId(display), "focusControl", getId(button));
    Fixture.fakeNotifyOperation(getId(button), EVENT_FOCUS_IN, null);

    Fixture.executeLifeCycleFromServerThread();

    assertEquals(FocusEvent.class, eventLog.get(0).getClass());
    assertEquals(MouseEvent.class, eventLog.get(1).getClass());
  }
Beispiel #2
0
  @Test
  public void testSelectionAfterRemoveAll() {
    combo = new Combo(shell, SWT.READ_ONLY);
    Fixture.markInitialized(display);
    Fixture.markInitialized(combo);
    combo.add("item 1");
    combo.select(0);
    Button button = new Button(shell, SWT.PUSH);
    button.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            combo.removeAll();
            combo.add("replacement for item 1");
            combo.select(0);
          }
        });

    // Simulate button click that executes widgetSelected
    Fixture.fakeNotifyOperation(getId(button), ClientMessageConst.EVENT_SELECTION, null);
    Fixture.executeLifeCycleFromServerThread();

    Message message = Fixture.getProtocolMessage();
    assertEquals(new Integer(0), message.findSetProperty(combo, PROP_SELECTION_INDEX));
  }
Beispiel #3
0
  @Test
  public void testTextIsNotRenderdBack() {
    Fixture.markInitialized(display);
    Fixture.markInitialized(shell);
    Fixture.markInitialized(combo);

    Fixture.fakeSetParameter(getId(combo), "text", "some text");
    Fixture.executeLifeCycleFromServerThread();

    // ensure that no text is sent back to the client
    Message message = Fixture.getProtocolMessage();
    assertNull(message.findSetOperation(combo, "text"));
    assertEquals("some text", combo.getText());
  }
Beispiel #4
0
  @Test
  public void testTextSelectionWithVerifyEvent_ListenerAdjustsSelection() {
    combo.setText("");
    combo.addVerifyListener(
        new VerifyListener() {
          public void verifyText(VerifyEvent event) {
            event.text = "";
          }
        });

    fakeTextAndSelectionParameters("verify me", 1, 0);
    Fixture.executeLifeCycleFromServerThread();

    assertEquals(new Point(0, 0), combo.getSelection());
    assertEquals("", combo.getText());
  }
  @Test
  public void testPhase() {
    final StringBuilder log = new StringBuilder();
    Button button = new Button(shell, SWT.PUSH);
    getRemoteObject(button).setHandler(new ButtonOperationHandler(button));
    Fixture.markInitialized(button);
    button.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent event) {
            log.append(EVENT_FIRED);
          }
        });
    Fixture.fakeNewRequest();
    Fixture.fakeNotifyOperation(getId(button), ClientMessageConst.EVENT_SELECTION, null);
    LifeCycle lifeCycle = getApplicationContext().getLifeCycleFactory().getLifeCycle();
    lifeCycle.addPhaseListener(
        new PhaseListener() {
          private static final long serialVersionUID = 1L;

          public void beforePhase(PhaseEvent event) {
            log.append("before" + event.getPhaseId() + "|");
          }

          public void afterPhase(PhaseEvent event) {
            log.append("after" + event.getPhaseId() + "|");
          }

          public PhaseId getPhaseId() {
            return PhaseId.ANY;
          }
        });

    Fixture.executeLifeCycleFromServerThread();

    String expected =
        BEFORE_PREPARE_UI_ROOT
            + AFTER_PREPARE_UI_ROOT
            + BEFORE_READ_DATA
            + AFTER_READ_DATA
            + BEFORE_PROCESS_ACTION
            + EVENT_FIRED
            + AFTER_PROCESS_ACTION
            + BEFORE_RENDER
            + AFTER_RENDER;
    assertEquals(expected, log.toString());
  }
Beispiel #6
0
  @Test
  public void testTextSelectionWithVerifyEvent_EmptyListener() {
    Fixture.markInitialized(display);
    Fixture.markInitialized(shell);
    Fixture.markInitialized(combo);
    VerifyListener listener = mock(VerifyListener.class);
    combo.addVerifyListener(listener);

    fakeTextAndSelectionParameters("verify me", 1, 0);
    Fixture.executeLifeCycleFromServerThread();

    verify(listener, times(1)).verifyText(any(VerifyEvent.class));
    assertEquals("verify me", combo.getText());
    assertEquals(new Point(1, 1), combo.getSelection());
    Message message = Fixture.getProtocolMessage();
    assertNull(message.findSetOperation(combo, "text"));
    assertNull(message.findSetOperation(combo, "selection"));
  }
Beispiel #7
0
  @Test
  public void testReadText_WithVerifyListener() {
    Fixture.fakePhase(PhaseId.PROCESS_ACTION);
    Fixture.markInitialized(display);
    Fixture.markInitialized(shell);
    Fixture.markInitialized(combo);
    combo.setText("some text");
    VerifyListener listener = mock(VerifyListener.class);
    combo.addVerifyListener(listener);

    Fixture.fakeSetParameter(getId(combo), "text", "verify me");
    Fixture.executeLifeCycleFromServerThread();

    assertEquals("verify me", combo.getText());
    ArgumentCaptor<VerifyEvent> captor = ArgumentCaptor.forClass(VerifyEvent.class);
    verify(listener, times(1)).verifyText(captor.capture());
    VerifyEvent event = captor.getValue();
    assertEquals("verify me", event.text);
    assertEquals(0, event.start);
    assertEquals(9, event.end);
  }