| Index: chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarControlLayoutTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarControlLayoutTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarControlLayoutTest.java
|
| index 8077c0e1a13051b723916780cea9399a2557c322..5e0b5a5c5f80ffb2c7ccbfc9dc9741adc81a9f55 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarControlLayoutTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarControlLayoutTest.java
|
| @@ -38,24 +38,49 @@ public class InfoBarControlLayoutTest extends InstrumentationTestCase {
|
| }
|
|
|
| /**
|
| + * A small control on the last line takes up the full width.
|
| + */
|
| + @SmallTest
|
| + @UiThreadTest
|
| + public void testOneSmallControlTakesFullWidth() {
|
| + InfoBarControlLayout layout = new InfoBarControlLayout(mContext);
|
| + layout.setLayoutParams(
|
| + new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
| + View smallSwitch = layout.addSwitch(0, "A", SWITCH_ID_1, false);
|
| +
|
| + // Trigger the measurement algorithm.
|
| + int parentWidthSpec =
|
| + MeasureSpec.makeMeasureSpec(mMaxInfoBarWidth, MeasureSpec.AT_MOST);
|
| + int parentHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
|
| + layout.measure(parentWidthSpec, parentHeightSpec);
|
| +
|
| + // Small control takes the full width of the layout because it's put on its own line.
|
| + ControlLayoutParams params = InfoBarControlLayout.getControlLayoutParams(smallSwitch);
|
| + assertEquals(0, params.top);
|
| + assertEquals(0, params.start);
|
| + assertEquals(2, params.columnsRequired);
|
| + assertEquals(mMaxInfoBarWidth, smallSwitch.getMeasuredWidth());
|
| + }
|
| +
|
| + /**
|
| * Tests the layout algorithm on a set of five controls, the second of which is a huge control
|
| * and takes up the whole line. The other smaller controls try to pack themselves as tightly
|
| - * as possible, resulting in a layout like this:
|
| + * as possible, strecthing out if necessary for aesthetics, resulting in a layout like this:
|
| *
|
| - * -----------------------
|
| - * | A | empty |
|
| - * -----------------------
|
| - * | B |
|
| - * -----------------------
|
| - * | C | D |
|
| - * -----------------------
|
| - * | E | empty |
|
| - * -----------------------
|
| + * -------------------------
|
| + * | A (small) |
|
| + * -------------------------
|
| + * | B (big) |
|
| + * -------------------------
|
| + * | C (small) | D (small) |
|
| + * -------------------------
|
| + * | E (small) |
|
| + * -------------------------
|
| */
|
| @SmallTest
|
| @UiThreadTest
|
| public void testComplexSwitchLayout() {
|
| - // Add five controls to the layout, with the second being as wide as the layout.
|
| + // Add five controls to the layout.
|
| InfoBarControlLayout layout = new InfoBarControlLayout(mContext);
|
| layout.setLayoutParams(
|
| new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
| @@ -65,6 +90,8 @@ public class InfoBarControlLayoutTest extends InstrumentationTestCase {
|
| View switch3 = layout.addSwitch(0, "C", SWITCH_ID_3, false);
|
| View switch4 = layout.addSwitch(0, "D", SWITCH_ID_4, false);
|
| View switch5 = layout.addSwitch(0, "E", SWITCH_ID_4, false);
|
| +
|
| + // Make the second control require the full layout width.
|
| switch2.setMinimumWidth(mMaxInfoBarWidth);
|
|
|
| // Trigger the measurement algorithm.
|
| @@ -79,32 +106,37 @@ public class InfoBarControlLayoutTest extends InstrumentationTestCase {
|
| ControlLayoutParams params4 = InfoBarControlLayout.getControlLayoutParams(switch4);
|
| ControlLayoutParams params5 = InfoBarControlLayout.getControlLayoutParams(switch5);
|
|
|
| - // Small control takes only half the width of the layout.
|
| + // Small control takes the full width of the layout because the next one doesn't fit.
|
| assertEquals(0, params1.top);
|
| assertEquals(0, params1.start);
|
| - assertTrue(switch1.getMeasuredWidth() < mMaxInfoBarWidth);
|
| + assertEquals(2, params1.columnsRequired);
|
| + assertEquals(mMaxInfoBarWidth, switch1.getMeasuredWidth());
|
|
|
| // Big control gets shunted onto the next row and takes up the whole space.
|
| assertTrue(params2.top > switch1.getMeasuredHeight());
|
| assertEquals(0, params2.start);
|
| + assertEquals(2, params2.columnsRequired);
|
| assertEquals(mMaxInfoBarWidth, switch2.getMeasuredWidth());
|
|
|
| // Small control gets placed onto the next line and takes only half the width.
|
| int bottomOfSwitch2 = params2.top + switch2.getMeasuredHeight();
|
| assertTrue(params3.top > bottomOfSwitch2);
|
| assertEquals(0, params3.start);
|
| + assertEquals(1, params3.columnsRequired);
|
| assertTrue(switch3.getMeasuredWidth() < mMaxInfoBarWidth);
|
|
|
| // Small control gets placed next to the previous small control.
|
| assertEquals(params3.top, params4.top);
|
| assertTrue(params4.start > switch3.getMeasuredWidth());
|
| + assertEquals(1, params4.columnsRequired);
|
| assertTrue(switch4.getMeasuredWidth() < mMaxInfoBarWidth);
|
|
|
| - // Last small control has no room left and gets put on its own line.
|
| + // Last small control has no room left and gets put on its own line, taking the full width.
|
| int bottomOfSwitch4 = params4.top + switch4.getMeasuredHeight();
|
| assertTrue(params5.top > bottomOfSwitch4);
|
| assertEquals(0, params5.start);
|
| - assertTrue(switch5.getMeasuredWidth() < mMaxInfoBarWidth);
|
| + assertEquals(2, params5.columnsRequired);
|
| + assertEquals(mMaxInfoBarWidth, switch5.getMeasuredWidth());
|
| }
|
|
|
| /**
|
| @@ -133,11 +165,13 @@ public class InfoBarControlLayoutTest extends InstrumentationTestCase {
|
| // Main message takes up the full space.
|
| assertEquals(0, params1.top);
|
| assertEquals(0, params1.start);
|
| + assertEquals(2, params1.columnsRequired);
|
| assertEquals(mMaxInfoBarWidth, view1.getMeasuredWidth());
|
|
|
| // Small control gets shunted onto the next row.
|
| assertTrue(params2.top > view1.getMeasuredHeight());
|
| assertEquals(0, params2.start);
|
| - assertTrue(mMaxInfoBarWidth > view2.getMeasuredWidth());
|
| + assertEquals(2, params2.columnsRequired);
|
| + assertEquals(mMaxInfoBarWidth, view2.getMeasuredWidth());
|
| }
|
| }
|
|
|