@SmallTest
  public void testReceiveBasicFavicon() throws Throwable {
    int callCount = mContentsClient.getFaviconHelper().getCallCount();

    final String faviconUrl =
        mWebServer.setResponseBase64(
            FAVICON1_URL,
            CommonResources.FAVICON_DATA_BASE64,
            CommonResources.getImagePngHeaders(true));
    final String pageUrl =
        mWebServer.setResponse(
            FAVICON1_PAGE_URL, FAVICON1_PAGE_HTML, CommonResources.getTextHtmlHeaders(true));

    loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);

    mContentsClient.getFaviconHelper().waitForCallback(callCount);
    assertEquals(1, mWebServer.getRequestCount(FAVICON1_URL));
    Object originalFaviconSource = (new URL(faviconUrl)).getContent();
    Bitmap originalFavicon = BitmapFactory.decodeStream((InputStream) originalFaviconSource);
    assertNotNull(originalFavicon);
    assertNotNull(mContentsClient.getFaviconHelper().getIcon());
    assertTrue(mContentsClient.getFaviconHelper().getIcon().sameAs(originalFavicon));

    // Make sure the request counter for favicon is incremented when the page is loaded again
    // successfully.
    loadUrlAsync(mAwContents, pageUrl);
    mContentsClient.getFaviconHelper().waitForCallback(callCount);
    assertEquals(2, mWebServer.getRequestCount(FAVICON1_URL));
  }
  @SmallTest
  @Feature({"AndroidWebView", "Navigation"})
  public void testCanIgnoreLoading() throws Throwable {
    standardSetup();

    final String redirectTargetUrl = createRedirectTargetPage();
    final String pageWithLinkToIgnorePath = "/page_with_link_to_ignore.html";
    final String pageWithLinkToIgnoreUrl =
        addPageToTestServer(
            pageWithLinkToIgnorePath,
            CommonResources.makeHtmlPageWithSimpleLinkTo(redirectTargetUrl));
    final String synchronizationPath = "/sync.html";
    final String synchronizationUrl =
        addPageToTestServer(
            synchronizationPath, CommonResources.makeHtmlPageWithSimpleLinkTo(redirectTargetUrl));

    loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), pageWithLinkToIgnoreUrl);

    setShouldOverrideUrlLoadingReturnValueOnUiThread(true);

    int callCount = mShouldOverrideUrlLoadingHelper.getCallCount();
    clickOnLinkUsingJs();
    // Some time around here true should be returned from the shouldOverrideUrlLoading
    // callback causing the navigation caused by calling clickOnLinkUsingJs to be ignored.
    // We validate this by checking which pages were loaded on the server.
    mShouldOverrideUrlLoadingHelper.waitForCallback(callCount);

    setShouldOverrideUrlLoadingReturnValueOnUiThread(false);

    loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), synchronizationUrl);

    assertEquals(1, mWebServer.getRequestCount(pageWithLinkToIgnorePath));
    assertEquals(1, mWebServer.getRequestCount(synchronizationPath));
    assertEquals(0, mWebServer.getRequestCount(REDIRECT_TARGET_PATH));
  }
  private void useAppCache() throws Exception {
    final String cachedFilePath = "/foo.js";
    final String cachedFileContents = "1 + 1;";
    mWebServer.setResponse(cachedFilePath, cachedFileContents, null);

    final String manifestPath = "/foo.manifest";
    final String manifestContents = "CACHE MANIFEST\nCACHE:\n" + cachedFilePath;
    List<Pair<String, String>> manifestHeaders = new ArrayList<Pair<String, String>>();
    manifestHeaders.add(Pair.create("Content-Disposition", "text/cache-manifest"));
    mWebServer.setResponse(manifestPath, manifestContents, manifestHeaders);

    final String pagePath = "/appcache.html";
    final String pageContents =
        "<html manifest=\""
            + manifestPath
            + "\">"
            + "<head><script src=\""
            + cachedFilePath
            + "\"></script></head></html>";
    String url = mWebServer.setResponse(pagePath, pageContents, null);

    loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url);
    executeJavaScriptAndWaitForResult(
        mAwContents, mContentsClient, "window.applicationCache.update();");
  }
  @MediumTest
  @Feature({"AndroidWebView", "Privacy"})
  public void testThirdPartyJavascriptCookie() throws Throwable {
    TestWebServer webServer = null;
    try {
      // This test again uses 127.0.0.1/localhost trick to simulate a third party.
      webServer = new TestWebServer(false);
      ThirdPartyCookiesTestHelper thirdParty = new ThirdPartyCookiesTestHelper(webServer);

      mCookieManager.setAcceptCookie(true);
      assertTrue(mCookieManager.acceptCookie());

      // When third party cookies are disabled...
      thirdParty.getSettings().setAcceptThirdPartyCookies(false);
      assertFalse(thirdParty.getSettings().getAcceptThirdPartyCookies());

      // ...we can't set third party cookies.
      thirdParty.assertThirdPartyIFrameCookieResult("1", false);

      // When third party cookies are enabled...
      thirdParty.getSettings().setAcceptThirdPartyCookies(true);
      assertTrue(thirdParty.getSettings().getAcceptThirdPartyCookies());

      // ...we can set third party cookies.
      thirdParty.assertThirdPartyIFrameCookieResult("2", true);
    } finally {
      if (webServer != null) webServer.shutdown();
    }
  }
