Пример #1
0
 private NetworkGetResponseBodyResponseMessage synthesizeResourceContentResponseMessage()
     throws MalformedDevtoolsMessageException {
   String responseString =
       "{\"id\":4,\"result\":{\"body\":\"<HTML>\\n<BODY>\\n<P>Hello World<\\/P>\\n"
           + "<IMG SRC=\\\"http:\\/\\/184.73.115.184\\/gaga\\/foo.png\\\">\\n"
           + "<IMG SRC=\\\"http:\\/\\/184.73.115.184\\/gaga\\/foo2.png\\\">\\n<\\/BODY>\\n"
           + "<\\/HTML>\\n\",\"base64Encoded\":false}}";
   JSONObject json = (JSONObject) JSONValue.parse(responseString);
   return (NetworkGetResponseBodyResponseMessage) devtoolsMessageFactory.decodeDevtoolsJson(json);
 }
Пример #2
0
  private DevtoolsMessage[] synthesizeRequestResponsePair(
      String url,
      BigDecimal requestTime,
      BigDecimal responseTime,
      BigDecimal loadTime,
      boolean connectionReused,
      long dnsStart,
      long dnsEnd,
      long connectStart,
      long connectEnd,
      long sslStart,
      long sslEnd,
      long proxyStart,
      long proxyEnd,
      long sendStart,
      long sendEnd,
      long receiveHeadersEnd)
      throws MalformedDevtoolsMessageException {

    DevtoolsMessage[] retval = new DevtoolsMessage[3];

    String requestJson =
        "{\"method\": \"Network.requestWillBeSent\", \"params\":"
            + "{\"documentURL\": \""
            + url
            + "\", \"initiator\": { \"type\": \"other\"},"
            + "\"loaderId\": \"16233.1\", \"request\": {\"headers\": {}, \"method\": \"GET\","
            + "\"url\": \""
            + url
            + "\"}, \"requestId\": \"16233.2\", \"stackTrace\": [],"
            + "\"timestamp\": "
            + requestTime.toString()
            + "}}";

    retval[0] =
        devtoolsMessageFactory.decodeDevtoolsJson((JSONObject) JSONValue.parse(requestJson));

    String responseJson =
        "{\"method\": \"Network.responseReceived\", \"params\":"
            + "{\"frameId\": \"16233.2\", \"loaderId\": \"16233.1\", \"requestId\": \"16233.2\","
            + "\"response\": {\"connectionId\": 26, \"connectionReused\": "
            + connectionReused
            + "\"headers\": {\"Content-Length\":\"1000\"}, \"headersText\": "
            + "\"Content-Length: 1000\r\n\r\n\", \"bodySize\": 850,"
            + "\"timing\": { ";
    responseJson += "\"requestTime\": " + requestTime.toString() + ", ";
    responseJson += "\"dnsStart\": " + dnsStart + ", ";
    responseJson += "\"dnsEnd\": " + dnsEnd + ", ";
    responseJson += "\"connectStart\": " + connectStart + ", ";
    responseJson += "\"connectEnd\": " + connectEnd + ", ";
    responseJson += "\"sslStart\": " + sslStart + ", ";
    responseJson += "\"sslEnd\": " + sslEnd + ", ";
    responseJson += "\"proxyStart\": " + proxyStart + ", ";
    responseJson += "\"proxyEnd\": " + proxyEnd + ", ";
    responseJson += "\"sendStart\": " + sendStart + ", ";
    responseJson += "\"sendEnd\": " + sendEnd + ", ";
    responseJson += "\"receiveHeadersEnd\": " + receiveHeadersEnd + ", ";
    responseJson +=
        "}, \"status\": 200,"
            + "\"url\": \""
            + url
            + "\",}, \"timestamp\": "
            + responseTime.toString()
            + ", \"type\": \"Document\"}}";

    retval[1] =
        devtoolsMessageFactory.decodeDevtoolsJson((JSONObject) JSONValue.parse(responseJson));

    String networkLoadingFinishedJson =
        "{\"method\": \"Network.loadingFinished\", \"params\": { "
            + "\"requestId\": \"16233.2\", \"timestamp\": "
            + loadTime.toString()
            + "}}";

    retval[2] =
        devtoolsMessageFactory.decodeDevtoolsJson(
            (JSONObject) JSONValue.parse(networkLoadingFinishedJson));

    return retval;
  }