OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.physicalweb; | 5 package org.chromium.chrome.browser.physicalweb; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.test.InstrumentationTestCase; | 8 import android.test.InstrumentationTestCase; |
9 import android.test.suitebuilder.annotation.SmallTest; | 9 import android.test.suitebuilder.annotation.SmallTest; |
10 import android.text.TextUtils; | 10 import android.text.TextUtils; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 String locale = new Locale("aa", "AA").toString(); | 82 String locale = new Locale("aa", "AA").toString(); |
83 String languageList = "xx-XX,xx,xx-YY"; | 83 String languageList = "xx-XX,xx,xx-YY"; |
84 | 84 |
85 // Should prepend the language tag "aa-AA" as well as the language code
"aa". | 85 // Should prepend the language tag "aa-AA" as well as the language code
"aa". |
86 String languageListWithTag = PwsClientImpl.prependToAcceptLanguagesIfNec
essary(locale, | 86 String languageListWithTag = PwsClientImpl.prependToAcceptLanguagesIfNec
essary(locale, |
87 languageList); | 87 languageList); |
88 assertEquals("aa-AA,aa,xx-XX,xx,xx-YY", languageListWithTag); | 88 assertEquals("aa-AA,aa,xx-XX,xx,xx-YY", languageListWithTag); |
89 } | 89 } |
90 | 90 |
91 @SmallTest | 91 @SmallTest |
| 92 public void testMultipleLanguageTagIsPrepended() { |
| 93 String locale = "aa_AA,bb_BB"; |
| 94 String languageList = "xx-XX,xx,xx-YY"; |
| 95 |
| 96 // Should prepend the language tag "aa-AA" as well as the language code
"aa". |
| 97 String languageListWithTag = PwsClientImpl.prependToAcceptLanguagesIfNec
essary(locale, |
| 98 languageList); |
| 99 assertEquals("aa-AA,aa,bb-BB,bb,xx-XX,xx,xx-YY", languageListWithTag); |
| 100 } |
| 101 |
| 102 @SmallTest |
92 public void testLanguageTagIsPrependedWhenListContainsLanguageCode() { | 103 public void testLanguageTagIsPrependedWhenListContainsLanguageCode() { |
93 String locale = new Locale("xx", "XX").toString(); | 104 String locale = new Locale("xx", "XX").toString(); |
94 String languageList = "xx-YY,xx"; | 105 String languageList = "xx-YY,xx"; |
95 | 106 |
96 // Should prepend the language tag "xx-XX" but not the language code "xx
" as it's already | 107 // Should prepend the language tag "xx-XX" but not the language code "xx
" as it's already |
97 // included at the end of the list. | 108 // included at the end of the list. |
98 String languageListWithTag = PwsClientImpl.prependToAcceptLanguagesIfNec
essary(locale, | 109 String languageListWithTag = PwsClientImpl.prependToAcceptLanguagesIfNec
essary(locale, |
99 languageList); | 110 languageList); |
100 assertEquals("xx-XX,xx-YY,xx", languageListWithTag); | 111 assertEquals("xx-XX,xx-YY,xx", languageListWithTag); |
101 | 112 |
(...skipping 20 matching lines...) Expand all Loading... |
122 String locale = new Locale("xx", "XX").toString(); | 133 String locale = new Locale("xx", "XX").toString(); |
123 String languageList = "xx-XX,xx,xx-YY"; | 134 String languageList = "xx-XX,xx,xx-YY"; |
124 | 135 |
125 // Language list should be unmodified since the tag is already present. | 136 // Language list should be unmodified since the tag is already present. |
126 String languageListWithTag = PwsClientImpl.prependToAcceptLanguagesIfNec
essary(locale, | 137 String languageListWithTag = PwsClientImpl.prependToAcceptLanguagesIfNec
essary(locale, |
127 languageList); | 138 languageList); |
128 assertEquals(languageList, languageListWithTag); | 139 assertEquals(languageList, languageListWithTag); |
129 } | 140 } |
130 | 141 |
131 @SmallTest | 142 @SmallTest |
| 143 public void testMultiLanguageTagNotPrependedWhenUnnecessary() { |
| 144 String locale = "xx-XX,yy-YY"; |
| 145 String languageList = "xx-XX,xx,yy-YY,yy"; |
| 146 |
| 147 // Language list should be unmodified since the tag is already present. |
| 148 String languageListWithTag = PwsClientImpl.prependToAcceptLanguagesIfNec
essary(locale, |
| 149 languageList); |
| 150 assertEquals(languageList, languageListWithTag); |
| 151 } |
| 152 |
| 153 @SmallTest |
132 public void testAcceptLanguageQvalues() { | 154 public void testAcceptLanguageQvalues() { |
133 String languageList = "xx-XX,xx,xx-YY,zz-ZZ,zz"; | 155 String languageList = "xx-XX,xx,xx-YY,zz-ZZ,zz"; |
134 | 156 |
135 // Should insert q-values for each item except the first which implicitl
y has q=1.0. | 157 // Should insert q-values for each item except the first which implicitl
y has q=1.0. |
136 String acceptLanguage = PwsClientImpl.generateAcceptLanguageHeader(langu
ageList); | 158 String acceptLanguage = PwsClientImpl.generateAcceptLanguageHeader(langu
ageList); |
137 assertEquals("xx-XX,xx;q=0.8,xx-YY;q=0.6,zz-ZZ;q=0.4,zz;q=0.2", acceptLa
nguage); | 159 assertEquals("xx-XX,xx;q=0.8,xx-YY;q=0.6,zz-ZZ;q=0.4,zz;q=0.2", acceptLa
nguage); |
138 | 160 |
139 // When there are six or more items, the q-value should not go below 0.2
. | 161 // When there are six or more items, the q-value should not go below 0.2
. |
140 languageList = "xx-XA,xx-XB,xx-XC,xx-XD,xx-XE,xx-XF"; | 162 languageList = "xx-XA,xx-XB,xx-XC,xx-XD,xx-XE,xx-XF"; |
141 acceptLanguage = PwsClientImpl.generateAcceptLanguageHeader(languageList
); | 163 acceptLanguage = PwsClientImpl.generateAcceptLanguageHeader(languageList
); |
142 assertEquals("xx-XA,xx-XB;q=0.8,xx-XC;q=0.6,xx-XD;q=0.4,xx-XE;q=0.2,xx-X
F;q=0.2", | 164 assertEquals("xx-XA,xx-XB;q=0.8,xx-XC;q=0.6,xx-XD;q=0.4,xx-XE;q=0.2,xx-X
F;q=0.2", |
143 acceptLanguage); | 165 acceptLanguage); |
144 } | 166 } |
145 } | 167 } |
OLD | NEW |