Пример #1
0
 /** Tests functionality of addResourceContentMessage. */
 @Test
 public void addResourceContentMessage() throws Exception {
   HarObject har = new HarObject();
   har.resources.put("23255.2", new HarResource("myPage"));
   NetworkGetResponseBodyResponseMessage response = synthesizeResourceContentResponseMessage();
   har.addResourceContentMessage(response, "23255.2");
   assertEquals(
       response.getJson(),
       har.resources.get("23255.2").getNetworkGetResponseBodyResponseMessage().getJson());
   try {
     har.addResourceContentMessage(synthesizeResourceContentResponseMessage(), "23255.9");
     fail();
   } catch (HarConstructionException expectedException) {
     /* Exception is expected because resource with ID 23255.9 does not exist. */
   }
   try {
     har.addResourceContentMessage(synthesizeResourceContentResponseMessage(), "23255.2");
     fail();
   } catch (HarConstructionException expectedException) {
     /* Exception is expected because content already added to this resource. */
   }
 }
Пример #2
0
  /** Tests that various methods succeed or fail before and after HAR population. */
  @Test
  public void harPopulationState() throws Exception {
    HarObject har = new HarObject();
    try {
      JSONObject harJson = har.getHar();
      fail();
    } catch (IllegalStateException e) {
      /* Exception is expected since HAR has not been populated yet. */
    }
    try {
      JSONObject pageTimings = har.getPageTimings();
      fail();
    } catch (IllegalStateException e) {
      /* Exception is expected since HAR has not been populated yet. */
    }
    TestUtils.populateTestHar(devtoolsMessageFactory, har, DEVTOOLS_MESSAGES_JSON);
    har.createHarFromMessages();

    // These should now succeed
    JSONObject harJson = har.getHar();
    JSONObject pageTimings = har.getPageTimings();
    try {
      har.addResourceContentMessage(synthesizeResourceContentResponseMessage(), "23255.2");
      fail();
    } catch (IllegalStateException e) {
      /* Exception is expected because HAR already populated */
    }
    try {
      TestUtils.populateTestHar(devtoolsMessageFactory, har, DEVTOOLS_MESSAGES_JSON);
      fail();
    } catch (IllegalStateException e) {
      /* Exception is expected because HAR already populated */
    }
    try {
      har.createHarFromMessages();
      fail();
    } catch (IllegalStateException e) {
      /* Exception is expected because HAR already populated */
    }

    har.clearData();
    try {
      harJson = har.getHar();
      fail();
    } catch (IllegalStateException e) {
      /* Exception is expected since HAR has been cleared */
    }
  }