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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
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.physicalweb; 5 package org.chromium.chrome.browser.physicalweb;
6 6
7 import android.app.Instrumentation.ActivityMonitor; 7 import android.app.Instrumentation.ActivityMonitor;
8 import android.content.ComponentName; 8 import android.content.ComponentName;
9 import android.content.Context; 9 import android.content.Context;
10 import android.content.ContextWrapper; 10 import android.content.ContextWrapper;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 59 }
60 } 60 }
61 61
62 @Override 62 @Override
63 protected void setUp() throws Exception { 63 protected void setUp() throws Exception {
64 super.setUp(); 64 super.setUp();
65 mContext = getInstrumentation().getTargetContext(); 65 mContext = getInstrumentation().getTargetContext();
66 // Restore the onboarding state 66 // Restore the onboarding state
67 ContextUtils.getAppSharedPreferences().edit().putInt("physical_web", 2). apply(); 67 ContextUtils.getAppSharedPreferences().edit().putInt("physical_web", 2). apply();
68 UrlManager urlManager = UrlManager.getInstance(); 68 UrlManager urlManager = UrlManager.getInstance();
69 urlManager.clearAllUrls();
69 mMockPwsClient = new MockPwsClient(); 70 mMockPwsClient = new MockPwsClient();
70 urlManager.overridePwsClientForTesting(mMockPwsClient); 71 urlManager.overridePwsClientForTesting(mMockPwsClient);
71 urlManager.overrideNotificationManagerForTesting(new MockNotificationMan agerProxy()); 72 urlManager.overrideNotificationManagerForTesting(new MockNotificationMan agerProxy());
72 } 73 }
73 74
74 @SmallTest 75 @SmallTest
75 public void testTapEntryOpensUrl() throws InterruptedException { 76 public void testTapEntryOpensUrl() throws InterruptedException {
76 // Ensure the Physical Web is enabled. 77 // Ensure the Physical Web is enabled.
77 PrivacyPreferencesManager prefsManager = PrivacyPreferencesManager.getIn stance(); 78 PrivacyPreferencesManager prefsManager = PrivacyPreferencesManager.getIn stance();
78 prefsManager.setPhysicalWebEnabled(true); 79 prefsManager.setPhysicalWebEnabled(true);
79 assertFalse(prefsManager.isPhysicalWebOnboarding()); 80 assertFalse(prefsManager.isPhysicalWebOnboarding());
80 assertTrue(prefsManager.isPhysicalWebEnabled()); 81 assertTrue(prefsManager.isPhysicalWebEnabled());
81 82
82 // Add URL. 83 // Add URLs.
83 addUrl(URL, TITLE, DESC); 84 addUrl(URL, TITLE, DESC);
84 85
85 // Launch the Activity. 86 // Launch the Activity.
86 ListUrlsActivity listActivity = launchActivity(); 87 ListUrlsActivity listActivity = launchActivity();
87 TestContextWrapper testContextWrapper = new TestContextWrapper(listActiv ity); 88 TestContextWrapper testContextWrapper = new TestContextWrapper(listActiv ity);
88 listActivity.overrideContextForTesting(testContextWrapper); 89 listActivity.overrideContextForTesting(testContextWrapper);
89 getInstrumentation().waitForIdleSync(); 90 getInstrumentation().waitForIdleSync();
90 View listView = listActivity.findViewById(R.id.physical_web_urls_list); 91 View listView = listActivity.findViewById(R.id.physical_web_urls_list);
91 92
92 // Read the activity and tap the list entry. 93 // Read the activity and tap the list entry.
93 ArrayList<View> entries = new ArrayList<>(); 94 ArrayList<View> entries = new ArrayList<>();
94 listView.findViewsWithText(entries, TITLE, View.FIND_VIEWS_WITH_TEXT); 95 listView.findViewsWithText(entries, TITLE, View.FIND_VIEWS_WITH_TEXT);
95 assertEquals(1, entries.size()); 96 assertEquals(1, entries.size());
96 View entry = entries.get(0); 97 View entry = entries.get(0);
97 TestTouchUtils.singleClickView(getInstrumentation(), entry); 98 TestTouchUtils.singleClickView(getInstrumentation(), entry);
98 testContextWrapper.waitForStartActivity(1000); 99 testContextWrapper.waitForStartActivity(1000);
99 100
100 // Test the fired intent. 101 // Test the fired intent.
101 assertEquals(1, testContextWrapper.startedIntents.size()); 102 assertEquals(1, testContextWrapper.startedIntents.size());
102 assertEquals(URL, testContextWrapper.startedIntents.get(0).getDataString ()); 103 assertEquals(URL, testContextWrapper.startedIntents.get(0).getDataString ());
103 } 104 }
104 105
105 @SmallTest 106 @SmallTest
107 public void testNearestEntryInGroupSelectedNoChange() throws InterruptedExce ption {
108 // Ensure the Physical Web is enabled.
109 PrivacyPreferencesManager prefsManager = PrivacyPreferencesManager.getIn stance();
110 prefsManager.setPhysicalWebEnabled(true);
111 assertFalse(prefsManager.isPhysicalWebOnboarding());
112 assertTrue(prefsManager.isPhysicalWebEnabled());
113 String url2 = "https://example.com/otherpage";
114 UrlInfo urlInfo1 = new UrlInfo(URL, 2.0, System.currentTimeMillis());
115 PwsResult pwsResult1 = new PwsResult(URL, URL, null, TITLE, DESC, null);
116 UrlInfo urlInfo2 = new UrlInfo(url2, 3.0, System.currentTimeMillis());
117 PwsResult pwsResult2 = new PwsResult(url2, url2, null, TITLE, DESC, null );
118
119 // Add the URLs.
120 mMockPwsClient.addPwsResult(pwsResult1);
121 mMockPwsClient.addPwsResult(pwsResult2);
122 mMockPwsClient.addCombinedPwsResults();
123 UrlManager.getInstance().addUrl(urlInfo1);
124 UrlManager.getInstance().addUrl(urlInfo2);
125 getInstrumentation().waitForIdleSync();
126
127 // Launch the Activity.
128 ListUrlsActivity listActivity = launchActivity();
129 TestContextWrapper testContextWrapper = new TestContextWrapper(listActiv ity);
130 listActivity.overrideContextForTesting(testContextWrapper);
131 getInstrumentation().waitForIdleSync();
132 View listView = listActivity.findViewById(R.id.physical_web_urls_list);
133
134 // Read the activity and tap the list entry.
135 ArrayList<View> entries = new ArrayList<>();
136 listView.findViewsWithText(entries, TITLE, View.FIND_VIEWS_WITH_TEXT);
137 assertEquals(1, entries.size());
138 View entry = entries.get(0);
139 TestTouchUtils.singleClickView(getInstrumentation(), entry);
140 testContextWrapper.waitForStartActivity(1000);
141
142 // Test the fired intent to make sure the nearer beacon is selected.
143 assertEquals(1, testContextWrapper.startedIntents.size());
144 assertEquals(URL, testContextWrapper.startedIntents.get(0).getDataString ());
145 }
146
147 @SmallTest
148 public void testNearestEntryInGroupSelectedAfterChange() throws InterruptedE xception {
149 // Ensure the Physical Web is enabled.
150 PrivacyPreferencesManager prefsManager = PrivacyPreferencesManager.getIn stance();
151 prefsManager.setPhysicalWebEnabled(true);
152 assertFalse(prefsManager.isPhysicalWebOnboarding());
153 assertTrue(prefsManager.isPhysicalWebEnabled());
154 String url2 = "https://example.com/otherpage";
155 UrlInfo urlInfo1 = new UrlInfo(URL, 2.0, System.currentTimeMillis());
156 PwsResult pwsResult1 = new PwsResult(URL, URL, null, TITLE, DESC, null);
157 UrlInfo urlInfo2 = new UrlInfo(url2, 3.0, System.currentTimeMillis());
158 PwsResult pwsResult2 = new PwsResult(url2, url2, null, TITLE, DESC, null );
159
160 // Add the URLs.
161 mMockPwsClient.addPwsResult(pwsResult1);
162 mMockPwsClient.addPwsResult(pwsResult2);
163 mMockPwsClient.addCombinedPwsResults();
164 UrlManager.getInstance().addUrl(urlInfo1);
165 UrlManager.getInstance().addUrl(urlInfo2);
166 getInstrumentation().waitForIdleSync();
167
168 // Launch the Activity.
169 ListUrlsActivity listActivity = launchActivity();
170 TestContextWrapper testContextWrapper = new TestContextWrapper(listActiv ity);
171 listActivity.overrideContextForTesting(testContextWrapper);
172 getInstrumentation().waitForIdleSync();
173 urlInfo2.setDistance(1.0);
174 getInstrumentation().waitForIdleSync();
175 View listView = listActivity.findViewById(R.id.physical_web_urls_list);
176
177 // Read the activity and tap the list entry.
178 ArrayList<View> entries = new ArrayList<>();
179 listView.findViewsWithText(entries, TITLE, View.FIND_VIEWS_WITH_TEXT);
180 assertEquals(1, entries.size());
181 View entry = entries.get(0);
182 TestTouchUtils.singleClickView(getInstrumentation(), entry);
183 testContextWrapper.waitForStartActivity(1000);
184
185 // Test the fired intent to make sure the nearer beacon is selected.
186 assertEquals(1, testContextWrapper.startedIntents.size());
187 assertEquals(url2, testContextWrapper.startedIntents.get(0).getDataStrin g());
188 }
189
190 @SmallTest
106 public void testUrlsListEmptyInOnboarding() { 191 public void testUrlsListEmptyInOnboarding() {
107 // In onboarding, we scan for nearby URLs but do not send them to the re solution service to 192 // In onboarding, we scan for nearby URLs but do not send them to the re solution service to
108 // protect the user's privacy. This test checks that the URL list, which only displays 193 // protect the user's privacy. This test checks that the URL list, which only displays
109 // resolved URLs, is empty during onboarding. 194 // resolved URLs, is empty during onboarding.
110 PrivacyPreferencesManager prefsManager = PrivacyPreferencesManager.getIn stance(); 195 PrivacyPreferencesManager prefsManager = PrivacyPreferencesManager.getIn stance();
111 assertTrue(prefsManager.isPhysicalWebOnboarding()); 196 assertTrue(prefsManager.isPhysicalWebOnboarding());
112 assertFalse(prefsManager.isPhysicalWebEnabled()); 197 assertFalse(prefsManager.isPhysicalWebEnabled());
113 198
114 // Add URL. 199 // Add URL.
115 addUrl(URL, TITLE, DESC); 200 addUrl(URL, TITLE, DESC);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 252 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
168 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 253 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
169 ActivityMonitor monitor = 254 ActivityMonitor monitor =
170 getInstrumentation().addMonitor(ListUrlsActivity.class.getName() , null, false); 255 getInstrumentation().addMonitor(ListUrlsActivity.class.getName() , null, false);
171 mContext.startActivity(intent); 256 mContext.startActivity(intent);
172 ListUrlsActivity activity = (ListUrlsActivity) monitor.waitForActivity() ; 257 ListUrlsActivity activity = (ListUrlsActivity) monitor.waitForActivity() ;
173 activity.overridePwsClientForTesting(mMockPwsClient); 258 activity.overridePwsClientForTesting(mMockPwsClient);
174 return activity; 259 return activity;
175 } 260 }
176 } 261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698