@SmallTest @Feature({"AndroidWebView"}) public void testCalledForImage() throws Throwable { final TestAwContentsClient contentsClient = new TestAwContentsClient(); final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); final TestAwContentsClient.ShouldInterceptRequestHelper shouldInterceptRequestHelper = contentsClient.getShouldInterceptRequestHelper(); final String imagePath = "/" + CommonResources.FAVICON_FILENAME; mWebServer.setResponseBase64( imagePath, CommonResources.FAVICON_DATA_BASE64, CommonResources.getImagePngHeaders(true)); final String pageWithImage = addPageToTestServer( mWebServer, "/page_with_image.html", CommonResources.getOnImageLoadedHtml(CommonResources.FAVICON_FILENAME)); int callCount = shouldInterceptRequestHelper.getCallCount(); loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), pageWithImage); shouldInterceptRequestHelper.waitForCallback(callCount, 2); assertEquals(2, shouldInterceptRequestHelper.getUrls().size()); assertTrue( shouldInterceptRequestHelper.getUrls().get(1).endsWith(CommonResources.FAVICON_FILENAME)); }
@SmallTest @Feature({"AndroidWebView"}) public void testDoesNotCrashOnInvalidData() throws Throwable { final TestAwContentsClient contentsClient = new TestAwContentsClient(); final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); final TestAwContentsClient.ShouldInterceptRequestHelper shouldInterceptRequestHelper = contentsClient.getShouldInterceptRequestHelper(); final String aboutPageUrl = addAboutPageToTestServer(mWebServer); shouldInterceptRequestHelper.setReturnValue( new InterceptedRequestData("text/html", "UTF-8", null)); int callCount = shouldInterceptRequestHelper.getCallCount(); loadUrlAsync(awContents, aboutPageUrl); shouldInterceptRequestHelper.waitForCallback(callCount); shouldInterceptRequestHelper.setReturnValue( new InterceptedRequestData(null, null, new ByteArrayInputStream(new byte[0]))); callCount = shouldInterceptRequestHelper.getCallCount(); loadUrlAsync(awContents, aboutPageUrl); shouldInterceptRequestHelper.waitForCallback(callCount); shouldInterceptRequestHelper.setReturnValue(new InterceptedRequestData(null, null, null)); callCount = shouldInterceptRequestHelper.getCallCount(); loadUrlAsync(awContents, aboutPageUrl); shouldInterceptRequestHelper.waitForCallback(callCount); }
@SmallTest @Feature({"AndroidWebView"}) public void testCalledForUnsupportedSchemes() throws Throwable { final TestAwContentsClient contentsClient = new TestAwContentsClient(); final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); final TestAwContentsClient.ShouldInterceptRequestHelper shouldInterceptRequestHelper = contentsClient.getShouldInterceptRequestHelper(); final String unhandledSchemeUrl = "foobar://resource/1"; int callCount = shouldInterceptRequestHelper.getCallCount(); loadUrlAsync(awContents, unhandledSchemeUrl); shouldInterceptRequestHelper.waitForCallback(callCount); assertEquals(unhandledSchemeUrl, shouldInterceptRequestHelper.getUrls().get(0)); }
@SmallTest @Feature({"AndroidWebView"}) public void testDoesNotChangeReportedUrl() throws Throwable { final TestAwContentsClient contentsClient = new TestAwContentsClient(); final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); final TestAwContentsClient.ShouldInterceptRequestHelper shouldInterceptRequestHelper = contentsClient.getShouldInterceptRequestHelper(); shouldInterceptRequestHelper.setReturnValue( stringToInterceptedRequestData(makePageWithTitle("some title"))); final String aboutPageUrl = addAboutPageToTestServer(mWebServer); loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), aboutPageUrl); assertEquals(aboutPageUrl, contentsClient.getOnPageFinishedHelper().getUrl()); assertEquals(aboutPageUrl, contentsClient.getOnPageStartedHelper().getUrl()); }
@SmallTest @Feature({"AndroidWebView"}) public void testCanInterceptMainFrame() throws Throwable { final TestAwContentsClient contentsClient = new TestAwContentsClient(); final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); final TestAwContentsClient.ShouldInterceptRequestHelper shouldInterceptRequestHelper = contentsClient.getShouldInterceptRequestHelper(); final String expectedTitle = "testShouldInterceptRequestCanInterceptMainFrame"; final String expectedPage = makePageWithTitle(expectedTitle); shouldInterceptRequestHelper.setReturnValue(stringToInterceptedRequestData(expectedPage)); final String aboutPageUrl = addAboutPageToTestServer(mWebServer); loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), aboutPageUrl); assertEquals(expectedTitle, getTitleOnUiThread(awContents)); assertEquals(0, mWebServer.getRequestCount("/" + CommonResources.ABOUT_FILENAME)); }
@SmallTest @Feature({"AndroidWebView"}) public void testCalledForIframe() throws Throwable { final TestAwContentsClient contentsClient = new TestAwContentsClient(); final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); final TestAwContentsClient.ShouldInterceptRequestHelper shouldInterceptRequestHelper = contentsClient.getShouldInterceptRequestHelper(); final String aboutPageUrl = addAboutPageToTestServer(mWebServer); final String pageWithIframe = addPageToTestServer( mWebServer, "/page_with_iframe.html", CommonResources.makeHtmlPageFrom("", "<iframe src=\"" + aboutPageUrl + "\"/>")); int callCount = shouldInterceptRequestHelper.getCallCount(); loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), pageWithIframe); shouldInterceptRequestHelper.waitForCallback(callCount, 2); assertEquals(2, shouldInterceptRequestHelper.getUrls().size()); assertEquals(aboutPageUrl, shouldInterceptRequestHelper.getUrls().get(1)); }
@SmallTest @Feature({"AndroidWebView"}) public void testCalledWithCorrectUrl() throws Throwable { final TestAwContentsClient contentsClient = new TestAwContentsClient(); final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); final TestAwContentsClient.ShouldInterceptRequestHelper shouldInterceptRequestHelper = contentsClient.getShouldInterceptRequestHelper(); final String aboutPageUrl = addAboutPageToTestServer(mWebServer); int callCount = shouldInterceptRequestHelper.getCallCount(); int onPageFinishedCallCount = contentsClient.getOnPageFinishedHelper().getCallCount(); loadUrlAsync(awContents, aboutPageUrl); shouldInterceptRequestHelper.waitForCallback(callCount); assertEquals(1, shouldInterceptRequestHelper.getUrls().size()); assertEquals(aboutPageUrl, shouldInterceptRequestHelper.getUrls().get(0)); contentsClient.getOnPageFinishedHelper().waitForCallback(onPageFinishedCallCount); assertEquals(CommonResources.ABOUT_TITLE, getTitleOnUiThread(awContents)); }