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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/UrlInfoTest.java

Issue 1970743003: Test Physical Web metadata serialization (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 7 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/physicalweb/UrlInfoTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/UrlInfoTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/UrlInfoTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..3f29bcfeb6b55643fbea68ac94654cc004a9c409
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/UrlInfoTest.java
@@ -0,0 +1,43 @@
+// Copyright 2015 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.browser.physicalweb;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import junit.framework.TestCase;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Tests for {@link UrlInfo}.
+ */
+public class UrlInfoTest extends TestCase {
+ private static final String URL = "https://example.com";
+ UrlInfo mReferenceUrlInfo = null;
+ JSONObject mReferenceJsonObject = null;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mReferenceUrlInfo = new UrlInfo(URL, 99.5, 42);
+ // Because we can't print JSON sorted by keys, the order is important here.
+ mReferenceJsonObject = new JSONObject("{"
+ + " \"url\": \"" + URL + "\","
+ + " \"distance\": 99.5,"
+ + " \"scan_timestamp\": 42"
+ + "}");
+ }
+
+ @SmallTest
+ public void testJsonSerializeWorks() throws JSONException {
+ assertEquals(mReferenceJsonObject.toString(), mReferenceUrlInfo.jsonSerialize().toString());
+ }
+
+ @SmallTest
+ public void testJsonDeserializeWorks() throws JSONException {
+ assertEquals(mReferenceUrlInfo, UrlInfo.jsonDeserialize(mReferenceJsonObject));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698