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

Side by Side Diff: base/android/javatests/src/org/chromium/base/AdvancedMockContextTest.java

Issue 1863353002: 🎯 Fail if an instrumentation test is missing size annotation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add annotation for SiteSettingsPreferencesTest.java Created 4 years, 7 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.base; 5 package org.chromium.base;
6 6
7 import android.app.Application; 7 import android.app.Application;
8 import android.content.ComponentCallbacks; 8 import android.content.ComponentCallbacks;
9 import android.content.ComponentCallbacks2; 9 import android.content.ComponentCallbacks2;
10 import android.content.Context; 10 import android.content.Context;
11 import android.content.res.Configuration; 11 import android.content.res.Configuration;
12 import android.test.InstrumentationTestCase; 12 import android.test.InstrumentationTestCase;
13 import android.test.suitebuilder.annotation.SmallTest;
13 14
14 import org.chromium.base.test.util.AdvancedMockContext; 15 import org.chromium.base.test.util.AdvancedMockContext;
15 16
16 /** 17 /**
17 * Tests for {@link org.chromium.base.test.util.AdvancedMockContext}. 18 * Tests for {@link org.chromium.base.test.util.AdvancedMockContext}.
18 */ 19 */
19 public class AdvancedMockContextTest extends InstrumentationTestCase { 20 public class AdvancedMockContextTest extends InstrumentationTestCase {
20 private static class Callback1 implements ComponentCallbacks { 21 private static class Callback1 implements ComponentCallbacks {
21 protected Configuration mConfiguration; 22 protected Configuration mConfiguration;
22 protected boolean mOnLowMemoryCalled; 23 protected boolean mOnLowMemoryCalled;
(...skipping 11 matching lines...) Expand all
34 35
35 private static class Callback2 extends Callback1 implements ComponentCallbac ks2 { 36 private static class Callback2 extends Callback1 implements ComponentCallbac ks2 {
36 private int mLevel; 37 private int mLevel;
37 38
38 @Override 39 @Override
39 public void onTrimMemory(int level) { 40 public void onTrimMemory(int level) {
40 mLevel = level; 41 mLevel = level;
41 } 42 }
42 } 43 }
43 44
45 @SmallTest
44 public void testComponentCallbacksForTargetContext() { 46 public void testComponentCallbacksForTargetContext() {
45 Context targetContext = getInstrumentation().getTargetContext(); 47 Context targetContext = getInstrumentation().getTargetContext();
46 Application targetApplication = (Application) targetContext.getApplicati onContext(); 48 Application targetApplication = (Application) targetContext.getApplicati onContext();
47 AdvancedMockContext context = new AdvancedMockContext(targetContext); 49 AdvancedMockContext context = new AdvancedMockContext(targetContext);
48 Callback1 callback1 = new Callback1(); 50 Callback1 callback1 = new Callback1();
49 Callback2 callback2 = new Callback2(); 51 Callback2 callback2 = new Callback2();
50 context.registerComponentCallbacks(callback1); 52 context.registerComponentCallbacks(callback1);
51 context.registerComponentCallbacks(callback2); 53 context.registerComponentCallbacks(callback2);
52 54
53 targetApplication.onLowMemory(); 55 targetApplication.onLowMemory();
54 assertTrue("onLowMemory should have been called.", callback1.mOnLowMemor yCalled); 56 assertTrue("onLowMemory should have been called.", callback1.mOnLowMemor yCalled);
55 assertTrue("onLowMemory should have been called.", callback2.mOnLowMemor yCalled); 57 assertTrue("onLowMemory should have been called.", callback2.mOnLowMemor yCalled);
56 58
57 Configuration configuration = new Configuration(); 59 Configuration configuration = new Configuration();
58 targetApplication.onConfigurationChanged(configuration); 60 targetApplication.onConfigurationChanged(configuration);
59 assertEquals("onConfigurationChanged should have been called.", configur ation, 61 assertEquals("onConfigurationChanged should have been called.", configur ation,
60 callback1.mConfiguration); 62 callback1.mConfiguration);
61 assertEquals("onConfigurationChanged should have been called.", configur ation, 63 assertEquals("onConfigurationChanged should have been called.", configur ation,
62 callback2.mConfiguration); 64 callback2.mConfiguration);
63 65
64 targetApplication.onTrimMemory(ComponentCallbacks2.TRIM_MEMORY_MODERATE) ; 66 targetApplication.onTrimMemory(ComponentCallbacks2.TRIM_MEMORY_MODERATE) ;
65 assertEquals("onTrimMemory should have been called.", ComponentCallbacks 2 67 assertEquals("onTrimMemory should have been called.", ComponentCallbacks 2
66 .TRIM_MEMORY_MODERATE, callback2.mLevel); 68 .TRIM_MEMORY_MODERATE, callback2.mLevel);
67 } 69 }
68 } 70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698