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.
9 module('DesktopViewport');
11 function size(width, height) {
12 return {width: width, height: height};
19 test('choosePluginSize() handles low-DPI client & host',
21 // 1. Client & host size the same.
22 var pluginSize = remoting.DesktopViewport.choosePluginSize(
23 size(640, 480), 1.0, size(640, 480), dpi(96, 96), 1.0, false, true);
24 QUnit.deepEqual(pluginSize, size(640, 480));
26 // 2. Client logical dimensions smaller than host's.
27 pluginSize = remoting.DesktopViewport.choosePluginSize(
28 size(640, 480), 1.0, size(1024, 600), dpi(96, 96), 1.0, false, true);
29 QUnit.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
31 // 3. Client Y dimension larger than host's, X dimension smaller.
32 pluginSize = remoting.DesktopViewport.choosePluginSize(
33 size(640, 640), 1.0, size(1024, 600), dpi(96, 96), 1.0, false, true);
34 QUnit.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
36 // 4. Client dimensions larger than host's by <2x.
37 pluginSize = remoting.DesktopViewport.choosePluginSize(
38 size(1280, 900), 1.0, size(640, 480), dpi(96, 96), 1.0, false, true);
39 QUnit.deepEqual(pluginSize, size(640, 480));
41 // 5. Client dimensions larger than host's by >2x.
42 pluginSize = remoting.DesktopViewport.choosePluginSize(
43 size(1280, 1024), 1.0, size(640, 480), dpi(96, 96), 1.0, false, true);
44 QUnit.deepEqual(pluginSize, size(2 * 640, 2 * 480));
46 // 6. Client X dimension larger than host's, Y dimension smaller.
47 pluginSize = remoting.DesktopViewport.choosePluginSize(
48 size(1152, 600), 1.0, size(1024, 768), dpi(96, 96), 1.0, false, true);
49 QUnit.deepEqual(pluginSize, size(1024 * (600 / 768), 600));
52 test('choosePluginSize() handles high-DPI client, low-DPI host',
54 // 1. Client & host size the same.
55 var pluginSize = remoting.DesktopViewport.choosePluginSize(
56 size(640, 480), 2.0, size(640, 480), dpi(96, 96), 1.0, false, true);
57 QUnit.deepEqual(pluginSize, size(640, 480));
59 // 2. Client logical dimensions smaller than host's.
60 pluginSize = remoting.DesktopViewport.choosePluginSize(
61 size(640, 480), 2.0, size(1024, 600), dpi(96, 96), 1.0, false, true);
62 QUnit.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
64 // 3. Client Y dimension larger than host's, X dimension smaller.
65 pluginSize = remoting.DesktopViewport.choosePluginSize(
66 size(640, 640), 2.0, size(1024, 600), dpi(96, 96), 1.0, false, true);
67 QUnit.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
69 // 4. Client logical dimensions larger than host's by <2x.
70 // Host dimensions fit into the client's _device_ dimensions 3x, so the
71 // size in client DIPs should be 1:3/2.
72 pluginSize = remoting.DesktopViewport.choosePluginSize(
73 size(1280, 900), 2.0, size(640, 480), dpi(96, 96), 1.0, false, true);
74 QUnit.deepEqual(pluginSize, size(640 * 3 / 2.0, 480 * 3 / 2.0));
76 // 5. Client dimensions larger than host's by >2x.
77 pluginSize = remoting.DesktopViewport.choosePluginSize(
78 size(1280, 1024), 2.0, size(640, 480), dpi(96, 96), 1.0, false, true);
79 QUnit.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
81 // 6. Client X dimension larger than host's, Y dimension smaller.
82 pluginSize = remoting.DesktopViewport.choosePluginSize(
83 size(1152, 600), 2.0, size(1024, 768), dpi(96, 96), 1.0, false, true);
84 QUnit.deepEqual(pluginSize, size(1024 * (600 / 768), 600));
87 test('choosePluginSize() handles low-DPI client, high-DPI host',
89 // 1. Client & host size the same.
90 var pluginSize = remoting.DesktopViewport.choosePluginSize(
91 size(640, 480), 1.0, size(640, 480), dpi(192, 192), 1.0, false, true);
92 QUnit.deepEqual(pluginSize, size(640, 480));
94 // 2. Client logical dimensions smaller than host's.
95 pluginSize = remoting.DesktopViewport.choosePluginSize(
96 size(640, 480), 1.0, size(1024, 600), dpi(192, 192), 1.0, false, true);
97 QUnit.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
99 // 3. Client Y dimension larger than host's, X dimension smaller.
100 pluginSize = remoting.DesktopViewport.choosePluginSize(
101 size(640, 640), 1.0, size(1024, 600), dpi(192, 192), 1.0, false, true);
102 QUnit.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
104 // 4. Client dimensions larger than host's by <2x.
105 pluginSize = remoting.DesktopViewport.choosePluginSize(
106 size(1280, 900), 1.0, size(640, 480), dpi(192, 192), 1.0, false, true);
107 QUnit.deepEqual(pluginSize, size(640, 480));
109 // 5. Client dimensions larger than host's by >2x.
110 pluginSize = remoting.DesktopViewport.choosePluginSize(
111 size(1280, 1024), 1.0, size(640, 480), dpi(192, 192), 1.0, false, true);
112 QUnit.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
114 // 6. Client X dimension larger than host's, Y dimension smaller.
115 pluginSize = remoting.DesktopViewport.choosePluginSize(
116 size(1152, 600), 1.0, size(1024, 768), dpi(192, 192), 1.0, false, true);
117 QUnit.deepEqual(pluginSize, size(1024 * (600 / 768), 600));
120 test('choosePluginSize() handles high-DPI client and host',
122 // 1. Client & host size the same.
123 var pluginSize = remoting.DesktopViewport.choosePluginSize(
124 size(640, 480), 2.0, size(640, 480), dpi(192, 192), 1.0, false, true);
125 QUnit.deepEqual(pluginSize, size(640, 480));
127 // 2. Client logical dimensions smaller than host's.
128 pluginSize = remoting.DesktopViewport.choosePluginSize(
129 size(640, 480), 2.0, size(1024, 600), dpi(192, 192), 1.0, false, true);
130 QUnit.deepEqual(pluginSize, size(1024 / 2.0, 600 / 2.0));
132 // 3. Client Y dimension larger than host's, X dimension smaller.
133 pluginSize = remoting.DesktopViewport.choosePluginSize(
134 size(640, 640), 2.0, size(1024, 600), dpi(192, 192), 1.0, false, true);
135 QUnit.deepEqual(pluginSize, size(1024 / 2.0, 600 / 2.0));
137 // 4. Client logical dimensions larger than host's by <2x.
138 // Host dimensions fit into the client's _device_ dimensions 3x, so the
139 // size in client DIPs should be 1:3/2.
140 pluginSize = remoting.DesktopViewport.choosePluginSize(
141 size(1280, 900), 2.0, size(640, 480), dpi(192, 192), 1.0, false, true);
142 QUnit.deepEqual(pluginSize, size(640 * 3 / 2.0, 480 * 3 / 2.0));
144 // 5. Client dimensions larger than host's by >2x.
145 pluginSize = remoting.DesktopViewport.choosePluginSize(
146 size(1280, 1024), 2.0, size(640, 480), dpi(192, 192), 1.0, false, true);
147 QUnit.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
149 // 6. Client X dimension larger than host's, Y dimension smaller.
150 pluginSize = remoting.DesktopViewport.choosePluginSize(
151 size(1152, 600), 2.0, size(1024, 768), dpi(192, 192), 1.0, false, true);
152 QUnit.deepEqual(pluginSize, size(1024 / 2.0, 768 / 2.0));
155 test('choosePluginSize() handles high-DPI client, 150% DPI host',
157 // 1. Client & host size the same.
158 var pluginSize = remoting.DesktopViewport.choosePluginSize(
159 size(640, 480), 2.0, size(640, 480), dpi(144, 144), 1.0, false, true);
160 QUnit.deepEqual(pluginSize, size(640, 480));
162 // 2. Client dimensions smaller than host's.
163 pluginSize = remoting.DesktopViewport.choosePluginSize(
164 size(640, 480), 2.0, size(1024, 600), dpi(144, 144), 1.0, false, true);
165 QUnit.deepEqual(pluginSize, size(1024 / 2.0, 600 / 2.0));
167 // 3. Client Y dimension larger than host's, X dimension smaller.
168 pluginSize = remoting.DesktopViewport.choosePluginSize(
169 size(640, 640), 2.0, size(1024, 600), dpi(144, 144), 1.0, false, true);
170 QUnit.deepEqual(pluginSize, size(1024 / 2.0, 600 / 2.0));
172 // 4. Client dimensions larger than host's by <2x.
173 // Host dimensions fit into the client's _device_ dimensions 3x, so the
174 // size in client DIPs should be 1:3/2.
175 pluginSize = remoting.DesktopViewport.choosePluginSize(
176 size(1280, 900), 2.0, size(640, 480), dpi(144, 144), 1.0, false, true);
177 QUnit.deepEqual(pluginSize, size(640 * 3 / 2.0, 480 * 3 / 2.0));
179 // 5. Client dimensions larger than host's by >2x.
180 pluginSize = remoting.DesktopViewport.choosePluginSize(
181 size(1280, 1024), 2.0, size(640, 480), dpi(144, 144), 1.0, false, true);
182 QUnit.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
184 // 6. Client X dimension larger than host's, Y dimension smaller.
185 pluginSize = remoting.DesktopViewport.choosePluginSize(
186 size(1152, 600), 2.0, size(1024, 768), dpi(144, 144), 1.0, false, true);
187 QUnit.deepEqual(pluginSize, size(1024 / 2.0, 768 / 2.0));
190 test('choosePluginSize() handles high-DPI client, 125% DPI host',
192 // 1. Client & host size the same.
193 var pluginSize = remoting.DesktopViewport.choosePluginSize(
194 size(640, 480), 2.0, size(640, 480), dpi(120, 120), 1.0, false, true);
195 QUnit.deepEqual(pluginSize, size(640, 480));
197 // 2. Client dimensions smaller than host's.
198 pluginSize = remoting.DesktopViewport.choosePluginSize(
199 size(640, 480), 2.0, size(1024, 600), dpi(120, 120), 1.0, false, true);
200 QUnit.deepEqual(pluginSize, size(640, 600 * (640 / 1024)));
202 // 3. Client Y dimension larger than host's, X dimension smaller.
203 pluginSize = remoting.DesktopViewport.choosePluginSize(
204 size(640, 640), 2.0, size(1024, 600), dpi(120, 120), 1.0, false, true);
205 QUnit.deepEqual(pluginSize, size(640, 600 * (640 / 1024)));
207 // 4. Client dimensions larger than host's by <2x.
208 // Host dimensions fit into the client's _device_ dimensions 3x, so the
209 // size in client DIPs should be 1:3/2.
210 pluginSize = remoting.DesktopViewport.choosePluginSize(
211 size(1280, 900), 2.0, size(640, 480), dpi(120, 120), 1.0, false, true);
212 QUnit.deepEqual(pluginSize, size(640 * 3 / 2.0, 480 * 3 / 2.0));
214 // 5. Client dimensions larger than host's by >2x.
215 pluginSize = remoting.DesktopViewport.choosePluginSize(
216 size(1280, 1024), 2.0, size(640, 480), dpi(120, 120), 1.0, false, true);
217 QUnit.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
219 // 6. Client X dimension larger than host's, Y dimension smaller.
220 pluginSize = remoting.DesktopViewport.choosePluginSize(
221 size(1152, 600), 2.0, size(1024, 768), dpi(120, 120), 1.0, false, true);
222 QUnit.deepEqual(pluginSize, size(1024 * (600 / 768), 600));
225 test('choosePluginSize() with shrink-to-fit disabled',
227 // 1. Client & host size the same.
228 var pluginSize = remoting.DesktopViewport.choosePluginSize(
229 size(640, 480), 1.0, size(640, 480), dpi(96, 96), 1.0, false, false);
230 QUnit.deepEqual(pluginSize, size(640, 480));
232 // 2. Client logical dimensions smaller than host's.
233 pluginSize = remoting.DesktopViewport.choosePluginSize(
234 size(640, 480), 1.0, size(1024, 600), dpi(96, 96), 1.0, false, false);
235 QUnit.deepEqual(pluginSize, size(1024, 600));
237 // 3. Client dimensions larger than host's by <2x.
238 pluginSize = remoting.DesktopViewport.choosePluginSize(
239 size(1280, 900), 1.0, size(640, 480), dpi(96, 96), 1.0, false, false);
240 QUnit.deepEqual(pluginSize, size(640, 480));
242 // 4. Client dimensions larger than host's by >2x.
243 pluginSize = remoting.DesktopViewport.choosePluginSize(
244 size(1280, 1024), 1.0, size(640, 480), dpi(96, 96), 1.0, false, false);
245 QUnit.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
247 // 5. Client smaller than host, client high-DPI, host low-DPI.
248 pluginSize = remoting.DesktopViewport.choosePluginSize(
249 size(640, 480), 2.0, size(1024, 600), dpi(96, 96), 1.0, false, false);
250 QUnit.deepEqual(pluginSize, size(1024, 600));
252 // 6. Client smaller than host, client low-DPI, host high-DPI.
253 pluginSize = remoting.DesktopViewport.choosePluginSize(
254 size(640, 480), 1.0, size(1024, 600), dpi(192, 192), 1.0, false, false);
255 QUnit.deepEqual(pluginSize, size(1024, 600));
257 // 7. Client smaller than host, both high-DPI.
258 pluginSize = remoting.DesktopViewport.choosePluginSize(
259 size(640, 480), 2.0, size(1024, 600), dpi(192, 192), 1.0, false, false);
260 QUnit.deepEqual(pluginSize, size(512, (512 / 1024) * 600));
262 // 8. Client smaller than host, client high-DPI, host 150% DPI.
263 pluginSize = remoting.DesktopViewport.choosePluginSize(
264 size(640, 480), 2.0, size(1024, 600), dpi(144, 144), 1.0, false, false);
265 QUnit.deepEqual(pluginSize, size(512, (512 / 1024) * 600));
268 test('choosePluginSize() full-screen multi-monitor optimization',
270 // Each test has a host sized to approximate two or more monitors.
272 // 1. Client & host per-monitor dimensions match, two monitors side-by-side.
273 var pluginSize = remoting.DesktopViewport.choosePluginSize(
274 size(640, 480), 1.0, size(2 * 640, 480), dpi(96, 96), 1.0, true, true);
275 QUnit.deepEqual(pluginSize, size(2 * 640, 480));
277 // 2. Client & host per-monitor dimensions match, two monitors stacked.
278 pluginSize = remoting.DesktopViewport.choosePluginSize(
279 size(640, 480), 1.0, size(640, 2 * 480), dpi(96, 96), 1.0, true, true);
280 QUnit.deepEqual(pluginSize, size(640, 2 * 480));
282 // 3. Client larger, two monitors stacked.
283 pluginSize = remoting.DesktopViewport.choosePluginSize(
284 size(1024, 768), 1.0, size(640, 2 * 480), dpi(96, 96), 1.0, true, true);
285 QUnit.deepEqual(pluginSize, size(640 * (768 / (2 * 480)), 768));
287 // 4. Client smaller, two monitors stacked.
288 pluginSize = remoting.DesktopViewport.choosePluginSize(
289 size(640, 480), 1.0, size(1024, 2 * 768), dpi(96, 96), 1.0, true, true);
290 QUnit.deepEqual(pluginSize, size(640, 2 * 768 * (640 / 1024)));
292 // 5. Client wide-screen, host two standard monitors stacked.
293 pluginSize = remoting.DesktopViewport.choosePluginSize(
294 size(1920, 1080), 1.0, size(1024, 2 * 768), dpi(96, 96), 1.0,
296 QUnit.deepEqual(pluginSize, size(1024 * (1080 / (2 * 768)), 1080));
298 // 6. Client & host per-monitor dimensions match, two monitors stacked,
300 pluginSize = remoting.DesktopViewport.choosePluginSize(
301 size(640, 480), 2.0, size(640, 2 * 480), dpi(96, 96), 1.0, true, true);
302 QUnit.deepEqual(pluginSize, size(640, 2 * 480));
304 // 7. Client & host per-monitor dimensions match, two monitors stacked,
306 pluginSize = remoting.DesktopViewport.choosePluginSize(
307 size(640, 480), 1.0, size(640, 2 * 480), dpi(192, 192),
309 QUnit.deepEqual(pluginSize, size(640, 2 * 480));
311 // 8. Client & host per-monitor dimensions match, two monitors stacked,
312 // high-DPI client & host.
313 pluginSize = remoting.DesktopViewport.choosePluginSize(
314 size(640, 480), 2.0, size(640, 2 * 480), dpi(192, 192),
316 QUnit.deepEqual(pluginSize, size(640 / 2.0, (2 * 480) / 2.0));