Ejemplo n.º 5
0
  @Feature({"AndroidWebView", "Downloads"})
  @SmallTest
  public void testDownload() throws Throwable {
    AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient);
    AwContents awContents = testView.getAwContents();

    final String data = "download data";
    final String contentDisposition = "attachment;filename=\"download.txt\"";
    final String mimeType = "text/plain";

    List<Pair<String, String>> downloadHeaders = new ArrayList<Pair<String, String>>();
    downloadHeaders.add(Pair.create("Content-Disposition", contentDisposition));
    downloadHeaders.add(Pair.create("Content-Type", mimeType));
    downloadHeaders.add(Pair.create("Content-Length", Integer.toString(data.length())));

    TestWebServer webServer = null;
    try {
      webServer = new TestWebServer(false);
      final String pageUrl = webServer.setResponse("/download.txt", data, downloadHeaders);
      final OnDownloadStartHelper downloadStartHelper = mContentsClient.getOnDownloadStartHelper();
      final int callCount = downloadStartHelper.getCallCount();
      loadUrlAsync(awContents, pageUrl);
      downloadStartHelper.waitForCallback(callCount);

      assertEquals(pageUrl, downloadStartHelper.getUrl());
      assertEquals(contentDisposition, downloadStartHelper.getContentDisposition());
      assertEquals(mimeType, downloadStartHelper.getMimeType());
      assertEquals(data.length(), downloadStartHelper.getContentLength());
    } finally {
      if (webServer != null) webServer.shutdown();
    }
  }
  @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());
  }
 protected void doReload() throws Throwable {
   String url = mServer.setResponse("/form", LOAD_RESPONSE, null);
   String postData = "content=blabla";
   byte[] data = EncodingUtils.getBytes(postData, "BASE64");
   postUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url, data);
   assertEquals(0, mContentsClient.getResubmissions());
   assertEquals("Load", getTitleOnUiThread(mAwContents));
   // Verify reload works as expected.
   mServer.setResponse("/form", RELOAD_RESPONSE, null);
   TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
       mContentsClient.getOnPageFinishedHelper();
   int callCount = onPageFinishedHelper.getCallCount();
   // Run reload on UI thread.
   getInstrumentation()
       .runOnMainSync(
           new Runnable() {
             @Override
             public void run() {
               mAwContents.getContentViewCore().reload(true);
             }
           });
   try {
     // Wait for page finished callback, or a timeout. A timeout is necessary
     // to detect a dontResend response.
     onPageFinishedHelper.waitForCallback(callCount, 1, TIMEOUT, TimeUnit.SECONDS);
   } catch (TimeoutException e) {
   }
 }
