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

Unified Diff: chrome/browser/android/interests_service_unittest.cc

Issue 1334233003: Add the JNI code in order to let Java use the InterestsFetcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ntp-interests-retriever
Patch Set: Fix some of the comments Created 5 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/browser/android/interests_service_unittest.cc
diff --git a/chrome/browser/android/interests_service_unittest.cc b/chrome/browser/android/interests_service_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ae9fb41b9d7f3743be40681b1fc4cf85a817d082
--- /dev/null
+++ b/chrome/browser/android/interests_service_unittest.cc
@@ -0,0 +1,46 @@
+// 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.
+
+#include <jni.h>
+
+#include "base/android/jni_android.h"
+#include "chrome/browser/android/interests_service.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using base::android::AttachCurrentThread;
+
+namespace {
+std::vector<InterestsFetcher::Interest> GetEmptyResponse() {
+ return std::vector<InterestsFetcher::Interest>();
+}
+
+std::vector<InterestsFetcher::Interest> GetSuccessfulResponse() {
+ std::vector<InterestsFetcher::Interest> res;
+ res.push_back(
+ InterestsFetcher::Interest{"Google", GURL("https://fake.com/fake.png"), 0.9});
+ res.push_back(InterestsFetcher::Interest{"Google Chrome",
+ GURL("https://fake.com/fake.png"), 0.98});
+ return res;
+}
+
+} // namespace
+
+class InterestsServiceTest : public testing::Test {
+ public:
+ InterestsServiceTest() {}
+};
+
+TEST_F(InterestsServiceTest, ConvertEmptyResponse) {
+ JNIEnv* env = AttachCurrentThread();
+ jobjectArray j_interests =
+ InterestsService::ConvertInterestsToJava(GetEmptyResponse());
+ EXPECT_EQ(0, env->GetArrayLength(j_interests));
+}
+
+TEST_F(InterestsServiceTest, ConvertSucccesfulResponse) {
+ JNIEnv* env = AttachCurrentThread();
+ jobjectArray j_interests =
+ InterestsService::ConvertInterestsToJava(GetSuccessfulResponse());
+ EXPECT_EQ(2, env->GetArrayLength(j_interests));
+}

Powered by Google App Engine
This is Rietveld 408576698