@SmallTest @Feature({"AndroidWebView", "Navigation"}) public void testNotCalledForIframeHttpNavigations() throws Throwable { standardSetup(); final String iframeRedirectTargetUrl = createRedirectTargetPage(); final String iframeRedirectUrl = mWebServer.setRedirect("/302.html", iframeRedirectTargetUrl); final String pageWithIframeUrl = addPageToTestServer( "/iframe_intercept.html", makeHtmlPageFrom("", "<iframe src=\"" + iframeRedirectUrl + "\" />")); final int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper.getCallCount(); assertEquals(0, mWebServer.getRequestCount(REDIRECT_TARGET_PATH)); loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), pageWithIframeUrl); // Wait for the redirect target URL to be fetched from the server. poll( new Callable<Boolean>() { @Override public Boolean call() throws Exception { return mWebServer.getRequestCount(REDIRECT_TARGET_PATH) == 1; } }); assertEquals(shouldOverrideUrlLoadingCallCount, mShouldOverrideUrlLoadingHelper.getCallCount()); }
@SmallTest @Feature({"AndroidWebView", "Navigation"}) public void testCalledOn302Redirect() throws Throwable { final String redirectTargetUrl = createRedirectTargetPage(); final String redirectUrl = mWebServer.setRedirect("/302.html", redirectTargetUrl); doTestCalledOnRedirect(redirectUrl, redirectTargetUrl, true); }
@SmallTest @Feature({"AndroidWebView", "Navigation"}) public void testCalledFor302AfterPostNavigations() throws Throwable { // The reason POST requests are excluded is BUG 155250. standardSetup(); final String redirectTargetUrl = createRedirectTargetPage(); final String postToGetRedirectUrl = mWebServer.setRedirect("/302.html", redirectTargetUrl); final String postLinkUrl = addPageToTestServer( "/page_with_post_link.html", CommonResources.makeHtmlPageWithSimplePostFormTo(postToGetRedirectUrl)); loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), postLinkUrl); final int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper.getCallCount(); clickOnLinkUsingJs(); mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingCallCount); // Wait for the target URL to be fetched from the server. poll( new Callable<Boolean>() { @Override public Boolean call() throws Exception { return mWebServer.getRequestCount(REDIRECT_TARGET_PATH) == 1; } }); assertEquals( redirectTargetUrl, mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()); assertTrue(mShouldOverrideUrlLoadingHelper.isRedirect()); assertFalse(mShouldOverrideUrlLoadingHelper.hasUserGesture()); assertTrue(mShouldOverrideUrlLoadingHelper.isMainFrame()); }
@SmallTest @Feature({"AndroidWebView"}) public void testNullContentsClientWithServerRedirect() throws Throwable { try { // The test will fire real intents through the test activity. // Need to temporarily suppress startActivity otherwise there will be a // handler selection window and the test can't dismiss that. getActivity().setIgnoreStartActivity(true); final String testUrl = mWebServer.setResponse( "/" + CommonResources.ABOUT_FILENAME, CommonResources.ABOUT_HTML, CommonResources.getTextHtmlHeaders(true)); setupWithProvidedContentsClient( new NullContentsClient() { @Override public boolean hasWebViewClient() { return false; } }); loadUrlAsync(mAwContents, testUrl); pollOnUiThread( new Callable<Boolean>() { @Override public Boolean call() { return mAwContents.getTitle().equals(CommonResources.ABOUT_TITLE); } }); assertNull(getActivity().getLastSentIntent()); // Now the server will redirect path1 to path2. Path2 will load ABOUT_HTML. // AwContents should create an intent for the server initiated redirection. final String path1 = "/from.html"; final String path2 = "/to.html"; final String fromUrl = mWebServer.setRedirect(path1, path2); final String toUrl = mWebServer.setResponse( path2, CommonResources.ABOUT_HTML, CommonResources.getTextHtmlHeaders(true)); loadUrlAsync(mAwContents, fromUrl); pollOnUiThread( new Callable<Boolean>() { @Override public Boolean call() { return getActivity().getLastSentIntent() != null; } }); assertEquals(toUrl, getActivity().getLastSentIntent().getData().toString()); } finally { getActivity().setIgnoreStartActivity(false); } }