summaryrefslogtreecommitdiffstats
path: root/android_webview
diff options
context:
space:
mode:
authorsgurun@chromium.org <sgurun@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-13 13:35:56 +0000
committersgurun@chromium.org <sgurun@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-13 13:35:56 +0000
commita69d3faca395a996f2b96a64c2bbc214ba85243b (patch)
treef1bfee8a4bf2d7f8732718ab63f8f1a8e0e8b886 /android_webview
parentb6376d501b780f7a1c8d1be5b55a925c440a805e (diff)
downloadchromium_src-a69d3faca395a996f2b96a64c2bbc214ba85243b.zip
chromium_src-a69d3faca395a996f2b96a64c2bbc214ba85243b.tar.gz
chromium_src-a69d3faca395a996f2b96a64c2bbc214ba85243b.tar.bz2
Implement touch icon functionality
BUG=b/6295380 Review URL: https://chromiumcodereview.appspot.com/12600025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187857 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
-rw-r--r--android_webview/browser/icon_helper.cc8
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFaviconTest.java111
2 files changed, 88 insertions, 31 deletions
diff --git a/android_webview/browser/icon_helper.cc b/android_webview/browser/icon_helper.cc
index 4cbe07a..9690df8 100644
--- a/android_webview/browser/icon_helper.cc
+++ b/android_webview/browser/icon_helper.cc
@@ -48,9 +48,10 @@ void IconHelper::DownloadFaviconCallback(
void IconHelper::DidUpdateFaviconURL(int32 page_id,
const std::vector<content::FaviconURL>& candidates) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
for (std::vector<content::FaviconURL>::const_iterator i = candidates.begin();
i != candidates.end(); ++i) {
- if (i->icon_url.is_empty())
+ if (!i->icon_url.is_valid())
continue;
switch(i->icon_type) {
@@ -61,10 +62,13 @@ void IconHelper::DidUpdateFaviconURL(int32 page_id,
web_contents()->DownloadFavicon(i->icon_url, 0, base::Bind(
&IconHelper::DownloadFaviconCallback, base::Unretained(this)));
break;
- // TODO(acleung): Touch Icon doesn't seem to work ATM.
case content::FaviconURL::TOUCH_ICON:
+ if (listener_)
+ listener_->OnReceivedTouchIconUrl(i->icon_url.spec(), false);
break;
case content::FaviconURL::TOUCH_PRECOMPOSED_ICON:
+ if (listener_)
+ listener_->OnReceivedTouchIconUrl(i->icon_url.spec(), true);
break;
case content::FaviconURL::INVALID_ICON:
// Silently ignore it. Only trigger a callback on valid icons.
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFaviconTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFaviconTest.java
index a04742f..6afa56f 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFaviconTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFaviconTest.java
@@ -15,6 +15,7 @@ import org.chromium.net.test.util.TestWebServer;
import java.io.InputStream;
import java.net.URL;
+import java.util.HashMap;
/**
* Tests for the Favicon and TouchIcon related APIs.
@@ -28,54 +29,74 @@ public class AwContentsClientFaviconTest extends AndroidWebViewTestBase {
"<link rel=\"icon\" href=\""+ FAVICON1_URL + "\" />",
"Body");
+ private static final String TOUCHICON_URL = "apple-touch-icon.png";
+ private static final String TOUCHICON_PRECOMPOSED_URL = "apple-touch-icon-precomposed.png";
+
+ private static final String TOUCHICON_REL_LINK = "touch.png";
+ private static final String TOUCHICON_REL_LINK_72 = "touch_72.png";
+ private static final String TOUCHICON_REL_URL = "/" + TOUCHICON_REL_LINK;
+ private static final String TOUCHICON_REL_URL_72 = "/" + TOUCHICON_REL_LINK_72;
+ private static final String TOUCHICON_REL_PAGE_HTML =
+ CommonResources.makeHtmlPageFrom(
+ "<link rel=\"apple-touch-icon\" href=\""+ TOUCHICON_REL_URL + "\" />" +
+ "<link rel=\"apple-touch-icon\" sizes=\"72x72\" href=\""+ TOUCHICON_REL_URL_72 + "\" />",
+ "Body");
+
private static class FaviconHelper extends CallbackHelper {
- private String mUrl;
private Bitmap mIcon;
- private boolean mTouch;
- private boolean mPrecomposed;
+ private HashMap<String, Boolean> mTouchIcons = new HashMap<String, Boolean>();
- public void notifyCalled(String url, Bitmap icon, boolean touch, boolean precomposed) {
- mUrl = url;
- mPrecomposed = precomposed;
- mTouch = touch;
+ public void notifyFavicon(Bitmap icon) {
mIcon = icon;
super.notifyCalled();
}
+
+ public void notifyTouchIcon(String url, boolean precomposed) {
+ mTouchIcons.put(url, precomposed);
+ super.notifyCalled();
+ }
}
- private static class TestAwContentsClient
+ private static class TestAwContentsClientBase
extends org.chromium.android_webview.test.TestAwContentsClient {
- private FaviconHelper mFaviconHelper = new FaviconHelper();
-
- @Override
- public void onReceivedIcon(Bitmap bitmap) {
- // We don't inform the API client about the URL of the icon.
- mFaviconHelper.notifyCalled(null, bitmap, false, false);
- }
-
- @Override
- public void onReceivedTouchIconUrl(String url, boolean precomposed) {
- mFaviconHelper.notifyCalled(url, null /* We don't download touch icons */,
- true, precomposed);
- }
+ FaviconHelper mFaviconHelper = new FaviconHelper();
+ }
+
+ private static class TestAwContentsClientFavicon extends TestAwContentsClientBase {
+ @Override
+ public void onReceivedIcon(Bitmap bitmap) {
+ // We don't inform the API client about the URL of the icon.
+ mFaviconHelper.notifyFavicon(bitmap);
+ }
}
- private TestAwContentsClient mContentsClient;
+ private static class TestAwContentsClientTouchIcon extends TestAwContentsClientBase {
+ @Override
+ public void onReceivedTouchIconUrl(String url, boolean precomposed) {
+ mFaviconHelper.notifyTouchIcon(url, precomposed);
+ }
+ }
+
+ private TestAwContentsClientBase mContentsClient;
private AwContents mAwContents;
private TestWebServer mWebServer;
@Override
protected void setUp() throws Exception {
super.setUp();
- mContentsClient = new TestAwContentsClient();
+ mWebServer = new TestWebServer(false);
+ }
+
+ private void init(TestAwContentsClientBase contentsClient) throws Exception {
+ mContentsClient = contentsClient;
AwTestContainerView testContainerView =
createAwTestContainerViewOnMainSync(mContentsClient);
mAwContents = testContainerView.getAwContents();
- mWebServer = new TestWebServer(false);
}
@SmallTest
- public void testRecieveBasicFavicon() throws Throwable {
+ public void testReceiveBasicFavicon() throws Throwable {
+ init(new TestAwContentsClientFavicon());
int callCount = mContentsClient.mFaviconHelper.getCallCount();
final String faviconUrl = mWebServer.setResponseBase64(FAVICON1_URL,
@@ -86,9 +107,6 @@ public class AwContentsClientFaviconTest extends AndroidWebViewTestBase {
loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
mContentsClient.mFaviconHelper.waitForCallback(callCount);
- assertNull(mContentsClient.mFaviconHelper.mUrl);
- assertFalse(mContentsClient.mFaviconHelper.mTouch);
- assertFalse(mContentsClient.mFaviconHelper.mPrecomposed);
Object originalFaviconSource = (new URL(faviconUrl)).getContent();
Bitmap originalFavicon = BitmapFactory.decodeStream((InputStream)originalFaviconSource);
assertNotNull(originalFavicon);
@@ -96,5 +114,40 @@ public class AwContentsClientFaviconTest extends AndroidWebViewTestBase {
assertTrue(mContentsClient.mFaviconHelper.mIcon.sameAs(originalFavicon));
}
- // TODO testTouchIcon. Not exactly working at the moment.
+ @SmallTest
+ public void testReceiveBasicTouchIconRoot() throws Throwable {
+ init(new TestAwContentsClientTouchIcon());
+ int callCount = mContentsClient.mFaviconHelper.getCallCount();
+
+ // Use the favicon page url. Since this does not specify a link rel for touch icon,
+ // we should get the default touch icon urls in the callback.
+ final String pageUrl = mWebServer.setResponse(FAVICON1_PAGE_URL, FAVICON1_PAGE_HTML,
+ CommonResources.getTextHtmlHeaders(true));
+
+ loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
+
+ mContentsClient.mFaviconHelper.waitForCallback(callCount, 2);
+
+ HashMap<String, Boolean> touchIcons = mContentsClient.mFaviconHelper.mTouchIcons;
+ assertEquals(2, touchIcons.size());
+ assertFalse(touchIcons.get(mWebServer.getBaseUrl() + TOUCHICON_URL));
+ assertTrue(touchIcons.get(mWebServer.getBaseUrl() + TOUCHICON_PRECOMPOSED_URL));
+ }
+
+ @SmallTest
+ public void testReceiveBasicTouchIconLinkRel() throws Throwable {
+ init(new TestAwContentsClientTouchIcon());
+ int callCount = mContentsClient.mFaviconHelper.getCallCount();
+
+ final String pageUrl = mWebServer.setResponse(TOUCHICON_REL_URL, TOUCHICON_REL_PAGE_HTML,
+ CommonResources.getTextHtmlHeaders(true));
+
+ loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
+
+ mContentsClient.mFaviconHelper.waitForCallback(callCount,2);
+ HashMap<String, Boolean> touchIcons = mContentsClient.mFaviconHelper.mTouchIcons;
+ assertEquals(2, touchIcons.size());
+ assertFalse(touchIcons.get(mWebServer.getBaseUrl() + TOUCHICON_REL_LINK));
+ assertFalse(touchIcons.get(mWebServer.getBaseUrl() + TOUCHICON_REL_LINK_72));
+ }
}