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

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: Created 5 years, 3 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..e006d92f4fe9d14c0a67cc0d12d24259d3a89bfa
--- /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", "https://fake.com/fake.png", 0.9});
+ res.push_back(InterestsFetcher::Interest{"Google Chrome",
+ "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());
+ CHECK_EQ(env->GetArrayLength(j_interests), 0);
Marc Treib 2015/09/11 16:02:14 EXPECT_EQ (CHECK will make the test crash) Also,
tache 2015/09/18 09:41:21 Done.
+}
+
+TEST_F(InterestsServiceTest, ConvertSucccesfulResponse) {
+ JNIEnv* env = AttachCurrentThread();
+ jobjectArray j_interests =
+ InterestsService::ConvertInterestsToJava(GetSuccessfulResponse());
+ CHECK_EQ(env->GetArrayLength(j_interests), 2);
+}

Powered by Google App Engine
This is Rietveld 408576698