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

Side by Side Diff: chrome/android/junit/src/org/chromium/chrome/browser/omaha/ResponseParserTest.java

Issue 994283006: Add initial test and build files for Robolectric unit test suites. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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.omaha; 5 package org.chromium.chrome.browser.omaha;
6 6
7 import android.test.InstrumentationTestCase; 7 import static org.junit.Assert.assertEquals;
jbudorick 2015/03/24 21:27:07 nix the import statics.
mikecase (-- gone --) 2015/03/24 22:00:40 Done.
8 import android.test.suitebuilder.annotation.SmallTest; 8 import static org.junit.Assert.fail;
9
9 import android.util.Xml; 10 import android.util.Xml;
10 11
11 import org.chromium.base.test.util.Feature; 12 import org.chromium.base.test.util.Feature;
13 import org.chromium.testing.local.LocalRobolectricTestRunner;
14
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17
18 import org.robolectric.annotation.Config;
19
12 import org.xmlpull.v1.XmlSerializer; 20 import org.xmlpull.v1.XmlSerializer;
13 21
14 import java.io.IOException; 22 import java.io.IOException;
15 import java.io.StringWriter; 23 import java.io.StringWriter;
16 24
17 /** 25 /**
18 * Unit tests for the Omaha ResponseParser. 26 * Unit tests for the Omaha ResponseParser.
19 */ 27 */
20 public class ResponseParserTest extends InstrumentationTestCase { 28 @RunWith(LocalRobolectricTestRunner.class)
29 @Config(manifest = Config.NONE)
30 public class ResponseParserTest {
21 // Note that the Omaha server appends "/" to the end of the URL codebase. 31 // Note that the Omaha server appends "/" to the end of the URL codebase.
22 private static final String STRIPPED_URL = 32 private static final String STRIPPED_URL =
23 "https://play.google.com/store/apps/details?id=com.google.android.ap ps.chrome"; 33 "https://play.google.com/store/apps/details?id=com.google.android.ap ps.chrome";
24 private static final String URL = STRIPPED_URL + "/"; 34 private static final String URL = STRIPPED_URL + "/";
25 private static final String NEXT_VERSION = "1.2.3.4"; 35 private static final String NEXT_VERSION = "1.2.3.4";
26 36
27 private static final String APP_STATUS_OK = "ok"; 37 private static final String APP_STATUS_OK = "ok";
28 private static final String APP_STATUS_RESTRICTED = "restricted"; 38 private static final String APP_STATUS_RESTRICTED = "restricted";
29 private static final String APP_STATUS_ERROR = "error-whatever-else"; 39 private static final String APP_STATUS_ERROR = "error-whatever-else";
30 40
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 try { 228 try {
219 parser.parseResponse(xml); 229 parser.parseResponse(xml);
220 } catch (RequestFailureException e) { 230 } catch (RequestFailureException e) {
221 assertEquals("Incorrect error code received.", expectedErrorCode, e. errorCode); 231 assertEquals("Incorrect error code received.", expectedErrorCode, e. errorCode);
222 return; 232 return;
223 } 233 }
224 234
225 fail("Failed to throw RequestFailureException for bad XML."); 235 fail("Failed to throw RequestFailureException for bad XML.");
226 } 236 }
227 237
228 @SmallTest 238 @Test
229 @Feature({"Omaha"}) 239 @Feature({"Omaha"})
230 public void testValidAllTypes() throws RequestFailureException { 240 public void testValidAllTypes() throws RequestFailureException {
231 runSuccessTest(APP_STATUS_OK, true, true, UPDATE_STATUS_OK); 241 runSuccessTest(APP_STATUS_OK, true, true, UPDATE_STATUS_OK);
232 } 242 }
233 243
234 @SmallTest 244 @Test
235 @Feature({"Omaha"}) 245 @Feature({"Omaha"})
236 public void testValidNoInstall() throws RequestFailureException { 246 public void testValidNoInstall() throws RequestFailureException {
237 runSuccessTest(APP_STATUS_OK, false, true, UPDATE_STATUS_OK); 247 runSuccessTest(APP_STATUS_OK, false, true, UPDATE_STATUS_OK);
238 } 248 }
239 249
240 @SmallTest 250 @Test
241 @Feature({"Omaha"}) 251 @Feature({"Omaha"})
242 public void testValidNoPing() throws RequestFailureException { 252 public void testValidNoPing() throws RequestFailureException {
243 runSuccessTest(APP_STATUS_OK, true, false, UPDATE_STATUS_OK); 253 runSuccessTest(APP_STATUS_OK, true, false, UPDATE_STATUS_OK);
244 } 254 }
245 255
246 @SmallTest 256 @Test
247 @Feature({"Omaha"}) 257 @Feature({"Omaha"})
248 public void testValidNoUpdatecheck() throws RequestFailureException { 258 public void testValidNoUpdatecheck() throws RequestFailureException {
249 runSuccessTest(APP_STATUS_OK, true, true, null); 259 runSuccessTest(APP_STATUS_OK, true, true, null);
250 } 260 }
251 261
252 @SmallTest 262 @Test
253 @Feature({"Omaha"}) 263 @Feature({"Omaha"})
254 public void testValidUpdatecheckNoUpdate() throws RequestFailureException { 264 public void testValidUpdatecheckNoUpdate() throws RequestFailureException {
255 runSuccessTest(APP_STATUS_OK, false, false, UPDATE_STATUS_NOUPDATE); 265 runSuccessTest(APP_STATUS_OK, false, false, UPDATE_STATUS_NOUPDATE);
256 } 266 }
257 267
258 @SmallTest 268 @Test
259 @Feature({"Omaha"}) 269 @Feature({"Omaha"})
260 public void testValidUpdatecheckError() throws RequestFailureException { 270 public void testValidUpdatecheckError() throws RequestFailureException {
261 runSuccessTest(APP_STATUS_OK, false, false, UPDATE_STATUS_ERROR); 271 runSuccessTest(APP_STATUS_OK, false, false, UPDATE_STATUS_ERROR);
262 } 272 }
263 273
264 @SmallTest 274 @Test
265 @Feature({"Omaha"}) 275 @Feature({"Omaha"})
266 public void testValidUpdatecheckUnknown() throws RequestFailureException { 276 public void testValidUpdatecheckUnknown() throws RequestFailureException {
267 runSuccessTest(APP_STATUS_OK, false, false, UPDATE_STATUS_WTF); 277 runSuccessTest(APP_STATUS_OK, false, false, UPDATE_STATUS_WTF);
268 } 278 }
269 279
270 @SmallTest 280 @Test
271 @Feature({"Omaha"}) 281 @Feature({"Omaha"})
272 public void testValidAppStatusRestricted() throws RequestFailureException { 282 public void testValidAppStatusRestricted() throws RequestFailureException {
273 runSuccessTest(APP_STATUS_RESTRICTED, false, false, null); 283 runSuccessTest(APP_STATUS_RESTRICTED, false, false, null);
274 } 284 }
275 285
276 @SmallTest 286 @Test
277 @Feature({"Omaha"}) 287 @Feature({"Omaha"})
278 public void testFailBogusResponse() { 288 public void testFailBogusResponse() {
279 String xml = "Bogus"; 289 String xml = "Bogus";
280 runFailureTest(xml, RequestFailureException.ERROR_MALFORMED_XML, false, false, false); 290 runFailureTest(xml, RequestFailureException.ERROR_MALFORMED_XML, false, false, false);
281 } 291 }
282 292
283 @SmallTest 293 @Test
284 @Feature({"Omaha"}) 294 @Feature({"Omaha"})
285 public void testBadResponseProtocol() { 295 public void testBadResponseProtocol() {
286 String xml = 296 String xml =
287 createTestXML("2.0", "12345", APP_STATUS_OK, false, false, UPDAT E_STATUS_OK, URL); 297 createTestXML("2.0", "12345", APP_STATUS_OK, false, false, UPDAT E_STATUS_OK, URL);
288 runFailureTest(xml, RequestFailureException.ERROR_PARSE_RESPONSE, false, false, false); 298 runFailureTest(xml, RequestFailureException.ERROR_PARSE_RESPONSE, false, false, false);
289 } 299 }
290 300
291 @SmallTest 301 @Test
292 @Feature({"Omaha"}) 302 @Feature({"Omaha"})
293 public void testFailMissingDaystart() { 303 public void testFailMissingDaystart() {
294 String xml = 304 String xml =
295 createTestXML("3.0", null, APP_STATUS_OK, false, false, UPDATE_S TATUS_OK, URL); 305 createTestXML("3.0", null, APP_STATUS_OK, false, false, UPDATE_S TATUS_OK, URL);
296 runFailureTest(xml, RequestFailureException.ERROR_PARSE_DAYSTART, false, false, true); 306 runFailureTest(xml, RequestFailureException.ERROR_PARSE_DAYSTART, false, false, true);
297 } 307 }
298 308
299 @SmallTest 309 @Test
300 @Feature({"Omaha"}) 310 @Feature({"Omaha"})
301 public void testAppTagMissingUpdatecheck() { 311 public void testAppTagMissingUpdatecheck() {
302 String xml = 312 String xml =
303 createTestXML("3.0", "12345", APP_STATUS_OK, true, false, null, URL); 313 createTestXML("3.0", "12345", APP_STATUS_OK, true, false, null, URL);
304 runFailureTest(xml, RequestFailureException.ERROR_PARSE_UPDATECHECK, tru e, false, true); 314 runFailureTest(xml, RequestFailureException.ERROR_PARSE_UPDATECHECK, tru e, false, true);
305 } 315 }
306 316
307 @SmallTest 317 @Test
308 @Feature({"Omaha"}) 318 @Feature({"Omaha"})
309 public void testAppTagUnexpectedUpdatecheck() { 319 public void testAppTagUnexpectedUpdatecheck() {
310 String xml = 320 String xml =
311 createTestXML("3.0", "12345", APP_STATUS_OK, true, false, UPDATE _STATUS_OK, URL); 321 createTestXML("3.0", "12345", APP_STATUS_OK, true, false, UPDATE _STATUS_OK, URL);
312 runFailureTest(xml, RequestFailureException.ERROR_PARSE_UPDATECHECK, tru e, false, false); 322 runFailureTest(xml, RequestFailureException.ERROR_PARSE_UPDATECHECK, tru e, false, false);
313 } 323 }
314 324
315 @SmallTest 325 @Test
316 @Feature({"Omaha"}) 326 @Feature({"Omaha"})
317 public void testAppTagMissingPing() { 327 public void testAppTagMissingPing() {
318 String xml = 328 String xml =
319 createTestXML("3.0", "12345", APP_STATUS_OK, false, false, UPDAT E_STATUS_OK, URL); 329 createTestXML("3.0", "12345", APP_STATUS_OK, false, false, UPDAT E_STATUS_OK, URL);
320 runFailureTest(xml, RequestFailureException.ERROR_PARSE_PING, false, tru e, true); 330 runFailureTest(xml, RequestFailureException.ERROR_PARSE_PING, false, tru e, true);
321 } 331 }
322 332
323 @SmallTest 333 @Test
324 @Feature({"Omaha"}) 334 @Feature({"Omaha"})
325 public void testAppTagUnexpectedPing() { 335 public void testAppTagUnexpectedPing() {
326 String xml = 336 String xml =
327 createTestXML("3.0", "12345", APP_STATUS_OK, false, true, UPDATE _STATUS_OK, URL); 337 createTestXML("3.0", "12345", APP_STATUS_OK, false, true, UPDATE _STATUS_OK, URL);
328 runFailureTest(xml, RequestFailureException.ERROR_PARSE_PING, false, fal se, true); 338 runFailureTest(xml, RequestFailureException.ERROR_PARSE_PING, false, fal se, true);
329 } 339 }
330 340
331 @SmallTest 341 @Test
332 @Feature({"Omaha"}) 342 @Feature({"Omaha"})
333 public void testAppTagMissingInstall() { 343 public void testAppTagMissingInstall() {
334 String xml = 344 String xml =
335 createTestXML("3.0", "12345", APP_STATUS_OK, false, false, UPDAT E_STATUS_OK, URL); 345 createTestXML("3.0", "12345", APP_STATUS_OK, false, false, UPDAT E_STATUS_OK, URL);
336 runFailureTest(xml, RequestFailureException.ERROR_PARSE_EVENT, true, fal se, true); 346 runFailureTest(xml, RequestFailureException.ERROR_PARSE_EVENT, true, fal se, true);
337 } 347 }
338 348
339 @SmallTest 349 @Test
340 @Feature({"Omaha"}) 350 @Feature({"Omaha"})
341 public void testAppTagUnexpectedInstall() { 351 public void testAppTagUnexpectedInstall() {
342 String xml = 352 String xml =
343 createTestXML("3.0", "12345", APP_STATUS_OK, true, false, UPDATE _STATUS_OK, URL); 353 createTestXML("3.0", "12345", APP_STATUS_OK, true, false, UPDATE _STATUS_OK, URL);
344 runFailureTest(xml, RequestFailureException.ERROR_PARSE_EVENT, false, fa lse, true); 354 runFailureTest(xml, RequestFailureException.ERROR_PARSE_EVENT, false, fa lse, true);
345 } 355 }
346 356
347 @SmallTest 357 @Test
348 @Feature({"Omaha"}) 358 @Feature({"Omaha"})
349 public void testAppTagStatusError() { 359 public void testAppTagStatusError() {
350 String xml = 360 String xml =
351 createTestXML("3.0", "12345", APP_STATUS_ERROR, false, false, nu ll, URL); 361 createTestXML("3.0", "12345", APP_STATUS_ERROR, false, false, nu ll, URL);
352 runFailureTest(xml, RequestFailureException.ERROR_PARSE_APP, false, fals e, false); 362 runFailureTest(xml, RequestFailureException.ERROR_PARSE_APP, false, fals e, false);
353 } 363 }
354 364
355 @SmallTest 365 @Test
356 @Feature({"Omaha"}) 366 @Feature({"Omaha"})
357 public void testUpdatecheckMissingUrl() { 367 public void testUpdatecheckMissingUrl() {
358 String xml = createTestXML( 368 String xml = createTestXML(
359 "3.0", "12345", APP_STATUS_OK, false, false, UPDATE_STATUS_OK, n ull); 369 "3.0", "12345", APP_STATUS_OK, false, false, UPDATE_STATUS_OK, n ull);
360 runFailureTest(xml, RequestFailureException.ERROR_PARSE_URLS, false, fal se, true); 370 runFailureTest(xml, RequestFailureException.ERROR_PARSE_URLS, false, fal se, true);
361 } 371 }
362 } 372 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698