Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / remoting / webapp / base / js / window_shape_unittest.js
blob7c2ef3b6e0b18c90b1b343eac0574ff917f67037
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 (function() {
7 'use strict';
9 /** @type {remoting.WindowShape} */
10 var windowShape;
11 /** @type {HTMLElement} */
12 var elementToPosition;
13 /** @type {sinon.TestStub} */
14 var currentWindowStub;
15 /** @type {sinon.TestStub} */
16 var isAppsV2Stub;
18 QUnit.module('WindowShape', {
19 beforeEach: function() {
20 windowShape = new remoting.WindowShape();
21 elementToPosition =
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() {
28 return {
29 setShape: base.doNothing
31 });
33 afterEach: function() {
34 windowShape = null;
35 elementToPosition = null;
36 currentWindowStub.restore();
37 isAppsV2Stub.restore();
39 });
41 QUnit.test('centerToDesktop() handles no desktop window',
42 function(assert) {
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;
54 });
56 QUnit.test('centerToDesktop() handles single desktop window',
57 function(assert) {
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');
62 });
64 QUnit.test('centerToDesktop() handles multiple desktop window',
65 function(assert) {
66 windowShape.setDesktopRects([
67 {left: 0, width: 10, top: 0, height: 10},
68 {left: 90, width: 10, top: 90, height: 10}
69 ]);
71 windowShape.centerToDesktop(elementToPosition);
72 assert.equal(elementToPosition.style.left, '25px');
73 assert.equal(elementToPosition.style.top, '25px');
74 });
76 })();