Skip to content

Commit

Permalink
[java] Fixing NetworkInterceptor (or commands sent by Fetch, even)
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Sep 18, 2019
1 parent 437cca6 commit 66c07d3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
15 changes: 8 additions & 7 deletions java/client/src/org/openqa/selenium/devtools/fetch/Fetch.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public static Command<Void> failRequest(RequestId requestId, ErrorReason errorRe
Objects.requireNonNull(requestId, "requestId is required");
Objects.requireNonNull(errorReason, "errorReason is required");
return new Command<>(
"Fetch.failRequest", ImmutableMap.of("requestId", requestId, "errorReason", errorReason));
"Fetch.failRequest",
ImmutableMap.of("requestId", requestId.toString(), "errorReason", errorReason));
}

/**
Expand All @@ -88,12 +89,12 @@ public static Command<Void> fulfillRequest(
throw new DevToolsException("Invalid http responseCode");
}
responseHeaders = validateHeaders(responseHeaders);
params.put("requestId", requestId);
params.put("requestId", requestId.toString());
params.put("responseHeaders", responseHeaders);
params.put("responseCode", responseCode);
body.ifPresent(b -> params.put("body", b));
responsePhrase.ifPresent(phrase -> params.put("responsePhrase", phrase));
return new Command<>("Fetch.failRequest", params.build());
return new Command<Void>("Fetch.fulfillRequest", params.build());
}

/**
Expand All @@ -107,7 +108,7 @@ public static Command<Void> continueRequest(
Optional<List<HeaderEntry>> headers) {
final ImmutableMap.Builder<String, Object> params = ImmutableMap.builder();
Objects.requireNonNull(requestId, "requestId is required");
params.put("requestId", requestId);
params.put("requestId", requestId.toString());
url.ifPresent(s -> params.put("url", s));
method.ifPresent(s -> params.put("method", s));
postData.ifPresent(s -> params.put("postData", s));
Expand All @@ -124,7 +125,7 @@ public static Command<Void> continueWithAuth(
Objects.requireNonNull(authChallengeResponse, "authChallengeResponse is required");
return new Command<>(
"Fetch.continueWithAuth",
ImmutableMap.of("requestId", requestId, "authChallengeResponse", authChallengeResponse));
ImmutableMap.of("requestId", requestId.toString(), "authChallengeResponse", authChallengeResponse));
}

/**
Expand All @@ -137,7 +138,7 @@ public static Command<ResponseBody> getResponseBody(RequestId requestId) {
Objects.requireNonNull(requestId, "requestId is required");
return new Command<>(
"Fetch.getResponseBody",
ImmutableMap.of("requestId", requestId),
ImmutableMap.of("requestId", requestId.toString()),
map("body", ResponseBody.class));
}

Expand All @@ -153,7 +154,7 @@ public static Command<StreamHandle> takeResponseBodyAsStream(RequestId requestId
Objects.requireNonNull(requestId, "requestId is required");
return new Command<>(
"Fetch.takeResponseBodyAsStream",
ImmutableMap.of("requestId", requestId),
ImmutableMap.of("requestId", requestId.toString()),
map("stream", StreamHandle.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@ private static HeaderEntry fromJson(JsonInput input) {
}
return new HeaderEntry(name, value);
}

public String getName() {
return name;
}

public String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ public RequestId(String id) {
private static RequestId fromJson(JsonInput input) {
return new RequestId(input.nextString());
}

public String toString() {
return id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.List;
import java.util.Optional;

// TODO: Add some checks, the tests does not ensure a listener is actually invoked
public class ChromeDevToolsFetchTests extends ChromeDevToolsTestBase {

@Test
Expand Down

0 comments on commit 66c07d3

Please sign in to comment.