/**
   * Types characters and check that output will not change for defined time (queue delay) and when
   * it actually change, check that it have value of input and that counters are printed right.
   */
  @Test
  public void testRequestDelay() {
    Integer[] delays = stringsToInteger.transform(MSG_DELAY_LIST);

    for (final int delay : delays) {
      setQueue(delay, false, false);

      // initiate time borders for the test
      final long start = currentTime();
      final long end = start + 10000;
      // create a buffer for whole text in input
      final StringBuffer typedText = new StringBuffer();

      // type at least 3 and at most 100 characters and don't exhause
      // border of 10 sec. for this tests
      while (typedText.length() <= 3 || (typedText.length() <= 100 && currentTime() < end)) {
        final String lastText = typedText.toString();

        // type char '1-9' like last decimal char of buffer's length
        typedText.append(Integer.toString(typedText.length() % 10));
        selenium.type(LOC_INPUT_TYPED_TEXT, typedText.toString());

        final long eventTime = currentTime();
        selenium.fireEvent(LOC_INPUT_TYPED_TEXT, Event.KEYUP);

        // check that text will not change for defined time (delay)
        Wait.dontFail()
            .interval(delay / 4)
            .timeout(delay)
            .until(
                new Condition() {
                  public boolean isTrue() {
                    final String actualText = selenium.getText(LOC_OUTPUT_TYPED_TEXT);
                    long currentTime = currentTime();
                    assertTrue(currentTime >= eventTime + delay || lastText.equals(actualText));
                    return currentTime >= eventTime + delay;
                  }
                });

        // wait for output actually changes to value of input
        waitForTextEquals(LOC_OUTPUT_TYPED_TEXT, typedText.toString());

        // check that all output counts are right
        String actualCount = Integer.toString(typedText.length());
        assertEquals(actualCount, selenium.getText(LOC_OUTPUT_EVENTS_COUNT));
        assertEquals(actualCount, selenium.getText(LOC_OUTPUT_REQUESTS_COUNT));
        assertEquals(actualCount, selenium.getText(LOC_OUTPUT_DOM_UPDATES_COUNT));
      }
    }
  }
Пример #2
0
  @Test
  public void testInvalidBewit4() throws Exception {
    // Test an invalid bewit due to missing mac
    SimpleHttpServer server = new SimpleHttpServer(this.testcredentials1, null);

    // Calculate expiry from ttl and current time
    Long expiry = System.currentTimeMillis() / 1000L + 120L;
    //    final String mac = Hawk.calculateMAC(this.testcredentials1, Hawk.AuthType.BEWIT, expiry,
    // new URI(BASEBEWITURI), null, null, null, null);

    final StringBuffer sb = new StringBuffer(256);
    sb.append(this.testcredentials1.getKeyId());
    sb.append('\\');
    sb.append(String.valueOf(expiry));
    sb.append('\\');
    sb.append('\\');
    final String bewit = BaseEncoding.base64().encode(sb.toString().getBytes());

    try {
      URI testUri = new URI(BASEBEWITURI + "?bewit=" + bewit);
      final HttpURLConnection connection = connect(testUri, null, null);
      assertEquals(connection.getResponseCode(), 401);
    } finally {
      server.stop();
    }
  }
  private void fastTyping() {
    StringBuffer text = new StringBuffer();

    for (int i = 1; i <= 75; i++) {
      text.append(MSG_CHAR_FAST_TYPING);

      selenium.type(LOC_INPUT_TYPED_TEXT, text.toString());
      selenium.fireEvent(LOC_INPUT_TYPED_TEXT, Event.KEYUP);
    }

    waitModelUpdate.waitForTimeout();
  }