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.
7 * - Source image: 200x50
8 * - Target: max size is 100x100
10 function testNormalImage() {
11 var source = new Image();
17 orientation: ImageOrientation.fromDriveOrientation(0)
19 var result = ImageLoader.calculateCopyParameters(source, options);
20 assertEquals(0, result.source.x);
21 assertEquals(0, result.source.y);
22 assertEquals(200, result.source.width);
23 assertEquals(50, result.source.height);
24 assertEquals(0, result.target.x);
25 assertEquals(0, result.target.y);
26 assertEquals(100, result.target.width);
27 assertEquals(25, result.target.height);
28 assertEquals(100, result.canvas.width);
29 assertEquals(25, result.canvas.height);
34 * - Source image: 50x200 90 deg clock-wise rotated image.
35 * - Target: max size is 100x100
37 function testRotatedImage() {
38 var source = new Image();
44 orientation: ImageOrientation.fromDriveOrientation(1)
46 var result = ImageLoader.calculateCopyParameters(source, options);
47 assertEquals(0, result.source.x);
48 assertEquals(0, result.source.y);
49 assertEquals(50, result.source.width);
50 assertEquals(200, result.source.height);
51 assertEquals(0, result.target.x);
52 assertEquals(0, result.target.y);
53 assertEquals(25, result.target.width);
54 assertEquals(100, result.target.height);
55 assertEquals(100, result.canvas.width);
56 assertEquals(25, result.canvas.height);
61 * - Source image: 800x100
62 * - Target: 50x50 cropped image.
64 function testCroppedImage() {
65 var source = new Image();
72 orientation: ImageOrientation.fromDriveOrientation(0)
74 var result = ImageLoader.calculateCopyParameters(source, options);
75 assertEquals(350, result.source.x);
76 assertEquals(0, result.source.y);
77 assertEquals(100, result.source.width);
78 assertEquals(100, result.source.height);
79 assertEquals(0, result.target.x);
80 assertEquals(0, result.target.y);
81 assertEquals(50, result.target.width);
82 assertEquals(50, result.target.height);
83 assertEquals(50, result.canvas.width);
84 assertEquals(50, result.canvas.height);
89 * - Source image: 200x25
90 * - Target: 50x50 cropped image.
92 function testCroppedImageWithResize() {
93 var source = new Image();
100 orientation: ImageOrientation.fromDriveOrientation(0)
102 var result = ImageLoader.calculateCopyParameters(source, options);
103 assertEquals(87, result.source.x);
104 assertEquals(0, result.source.y);
105 assertEquals(25, result.source.width);
106 assertEquals(25, result.source.height);
107 assertEquals(0, result.target.x);
108 assertEquals(0, result.target.y);
109 assertEquals(50, result.target.width);
110 assertEquals(50, result.target.height);
111 assertEquals(50, result.canvas.width);
112 assertEquals(50, result.canvas.height);
117 * - Source image: 20x10
118 * - Target: 50x50 cropped image.
120 function testCroppedTinyImage() {
121 var source = new Image();
128 orientation: ImageOrientation.fromDriveOrientation(0)
130 var result = ImageLoader.calculateCopyParameters(source, options);
131 assertEquals(5, result.source.x);
132 assertEquals(0, result.source.y);
133 assertEquals(10, result.source.width);
134 assertEquals(10, result.source.height);
135 assertEquals(0, result.target.x);
136 assertEquals(0, result.target.y);
137 assertEquals(50, result.target.width);
138 assertEquals(50, result.target.height);
139 assertEquals(50, result.canvas.width);
140 assertEquals(50, result.canvas.height);
145 * - Source image: 100x400 90 degree clock-wise rotated.
146 * - Target: 50x50 cropped image
148 function testCroppedRotatedImage() {
149 var source = new Image();
156 orientation: ImageOrientation.fromDriveOrientation(1)
158 var result = ImageLoader.calculateCopyParameters(source, options);
159 assertEquals(0, result.source.x);
160 assertEquals(150, result.source.y);
161 assertEquals(100, result.source.width);
162 assertEquals(100, result.source.height);
163 assertEquals(0, result.target.x);
164 assertEquals(0, result.target.y);
165 assertEquals(50, result.target.width);
166 assertEquals(50, result.target.height);
167 assertEquals(50, result.canvas.width);
168 assertEquals(50, result.canvas.height);