Ejemplo n.º 8
0
 @Override
 public void setUp() throws Exception {
   super.setUp();
   mContentsClient = new TestAwContentsClient();
   mTestView = createAwTestContainerViewOnMainSync(mContentsClient);
   mAwContents = mTestView.getAwContents();
   mWebServer = TestWebServer.start();
   final String imagePath = "/" + CommonResources.TEST_IMAGE_FILENAME;
   mWebServer.setResponseBase64(
       imagePath, CommonResources.FAVICON_DATA_BASE64, CommonResources.getImagePngHeaders(true));
 }
  @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);
    }
  }
  @MediumTest
  @Feature({"AndroidWebView", "Privacy"})
  public void testThirdPartyCookie() throws Throwable {
    TestWebServer webServer = null;
    try {
      // In theory we need two servers to test this, one server ('the first party')
      // which returns a response with a link to a second server ('the third party')
      // at different origin. This second server attempts to set a cookie which should
      // fail if AcceptThirdPartyCookie() is false.
      // Strictly according to the letter of RFC6454 it should be possible to set this
      // situation up with two TestServers on different ports (these count as having
      // different origins) but Chrome is not strict about this and does not check the
      // port. Instead we cheat making some of the urls come from localhost and some
      // from 127.0.0.1 which count (both in theory and pratice) as having different
      // origins.
      webServer = new TestWebServer(false);

      // Turn global allow on.
      mCookieManager.setAcceptCookie(true);
      assertTrue(mCookieManager.acceptCookie());

      // When third party cookies are disabled...
      mAwContents.getSettings().setAcceptThirdPartyCookies(false);
      assertFalse(mAwContents.getSettings().getAcceptThirdPartyCookies());

      // ...we can't set third party cookies.
      // First on the third party server we create a url which tries to set a cookie.
      String cookieUrl =
          toThirdPartyUrl(makeCookieUrl(webServer, "/cookie_1.js", "test1", "value1"));
      // Then we create a url on the first party server which links to the first url.
      String url = makeScriptLinkUrl(webServer, "/content_1.html", cookieUrl);
      loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url);
      assertNull(mCookieManager.getCookie(cookieUrl));

      // When third party cookies are enabled...
      mAwContents.getSettings().setAcceptThirdPartyCookies(true);
      assertTrue(mAwContents.getSettings().getAcceptThirdPartyCookies());

      // ...we can set third party cookies.
      cookieUrl = toThirdPartyUrl(makeCookieUrl(webServer, "/cookie_2.js", "test2", "value2"));
      url = makeScriptLinkUrl(webServer, "/content_2.html", cookieUrl);
      loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url);
      waitForCookie(cookieUrl);
      String cookie = mCookieManager.getCookie(cookieUrl);
      assertNotNull(cookie);
      validateCookies(cookie, "test2");
    } finally {
      if (webServer != null) webServer.shutdown();
    }
  }
  @Override
  public void setUp() throws Exception {
    super.setUp();
    mContentsClient = new TestAwContentsClient();
    mTestView = createAwTestContainerViewOnMainSync(mContentsClient);
    mAwContents = mTestView.getAwContents();
    mWebServer = TestWebServer.start();
    mOrigin = mWebServer.getBaseUrl();

    AwSettings settings = getAwSettingsOnUiThread(mAwContents);
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setAppCacheEnabled(true);
    settings.setAppCachePath("whatever"); // Enables AppCache.
  }
  @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));
  }
