Пример #1
0
 // TODO(mdsteele): Make a cleaner API than this (will need to change some other classes).
 public synchronized JSONObject getMetrics() {
   JSONObject obj = new JSONObject();
   Json.put(obj, "time_to_first_byte_ms", this.timeToFirstByteMillis);
   Json.put(obj, "time_to_base_page_complete_ms", this.timeToBasePageCompleteMillis);
   Json.put(obj, "load_time_ms", this.loadTimeMillis);
   return obj;
 }
Пример #2
0
 public synchronized void addResourceContent(
     String requestId, String body, boolean isBase64Encoded) {
   JSONObject result = new JSONObject();
   Json.put(result, "content", body);
   Json.put(result, "base64Encoded", isBase64Encoded);
   JSONObject obj = new JSONObject();
   Json.put(obj, "method", "__Internal.resourceContent");
   Json.put(obj, "requestId", requestId);
   Json.put(obj, "result", result);
   this.dataForHar.add(obj);
 }
Пример #3
0
 // Ask the tab to load the given URL.
 private synchronized void startLoadingUrl(String url) {
   // A previous version of Chrome had a "Page.load" method, but that has since been removed (at
   // least as of M16).  Simply evaluating "window.location.href=url" seems to work fine,
   // though.
   JSONObject params = new JSONObject();
   Json.put(params, "expression", "window.location.href=" + JSONValue.toJSONString(url));
   Json.put(params, "returnByValue", true);
   this.tab.asyncCall(
       "Runtime.evaluate",
       params,
       new Callback() {
         public void onSuccess(JSONObject result) {}
       });
 }
Пример #4
0
    // Enter the FETCHING_DOM phase; ask the Chrome tab to retrieve the DOM tree from the page.
    private synchronized void fetchDomTree() {
      assert this.phase == Phase.LOADING_PAGE;
      this.phase = Phase.FETCHING_DOM;

      JSONObject params = new JSONObject();
      Json.put(params, "expression", DOM_COLLECTOR_SCRIPT);
      Json.put(params, "returnByValue", true);

      this.tab.asyncCall(
          "Runtime.evaluate",
          params,
          new Callback() {
            public void onSuccess(JSONObject response) {
              RunnerImpl.this.handleDomTree(response);
            }
          });
    }
Пример #5
0
    // Ask the Chrome tab to retrieve the contents of the specified resource.  The requestId object
    // is some key object given to us by the Chrome tab.
    private synchronized void fetchResourceContent(final String requestId) {
      JSONObject params = new JSONObject();
      Json.put(params, REQUEST_ID_KEY, requestId);
      this.tab.asyncCall(
          "Network.getResponseBody",
          params,
          new AsyncCallback() {
            public void onSuccess(JSONObject response) {
              RunnerImpl.this.handleResourceContent(requestId, response);
            }

            public void onError(String message) {
              // Some resources just don't have data; that's okay, so if that's the error we got,
              // ignore it.
              if (!message.equals("No data found for resource with given identifier")) {
                RunnerImpl.this.abortTest(message);
              }
            }
          });
    }
Пример #6
0
 // TODO(mdsteele): Make a cleaner API than this (will need to change TestRunner).
 public synchronized void addDataForHar(String methodName, JSONObject params) {
   JSONObject obj = new JSONObject();
   Json.put(obj, "method", methodName);
   Json.put(obj, "params", params);
   this.dataForHar.add(obj);
 }