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

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

Issue 2224223002: Combine Physical Web URLs into groups (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make mPwsResults final 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/ListUrlsActivityTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/ListUrlsActivityTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/ListUrlsActivityTest.java
index 14756b9362a0ce64d32e52881697c8105d4891f4..7bfb9e4603ee0f50944778c1ddb3b9b14920d75b 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/ListUrlsActivityTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/ListUrlsActivityTest.java
@@ -66,6 +66,7 @@ public class ListUrlsActivityTest extends InstrumentationTestCase {
// Restore the onboarding state
ContextUtils.getAppSharedPreferences().edit().putInt("physical_web", 2).apply();
UrlManager urlManager = UrlManager.getInstance();
+ urlManager.clearAllUrls();
mMockPwsClient = new MockPwsClient();
urlManager.overridePwsClientForTesting(mMockPwsClient);
urlManager.overrideNotificationManagerForTesting(new MockNotificationManagerProxy());
@@ -79,7 +80,7 @@ public class ListUrlsActivityTest extends InstrumentationTestCase {
assertFalse(prefsManager.isPhysicalWebOnboarding());
assertTrue(prefsManager.isPhysicalWebEnabled());
- // Add URL.
+ // Add URLs.
addUrl(URL, TITLE, DESC);
// Launch the Activity.
@@ -103,6 +104,90 @@ public class ListUrlsActivityTest extends InstrumentationTestCase {
}
@SmallTest
+ public void testNearestEntryInGroupSelectedNoChange() throws InterruptedException {
+ // Ensure the Physical Web is enabled.
+ PrivacyPreferencesManager prefsManager = PrivacyPreferencesManager.getInstance();
+ prefsManager.setPhysicalWebEnabled(true);
+ assertFalse(prefsManager.isPhysicalWebOnboarding());
+ assertTrue(prefsManager.isPhysicalWebEnabled());
+ String url2 = "https://example.com/otherpage";
+ UrlInfo urlInfo1 = new UrlInfo(URL, 2.0, System.currentTimeMillis());
+ PwsResult pwsResult1 = new PwsResult(URL, URL, null, TITLE, DESC, null);
+ UrlInfo urlInfo2 = new UrlInfo(url2, 3.0, System.currentTimeMillis());
+ PwsResult pwsResult2 = new PwsResult(url2, url2, null, TITLE, DESC, null);
+
+ // Add the URLs.
+ mMockPwsClient.addPwsResult(pwsResult1);
+ mMockPwsClient.addPwsResult(pwsResult2);
+ mMockPwsClient.addCombinedPwsResults();
+ UrlManager.getInstance().addUrl(urlInfo1);
+ UrlManager.getInstance().addUrl(urlInfo2);
+ getInstrumentation().waitForIdleSync();
+
+ // Launch the Activity.
+ ListUrlsActivity listActivity = launchActivity();
+ TestContextWrapper testContextWrapper = new TestContextWrapper(listActivity);
+ listActivity.overrideContextForTesting(testContextWrapper);
+ getInstrumentation().waitForIdleSync();
+ View listView = listActivity.findViewById(R.id.physical_web_urls_list);
+
+ // Read the activity and tap the list entry.
+ ArrayList<View> entries = new ArrayList<>();
+ listView.findViewsWithText(entries, TITLE, View.FIND_VIEWS_WITH_TEXT);
+ assertEquals(1, entries.size());
+ View entry = entries.get(0);
+ TestTouchUtils.singleClickView(getInstrumentation(), entry);
+ testContextWrapper.waitForStartActivity(1000);
+
+ // Test the fired intent to make sure the nearer beacon is selected.
+ assertEquals(1, testContextWrapper.startedIntents.size());
+ assertEquals(URL, testContextWrapper.startedIntents.get(0).getDataString());
+ }
+
+ @SmallTest
+ public void testNearestEntryInGroupSelectedAfterChange() throws InterruptedException {
+ // Ensure the Physical Web is enabled.
+ PrivacyPreferencesManager prefsManager = PrivacyPreferencesManager.getInstance();
+ prefsManager.setPhysicalWebEnabled(true);
+ assertFalse(prefsManager.isPhysicalWebOnboarding());
+ assertTrue(prefsManager.isPhysicalWebEnabled());
+ String url2 = "https://example.com/otherpage";
+ UrlInfo urlInfo1 = new UrlInfo(URL, 2.0, System.currentTimeMillis());
+ PwsResult pwsResult1 = new PwsResult(URL, URL, null, TITLE, DESC, null);
+ UrlInfo urlInfo2 = new UrlInfo(url2, 3.0, System.currentTimeMillis());
+ PwsResult pwsResult2 = new PwsResult(url2, url2, null, TITLE, DESC, null);
+
+ // Add the URLs.
+ mMockPwsClient.addPwsResult(pwsResult1);
+ mMockPwsClient.addPwsResult(pwsResult2);
+ mMockPwsClient.addCombinedPwsResults();
+ UrlManager.getInstance().addUrl(urlInfo1);
+ UrlManager.getInstance().addUrl(urlInfo2);
+ getInstrumentation().waitForIdleSync();
+
+ // Launch the Activity.
+ ListUrlsActivity listActivity = launchActivity();
+ TestContextWrapper testContextWrapper = new TestContextWrapper(listActivity);
+ listActivity.overrideContextForTesting(testContextWrapper);
+ getInstrumentation().waitForIdleSync();
+ urlInfo2.setDistance(1.0);
+ getInstrumentation().waitForIdleSync();
+ View listView = listActivity.findViewById(R.id.physical_web_urls_list);
+
+ // Read the activity and tap the list entry.
+ ArrayList<View> entries = new ArrayList<>();
+ listView.findViewsWithText(entries, TITLE, View.FIND_VIEWS_WITH_TEXT);
+ assertEquals(1, entries.size());
+ View entry = entries.get(0);
+ TestTouchUtils.singleClickView(getInstrumentation(), entry);
+ testContextWrapper.waitForStartActivity(1000);
+
+ // Test the fired intent to make sure the nearer beacon is selected.
+ assertEquals(1, testContextWrapper.startedIntents.size());
+ assertEquals(url2, testContextWrapper.startedIntents.get(0).getDataString());
+ }
+
+ @SmallTest
public void testUrlsListEmptyInOnboarding() {
// In onboarding, we scan for nearby URLs but do not send them to the resolution service to
// protect the user's privacy. This test checks that the URL list, which only displays

Powered by Google App Engine
This is Rietveld 408576698