public void testShouldOverrideUrlLoadingForDataUrl() { try { final String dataUrl = "data:text/html;base64," + "PGh0bWw+PGhlYWQ+PHRpdGxlPmRhdGFVcmxUZXN0QmFzZTY0PC90aXRsZT48" + "L2hlYWQ+PC9odG1sPg=="; loadDataSync(null, CommonResources.makeHtmlPageWithSimpleLinkTo(dataUrl), "text/html", false); ShouldOverrideUrlLoadingHelper mShouldOverrideUrlLoadingHelper = mTestHelperBridge.getShouldOverrideUrlLoadingHelper(); int callCount = mShouldOverrideUrlLoadingHelper.getCallCount(); clickOnElementId("link", null); mShouldOverrideUrlLoadingHelper.waitForCallback(callCount); assertTrue( "Expected URL that starts with 'data:' but got: <" + mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl() + "> instead.", mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl().startsWith("data:")); assertEquals(1, mShouldOverrideUrlLoadingHelper.getCallCount()); } catch (Exception e) { assertTrue(false); e.printStackTrace(); } catch (Throwable e) { assertTrue(false); e.printStackTrace(); } }
public void testShouldOverrideUrlLoadingWithCorrectUrl() { try { final String redirectTargetUrl = addPageToTestServer( mWebServer, REDIRECT_TARGET_PATH, CommonResources.makeHtmlPageFrom( "<title>" + TITLE + "</title> ", "<div>This is the end of the redirect chain</div>")); loadDataSync( null, CommonResources.makeHtmlPageWithSimpleLinkTo(redirectTargetUrl), "text/html", false); ShouldOverrideUrlLoadingHelper mShouldOverrideUrlLoadingHelper = mTestHelperBridge.getShouldOverrideUrlLoadingHelper(); int callCount = mShouldOverrideUrlLoadingHelper.getCallCount(); clickOnElementId("link", null); mShouldOverrideUrlLoadingHelper.waitForCallback(callCount); assertEquals( redirectTargetUrl, mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()); } catch (Exception e) { assertTrue(false); e.printStackTrace(); } catch (Throwable e) { assertTrue(false); e.printStackTrace(); } }
public void testShouldOverrideUrlLoadingFor302AfterPostNavigations() { try { final String redirectTargetUrl = addPageToTestServer( mWebServer, REDIRECT_TARGET_PATH, CommonResources.makeHtmlPageFrom( "<title>" + TITLE + "</title> ", "<div>This is the end of the redirect chain</div>")); final String postToGetRedirectUrl = mWebServer.setRedirect("/302.html", redirectTargetUrl); final String postLinkUrl = addPageToTestServer( mWebServer, "/page_with_post_link.html", CommonResources.makeHtmlPageWithSimplePostFormTo(postToGetRedirectUrl)); loadUrlSync(postLinkUrl); ShouldOverrideUrlLoadingHelper mShouldOverrideUrlLoadingHelper = mTestHelperBridge.getShouldOverrideUrlLoadingHelper(); final int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper.getCallCount(); clickOnElementId("link", null); mShouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingCallCount); // Wait for the target URL to be fetched from the server. pollOnUiThread( new Callable<Boolean>() { @Override public Boolean call() throws Exception { return mWebServer.getRequestCount(REDIRECT_TARGET_PATH) == 1; } }); assertEquals( redirectTargetUrl, mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()); } catch (Exception e) { assertTrue(false); e.printStackTrace(); } catch (Throwable e) { assertTrue(false); e.printStackTrace(); } }
public void testShouldOverrideUrlLoadingWhenSelfLinkClicked() { try { final String httpPath = "/page_with_link_to_self.html"; final String httpPathOnServer = mWebServer.getResponseUrl(httpPath); addPageToTestServer( mWebServer, httpPath, CommonResources.makeHtmlPageWithSimpleLinkTo(httpPathOnServer)); ShouldOverrideUrlLoadingHelper mShouldOverrideUrlLoadingHelper = mTestHelperBridge.getShouldOverrideUrlLoadingHelper(); loadUrlSync(httpPathOnServer); int callCount = mShouldOverrideUrlLoadingHelper.getCallCount(); clickOnElementId("link", null); mShouldOverrideUrlLoadingHelper.waitForCallback(callCount); assertEquals( httpPathOnServer, mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()); } catch (Exception e) { assertTrue(false); e.printStackTrace(); } catch (Throwable e) { assertTrue(false); e.printStackTrace(); } }
public void testShouldOverrideUrlLoadingForUnsupportedSchemes() { try { final String unsupportedSchemeUrl = "foobar://resource/1"; loadDataSync( null, CommonResources.makeHtmlPageWithSimpleLinkTo(unsupportedSchemeUrl), "text/html", false); ShouldOverrideUrlLoadingHelper mShouldOverrideUrlLoadingHelper = mTestHelperBridge.getShouldOverrideUrlLoadingHelper(); int callCount = mShouldOverrideUrlLoadingHelper.getCallCount(); clickOnElementId("link", null); mShouldOverrideUrlLoadingHelper.waitForCallback(callCount); assertEquals( unsupportedSchemeUrl, mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()); } catch (Exception e) { assertTrue(false); e.printStackTrace(); } catch (Throwable e) { assertTrue(false); e.printStackTrace(); } }