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