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

Side by Side Diff: ui/android/javatests/src/org/chromium/ui/resources/sprites/CrushedSpriteResourceTest.java

Issue 2798123002: Remove crushed sprite resource and layer (Closed)
Patch Set: Rebase and fix my nits Created 3 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.ui.resources.sprites;
6
7 import android.support.test.filters.MediumTest;
8 import android.test.InstrumentationTestCase;
9 import android.test.mock.MockResources;
10 import android.util.DisplayMetrics;
11
12 import java.io.ByteArrayInputStream;
13 import java.io.IOException;
14 import java.io.InputStream;
15
16 /**
17 * Tests for CrushedSpriteResource.
18 */
19 public class CrushedSpriteResourceTest extends InstrumentationTestCase {
20 private static final int METADATA_RESOURCE_ID = 1;
21
22 /**
23 * Tests that the metadata is parsed correctly for a dummy CrushedSpriteReso urce.
24 */
25 @MediumTest
26 public void testParseMetadata() {
27 MockCrushedSpriteResources mockResources = new MockCrushedSpriteResource s();
28 CrushedSpriteResource crushedSpriteResource = new CrushedSpriteResource(
29 0, METADATA_RESOURCE_ID, mockResources);
30 try {
31 crushedSpriteResource.parseMetadata(METADATA_RESOURCE_ID, DisplayMet rics.DENSITY_XXHIGH,
32 mockResources);
33
34 int[][] expectedRectangles = {{35, 30, 38, 165, 18, 12, 0, 70, 0, 14 6, 72, 2},
35 {}, {0, 0, 73, 0, 72, 72}};
36 int[][] actualRectangles = crushedSpriteResource.getFrameRectangles( );
37 float dpToPx = mockResources.getDisplayMetrics().density;
38
39 assertEquals(108, crushedSpriteResource.getUnscaledSpriteWidth());
40 assertEquals(108, crushedSpriteResource.getUnscaledSpriteHeight());
41 assertEquals(36 * dpToPx, crushedSpriteResource.getScaledSpriteWidth ());
42 assertEquals(36 * dpToPx, crushedSpriteResource.getScaledSpriteHeigh t());
43 assertEquals(expectedRectangles.length, actualRectangles.length);
44 for (int i = 0; i < expectedRectangles.length; i++) {
45 assertEquals(expectedRectangles[i].length, actualRectangles[i].l ength);
46 for (int j = 0; j < expectedRectangles[i].length; j++) {
47 assertEquals(expectedRectangles[i][j], actualRectangles[i][j ]);
48 }
49 }
50 } catch (IOException e) {
51 e.printStackTrace();
52 fail();
53 }
54 }
55
56 private static class MockCrushedSpriteResources extends MockResources {
57
58 @Override
59 public InputStream openRawResource(int id) {
60 if (id == METADATA_RESOURCE_ID) {
61 return new ByteArrayInputStream(METADATA.getBytes());
62 } else {
63 return null;
64 }
65 }
66
67 @Override
68 public DisplayMetrics getDisplayMetrics() {
69 DisplayMetrics metrics = new DisplayMetrics();
70 metrics.density = 2;
71 return metrics;
72 }
73
74 private static final String METADATA =
75 "{"
76 + "\"apiVersion\": \"1.0\","
77 + "\"scaledSpriteWidthDp\": 36,"
78 + "\"scaledSpriteHeightDp\": 36,"
79 + "\"densities\":"
80 + "["
81 + " {"
82 + " \"density\": 160,"
83 + " \"width\": 36,"
84 + " \"height\": 36,"
85 + " \"rectangles\": ["
86 + " [17, 14, 47, 69, 10, 8, 0, 34, 37, 0, 36, 2],"
87 + " [],"
88 + " [0, 0, 0, 0, 36, 36]"
89 + " ]"
90 + " },"
91 + " {"
92 + " \"density\": 480,"
93 + " \"width\": 108,"
94 + " \"height\": 108,"
95 + " \"rectangles\": ["
96 + " [35, 30, 38, 165, 18, 12, 0, 70, 0, 146, 72, 2],"
97 + " [],"
98 + " [0, 0, 73, 0, 72, 72]"
99 + " ]"
100 + " },"
101 + " {"
102 + " \"density\": 640,"
103 + " \"width\": 144,"
104 + " \"height\": 144,"
105 + " \"rectangles\": ["
106 + " [71, 62, 820, 3, 34, 21, 0, 142, 725, 0, 144, 2],"
107 + " [],"
108 + " [0, 0, 145, 0, 144, 144]"
109 + " ]"
110 + " }"
111 + "]}";
112 }
113
114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698