Ejemplo n.º 13
0
 @Override
 public void tearDown() throws Exception {
   if (mWebServer != null) {
     mWebServer.shutdown();
   }
   super.tearDown();
 }
  @SmallTest
  @Feature({"ShouldInterceptLoadRequest"})
  public void testHttpStatusField() throws Throwable {
    final String syncGetUrl = mWebServer.getResponseUrl("/intercept_me");
    final String syncGetJs =
        "(function() {"
            + "  var xhr = new XMLHttpRequest();"
            + "  xhr.open('GET', '"
            + syncGetUrl
            + "', false);"
            + "  xhr.send(null);"
            + "  console.info('xhr.status = ' + xhr.status);"
            + "  return xhr.status;"
            + "})();";

    getInstrumentation()
        .runOnMainSync(
            new Runnable() {
              @Override
              public void run() {
                getXWalkView().getSettings().setJavaScriptEnabled(true);
              }
            });

    final String aboutPageUrl = addAboutPageToTestServer(mWebServer);
    loadUrlSync(aboutPageUrl);

    mShouldInterceptLoadRequestHelper.setReturnValue(
        new WebResourceResponse("text/html", "UTF-8", null));
    assertEquals("404", executeJavaScriptAndWaitForResult(syncGetJs));

    mShouldInterceptLoadRequestHelper.setReturnValue(
        new WebResourceResponse("text/html", "UTF-8", new EmptyInputStream()));
    assertEquals("200", executeJavaScriptAndWaitForResult(syncGetJs));
  }
  private void doTestNotCalledForAnchorNavigations(boolean useLoadData) throws Throwable {
    standardSetup();

    final String anchorLinkPath = "/anchor_link.html";
    final String anchorLinkUrl = mWebServer.getResponseUrl(anchorLinkPath);
    addPageToTestServer(
        anchorLinkPath, CommonResources.makeHtmlPageWithSimpleLinkTo(anchorLinkUrl + "#anchor"));

    if (useLoadData) {
      loadDataSync(
          mAwContents,
          mContentsClient.getOnPageFinishedHelper(),
          CommonResources.makeHtmlPageWithSimpleLinkTo("#anchor"),
          "text/html",
          false);
    } else {
      loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), anchorLinkUrl);
    }

    final int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper.getCallCount();

    clickOnLinkUsingJs();

    // After we load this URL we're certain that any in-flight callbacks for the previous
    // navigation have been delivered.
    loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), ABOUT_BLANK_URL);

    assertEquals(shouldOverrideUrlLoadingCallCount, mShouldOverrideUrlLoadingHelper.getCallCount());
  }
  @SmallTest
  @Feature({"AndroidWebView", "Navigation"})
  public void testNotCalledForPostNavigations() throws Throwable {
    // The reason POST requests are excluded is BUG 155250.
    standardSetup();

    final String redirectTargetUrl = createRedirectTargetPage();
    final String postLinkUrl =
        addPageToTestServer(
            "/page_with_post_link.html",
            CommonResources.makeHtmlPageWithSimplePostFormTo(redirectTargetUrl));

    loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), postLinkUrl);

    final int shouldOverrideUrlLoadingCallCount = mShouldOverrideUrlLoadingHelper.getCallCount();

    assertEquals(0, mWebServer.getRequestCount(REDIRECT_TARGET_PATH));
    clickOnLinkUsingJs();

    // 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;
          }
        });

    // Since the targetURL was loaded from the test server it means all processing related
    // to dispatching a shouldOverrideUrlLoading callback had finished and checking the call
    // is stable.
    assertEquals(shouldOverrideUrlLoadingCallCount, mShouldOverrideUrlLoadingHelper.getCallCount());
  }
  @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", "Navigation"})
 public void testCalledOn302Redirect() throws Throwable {
   final String redirectTargetUrl = createRedirectTargetPage();
   final String redirectUrl = mWebServer.setRedirect("/302.html", redirectTargetUrl);
   doTestCalledOnRedirect(redirectUrl, redirectTargetUrl, true);
 }
 /**
  * Creates a response on the TestWebServer which attempts to set a cookie when fetched.
  *
  * @param webServer the webServer on which to create the response
  * @param path the path component of the url (e.g "/my_thing_with_iframe.html")
  * @param url the url which which should appear as the src of the iframe.
  * @return the url which gets the response
  */
 private String makeIframeUrl(TestWebServer webServer, String path, String url) {
   String responseStr =
       "<html><head><title>Content!</title></head>"
           + "<body><iframe src="
           + url
           + "></iframe></body></html>";
   return webServer.setResponse(path, responseStr, null);
 }
Ejemplo n.º 20
0
 private void blankHrefTestBody(boolean byTouch) throws Throwable {
   String fullPath = mWebServer.getResponseUrl("/hittest.html");
   String page = fullPageLink("", ANCHOR_TEXT);
   setServerResponseAndLoad(page);
   simulateInput(byTouch);
   pollForHitTestDataOnUiThread(HitTestResult.SRC_ANCHOR_TYPE, fullPath);
   pollForHrefAndImageSrcOnUiThread(fullPath, ANCHOR_TEXT, null);
 }
Ejemplo n.º 21
0
  @SmallTest
  @Feature({"AndroidWebView"})
  public void testGetFavicon() throws Throwable {
    final AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient);
    final AwContents awContents = testView.getAwContents();

    TestWebServer webServer = null;
    try {
      webServer = new TestWebServer(false);

      final String faviconUrl =
          webServer.setResponseBase64(
              "/" + CommonResources.FAVICON_FILENAME,
              CommonResources.FAVICON_DATA_BASE64,
              CommonResources.getImagePngHeaders(false));
      final String pageUrl =
          webServer.setResponse("/favicon.html", CommonResources.FAVICON_STATIC_HTML, null);

      // The getFavicon will return the right icon a certain time after
      // the page load completes which makes it slightly hard to test.
      final Bitmap defaultFavicon = awContents.getFavicon();

      getAwSettingsOnUiThread(awContents).setImagesEnabled(true);
      loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);

      pollOnUiThread(
          new Callable<Boolean>() {
            @Override
            public Boolean call() {
              return awContents.getFavicon() != null
                  && !awContents.getFavicon().sameAs(defaultFavicon);
            }
          });

      final Object originalFaviconSource = (new URL(faviconUrl)).getContent();
      final Bitmap originalFavicon =
          BitmapFactory.decodeStream((InputStream) originalFaviconSource);
      assertNotNull(originalFavicon);

      assertTrue(awContents.getFavicon().sameAs(originalFavicon));

    } finally {
      if (webServer != null) webServer.shutdown();
    }
  }
