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

Side by Side Diff: content/public/android/javatests/src/org/chromium/content/browser/accessibility/captioning/CaptioningChangeDelegateTest.java

Issue 2708243004: Auto convert content shell tests to JUnit4 (Closed)
Patch Set: organized import order and removed broken tests Created 3 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 2015 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.content.browser.accessibility.captioning; 5 package org.chromium.content.browser.accessibility.captioning;
6 6
7 import android.graphics.Color; 7 import android.graphics.Color;
8 import android.graphics.Typeface; 8 import android.graphics.Typeface;
9 import android.support.test.filters.SmallTest; 9 import android.support.test.filters.SmallTest;
10 10
11 import org.junit.Assert;
12 import org.junit.Rule;
13 import org.junit.Test;
14 import org.junit.runner.RunWith;
15
16 import org.chromium.base.test.BaseJUnit4ClassRunner;
11 import org.chromium.content.browser.accessibility.captioning.CaptioningChangeDel egate.ClosedCaptionEdgeAttribute; 17 import org.chromium.content.browser.accessibility.captioning.CaptioningChangeDel egate.ClosedCaptionEdgeAttribute;
12 import org.chromium.content.browser.accessibility.captioning.CaptioningChangeDel egate.ClosedCaptionFont; 18 import org.chromium.content.browser.accessibility.captioning.CaptioningChangeDel egate.ClosedCaptionFont;
13 import org.chromium.content_shell_apk.ContentShellTestBase; 19 import org.chromium.content_shell_apk.ContentShellActivityTestRule;
14 20
15 /** 21 /**
16 * Test suite to ensure that platform settings are translated to CSS appropriat ely 22 * Test suite to ensure that platform settings are translated to CSS appropriat ely
17 */ 23 */
18 public class CaptioningChangeDelegateTest extends ContentShellTestBase { 24 @RunWith(BaseJUnit4ClassRunner.class)
25 public class CaptioningChangeDelegateTest {
26 @Rule
27 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi vityTestRule();
28
19 private static final String DEFAULT_CAPTIONING_PREF_VALUE = 29 private static final String DEFAULT_CAPTIONING_PREF_VALUE =
20 CaptioningChangeDelegate.DEFAULT_CAPTIONING_PREF_VALUE; 30 CaptioningChangeDelegate.DEFAULT_CAPTIONING_PREF_VALUE;
21 31
32 @Test
22 @SmallTest 33 @SmallTest
23 public void testFontScaleToPercentage() { 34 public void testFontScaleToPercentage() {
24 String result = CaptioningChangeDelegate.androidFontScaleToPercentage(0f ); 35 String result = CaptioningChangeDelegate.androidFontScaleToPercentage(0f );
25 assertEquals("0%", result); 36 Assert.assertEquals("0%", result);
26 37
27 result = CaptioningChangeDelegate.androidFontScaleToPercentage(0.000f); 38 result = CaptioningChangeDelegate.androidFontScaleToPercentage(0.000f);
28 assertEquals("0%", result); 39 Assert.assertEquals("0%", result);
29 40
30 result = CaptioningChangeDelegate.androidFontScaleToPercentage(0.25f); 41 result = CaptioningChangeDelegate.androidFontScaleToPercentage(0.25f);
31 assertEquals("25%", result); 42 Assert.assertEquals("25%", result);
32 43
33 result = CaptioningChangeDelegate.androidFontScaleToPercentage(1f); 44 result = CaptioningChangeDelegate.androidFontScaleToPercentage(1f);
34 assertEquals("100%", result); 45 Assert.assertEquals("100%", result);
35 46
36 result = CaptioningChangeDelegate.androidFontScaleToPercentage(1.5f); 47 result = CaptioningChangeDelegate.androidFontScaleToPercentage(1.5f);
37 assertEquals("150%", result); 48 Assert.assertEquals("150%", result);
38 49
39 result = CaptioningChangeDelegate.androidFontScaleToPercentage(0.50125f) ; 50 result = CaptioningChangeDelegate.androidFontScaleToPercentage(0.50125f) ;
40 assertEquals("50%", result); 51 Assert.assertEquals("50%", result);
41 52
42 result = CaptioningChangeDelegate.androidFontScaleToPercentage(0.50925f) ; 53 result = CaptioningChangeDelegate.androidFontScaleToPercentage(0.50925f) ;
43 assertEquals("51%", result); 54 Assert.assertEquals("51%", result);
44 } 55 }
45 56
57 @Test
46 @SmallTest 58 @SmallTest
47 public void testAndroidColorToCssColor() { 59 public void testAndroidColorToCssColor() {
48 String result = CaptioningChangeDelegate.androidColorToCssColor(null); 60 String result = CaptioningChangeDelegate.androidColorToCssColor(null);
49 assertEquals(DEFAULT_CAPTIONING_PREF_VALUE, result); 61 Assert.assertEquals(DEFAULT_CAPTIONING_PREF_VALUE, result);
50 62
51 result = CaptioningChangeDelegate.androidColorToCssColor(Color.BLACK); 63 result = CaptioningChangeDelegate.androidColorToCssColor(Color.BLACK);
52 assertEquals("rgba(0, 0, 0, 1)", result); 64 Assert.assertEquals("rgba(0, 0, 0, 1)", result);
53 65
54 result = CaptioningChangeDelegate.androidColorToCssColor(Color.WHITE); 66 result = CaptioningChangeDelegate.androidColorToCssColor(Color.WHITE);
55 assertEquals("rgba(255, 255, 255, 1)", result); 67 Assert.assertEquals("rgba(255, 255, 255, 1)", result);
56 68
57 result = CaptioningChangeDelegate.androidColorToCssColor(Color.BLUE); 69 result = CaptioningChangeDelegate.androidColorToCssColor(Color.BLUE);
58 assertEquals("rgba(0, 0, 255, 1)", result); 70 Assert.assertEquals("rgba(0, 0, 255, 1)", result);
59 71
60 // Transparent-black 72 // Transparent-black
61 result = CaptioningChangeDelegate.androidColorToCssColor(0x00000000); 73 result = CaptioningChangeDelegate.androidColorToCssColor(0x00000000);
62 assertEquals("rgba(0, 0, 0, 0)", result); 74 Assert.assertEquals("rgba(0, 0, 0, 0)", result);
63 75
64 // Transparent-white 76 // Transparent-white
65 result = CaptioningChangeDelegate.androidColorToCssColor(0x00FFFFFF); 77 result = CaptioningChangeDelegate.androidColorToCssColor(0x00FFFFFF);
66 assertEquals("rgba(255, 255, 255, 0)", result); 78 Assert.assertEquals("rgba(255, 255, 255, 0)", result);
67 79
68 // 50% opaque blue 80 // 50% opaque blue
69 result = CaptioningChangeDelegate.androidColorToCssColor(0x7f0000ff); 81 result = CaptioningChangeDelegate.androidColorToCssColor(0x7f0000ff);
70 assertEquals("rgba(0, 0, 255, 0.5)", result); 82 Assert.assertEquals("rgba(0, 0, 255, 0.5)", result);
71 83
72 // No alpha information 84 // No alpha information
73 result = CaptioningChangeDelegate.androidColorToCssColor(0xFFFFFF); 85 result = CaptioningChangeDelegate.androidColorToCssColor(0xFFFFFF);
74 assertEquals("rgba(255, 255, 255, 0)", result); 86 Assert.assertEquals("rgba(255, 255, 255, 0)", result);
75 } 87 }
76 88
89 @Test
77 @SmallTest 90 @SmallTest
78 public void testClosedCaptionEdgeAttributeWithDefaults() { 91 public void testClosedCaptionEdgeAttributeWithDefaults() {
79 ClosedCaptionEdgeAttribute edge = ClosedCaptionEdgeAttribute.fromSystemE dgeAttribute( 92 ClosedCaptionEdgeAttribute edge = ClosedCaptionEdgeAttribute.fromSystemE dgeAttribute(
80 null, null); 93 null, null);
81 assertEquals(DEFAULT_CAPTIONING_PREF_VALUE, edge.getTextShadow()); 94 Assert.assertEquals(DEFAULT_CAPTIONING_PREF_VALUE, edge.getTextShadow()) ;
82 95
83 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(null, "red"); 96 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(null, "red");
84 assertEquals(DEFAULT_CAPTIONING_PREF_VALUE, edge.getTextShadow()); 97 Assert.assertEquals(DEFAULT_CAPTIONING_PREF_VALUE, edge.getTextShadow()) ;
85 98
86 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(0, "red"); 99 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(0, "red");
87 assertEquals(DEFAULT_CAPTIONING_PREF_VALUE, edge.getTextShadow()); 100 Assert.assertEquals(DEFAULT_CAPTIONING_PREF_VALUE, edge.getTextShadow()) ;
88 101
89 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(2, null); 102 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(2, null);
90 assertEquals("silver 0.05em 0.05em 0.1em", edge.getTextShadow()); 103 Assert.assertEquals("silver 0.05em 0.05em 0.1em", edge.getTextShadow());
91 104
92 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(2, ""); 105 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(2, "");
93 assertEquals("silver 0.05em 0.05em 0.1em", edge.getTextShadow()); 106 Assert.assertEquals("silver 0.05em 0.05em 0.1em", edge.getTextShadow());
94 107
95 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(2, "red"); 108 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(2, "red");
96 assertEquals("red 0.05em 0.05em 0.1em", edge.getTextShadow()); 109 Assert.assertEquals("red 0.05em 0.05em 0.1em", edge.getTextShadow());
97 } 110 }
98 111
112 @Test
99 @SmallTest 113 @SmallTest
100 public void testClosedCaptionEdgeAttributeWithCustomDefaults() { 114 public void testClosedCaptionEdgeAttributeWithCustomDefaults() {
101 ClosedCaptionEdgeAttribute.setShadowOffset("0.00em"); 115 ClosedCaptionEdgeAttribute.setShadowOffset("0.00em");
102 ClosedCaptionEdgeAttribute.setDefaultEdgeColor("red"); 116 ClosedCaptionEdgeAttribute.setDefaultEdgeColor("red");
103 ClosedCaptionEdgeAttribute edge = ClosedCaptionEdgeAttribute.fromSystemE dgeAttribute( 117 ClosedCaptionEdgeAttribute edge = ClosedCaptionEdgeAttribute.fromSystemE dgeAttribute(
104 null, null); 118 null, null);
105 assertEquals(DEFAULT_CAPTIONING_PREF_VALUE, edge.getTextShadow()); 119 Assert.assertEquals(DEFAULT_CAPTIONING_PREF_VALUE, edge.getTextShadow()) ;
106 120
107 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(null, "red"); 121 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(null, "red");
108 assertEquals(DEFAULT_CAPTIONING_PREF_VALUE, edge.getTextShadow()); 122 Assert.assertEquals(DEFAULT_CAPTIONING_PREF_VALUE, edge.getTextShadow()) ;
109 123
110 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(0, "red"); 124 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(0, "red");
111 assertEquals(DEFAULT_CAPTIONING_PREF_VALUE, edge.getTextShadow()); 125 Assert.assertEquals(DEFAULT_CAPTIONING_PREF_VALUE, edge.getTextShadow()) ;
112 126
113 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(2, null); 127 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(2, null);
114 assertEquals("red 0.00em 0.00em 0.1em", edge.getTextShadow()); 128 Assert.assertEquals("red 0.00em 0.00em 0.1em", edge.getTextShadow());
115 129
116 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(2, "silver"); 130 edge = ClosedCaptionEdgeAttribute.fromSystemEdgeAttribute(2, "silver");
117 assertEquals("silver 0.00em 0.00em 0.1em", edge.getTextShadow()); 131 Assert.assertEquals("silver 0.00em 0.00em 0.1em", edge.getTextShadow());
118 } 132 }
119 133
120 /** 134 /**
121 * Verifies that certain system fonts always correspond to the default capti oning font. 135 * Verifies that certain system fonts always correspond to the default capti oning font.
122 */ 136 */
137 @Test
123 @SmallTest 138 @SmallTest
124 public void testClosedCaptionDefaultFonts() { 139 public void testClosedCaptionDefaultFonts() {
125 final ClosedCaptionFont nullFont = ClosedCaptionFont.fromSystemFont(null ); 140 final ClosedCaptionFont nullFont = ClosedCaptionFont.fromSystemFont(null );
126 assertEquals( 141 Assert.assertEquals("Null typeface should return the default font family .",
127 "Null typeface should return the default font family.",
128 DEFAULT_CAPTIONING_PREF_VALUE, nullFont.getFontFamily()); 142 DEFAULT_CAPTIONING_PREF_VALUE, nullFont.getFontFamily());
129 143
130 final ClosedCaptionFont defaultFont = ClosedCaptionFont.fromSystemFont(T ypeface.DEFAULT); 144 final ClosedCaptionFont defaultFont = ClosedCaptionFont.fromSystemFont(T ypeface.DEFAULT);
131 assertEquals( 145 Assert.assertEquals("Typeface.DEFAULT should return the default font fam ily.",
132 "Typeface.DEFAULT should return the default font family.",
133 DEFAULT_CAPTIONING_PREF_VALUE, defaultFont.getFontFamily()); 146 DEFAULT_CAPTIONING_PREF_VALUE, defaultFont.getFontFamily());
134 147
135 final ClosedCaptionFont defaultBoldFont = ClosedCaptionFont.fromSystemFo nt( 148 final ClosedCaptionFont defaultBoldFont = ClosedCaptionFont.fromSystemFo nt(
136 Typeface.DEFAULT_BOLD); 149 Typeface.DEFAULT_BOLD);
137 assertEquals( 150 Assert.assertEquals("Typeface.BOLD should return the default font family .",
138 "Typeface.BOLD should return the default font family.",
139 DEFAULT_CAPTIONING_PREF_VALUE, defaultBoldFont.getFontFamily()); 151 DEFAULT_CAPTIONING_PREF_VALUE, defaultBoldFont.getFontFamily());
140 } 152 }
141 153
142 /** 154 /**
143 * Typeface.DEFAULT may be equivalent to another Typeface such as Typeface.S ANS_SERIF 155 * Typeface.DEFAULT may be equivalent to another Typeface such as Typeface.S ANS_SERIF
144 * so this test ensures that each typeface returns DEFAULT_CAPTIONING_PREF_V ALUE if it is 156 * so this test ensures that each typeface returns DEFAULT_CAPTIONING_PREF_V ALUE if it is
145 * equal to Typeface.DEFAULT or returns an explicit font family otherwise. 157 * equal to Typeface.DEFAULT or returns an explicit font family otherwise.
146 */ 158 */
159 @Test
147 @SmallTest 160 @SmallTest
148 public void testClosedCaptionNonDefaultFonts() { 161 public void testClosedCaptionNonDefaultFonts() {
149 final ClosedCaptionFont monospaceFont = ClosedCaptionFont.fromSystemFont ( 162 final ClosedCaptionFont monospaceFont = ClosedCaptionFont.fromSystemFont (
150 Typeface.MONOSPACE); 163 Typeface.MONOSPACE);
151 if (Typeface.MONOSPACE.equals(Typeface.DEFAULT)) { 164 if (Typeface.MONOSPACE.equals(Typeface.DEFAULT)) {
152 assertEquals( 165 Assert.assertEquals(
153 "Since the default font is monospace, the default family sho uld be returned.", 166 "Since the default font is monospace, the default family sho uld be returned.",
154 DEFAULT_CAPTIONING_PREF_VALUE, monospaceFont.getFontFamily() ); 167 DEFAULT_CAPTIONING_PREF_VALUE, monospaceFont.getFontFamily() );
155 } else { 168 } else {
156 assertTrue( 169 Assert.assertTrue("Typeface.MONOSPACE should return a monospace font family.",
157 "Typeface.MONOSPACE should return a monospace font family.",
158 monospaceFont.mFlags.contains(ClosedCaptionFont.Flags.MONOSP ACE)); 170 monospaceFont.mFlags.contains(ClosedCaptionFont.Flags.MONOSP ACE));
159 } 171 }
160 172
161 final ClosedCaptionFont sansSerifFont = ClosedCaptionFont.fromSystemFont ( 173 final ClosedCaptionFont sansSerifFont = ClosedCaptionFont.fromSystemFont (
162 Typeface.SANS_SERIF); 174 Typeface.SANS_SERIF);
163 if (Typeface.SANS_SERIF.equals(Typeface.DEFAULT)) { 175 if (Typeface.SANS_SERIF.equals(Typeface.DEFAULT)) {
164 assertEquals( 176 Assert.assertEquals(
165 "Since the default font is sans-serif, the default family sh ould be returned.", 177 "Since the default font is sans-serif, the default family sh ould be returned.",
166 DEFAULT_CAPTIONING_PREF_VALUE, sansSerifFont.getFontFamily() ); 178 DEFAULT_CAPTIONING_PREF_VALUE, sansSerifFont.getFontFamily() );
167 } else { 179 } else {
168 assertTrue( 180 Assert.assertTrue("Typeface.SANS_SERIF should return a sans-serif fo nt family.",
169 "Typeface.SANS_SERIF should return a sans-serif font family. ",
170 sansSerifFont.mFlags.contains(ClosedCaptionFont.Flags.SANS_S ERIF)); 181 sansSerifFont.mFlags.contains(ClosedCaptionFont.Flags.SANS_S ERIF));
171 } 182 }
172 183
173 final ClosedCaptionFont serifFont = ClosedCaptionFont.fromSystemFont(Typ eface.SERIF); 184 final ClosedCaptionFont serifFont = ClosedCaptionFont.fromSystemFont(Typ eface.SERIF);
174 if (Typeface.SERIF.equals(Typeface.DEFAULT)) { 185 if (Typeface.SERIF.equals(Typeface.DEFAULT)) {
175 assertEquals( 186 Assert.assertEquals(
176 "Since the default font is serif, the default font family sh ould be returned.", 187 "Since the default font is serif, the default font family sh ould be returned.",
177 DEFAULT_CAPTIONING_PREF_VALUE, serifFont.getFontFamily()); 188 DEFAULT_CAPTIONING_PREF_VALUE, serifFont.getFontFamily());
178 } else { 189 } else {
179 assertTrue( 190 Assert.assertTrue("Typeface.SERIF should return a serif font family. ",
180 "Typeface.SERIF should return a serif font family.",
181 serifFont.mFlags.contains(ClosedCaptionFont.Flags.SERIF)); 191 serifFont.mFlags.contains(ClosedCaptionFont.Flags.SERIF));
182 } 192 }
183 } 193 }
184 } 194 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698