| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.engagement; | 5 package org.chromium.chrome.browser.engagement; |
| 6 | 6 |
| 7 import android.support.test.filters.SmallTest; | 7 import android.support.test.filters.SmallTest; |
| 8 import android.test.UiThreadTest; | |
| 9 | 8 |
| 9 import org.junit.Assert; |
| 10 import org.junit.Before; |
| 11 import org.junit.Rule; |
| 12 import org.junit.Test; |
| 13 import org.junit.runner.RunWith; |
| 14 |
| 15 import org.chromium.base.test.util.CommandLineFlags; |
| 10 import org.chromium.base.test.util.Feature; | 16 import org.chromium.base.test.util.Feature; |
| 11 import org.chromium.chrome.browser.ChromeActivity; | 17 import org.chromium.chrome.browser.ChromeActivity; |
| 18 import org.chromium.chrome.browser.ChromeSwitches; |
| 12 import org.chromium.chrome.browser.profiles.Profile; | 19 import org.chromium.chrome.browser.profiles.Profile; |
| 13 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 20 import org.chromium.chrome.test.ChromeActivityTestRule; |
| 21 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
| 14 | 22 |
| 15 /** | 23 /** |
| 16 * Test for the Site Engagement Service Java binding. | 24 * Test for the Site Engagement Service Java binding. |
| 17 */ | 25 */ |
| 18 public class SiteEngagementServiceTest extends ChromeActivityTestCaseBase<Chrome
Activity> { | 26 @RunWith(ChromeJUnit4ClassRunner.class) |
| 19 | 27 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
| 20 public SiteEngagementServiceTest() { | 28 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
| 21 super(ChromeActivity.class); | 29 public class SiteEngagementServiceTest { |
| 22 } | 30 @Rule |
| 31 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = |
| 32 new ChromeActivityTestRule<>(ChromeActivity.class); |
| 23 | 33 |
| 24 /** | 34 /** |
| 25 * Verify that setting the engagement score for a URL and reading it back it
works. | 35 * Verify that setting the engagement score for a URL and reading it back it
works. |
| 26 */ | 36 */ |
| 37 @Test |
| 27 @SmallTest | 38 @SmallTest |
| 28 @UiThreadTest | |
| 29 @Feature({"Engagement"}) | 39 @Feature({"Engagement"}) |
| 30 public void testSettingAndRetrievingScore() { | 40 public void testSettingAndRetrievingScore() throws Throwable { |
| 31 final String url = "https://www.google.com"; | 41 mActivityTestRule.runOnUiThread(new Runnable() { |
| 32 SiteEngagementService service = SiteEngagementService.getForProfile( | 42 @Override |
| 33 getActivity().getActivityTab().getProfile()); | 43 public void run() { |
| 44 final String url = "https://www.google.com"; |
| 45 SiteEngagementService service = SiteEngagementService.getForProf
ile( |
| 46 mActivityTestRule.getActivity().getActivityTab().getProf
ile()); |
| 34 | 47 |
| 35 assertEquals(0.0, service.getScore(url)); | 48 Assert.assertEquals(0.0, service.getScore(url), 0); |
| 36 service.resetBaseScoreForUrl(url, 5.0); | 49 service.resetBaseScoreForUrl(url, 5.0); |
| 37 assertEquals(5.0, service.getScore(url)); | 50 Assert.assertEquals(5.0, service.getScore(url), 0); |
| 38 | 51 |
| 39 service.resetBaseScoreForUrl(url, 2.0); | 52 service.resetBaseScoreForUrl(url, 2.0); |
| 40 assertEquals(2.0, service.getScore(url)); | 53 Assert.assertEquals(2.0, service.getScore(url), 0); |
| 54 } |
| 55 }); |
| 41 } | 56 } |
| 42 | 57 |
| 43 /** | 58 /** |
| 44 * Verify that repeatedly fetching and throwing away the SiteEngagementServi
ce works. | 59 * Verify that repeatedly fetching and throwing away the SiteEngagementServi
ce works. |
| 45 */ | 60 */ |
| 61 @Test |
| 46 @SmallTest | 62 @SmallTest |
| 47 @UiThreadTest | |
| 48 @Feature({"Engagement"}) | 63 @Feature({"Engagement"}) |
| 49 public void testRepeatedlyGettingService() { | 64 public void testRepeatedlyGettingService() throws Throwable { |
| 50 final String url = "https://www.google.com"; | 65 mActivityTestRule.runOnUiThread(new Runnable() { |
| 51 Profile profile = getActivity().getActivityTab().getProfile(); | 66 @Override |
| 67 public void run() { |
| 68 final String url = "https://www.google.com"; |
| 69 Profile profile = mActivityTestRule.getActivity().getActivityTab
().getProfile(); |
| 52 | 70 |
| 53 assertEquals(0.0, SiteEngagementService.getForProfile(profile).getScore(
url)); | 71 Assert.assertEquals( |
| 54 SiteEngagementService.getForProfile(profile).resetBaseScoreForUrl(url, 5
.0); | 72 0.0, SiteEngagementService.getForProfile(profile).getSco
re(url), 0); |
| 55 assertEquals(5.0, SiteEngagementService.getForProfile(profile).getScore(
url)); | 73 SiteEngagementService.getForProfile(profile).resetBaseScoreForUr
l(url, 5.0); |
| 74 Assert.assertEquals( |
| 75 5.0, SiteEngagementService.getForProfile(profile).getSco
re(url), 0); |
| 56 | 76 |
| 57 SiteEngagementService.getForProfile(profile).resetBaseScoreForUrl(url, 2
.0); | 77 SiteEngagementService.getForProfile(profile).resetBaseScoreForUr
l(url, 2.0); |
| 58 assertEquals(2.0, SiteEngagementService.getForProfile(profile).getScore(
url)); | 78 Assert.assertEquals( |
| 79 2.0, SiteEngagementService.getForProfile(profile).getSco
re(url), 0); |
| 80 } |
| 81 }); |
| 59 } | 82 } |
| 60 | 83 |
| 61 @Override | 84 @Before |
| 62 public void startMainActivity() throws InterruptedException { | 85 public void setUp() throws InterruptedException { |
| 63 startMainActivityOnBlankPage(); | 86 mActivityTestRule.startMainActivityOnBlankPage(); |
| 64 } | 87 } |
| 65 } | 88 } |
| OLD | NEW |