Ejemplo n.º 22
0
 private void srcAnchorTypeRelativeUrlTestBody(boolean byTouch) throws Throwable {
   String relPath = "/foo.html";
   String fullPath = mWebServer.getResponseUrl(relPath);
   String page = fullPageLink(relPath, ANCHOR_TEXT);
   setServerResponseAndLoad(page);
   simulateInput(byTouch);
   pollForHitTestDataOnUiThread(HitTestResult.SRC_ANCHOR_TYPE, fullPath);
   pollForHrefAndImageSrcOnUiThread(fullPath, ANCHOR_TEXT, null);
 }
Ejemplo n.º 23
0
 private void srcImgeAnchorTypeRelativeUrlTestBody(boolean byTouch) throws Throwable {
   String relImageSrc = "/nonexistent.jpg";
   String fullImageSrc = mWebServer.getResponseUrl(relImageSrc);
   String relPath = "/foo.html";
   String fullPath = mWebServer.getResponseUrl(relPath);
   String page =
       CommonResources.makeHtmlPageFrom(
           "",
           "<a class=\"full_view\" href=\""
               + relPath
               + "\"onclick=\"return false;\"><img class=\"full_view\" src=\""
               + relImageSrc
               + "\"></a>");
   setServerResponseAndLoad(page);
   simulateInput(byTouch);
   pollForHitTestDataOnUiThread(HitTestResult.SRC_IMAGE_ANCHOR_TYPE, fullImageSrc);
   pollForHrefAndImageSrcOnUiThread(fullPath, null, fullImageSrc);
 }
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   AwContents.setShouldDownloadFavicons();
   mContentsClient = new TestAwContentsClient();
   AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(mContentsClient);
   mAwContents = testContainerView.getAwContents();
   mWebServer = TestWebServer.start();
 }
  @SmallTest
  @Feature({"AndroidWebView"})
  public void testNullContentsClientClickableContent() 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);
      setupWithProvidedContentsClient(
          new NullContentsClient() {
            @Override
            public boolean hasWebViewClient() {
              return false;
            }
          });
      final String pageTitle = "Click Title";
      final String testEmail = "*****@*****.**";
      final String testUrl =
          mWebServer.setResponse(
              "/email_test.html",
              "<html><head><title>"
                  + pageTitle
                  + "</title></head>"
                  + "<body><span id='email'>"
                  + testEmail
                  + "</span></body>",
              null);

      // JS is required for the click simulator.
      mAwContents.getSettings().setJavaScriptEnabled(true);
      loadUrlAsync(mAwContents, testUrl);
      pollOnUiThread(
          new Callable<Boolean>() {
            @Override
            public Boolean call() {
              return mAwContents.getTitle().equals(pageTitle);
            }
          });

      // Clicking on an email should create an intent.
      DOMUtils.clickNode(this, mAwContents.getContentViewCore(), "email");
      pollOnUiThread(
          new Callable<Boolean>() {
            @Override
            public Boolean call() {
              return getActivity().getLastSentIntent() != null;
            }
          });
      assertEquals(
          "mailto:" + testEmail.replace("@", "%40"),
          getActivity().getLastSentIntent().getData().toString());
    } finally {
      getActivity().setIgnoreStartActivity(false);
    }
  }
  @MediumTest
  @Feature({"AndroidWebView", "Privacy"})
  public void testThirdPartyCookiesArePerWebview() throws Throwable {
    TestWebServer webServer = null;
    try {
      webServer = new TestWebServer(false);
      mCookieManager.setAcceptCookie(true);
      mCookieManager.removeAllCookie();
      assertTrue(mCookieManager.acceptCookie());
      assertFalse(mCookieManager.hasCookies());

      ThirdPartyCookiesTestHelper helperOne = new ThirdPartyCookiesTestHelper(webServer);
      ThirdPartyCookiesTestHelper helperTwo = new ThirdPartyCookiesTestHelper(webServer);

      helperOne.getSettings().setAcceptThirdPartyCookies(false);
      helperTwo.getSettings().setAcceptThirdPartyCookies(false);
      assertFalse(helperOne.getSettings().getAcceptThirdPartyCookies());
      assertFalse(helperTwo.getSettings().getAcceptThirdPartyCookies());
      helperOne.assertThirdPartyIFrameCookieResult("1", false);
      helperTwo.assertThirdPartyIFrameCookieResult("2", false);

      helperTwo.getSettings().setAcceptThirdPartyCookies(true);
      assertFalse(helperOne.getSettings().getAcceptThirdPartyCookies());
      assertTrue(helperTwo.getSettings().getAcceptThirdPartyCookies());
      helperOne.assertThirdPartyIFrameCookieResult("3", false);
      helperTwo.assertThirdPartyIFrameCookieResult("4", true);

      helperOne.getSettings().setAcceptThirdPartyCookies(true);
      assertTrue(helperOne.getSettings().getAcceptThirdPartyCookies());
      assertTrue(helperTwo.getSettings().getAcceptThirdPartyCookies());
      helperOne.assertThirdPartyIFrameCookieResult("5", true);
      helperTwo.assertThirdPartyIFrameCookieResult("6", true);

      helperTwo.getSettings().setAcceptThirdPartyCookies(false);
      assertTrue(helperOne.getSettings().getAcceptThirdPartyCookies());
      assertFalse(helperTwo.getSettings().getAcceptThirdPartyCookies());
      helperOne.assertThirdPartyIFrameCookieResult("7", true);
      helperTwo.assertThirdPartyIFrameCookieResult("8", false);
    } finally {
      if (webServer != null) webServer.shutdown();
    }
  }
 /**
  * Creates a response on the TestWebServer with a script that attempts to set a cookie.
  *
  * @param webServer the webServer on which to create the response
  * @param path the path component of the url (e.g "/cookie_test.html")
  * @param key the key of the cookie
  * @param value the value of the cookie
  * @return the url which gets the response
  */
 private String makeCookieScriptUrl(
     TestWebServer webServer, String path, String key, String value) {
   String response =
       "<html><head></head><body>"
           + "<script>document.cookie = \""
           + key
           + "="
           + value
           + "\";</script></body></html>";
   return webServer.setResponse(path, response, null);
 }
  @SmallTest
  public void testReceiveBasicTouchIconLinkRel() throws Throwable {
    int callCount = mContentsClient.getFaviconHelper().getCallCount();

    final String pageUrl =
        mWebServer.setResponse(
            TOUCHICON_REL_URL, TOUCHICON_REL_PAGE_HTML, CommonResources.getTextHtmlHeaders(true));

    loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);

    mContentsClient.getTouchIconHelper().waitForCallback(callCount, 2);
    assertEquals(2, mContentsClient.getTouchIconHelper().getTouchIconsCount());
    assertFalse(
        mContentsClient
            .getTouchIconHelper()
            .hasTouchIcon(mWebServer.getBaseUrl() + TOUCHICON_REL_LINK));
    assertFalse(
        mContentsClient
            .getTouchIconHelper()
            .hasTouchIcon(mWebServer.getBaseUrl() + TOUCHICON_REL_LINK_72));
  }
