OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.widget; | 5 package org.chromium.chrome.browser.widget; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.DialogInterface; | 8 import android.content.DialogInterface; |
9 import android.support.test.InstrumentationRegistry; | 9 import android.support.test.InstrumentationRegistry; |
10 import android.support.test.filters.SmallTest; | 10 import android.support.test.filters.SmallTest; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 @After | 95 @After |
96 public void tearDown() throws Exception { | 96 public void tearDown() throws Exception { |
97 ApplicationTestUtils.tearDown(InstrumentationRegistry.getTargetContext()
); | 97 ApplicationTestUtils.tearDown(InstrumentationRegistry.getTargetContext()
); |
98 } | 98 } |
99 | 99 |
100 @Test | 100 @Test |
101 @SmallTest | 101 @SmallTest |
102 public void testBasic_Visibility() throws Exception { | 102 public void testBasic_Visibility() throws Exception { |
103 // Create a full dialog. | 103 // Create a full dialog. |
104 DialogParams dialogParams = new DialogParams(); | 104 DialogParams dialogParams = new DialogParams(); |
105 dialogParams.drawableResource = R.drawable.search_sogou; | 105 dialogParams.drawableResource = R.drawable.data_reduction_illustration; |
106 dialogParams.headerStringResource = R.string.search_with_sogou; | 106 dialogParams.headerStringResource = R.string.data_reduction_promo_title; |
107 dialogParams.subheaderStringResource = R.string.sogou_explanation; | 107 dialogParams.subheaderStringResource = R.string.data_reduction_promo_sum
mary; |
108 dialogParams.primaryButtonStringResource = R.string.ok; | 108 dialogParams.primaryButtonStringResource = R.string.ok; |
109 dialogParams.secondaryButtonStringResource = R.string.cancel; | 109 dialogParams.secondaryButtonStringResource = R.string.cancel; |
110 dialogParams.footerStringResource = R.string.learn_more; | 110 dialogParams.footerStringResource = R.string.learn_more; |
111 checkDialogControlVisibility(dialogParams); | 111 checkDialogControlVisibility(dialogParams); |
112 | 112 |
113 // Create a minimal dialog. | 113 // Create a minimal dialog. |
114 dialogParams = new DialogParams(); | 114 dialogParams = new DialogParams(); |
115 dialogParams.headerStringResource = R.string.search_with_sogou; | 115 dialogParams.headerStringResource = R.string.data_reduction_promo_title; |
116 dialogParams.primaryButtonStringResource = R.string.ok; | 116 dialogParams.primaryButtonStringResource = R.string.ok; |
117 checkDialogControlVisibility(dialogParams); | 117 checkDialogControlVisibility(dialogParams); |
118 } | 118 } |
119 | 119 |
120 /** Confirm that PromoDialogs are constructed with all the elements expected
. */ | 120 /** Confirm that PromoDialogs are constructed with all the elements expected
. */ |
121 private void checkDialogControlVisibility(final DialogParams dialogParams) t
hrows Exception { | 121 private void checkDialogControlVisibility(final DialogParams dialogParams) t
hrows Exception { |
122 PromoDialogWrapper wrapper = new PromoDialogWrapper(dialogParams); | 122 PromoDialogWrapper wrapper = new PromoDialogWrapper(dialogParams); |
123 PromoDialog dialog = wrapper.dialog; | 123 PromoDialog dialog = wrapper.dialog; |
124 PromoDialogLayout promoDialogLayout = | 124 PromoDialogLayout promoDialogLayout = |
125 (PromoDialogLayout) dialog.getWindow().getDecorView().findViewBy
Id( | 125 (PromoDialogLayout) dialog.getWindow().getDecorView().findViewBy
Id( |
(...skipping 21 matching lines...) Expand all Loading... |
147 if (view != null) { | 147 if (view != null) { |
148 Assert.assertTrue(view.getMeasuredWidth() > 0); | 148 Assert.assertTrue(view.getMeasuredWidth() > 0); |
149 Assert.assertTrue(view.getMeasuredHeight() > 0); | 149 Assert.assertTrue(view.getMeasuredHeight() > 0); |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 @Test | 153 @Test |
154 @SmallTest | 154 @SmallTest |
155 public void testBasic_Orientation() throws Exception { | 155 public void testBasic_Orientation() throws Exception { |
156 DialogParams dialogParams = new DialogParams(); | 156 DialogParams dialogParams = new DialogParams(); |
157 dialogParams.drawableResource = R.drawable.search_sogou; | 157 dialogParams.drawableResource = R.drawable.data_reduction_illustration; |
158 dialogParams.headerStringResource = R.string.search_with_sogou; | 158 dialogParams.headerStringResource = R.string.data_reduction_promo_title; |
159 dialogParams.subheaderStringResource = R.string.sogou_explanation; | 159 dialogParams.subheaderStringResource = R.string.data_reduction_promo_sum
mary; |
160 dialogParams.primaryButtonStringResource = R.string.ok; | 160 dialogParams.primaryButtonStringResource = R.string.ok; |
161 dialogParams.secondaryButtonStringResource = R.string.cancel; | 161 dialogParams.secondaryButtonStringResource = R.string.cancel; |
162 dialogParams.footerStringResource = R.string.learn_more; | 162 dialogParams.footerStringResource = R.string.learn_more; |
163 | 163 |
164 PromoDialogWrapper wrapper = new PromoDialogWrapper(dialogParams); | 164 PromoDialogWrapper wrapper = new PromoDialogWrapper(dialogParams); |
165 final PromoDialogLayout promoDialogLayout = | 165 final PromoDialogLayout promoDialogLayout = |
166 (PromoDialogLayout) wrapper.dialog.getWindow().getDecorView().fi
ndViewById( | 166 (PromoDialogLayout) wrapper.dialog.getWindow().getDecorView().fi
ndViewById( |
167 R.id.promo_dialog_layout); | 167 R.id.promo_dialog_layout); |
168 LinearLayout flippableLayout = | 168 LinearLayout flippableLayout = |
169 (LinearLayout) promoDialogLayout.findViewById(R.id.full_promo_co
ntent); | 169 (LinearLayout) promoDialogLayout.findViewById(R.id.full_promo_co
ntent); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 View header = promoDialogLayout.findViewById(R.id.header); | 246 View header = promoDialogLayout.findViewById(R.id.header); |
247 MarginLayoutParams headerParams = (MarginLayoutParams) header.getLay
outParams(); | 247 MarginLayoutParams headerParams = (MarginLayoutParams) header.getLay
outParams(); |
248 Assert.assertEquals(promoDialogLayout.getChildAt(0), header); | 248 Assert.assertEquals(promoDialogLayout.getChildAt(0), header); |
249 Assert.assertNotEquals(0, ApiCompatibilityUtils.getMarginStart(heade
rParams)); | 249 Assert.assertNotEquals(0, ApiCompatibilityUtils.getMarginStart(heade
rParams)); |
250 Assert.assertNotEquals(0, ApiCompatibilityUtils.getMarginEnd(headerP
arams)); | 250 Assert.assertNotEquals(0, ApiCompatibilityUtils.getMarginEnd(headerP
arams)); |
251 } | 251 } |
252 | 252 |
253 // With an illustration, the header View is part of the scrollable conte
nt. | 253 // With an illustration, the header View is part of the scrollable conte
nt. |
254 { | 254 { |
255 DialogParams dialogParams = new DialogParams(); | 255 DialogParams dialogParams = new DialogParams(); |
256 dialogParams.drawableResource = R.drawable.search_sogou; | 256 dialogParams.drawableResource = R.drawable.data_reduction_illustrati
on; |
| 257 dialogParams.headerStringResource = R.string.data_reduction_promo_ti
tle; |
| 258 dialogParams.primaryButtonStringResource = R.string.data_reduction_e
nable_button; |
| 259 |
| 260 PromoDialogWrapper wrapper = new PromoDialogWrapper(dialogParams); |
| 261 PromoDialogLayout promoDialogLayout = |
| 262 (PromoDialogLayout) wrapper.dialog.getWindow().getDecorView(
).findViewById( |
| 263 R.id.promo_dialog_layout); |
| 264 ViewGroup scrollableLayout = |
| 265 (ViewGroup) promoDialogLayout.findViewById(R.id.scrollable_p
romo_content); |
| 266 |
| 267 View header = promoDialogLayout.findViewById(R.id.header); |
| 268 MarginLayoutParams headerParams = (MarginLayoutParams) header.getLay
outParams(); |
| 269 Assert.assertEquals(scrollableLayout.getChildAt(0), header); |
| 270 Assert.assertEquals(0, ApiCompatibilityUtils.getMarginStart(headerPa
rams)); |
| 271 Assert.assertEquals(0, ApiCompatibilityUtils.getMarginEnd(headerPara
ms)); |
| 272 } |
| 273 |
| 274 // With a vector illustration, the header View is part of the scrollable
content. |
| 275 { |
| 276 DialogParams dialogParams = new DialogParams(); |
| 277 dialogParams.vectorDrawableResource = R.drawable.search_sogou; |
257 dialogParams.headerStringResource = R.string.search_with_sogou; | 278 dialogParams.headerStringResource = R.string.search_with_sogou; |
258 dialogParams.primaryButtonStringResource = R.string.ok; | 279 dialogParams.primaryButtonStringResource = R.string.ok; |
259 | 280 |
260 PromoDialogWrapper wrapper = new PromoDialogWrapper(dialogParams); | 281 PromoDialogWrapper wrapper = new PromoDialogWrapper(dialogParams); |
261 PromoDialogLayout promoDialogLayout = | 282 PromoDialogLayout promoDialogLayout = |
262 (PromoDialogLayout) wrapper.dialog.getWindow().getDecorView(
).findViewById( | 283 (PromoDialogLayout) wrapper.dialog.getWindow().getDecorView(
).findViewById( |
263 R.id.promo_dialog_layout); | 284 R.id.promo_dialog_layout); |
264 ViewGroup scrollableLayout = | 285 ViewGroup scrollableLayout = |
265 (ViewGroup) promoDialogLayout.findViewById(R.id.scrollable_p
romo_content); | 286 (ViewGroup) promoDialogLayout.findViewById(R.id.scrollable_p
romo_content); |
266 | 287 |
267 View header = promoDialogLayout.findViewById(R.id.header); | 288 View header = promoDialogLayout.findViewById(R.id.header); |
268 MarginLayoutParams headerParams = (MarginLayoutParams) header.getLay
outParams(); | 289 MarginLayoutParams headerParams = (MarginLayoutParams) header.getLay
outParams(); |
269 Assert.assertEquals(scrollableLayout.getChildAt(0), header); | 290 Assert.assertEquals(scrollableLayout.getChildAt(0), header); |
270 Assert.assertEquals(0, ApiCompatibilityUtils.getMarginStart(headerPa
rams)); | 291 Assert.assertEquals(0, ApiCompatibilityUtils.getMarginStart(headerPa
rams)); |
271 Assert.assertEquals(0, ApiCompatibilityUtils.getMarginEnd(headerPara
ms)); | 292 Assert.assertEquals(0, ApiCompatibilityUtils.getMarginEnd(headerPara
ms)); |
272 } | 293 } |
273 } | 294 } |
274 } | 295 } |
OLD | NEW |