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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarControlLayoutTest.java

Issue 2766373004: Convert the rest of chrome_public_test_apk InstrumentationTestCases to JUnit4 (Closed)
Patch Set: nits and rebase Created 3 years, 8 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.infobar; 5 package org.chromium.chrome.browser.infobar;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.support.test.InstrumentationRegistry;
9 import android.support.test.annotation.UiThreadTest;
8 import android.support.test.filters.SmallTest; 10 import android.support.test.filters.SmallTest;
9 import android.test.InstrumentationTestCase; 11 import android.support.test.rule.UiThreadTestRule;
10 import android.test.UiThreadTest;
11 import android.view.View; 12 import android.view.View;
12 import android.view.View.MeasureSpec; 13 import android.view.View.MeasureSpec;
13 import android.view.ViewGroup.LayoutParams; 14 import android.view.ViewGroup.LayoutParams;
14 15
16 import org.junit.Assert;
17 import org.junit.Before;
18 import org.junit.Rule;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21
15 import org.chromium.chrome.R; 22 import org.chromium.chrome.R;
16 import org.chromium.chrome.browser.infobar.InfoBarControlLayout.ControlLayoutPar ams; 23 import org.chromium.chrome.browser.infobar.InfoBarControlLayout.ControlLayoutPar ams;
24 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
17 25
18 /** 26 /**
19 * Tests for InfoBarControlLayout. This suite doesn't check for specific detail s, like margins 27 * Tests for InfoBarControlLayout. This suite doesn't check for specific detail s, like margins
20 * paddings, and instead focuses on whether controls are placed correctly. 28 * paddings, and instead focuses on whether controls are placed correctly.
21 */ 29 */
22 public class InfoBarControlLayoutTest extends InstrumentationTestCase { 30 @RunWith(ChromeJUnit4ClassRunner.class)
31 public class InfoBarControlLayoutTest {
23 private static final int SWITCH_ID_1 = 1; 32 private static final int SWITCH_ID_1 = 1;
24 private static final int SWITCH_ID_2 = 2; 33 private static final int SWITCH_ID_2 = 2;
25 private static final int SWITCH_ID_3 = 3; 34 private static final int SWITCH_ID_3 = 3;
26 private static final int SWITCH_ID_4 = 4; 35 private static final int SWITCH_ID_4 = 4;
27 private static final int SWITCH_ID_5 = 5; 36 private static final int SWITCH_ID_5 = 5;
28 private static final int INFOBAR_WIDTH = 3200; 37 private static final int INFOBAR_WIDTH = 3200;
29 38
30 private Context mContext; 39 private Context mContext;
31 40
32 @Override 41 @Rule
42 public UiThreadTestRule mRule = new UiThreadTestRule();
43
44 @Before
33 public void setUp() throws Exception { 45 public void setUp() throws Exception {
34 super.setUp(); 46 mContext = InstrumentationRegistry.getInstrumentation().getTargetContext ();
35 mContext = getInstrumentation().getTargetContext();
36 mContext.setTheme(R.style.MainTheme); 47 mContext.setTheme(R.style.MainTheme);
37 } 48 }
38 49
39 /** 50 /**
40 * A small control on the last line takes up the full width. 51 * A small control on the last line takes up the full width.
41 */ 52 */
53 @Test
42 @SmallTest 54 @SmallTest
43 @UiThreadTest 55 @UiThreadTest
44 public void testOneSmallControlTakesFullWidth() { 56 public void testOneSmallControlTakesFullWidth() {
45 InfoBarControlLayout layout = new InfoBarControlLayout(mContext); 57 InfoBarControlLayout layout = new InfoBarControlLayout(mContext);
46 layout.setLayoutParams( 58 layout.setLayoutParams(
47 new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CO NTENT)); 59 new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CO NTENT));
48 View smallSwitch = layout.addSwitch(0, 0, "A", SWITCH_ID_1, false); 60 View smallSwitch = layout.addSwitch(0, 0, "A", SWITCH_ID_1, false);
49 61
50 // Trigger the measurement algorithm. 62 // Trigger the measurement algorithm.
51 int parentWidthSpec = 63 int parentWidthSpec =
52 MeasureSpec.makeMeasureSpec(INFOBAR_WIDTH, MeasureSpec.AT_MOST); 64 MeasureSpec.makeMeasureSpec(INFOBAR_WIDTH, MeasureSpec.AT_MOST);
53 int parentHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPEC IFIED); 65 int parentHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPEC IFIED);
54 layout.measure(parentWidthSpec, parentHeightSpec); 66 layout.measure(parentWidthSpec, parentHeightSpec);
55 67
56 // Small control takes the full width of the layout because it's put on its own line. 68 // Small control takes the full width of the layout because it's put on its own line.
57 ControlLayoutParams params = InfoBarControlLayout.getControlLayoutParams (smallSwitch); 69 ControlLayoutParams params = InfoBarControlLayout.getControlLayoutParams (smallSwitch);
58 assertEquals(0, params.top); 70 Assert.assertEquals(0, params.top);
59 assertEquals(0, params.start); 71 Assert.assertEquals(0, params.start);
60 assertEquals(2, params.columnsRequired); 72 Assert.assertEquals(2, params.columnsRequired);
61 assertEquals(INFOBAR_WIDTH, smallSwitch.getMeasuredWidth()); 73 Assert.assertEquals(INFOBAR_WIDTH, smallSwitch.getMeasuredWidth());
62 } 74 }
63 75
64 /** 76 /**
65 * Tests the layout algorithm on a set of five controls, the second of which is a huge control 77 * Tests the layout algorithm on a set of five controls, the second of which is a huge control
66 * and takes up the whole line. The other smaller controls try to pack them selves as tightly 78 * and takes up the whole line. The other smaller controls try to pack them selves as tightly
67 * as possible, strecthing out if necessary for aesthetics, resulting in a l ayout like this: 79 * as possible, strecthing out if necessary for aesthetics, resulting in a l ayout like this:
68 * 80 *
69 * ------------------------- 81 * -------------------------
70 * | A (small) | 82 * | A (small) |
71 * ------------------------- 83 * -------------------------
72 * | B (big) | 84 * | B (big) |
73 * ------------------------- 85 * -------------------------
74 * | C (small) | D (small) | 86 * | C (small) | D (small) |
75 * ------------------------- 87 * -------------------------
76 * | E (small) | 88 * | E (small) |
77 * ------------------------- 89 * -------------------------
78 */ 90 */
91 @Test
79 @SmallTest 92 @SmallTest
80 @UiThreadTest 93 @UiThreadTest
81 public void testComplexSwitchLayout() { 94 public void testComplexSwitchLayout() {
82 // Add five controls to the layout. 95 // Add five controls to the layout.
83 InfoBarControlLayout layout = new InfoBarControlLayout(mContext); 96 InfoBarControlLayout layout = new InfoBarControlLayout(mContext);
84 layout.setLayoutParams( 97 layout.setLayoutParams(
85 new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CO NTENT)); 98 new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CO NTENT));
86 99
87 View switch1 = layout.addSwitch(0, 0, "A", SWITCH_ID_1, false); 100 View switch1 = layout.addSwitch(0, 0, "A", SWITCH_ID_1, false);
88 View switch2 = layout.addSwitch(0, 0, "B", SWITCH_ID_2, false); 101 View switch2 = layout.addSwitch(0, 0, "B", SWITCH_ID_2, false);
(...skipping 10 matching lines...) Expand all
99 int parentHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPEC IFIED); 112 int parentHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPEC IFIED);
100 layout.measure(parentWidthSpec, parentHeightSpec); 113 layout.measure(parentWidthSpec, parentHeightSpec);
101 114
102 ControlLayoutParams params1 = InfoBarControlLayout.getControlLayoutParam s(switch1); 115 ControlLayoutParams params1 = InfoBarControlLayout.getControlLayoutParam s(switch1);
103 ControlLayoutParams params2 = InfoBarControlLayout.getControlLayoutParam s(switch2); 116 ControlLayoutParams params2 = InfoBarControlLayout.getControlLayoutParam s(switch2);
104 ControlLayoutParams params3 = InfoBarControlLayout.getControlLayoutParam s(switch3); 117 ControlLayoutParams params3 = InfoBarControlLayout.getControlLayoutParam s(switch3);
105 ControlLayoutParams params4 = InfoBarControlLayout.getControlLayoutParam s(switch4); 118 ControlLayoutParams params4 = InfoBarControlLayout.getControlLayoutParam s(switch4);
106 ControlLayoutParams params5 = InfoBarControlLayout.getControlLayoutParam s(switch5); 119 ControlLayoutParams params5 = InfoBarControlLayout.getControlLayoutParam s(switch5);
107 120
108 // Small control takes the full width of the layout because the next one doesn't fit. 121 // Small control takes the full width of the layout because the next one doesn't fit.
109 assertEquals(0, params1.top); 122 Assert.assertEquals(0, params1.top);
110 assertEquals(0, params1.start); 123 Assert.assertEquals(0, params1.start);
111 assertEquals(2, params1.columnsRequired); 124 Assert.assertEquals(2, params1.columnsRequired);
112 assertEquals(INFOBAR_WIDTH, switch1.getMeasuredWidth()); 125 Assert.assertEquals(INFOBAR_WIDTH, switch1.getMeasuredWidth());
113 126
114 // Big control gets shunted onto the next row and takes up the whole spa ce. 127 // Big control gets shunted onto the next row and takes up the whole spa ce.
115 assertTrue(params2.top > switch1.getMeasuredHeight()); 128 Assert.assertTrue(params2.top > switch1.getMeasuredHeight());
116 assertEquals(0, params2.start); 129 Assert.assertEquals(0, params2.start);
117 assertEquals(2, params2.columnsRequired); 130 Assert.assertEquals(2, params2.columnsRequired);
118 assertEquals(INFOBAR_WIDTH, switch2.getMeasuredWidth()); 131 Assert.assertEquals(INFOBAR_WIDTH, switch2.getMeasuredWidth());
119 132
120 // Small control gets placed onto the next line and takes only half the width. 133 // Small control gets placed onto the next line and takes only half the width.
121 int bottomOfSwitch2 = params2.top + switch2.getMeasuredHeight(); 134 int bottomOfSwitch2 = params2.top + switch2.getMeasuredHeight();
122 assertTrue(params3.top > bottomOfSwitch2); 135 Assert.assertTrue(params3.top > bottomOfSwitch2);
123 assertEquals(0, params3.start); 136 Assert.assertEquals(0, params3.start);
124 assertEquals(1, params3.columnsRequired); 137 Assert.assertEquals(1, params3.columnsRequired);
125 assertTrue(switch3.getMeasuredWidth() < INFOBAR_WIDTH); 138 Assert.assertTrue(switch3.getMeasuredWidth() < INFOBAR_WIDTH);
126 139
127 // Small control gets placed next to the previous small control. 140 // Small control gets placed next to the previous small control.
128 assertEquals(params3.top, params4.top); 141 Assert.assertEquals(params3.top, params4.top);
129 assertTrue(params4.start > switch3.getMeasuredWidth()); 142 Assert.assertTrue(params4.start > switch3.getMeasuredWidth());
130 assertEquals(1, params4.columnsRequired); 143 Assert.assertEquals(1, params4.columnsRequired);
131 assertTrue(switch4.getMeasuredWidth() < INFOBAR_WIDTH); 144 Assert.assertTrue(switch4.getMeasuredWidth() < INFOBAR_WIDTH);
132 145
133 // Last small control has no room left and gets put on its own line, tak ing the full width. 146 // Last small control has no room left and gets put on its own line, tak ing the full width.
134 int bottomOfSwitch4 = params4.top + switch4.getMeasuredHeight(); 147 int bottomOfSwitch4 = params4.top + switch4.getMeasuredHeight();
135 assertTrue(params5.top > bottomOfSwitch4); 148 Assert.assertTrue(params5.top > bottomOfSwitch4);
136 assertEquals(0, params5.start); 149 Assert.assertEquals(0, params5.start);
137 assertEquals(2, params5.columnsRequired); 150 Assert.assertEquals(2, params5.columnsRequired);
138 assertEquals(INFOBAR_WIDTH, switch5.getMeasuredWidth()); 151 Assert.assertEquals(INFOBAR_WIDTH, switch5.getMeasuredWidth());
139 } 152 }
140 153
141 /** 154 /**
142 * Tests that the message is always the full width of the layout. 155 * Tests that the message is always the full width of the layout.
143 */ 156 */
157 @Test
144 @SmallTest 158 @SmallTest
145 @UiThreadTest 159 @UiThreadTest
146 public void testFullWidthMessageControl() { 160 public void testFullWidthMessageControl() {
147 // Add two controls to the layout. The main message automatically reque sts the full width. 161 // Add two controls to the layout. The main message automatically reque sts the full width.
148 InfoBarControlLayout layout = new InfoBarControlLayout(mContext); 162 InfoBarControlLayout layout = new InfoBarControlLayout(mContext);
149 layout.setLayoutParams( 163 layout.setLayoutParams(
150 new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CO NTENT)); 164 new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CO NTENT));
151 165
152 View view1 = layout.addMainMessage("A"); 166 View view1 = layout.addMainMessage("A");
153 View view2 = layout.addSwitch(0, 0, "B", SWITCH_ID_2, false); 167 View view2 = layout.addSwitch(0, 0, "B", SWITCH_ID_2, false);
154 168
155 // Trigger the measurement algorithm. 169 // Trigger the measurement algorithm.
156 int parentWidthSpec = 170 int parentWidthSpec =
157 MeasureSpec.makeMeasureSpec(INFOBAR_WIDTH, MeasureSpec.AT_MOST); 171 MeasureSpec.makeMeasureSpec(INFOBAR_WIDTH, MeasureSpec.AT_MOST);
158 int parentHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPEC IFIED); 172 int parentHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPEC IFIED);
159 layout.measure(parentWidthSpec, parentHeightSpec); 173 layout.measure(parentWidthSpec, parentHeightSpec);
160 174
161 ControlLayoutParams params1 = InfoBarControlLayout.getControlLayoutParam s(view1); 175 ControlLayoutParams params1 = InfoBarControlLayout.getControlLayoutParam s(view1);
162 ControlLayoutParams params2 = InfoBarControlLayout.getControlLayoutParam s(view2); 176 ControlLayoutParams params2 = InfoBarControlLayout.getControlLayoutParam s(view2);
163 177
164 // Main message takes up the full space. 178 // Main message takes up the full space.
165 assertEquals(0, params1.top); 179 Assert.assertEquals(0, params1.top);
166 assertEquals(0, params1.start); 180 Assert.assertEquals(0, params1.start);
167 assertEquals(2, params1.columnsRequired); 181 Assert.assertEquals(2, params1.columnsRequired);
168 assertEquals(INFOBAR_WIDTH, view1.getMeasuredWidth()); 182 Assert.assertEquals(INFOBAR_WIDTH, view1.getMeasuredWidth());
169 183
170 // Small control gets shunted onto the next row. 184 // Small control gets shunted onto the next row.
171 assertTrue(params2.top > view1.getMeasuredHeight()); 185 Assert.assertTrue(params2.top > view1.getMeasuredHeight());
172 assertEquals(0, params2.start); 186 Assert.assertEquals(0, params2.start);
173 assertEquals(2, params2.columnsRequired); 187 Assert.assertEquals(2, params2.columnsRequired);
174 assertEquals(INFOBAR_WIDTH, view2.getMeasuredWidth()); 188 Assert.assertEquals(INFOBAR_WIDTH, view2.getMeasuredWidth());
175 } 189 }
176 } 190 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698