Ejemplo n.º 29
0
 @SmallTest
 @Feature({"AndroidWebView", "WebKitHitTest"})
 public void testImgeType() throws Throwable {
   String relImageSrc = "/" + CommonResources.TEST_IMAGE_FILENAME;
   String fullImageSrc = mWebServer.getResponseUrl(relImageSrc);
   String page =
       CommonResources.makeHtmlPageFrom(
           "", "<img class=\"full_view\" src=\"" + relImageSrc + "\">");
   setServerResponseAndLoad(page);
   AwTestTouchUtils.simulateTouchCenterOfView(mTestView);
   pollForHitTestDataOnUiThread(HitTestResult.IMAGE_TYPE, fullImageSrc);
   pollForHrefAndImageSrcOnUiThread(null, null, fullImageSrc);
 }
  @SmallTest
  public void testDoNotMakeRequestForFaviconAfter404() throws Throwable {
    mWebServer.setResponseWithNotFoundStatus(FAVICON1_URL);
    final String pageUrl =
        mWebServer.setResponse(
            FAVICON1_PAGE_URL, FAVICON1_PAGE_HTML, CommonResources.getTextHtmlHeaders(true));

    loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
    poll(
        new Callable<Boolean>() {
          @Override
          public Boolean call() throws Exception {
            return mWebServer.getRequestCount(FAVICON1_URL) == 1;
          }
        });

    // Make sure the request counter for favicon is not incremented, since we already got 404.
    loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
    // If a request hasn't been done within this time period, we assume it won't be done.
    Thread.sleep(MAX_REQUEST_WAITING_LIMIT_MS);
    assertEquals(1, mWebServer.getRequestCount(FAVICON1_URL));
  }