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

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

Issue 2209333004: Add serialization capabilities to PwsResult (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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/PwsResultTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/PwsResultTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/PwsResultTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..a3547a0e4694196f08501a30645aa6ef3308d113
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/PwsResultTest.java
@@ -0,0 +1,58 @@
+// 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 PwsResult}.
+ */
+public class PwsResultTest extends TestCase {
+ PwsResult mReferencePwsResult = null;
+ JSONObject mReferenceJsonObject = null;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mReferencePwsResult = new PwsResult(
+ "https://shorturl.com",
+ "https://longurl.com",
+ "https://longurl.com/favicon.ico",
+ "This is a page",
+ "Pages are the best",
+ "group1");
+ // Because we can't print JSON sorted by keys, the order is important here.
+ mReferenceJsonObject = new JSONObject("{"
+ + " \"scannedUrl\": \"https://shorturl.com\","
+ + " \"resolvedUrl\": \"https://longurl.com\","
+ + " \"icon\": \"https://longurl.com/favicon.ico\","
+ + " \"title\": \"This is a page\","
+ + " \"description\": \"Pages are the best\","
+ + " \"group\": \"group1\""
+ + "}");
+ }
+
+ @SmallTest
+ public void testJsonSerializeWorks() throws JSONException {
+ assertEquals(mReferenceJsonObject.toString(),
+ mReferencePwsResult.jsonSerialize().toString());
+ }
+
+ @SmallTest
+ public void testJsonDeserializeWorks() throws JSONException {
+ PwsResult pwsResult = PwsResult.jsonDeserialize(mReferenceJsonObject);
+ assertEquals(mReferencePwsResult.requestUrl, pwsResult.requestUrl);
+ assertEquals(mReferencePwsResult.responseUrl, pwsResult.responseUrl);
+ assertEquals(mReferencePwsResult.iconUrl, pwsResult.iconUrl);
+ assertEquals(mReferencePwsResult.title, pwsResult.title);
+ assertEquals(mReferencePwsResult.description, pwsResult.description);
+ assertEquals(mReferencePwsResult.group, pwsResult.group);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698