Roll src/third_party/WebKit 605a979:06cb9e9 (svn 202556:202558)
[chromium-blink-merge.git] / ui / file_manager / image_loader / image_loader_unittest.js
blobf6cf64ad48363d11837dfe126b2ed16956d1dcd2
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.
5 /**
6 * Test case:
7 * - Source image: 200x50
8 * - Target: max size is 100x100
9 */
10 function testNormalImage() {
11 var source = new Image();
12 source.width = 200;
13 source.height = 50;
14 var options = {
15 maxWidth: 100,
16 maxHeight: 100,
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);
32 /**
33 * Test case:
34 * - Source image: 50x200 90 deg clock-wise rotated image.
35 * - Target: max size is 100x100
37 function testRotatedImage() {
38 var source = new Image();
39 source.width = 50;
40 source.height = 200;
41 var options = {
42 maxWidth: 100,
43 maxHeight: 100,
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);
59 /**
60 * Test case:
61 * - Source image: 800x100
62 * - Target: 50x50 cropped image.
64 function testCroppedImage() {
65 var source = new Image();
66 source.width = 800;
67 source.height = 100;
68 var options = {
69 width: 50,
70 height: 50,
71 crop: true,
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);
87 /**
88 * Test case:
89 * - Source image: 200x25
90 * - Target: 50x50 cropped image.
92 function testCroppedImageWithResize() {
93 var source = new Image();
94 source.width = 200;
95 source.height = 25;
96 var options = {
97 width: 50,
98 height: 50,
99 crop: true,
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);
116 * Test case:
117 * - Source image: 20x10
118 * - Target: 50x50 cropped image.
120 function testCroppedTinyImage() {
121 var source = new Image();
122 source.width = 20;
123 source.height = 10;
124 var options = {
125 width: 50,
126 height: 50,
127 crop: true,
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);
144 * Test case:
145 * - Source image: 100x400 90 degree clock-wise rotated.
146 * - Target: 50x50 cropped image
148 function testCroppedRotatedImage() {
149 var source = new Image();
150 source.width = 100;
151 source.height = 400;
152 var options = {
153 width: 50,
154 height: 50,
155 crop: true,
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);