mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 15:55:36 +00:00
Bug 1529297 - Make GeckoWebExecutor.resolve() fail with UnknownHostException r=geckoview-reviewers,esawin
Also clean up some doc strings. Differential Revision: https://phabricator.services.mozilla.com/D20498 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
0e59b4108e
commit
6f4446a1d8
@ -42,6 +42,7 @@ import org.mozilla.geckoview.WebResponse
|
||||
import org.mozilla.geckoview.test.util.Environment
|
||||
import org.mozilla.geckoview.test.util.HttpBin
|
||||
import org.mozilla.geckoview.test.util.RuntimeCreator
|
||||
import java.net.UnknownHostException
|
||||
|
||||
@MediumTest
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@ -249,9 +250,14 @@ class WebExecutorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFetchUnknownHost() {
|
||||
thrown.expect(equalTo(WebRequestError(WebRequestError.ERROR_UNKNOWN_HOST, WebRequestError.ERROR_CATEGORY_URI)))
|
||||
fetch(WebRequest("https://this.should.not.resolve"))
|
||||
}
|
||||
|
||||
@Test(expected = UnknownHostException::class)
|
||||
fun testResolveError() {
|
||||
thrown.expect(equalTo(WebRequestError(WebRequestError.ERROR_UNKNOWN_HOST, WebRequestError.ERROR_CATEGORY_URI)));
|
||||
executor.resolve("this should not resolve").poll()
|
||||
executor.resolve("this.should.not.resolve").poll()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -14,6 +14,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
|
||||
@ -87,7 +88,9 @@ public class GeckoWebExecutor {
|
||||
* Send the given {@link WebRequest}.
|
||||
*
|
||||
* @param request A {@link WebRequest} instance
|
||||
* @return A GeckoResult which will be completed with a {@link WebResponse}
|
||||
* @return A {@link GeckoResult} which will be completed with a {@link WebResponse}. If the
|
||||
* request fails to complete, the {@link GeckoResult} will be completed exceptionally
|
||||
* with a {@link WebRequestError}.
|
||||
* @throws IllegalArgumentException if request is null or otherwise unusable.
|
||||
*/
|
||||
public @NonNull GeckoResult<WebResponse> fetch(final @NonNull WebRequest request) {
|
||||
@ -99,7 +102,9 @@ public class GeckoWebExecutor {
|
||||
*
|
||||
* @param request A {@link WebRequest} instance
|
||||
* @param flags The specified flags. One or more of {@link FetchFlags}.
|
||||
* @return A GeckoResult which will be completed with a {@link WebResponse}
|
||||
* @return A {@link GeckoResult} which will be completed with a {@link WebResponse}. If the
|
||||
* request fails to complete, the {@link GeckoResult} will be completed exceptionally
|
||||
* with a {@link WebRequestError}.
|
||||
* @throws IllegalArgumentException if request is null or otherwise unusable.
|
||||
*/
|
||||
public @NonNull GeckoResult<WebResponse> fetch(final @NonNull WebRequest request,
|
||||
@ -137,7 +142,8 @@ public class GeckoWebExecutor {
|
||||
*
|
||||
* @param host An Internet host name, e.g. mozilla.org.
|
||||
* @return A {@link GeckoResult} which will be fulfilled with a {@link List}
|
||||
* of {@link InetAddress}.
|
||||
* of {@link InetAddress}. In case of failure, the {@link GeckoResult}
|
||||
* will be completed exceptionally with a {@link java.net.UnknownHostException}.
|
||||
*/
|
||||
public GeckoResult<InetAddress[]> resolve(final @NonNull String host) {
|
||||
final GeckoResult<InetAddress[]> result = new GeckoResult<>();
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
#include "nsNetUtil.h" // for NS_NewURI, NS_NewChannel, NS_NewStreamLoader
|
||||
|
||||
#include "InetAddress.h" // for java::sdk::InetAddress
|
||||
#include "InetAddress.h" // for java::sdk::InetAddress and java::sdk::UnknownHostException
|
||||
|
||||
namespace mozilla {
|
||||
using namespace net;
|
||||
@ -331,19 +331,25 @@ class DNSListener final : public nsIDNSListener {
|
||||
OnLookupComplete(nsICancelable* aRequest, nsIDNSRecord* aRecord,
|
||||
nsresult aStatus) override {
|
||||
if (NS_FAILED(aStatus)) {
|
||||
CompleteWithError(mResult, aStatus);
|
||||
CompleteUnknownHostError();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = CompleteWithRecord(aRecord);
|
||||
if (NS_FAILED(rv)) {
|
||||
CompleteWithError(mResult, rv);
|
||||
CompleteUnknownHostError();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void CompleteUnknownHostError() {
|
||||
java::sdk::UnknownHostException::LocalRef error =
|
||||
java::sdk::UnknownHostException::New();
|
||||
mResult->CompleteExceptionally(error.Cast<jni::Throwable>());
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
OnLookupByTypeComplete(nsICancelable* aRequest, nsIDNSByTypeRecord* aRecord,
|
||||
nsresult aStatus) override {
|
||||
@ -548,7 +554,9 @@ void WebExecutorSupport::Resolve(jni::String::Param aUri,
|
||||
nsCString uri = aUri->ToCString();
|
||||
nsresult rv = ResolveHost(uri, result);
|
||||
if (NS_FAILED(rv)) {
|
||||
CompleteWithError(result, rv);
|
||||
java::sdk::UnknownHostException::LocalRef error =
|
||||
java::sdk::UnknownHostException::New();
|
||||
result->CompleteExceptionally(error.Cast<jni::Throwable>());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
# We only want getByAddress(String, byte[])
|
||||
[java.net.InetAddress = skip:true]
|
||||
getByAddress(Ljava/lang/String;[B)Ljava/net/InetAddress; = skip:false
|
||||
|
||||
[java.net.UnknownHostException = skip:true]
|
||||
<init>()V =
|
||||
|
Loading…
Reference in New Issue
Block a user