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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/feedback/ConnectivityTaskTest.java

Issue 1220053004: [Feedback] Add connection type data to feedback reports. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@change-test-types-for-feedback
Patch Set: Rebased Created 5 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.feedback; 5 package org.chromium.chrome.browser.feedback;
6 6
7 import android.test.suitebuilder.annotation.MediumTest; 7 import android.test.suitebuilder.annotation.MediumTest;
8 import android.test.suitebuilder.annotation.SmallTest; 8 import android.test.suitebuilder.annotation.SmallTest;
9 9
10 import org.chromium.base.ThreadUtils; 10 import org.chromium.base.ThreadUtils;
11 import org.chromium.base.test.util.Feature; 11 import org.chromium.base.test.util.Feature;
12 import org.chromium.chrome.browser.feedback.ConnectivityTask.FeedbackData; 12 import org.chromium.chrome.browser.feedback.ConnectivityTask.FeedbackData;
13 import org.chromium.chrome.browser.feedback.ConnectivityTask.Type; 13 import org.chromium.chrome.browser.feedback.ConnectivityTask.Type;
14 import org.chromium.chrome.browser.profiles.Profile; 14 import org.chromium.chrome.browser.profiles.Profile;
15 import org.chromium.content.browser.test.util.Criteria; 15 import org.chromium.content.browser.test.util.Criteria;
16 import org.chromium.content.browser.test.util.CriteriaHelper; 16 import org.chromium.content.browser.test.util.CriteriaHelper;
17 import org.chromium.net.ConnectionType;
17 18
18 import java.util.HashMap; 19 import java.util.HashMap;
19 import java.util.Map; 20 import java.util.Map;
20 import java.util.concurrent.Semaphore; 21 import java.util.concurrent.Semaphore;
21 import java.util.concurrent.TimeUnit; 22 import java.util.concurrent.TimeUnit;
22 import java.util.concurrent.atomic.AtomicReference; 23 import java.util.concurrent.atomic.AtomicReference;
23 24
24 /** 25 /**
25 * Tests for {@link ConnectivityTask}. 26 * Tests for {@link ConnectivityTask}.
26 */ 27 */
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 break; 69 break;
69 default: 70 default:
70 fail("Failed to recognize type " + result.getKey()); 71 fail("Failed to recognize type " + result.getKey());
71 } 72 }
72 } 73 }
73 assertTrue("The elapsed time should be non-negative.", feedback.getElaps edTimeMs() >= 0); 74 assertTrue("The elapsed time should be non-negative.", feedback.getElaps edTimeMs() >= 0);
74 } 75 }
75 76
76 private static void assertResult(int expectedValue, Map.Entry<Type, Integer> actualEntry) { 77 private static void assertResult(int expectedValue, Map.Entry<Type, Integer> actualEntry) {
77 assertEquals("Wrong result for " + actualEntry.getKey(), 78 assertEquals("Wrong result for " + actualEntry.getKey(),
78 ConnectivityTask.getHumanReadableString(expectedValue), 79 ConnectivityTask.getHumanReadableResult(expectedValue),
79 ConnectivityTask.getHumanReadableString(actualEntry.getValue())) ; 80 ConnectivityTask.getHumanReadableResult(actualEntry.getValue())) ;
80 } 81 }
81 82
82 @SmallTest 83 @SmallTest
83 @Feature({"Feedback"}) 84 @Feature({"Feedback"})
84 public void testCallbackNormalCaseShouldWork() throws InterruptedException { 85 public void testCallbackNormalCaseShouldWork() throws InterruptedException {
85 final Semaphore semaphore = new Semaphore(0); 86 final Semaphore semaphore = new Semaphore(0);
86 final AtomicReference<ConnectivityTask> task = new AtomicReference<>(); 87 final AtomicReference<ConnectivityTask> task = new AtomicReference<>();
87 final AtomicReference<FeedbackData> feedbackRef = new AtomicReference<>( ); 88 final AtomicReference<FeedbackData> feedbackRef = new AtomicReference<>( );
88 final ConnectivityTask.ConnectivityResult callback = 89 final ConnectivityTask.ConnectivityResult callback =
89 new ConnectivityTask.ConnectivityResult() { 90 new ConnectivityTask.ConnectivityResult() {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 177
177 @SmallTest 178 @SmallTest
178 @Feature({"Feedback"}) 179 @Feature({"Feedback"})
179 public void testFeedbackDataConversion() { 180 public void testFeedbackDataConversion() {
180 Map<Type, Integer> connectionMap = new HashMap<>(); 181 Map<Type, Integer> connectionMap = new HashMap<>();
181 connectionMap.put(Type.CHROME_HTTP, ConnectivityCheckResult.NOT_CONNECTE D); 182 connectionMap.put(Type.CHROME_HTTP, ConnectivityCheckResult.NOT_CONNECTE D);
182 connectionMap.put(Type.CHROME_HTTPS, ConnectivityCheckResult.CONNECTED); 183 connectionMap.put(Type.CHROME_HTTPS, ConnectivityCheckResult.CONNECTED);
183 connectionMap.put(Type.SYSTEM_HTTP, ConnectivityCheckResult.UNKNOWN); 184 connectionMap.put(Type.SYSTEM_HTTP, ConnectivityCheckResult.UNKNOWN);
184 connectionMap.put(Type.SYSTEM_HTTPS, ConnectivityCheckResult.CONNECTED); 185 connectionMap.put(Type.SYSTEM_HTTPS, ConnectivityCheckResult.CONNECTED);
185 186
186 FeedbackData feedback = new FeedbackData(connectionMap, 42, 21); 187 FeedbackData feedback =
188 new FeedbackData(connectionMap, 42, 21, ConnectionType.CONNECTIO N_WIFI, 4.2);
187 Map<String, String> map = feedback.toMap(); 189 Map<String, String> map = feedback.toMap();
188 190
189 assertEquals("Should have 6 entries.", 6, map.size()); 191 assertEquals("Should have 8 entries.", 8, map.size());
190 assertTrue(map.containsKey(ConnectivityTask.CHROME_HTTP_KEY)); 192 assertTrue(map.containsKey(ConnectivityTask.CHROME_HTTP_KEY));
191 assertEquals("NOT_CONNECTED", map.get(ConnectivityTask.CHROME_HTTP_KEY)) ; 193 assertEquals("NOT_CONNECTED", map.get(ConnectivityTask.CHROME_HTTP_KEY)) ;
192 assertTrue(map.containsKey(ConnectivityTask.CHROME_HTTPS_KEY)); 194 assertTrue(map.containsKey(ConnectivityTask.CHROME_HTTPS_KEY));
193 assertEquals("CONNECTED", map.get(ConnectivityTask.CHROME_HTTPS_KEY)); 195 assertEquals("CONNECTED", map.get(ConnectivityTask.CHROME_HTTPS_KEY));
194 assertTrue(map.containsKey(ConnectivityTask.SYSTEM_HTTP_KEY)); 196 assertTrue(map.containsKey(ConnectivityTask.SYSTEM_HTTP_KEY));
195 assertEquals("UNKNOWN", map.get(ConnectivityTask.SYSTEM_HTTP_KEY)); 197 assertEquals("UNKNOWN", map.get(ConnectivityTask.SYSTEM_HTTP_KEY));
196 assertTrue(map.containsKey(ConnectivityTask.SYSTEM_HTTPS_KEY)); 198 assertTrue(map.containsKey(ConnectivityTask.SYSTEM_HTTPS_KEY));
197 assertEquals("CONNECTED", map.get(ConnectivityTask.SYSTEM_HTTPS_KEY)); 199 assertEquals("CONNECTED", map.get(ConnectivityTask.SYSTEM_HTTPS_KEY));
198 assertTrue(map.containsKey(ConnectivityTask.CONNECTION_CHECK_TIMEOUT_KEY )); 200 assertTrue(map.containsKey(ConnectivityTask.CONNECTION_CHECK_TIMEOUT_KEY ));
199 assertEquals("42", map.get(ConnectivityTask.CONNECTION_CHECK_TIMEOUT_KEY )); 201 assertEquals("42", map.get(ConnectivityTask.CONNECTION_CHECK_TIMEOUT_KEY ));
200 assertTrue(map.containsKey(ConnectivityTask.CONNECTION_CHECK_ELAPSED_KEY )); 202 assertTrue(map.containsKey(ConnectivityTask.CONNECTION_CHECK_ELAPSED_KEY ));
201 assertEquals("21", map.get(ConnectivityTask.CONNECTION_CHECK_ELAPSED_KEY )); 203 assertEquals("21", map.get(ConnectivityTask.CONNECTION_CHECK_ELAPSED_KEY ));
204 assertTrue(map.containsKey(ConnectivityTask.CONNECTION_TYPE_KEY));
205 assertEquals("WiFi", map.get(ConnectivityTask.CONNECTION_TYPE_KEY));
206 assertTrue(map.containsKey(ConnectivityTask.CONNECTION_BANDWIDTH_KEY));
207 assertEquals("4.2", map.get(ConnectivityTask.CONNECTION_BANDWIDTH_KEY));
202 } 208 }
203 209
204 private static FeedbackData getResult(final AtomicReference<ConnectivityTask > task) { 210 private static FeedbackData getResult(final AtomicReference<ConnectivityTask > task) {
205 final AtomicReference<FeedbackData> result = new AtomicReference<>(); 211 final AtomicReference<FeedbackData> result = new AtomicReference<>();
206 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 212 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
207 @Override 213 @Override
208 public void run() { 214 public void run() {
209 result.set(task.get().get()); 215 result.set(task.get().get());
210 } 216 }
211 }); 217 });
212 return result.get(); 218 return result.get();
213 } 219 }
214 } 220 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698