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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/engagement/SiteEngagementServiceTest.java

Issue 2553013002: Expose the Site Engagement Service to Java. (Closed)
Patch Set: LocalRef to GlobalRef Created 4 years 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/engagement/SiteEngagementServiceTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/engagement/SiteEngagementServiceTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/engagement/SiteEngagementServiceTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..35e546831886b24d5f8d41cf345f966837fdc185
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/engagement/SiteEngagementServiceTest.java
@@ -0,0 +1,65 @@
+// Copyright 2016 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.engagement;
+
+import android.test.UiThreadTest;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.chromium.base.test.util.Feature;
+import org.chromium.chrome.browser.ChromeActivity;
+import org.chromium.chrome.browser.profiles.Profile;
+import org.chromium.chrome.test.ChromeActivityTestCaseBase;
+
+/**
+ * Test for the Site Engagement Service Java binding.
+ */
+public class SiteEngagementServiceTest extends ChromeActivityTestCaseBase<ChromeActivity> {
+
+ public SiteEngagementServiceTest() {
+ super(ChromeActivity.class);
+ }
+
+ /**
+ * Verify that setting the engagement score for a URL and reading it back it works.
+ */
+ @SmallTest
+ @UiThreadTest
+ @Feature({"Engagement"})
+ public void testSettingAndRetrievingScore() {
+ final String url = "https://www.google.com";
+ SiteEngagementService service = SiteEngagementService.getForProfile(
+ getActivity().getActivityTab().getProfile());
+
+ assertEquals(0.0, service.getScore(url));
+ service.resetScoreForUrl(url, 5.0);
+ assertEquals(5.0, service.getScore(url));
+
+ service.resetScoreForUrl(url, 2.0);
+ assertEquals(2.0, service.getScore(url));
+ }
+
+ /**
+ * Verify that repeatedly fetching and throwing away the SiteEngagementService works.
+ */
+ @SmallTest
+ @UiThreadTest
+ @Feature({"Engagement"})
+ public void testRepeatedlyGettingService() {
+ final String url = "https://www.google.com";
+ Profile profile = getActivity().getActivityTab().getProfile();
+
+ assertEquals(0.0, SiteEngagementService.getForProfile(profile).getScore(url));
+ SiteEngagementService.getForProfile(profile).resetScoreForUrl(url, 5.0);
+ assertEquals(5.0, SiteEngagementService.getForProfile(profile).getScore(url));
+
+ SiteEngagementService.getForProfile(profile).resetScoreForUrl(url, 2.0);
+ assertEquals(2.0, SiteEngagementService.getForProfile(profile).getScore(url));
+ }
+
+ @Override
+ public void startMainActivity() throws InterruptedException {
+ startMainActivityOnBlankPage();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698