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 /** @type {remoting.WindowShape} */
11 /** @type {HTMLElement} */
12 var elementToPosition;
13 /** @type {sinon.TestStub} */
14 var currentWindowStub;
15 /** @type {sinon.TestStub} */
18 QUnit.module('WindowShape', {
19 beforeEach: function() {
20 windowShape = new remoting.WindowShape();
22 /** @type {HTMLElement} */ (document.createElement('div'));
23 sinon.stub(elementToPosition, 'getBoundingClientRect')
24 .returns({left: -50, top: -50, width: 50, height: 50});
26 isAppsV2Stub = sinon.stub(base, 'isAppsV2', function() { return true; });
27 currentWindowStub = sinon.stub(chrome.app.window, 'current', function() {
29 setShape: base.doNothing
33 afterEach: function() {
35 elementToPosition = null;
36 currentWindowStub.restore();
37 isAppsV2Stub.restore();
41 QUnit.test('centerToDesktop() handles no desktop window',
43 var originalInnerWidth = window.innerWidth;
44 var originalInnerHeight = window.innerHeight;
45 window.innerHeight = 100;
46 window.innerWidth = 100;
48 windowShape.centerToDesktop(elementToPosition);
49 assert.equal(elementToPosition.style.left, '25px');
50 assert.equal(elementToPosition.style.top, '25px');
52 window.innerWidth = originalInnerWidth;
53 window.innerHeight = originalInnerHeight;
56 QUnit.test('centerToDesktop() handles single desktop window',
58 windowShape.setDesktopRects([{left: 0, width: 100, top: 0, height: 100}]);
59 windowShape.centerToDesktop(elementToPosition);
60 assert.equal(elementToPosition.style.left, '25px');
61 assert.equal(elementToPosition.style.top, '25px');
64 QUnit.test('centerToDesktop() handles multiple desktop window',
66 windowShape.setDesktopRects([
67 {left: 0, width: 10, top: 0, height: 10},
68 {left: 90, width: 10, top: 90, height: 10}
71 windowShape.centerToDesktop(elementToPosition);
72 assert.equal(elementToPosition.style.left, '25px');
73 assert.equal(elementToPosition.style.top, '25px');