| 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.chrome.browser.webapps; | 5 package org.chromium.chrome.browser.webapps; |
| 6 | 6 |
| 7 import android.content.Intent; | 7 import android.content.Intent; |
| 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 | 10 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 String id = "webapp id"; | 146 String id = "webapp id"; |
| 147 String name = "longName"; | 147 String name = "longName"; |
| 148 String shortName = "name"; | 148 String shortName = "name"; |
| 149 String url = "http://money.cnn.com"; | 149 String url = "http://money.cnn.com"; |
| 150 long themeColor = 0xFF00FF00L; | 150 long themeColor = 0xFF00FF00L; |
| 151 long backgroundColor = 0xFF0000FFL; | 151 long backgroundColor = 0xFF0000FFL; |
| 152 | 152 |
| 153 WebappInfo info = WebappInfo.create(id, url, null, name, shortName, | 153 WebappInfo info = WebappInfo.create(id, url, null, name, shortName, |
| 154 WebDisplayMode.Standalone, ScreenOrientationValues.DEFAULT, | 154 WebDisplayMode.Standalone, ScreenOrientationValues.DEFAULT, |
| 155 ShortcutSource.UNKNOWN, themeColor, backgroundColor, false, null
); | 155 ShortcutSource.UNKNOWN, themeColor, backgroundColor, false, null
); |
| 156 assertEquals(info.themeColor(), themeColor); | 156 assertEquals(themeColor, info.themeColor()); |
| 157 assertEquals(info.backgroundColor(), backgroundColor); | 157 assertEquals(backgroundColor, info.backgroundColor()); |
| 158 } | 158 } |
| 159 | 159 |
| 160 @SmallTest | 160 @SmallTest |
| 161 @Feature({"Webapps"}) | 161 @Feature({"Webapps"}) |
| 162 public void testInvalidOrMissingColors() { | 162 public void testInvalidOrMissingColors() { |
| 163 String id = "webapp id"; | 163 String id = "webapp id"; |
| 164 String name = "longName"; | 164 String name = "longName"; |
| 165 String shortName = "name"; | 165 String shortName = "name"; |
| 166 String url = "http://money.cnn.com"; | 166 String url = "http://money.cnn.com"; |
| 167 | 167 |
| 168 WebappInfo info = WebappInfo.create(id, url, null, name, shortName, | 168 WebappInfo info = WebappInfo.create(id, url, null, name, shortName, |
| 169 WebDisplayMode.Standalone, ScreenOrientationValues.DEFAULT, Shor
tcutSource.UNKNOWN, | 169 WebDisplayMode.Standalone, ScreenOrientationValues.DEFAULT, Shor
tcutSource.UNKNOWN, |
| 170 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, | 170 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, |
| 171 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, false, null); | 171 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, false, null); |
| 172 assertEquals(info.themeColor(), ShortcutHelper.MANIFEST_COLOR_INVALID_OR
_MISSING); | 172 assertEquals(ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, info.them
eColor()); |
| 173 assertEquals(info.backgroundColor(), ShortcutHelper.MANIFEST_COLOR_INVAL
ID_OR_MISSING); | 173 assertEquals(ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, info.back
groundColor()); |
| 174 } | 174 } |
| 175 | 175 |
| 176 @SmallTest | 176 @SmallTest |
| 177 @Feature({"Webapps"}) | 177 @Feature({"Webapps"}) |
| 178 public void testColorsIntentCreation() { | 178 public void testColorsIntentCreation() { |
| 179 long themeColor = 0xFF00FF00L; | 179 long themeColor = 0xFF00FF00L; |
| 180 long backgroundColor = 0xFF0000FFL; | 180 long backgroundColor = 0xFF0000FFL; |
| 181 | 181 |
| 182 Intent intent = createIntentWithUrlAndId(); | 182 Intent intent = createIntentWithUrlAndId(); |
| 183 intent.putExtra(ShortcutHelper.EXTRA_THEME_COLOR, themeColor); | 183 intent.putExtra(ShortcutHelper.EXTRA_THEME_COLOR, themeColor); |
| 184 intent.putExtra(ShortcutHelper.EXTRA_BACKGROUND_COLOR, backgroundColor); | 184 intent.putExtra(ShortcutHelper.EXTRA_BACKGROUND_COLOR, backgroundColor); |
| 185 | 185 |
| 186 WebappInfo info = WebappInfo.create(intent); | 186 WebappInfo info = WebappInfo.create(intent); |
| 187 assertEquals(info.themeColor(), themeColor); | 187 assertEquals(themeColor, info.themeColor()); |
| 188 assertEquals(info.backgroundColor(), backgroundColor); | 188 assertEquals(backgroundColor, info.backgroundColor()); |
| 189 } | 189 } |
| 190 | 190 |
| 191 @SmallTest | 191 @SmallTest |
| 192 @Feature({"Webapps", "WebApk"}) | 192 @Feature({"Webapps", "WebApk"}) |
| 193 public void testIntentDisplayMode() { | 193 public void testIntentDisplayMode() { |
| 194 { | 194 { |
| 195 Intent intent = createIntentWithUrlAndId(); | 195 Intent intent = createIntentWithUrlAndId(); |
| 196 intent.putExtra(ShortcutHelper.EXTRA_DISPLAY_MODE, WebDisplayMode.Mi
nimalUi); | 196 intent.putExtra(ShortcutHelper.EXTRA_DISPLAY_MODE, WebDisplayMode.Mi
nimalUi); |
| 197 WebappInfo info = WebappInfo.create(intent); | 197 WebappInfo info = WebappInfo.create(intent); |
| 198 assertEquals(WebDisplayMode.MinimalUi, info.displayMode()); | 198 assertEquals(WebDisplayMode.MinimalUi, info.displayMode()); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 public void testIntentWebApkPackageName() { | 311 public void testIntentWebApkPackageName() { |
| 312 String packageName = WebApkConstants.WEBAPK_PACKAGE_PREFIX + ".foo"; | 312 String packageName = WebApkConstants.WEBAPK_PACKAGE_PREFIX + ".foo"; |
| 313 | 313 |
| 314 Intent intent = createIntentWithUrlAndId(); | 314 Intent intent = createIntentWithUrlAndId(); |
| 315 intent.putExtra(ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, packageName); | 315 intent.putExtra(ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, packageName); |
| 316 | 316 |
| 317 WebappInfo info = WebappInfo.create(intent); | 317 WebappInfo info = WebappInfo.create(intent); |
| 318 assertEquals(packageName, info.webApkPackageName()); | 318 assertEquals(packageName, info.webApkPackageName()); |
| 319 } | 319 } |
| 320 | 320 |
| 321 @SmallTest |
| 322 @Feature({"Webapps"}) |
| 323 public void testUpdateThemeColorAndOrientation() { |
| 324 long themeColor = 0xFF00FF00L; |
| 325 int orientation = ScreenOrientationValues.DEFAULT; |
| 326 |
| 327 Intent intent = createIntentWithUrlAndId(); |
| 328 intent.putExtra(ShortcutHelper.EXTRA_THEME_COLOR, themeColor); |
| 329 intent.putExtra(ShortcutHelper.EXTRA_ORIENTATION, orientation); |
| 330 |
| 331 WebappInfo info = WebappInfo.create(intent); |
| 332 assertEquals(themeColor, info.themeColor()); |
| 333 assertEquals(orientation, info.orientation()); |
| 334 |
| 335 // Updates the theme color and orientation. |
| 336 themeColor = 0xFF0000FFL; |
| 337 orientation = ScreenOrientationValues.LANDSCAPE; |
| 338 info.updateThemeColor(themeColor); |
| 339 info.updateOrientation(orientation); |
| 340 assertEquals(themeColor, info.themeColor()); |
| 341 assertEquals(orientation, info.orientation()); |
| 342 } |
| 343 |
| 321 /** | 344 /** |
| 322 * Creates intent with url and id. If the url or id are not set WebappInfo#c
reate() returns | 345 * Creates intent with url and id. If the url or id are not set WebappInfo#c
reate() returns |
| 323 * null. | 346 * null. |
| 324 */ | 347 */ |
| 325 private Intent createIntentWithUrlAndId() { | 348 private Intent createIntentWithUrlAndId() { |
| 326 Intent intent = new Intent(); | 349 Intent intent = new Intent(); |
| 327 intent.putExtra(ShortcutHelper.EXTRA_ID, "web app id"); | 350 intent.putExtra(ShortcutHelper.EXTRA_ID, "web app id"); |
| 328 intent.putExtra(ShortcutHelper.EXTRA_URL, "about:blank"); | 351 intent.putExtra(ShortcutHelper.EXTRA_URL, "about:blank"); |
| 329 return intent; | 352 return intent; |
| 330 } | 353 } |
| 331 } | 354 } |
| OLD | NEW |