コード例 #1
0
ファイル: TestRunner.java プロジェクト: is00hcw/page-speed
 // Receive a notification message from the Chrome tab.
 @Override
 public synchronized void handleNotification(String method, JSONObject params) {
   this.testData.addDataForHar(method, params);
   try {
     if (this.phase == Phase.ABOUT_BLANK) {
       // Once we've loaded about:blank, we can begin the real test.
       if (method.equals("Page.loadEventFired")) {
         this.resetBrowserAndBeginLoadingPage();
       }
     } else if (method.equals("Network.requestWillBeSent")) {
       if (this.mainRequestId == null) {
         this.mainRequestId = Json.getString(params, REQUEST_ID_KEY);
       }
     } else if (method.equals("Network.loadingFinished")
         || method.equals("Network.resourceLoadedFromMemoryCache")) {
       this.fetchResourceContent(Json.getString(params, REQUEST_ID_KEY));
     } else if (method.equals("Network.responseReceived")) {
       if (this.mainRequestId != null
           && this.mainRequestId.equals(Json.getString(params, REQUEST_ID_KEY))) {
         this.startTimestampMillis =
             1000.0
                 * Json.getDouble(
                     Json.getObject(Json.getObject(params, "response"), "timing"),
                     "requestTime");
         this.testData.setTimeToFirstByteMillis(
             1000.0 * Json.getDouble(params, "timestamp") - this.startTimestampMillis);
       }
     } else if (method.equals("Page.domContentEventFired")) {
       if (!Double.isNaN(this.startTimestampMillis)) {
         this.testData.setTimeToBasePageCompleteMillis(
             1000.0 * Json.getDouble(params, "timestamp") - this.startTimestampMillis);
       } else {
         this.abortTest("Saw Page.domContentEventFired before receiving main response");
       }
     } else if (method.equals("Page.loadEventFired")) {
       if (!Double.isNaN(this.startTimestampMillis)) {
         this.testData.setLoadTimeMillis(
             1000.0 * Json.getDouble(params, "timestamp") - this.startTimestampMillis);
         this.fetchDomTree();
       } else {
         this.abortTest("Saw Page.loadEventFired before receiving main response");
       }
     } else if (method.equals("Timeline.eventRecorded")) {
       this.testData.addTimelineEvent(Json.getObject(params, "record"));
     }
   } catch (JsonException e) {
     this.abortTest("Bad JSON from Chrome: " + e.getMessage());
   }
 }
コード例 #2
0
ファイル: TestRunner.java プロジェクト: is00hcw/page-speed
 // Callback for fetchResourceContent().
 private synchronized void handleResourceContent(String requestId, JSONObject result) {
   try {
     this.testData.addResourceContent(
         requestId, Json.getString(result, "body"), Json.getBoolean(result, "base64Encoded"));
     this.checkIfDone();
   } catch (JsonException e) {
     this.abortTest("Bad JSON from Chrome: " + e.getMessage());
   }
 }
コード例 #3
0
ファイル: TestRunner.java プロジェクト: is00hcw/page-speed
 // Callback for fetchDomTree().
 private synchronized void handleDomTree(JSONObject result) {
   assert this.phase == Phase.FETCHING_DOM;
   this.phase = Phase.FINISHING;
   try {
     this.testData.setDomString(Json.getString(Json.getObject(result, "result"), "value"));
     this.checkIfDone();
   } catch (JsonException e) {
     this.abortTest("Bad JSON from Chrome: " + e.getMessage());
   }
 }