Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/test/util/BookmarkUtils.java

Issue 11085008: [Android] Upstream content detection and ChromeBrowserProvider tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase after landing resources separately. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/test/util/BookmarkUtils.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/test/util/BookmarkUtils.java b/chrome/android/javatests/src/org/chromium/chrome/browser/test/util/BookmarkUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..69701175750965afcfe0b91ea1ef5a085877a2b3
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/test/util/BookmarkUtils.java
@@ -0,0 +1,56 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.testshell.util;
+
+import android.graphics.Bitmap;
+import android.graphics.Bitmap.CompressFormat;
+import android.graphics.BitmapFactory;
+import android.util.Log;
+
+import org.chromium.base.test.util.UrlUtils;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Arrays;
+
+/**
+ * Set of utility functions shared between tests managing bookmarks.
+ */
+public class BookmarkUtils {
+ private static final String TAG = "BookmarkUtils";
+
+ /**
+ * Checks if two byte arrays are equal. Used to compare icons.
+ * @return True if equal, false otherwise.
+ */
+ public static boolean byteArrayEqual(byte[] byte1, byte[] byte2) {
+ if (byte1 == null && byte2 != null) {
+ return byte2.length == 0;
+ }
+ if (byte2 == null && byte1 != null) {
+ return byte1.length == 0;
+ }
+ return Arrays.equals(byte1, byte2);
+ }
+
+ /**
+ * Retrieves a byte array with the decoded image data of an icon.
+ * @return Data of the icon.
+ */
+ public static byte[] getIcon(String testPath) {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ try {
+ InputStream faviconStream = (InputStream) (new URL(
+ UrlUtils.getTestFileUrl(testPath))).getContent();
+ Bitmap faviconBitmap = BitmapFactory.decodeStream(faviconStream);
+ faviconBitmap.compress(CompressFormat.PNG, 0, bos);
+ } catch (IOException e) {
+ Log.e(TAG, "Error trying to get the icon '" + testPath + "': " + e.getMessage());
+ }
+ return bos.toByteArray();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698