|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 "use strict"; |
|
4 |
|
5 const ZOOM = 2; |
|
6 const RESIZE = 50; |
|
7 let tiltOpened = false; |
|
8 |
|
9 function test() { |
|
10 if (!isTiltEnabled()) { |
|
11 info("Skipping controller test because Tilt isn't enabled."); |
|
12 return; |
|
13 } |
|
14 if (!isWebGLSupported()) { |
|
15 info("Skipping controller test because WebGL isn't supported."); |
|
16 return; |
|
17 } |
|
18 |
|
19 waitForExplicitFinish(); |
|
20 |
|
21 createTab(function() { |
|
22 TiltUtils.setDocumentZoom(window, ZOOM); |
|
23 |
|
24 createTilt({ |
|
25 onTiltOpen: function(instance) |
|
26 { |
|
27 tiltOpened = true; |
|
28 |
|
29 ok(isApprox(instance.presenter._getPageZoom(), ZOOM), |
|
30 "The Highlighter zoom doesn't have the expected results."); |
|
31 |
|
32 ok(isApprox(instance.presenter.transforms.zoom, ZOOM), |
|
33 "The presenter transforms zoom wasn't initially set correctly."); |
|
34 |
|
35 let contentWindow = gBrowser.selectedBrowser.contentWindow; |
|
36 let initialWidth = contentWindow.innerWidth; |
|
37 let initialHeight = contentWindow.innerHeight; |
|
38 |
|
39 let renderer = instance.presenter._renderer; |
|
40 let arcball = instance.controller.arcball; |
|
41 |
|
42 ok(isApprox(contentWindow.innerWidth * ZOOM, renderer.width, 1), |
|
43 "The renderer width wasn't set correctly before the resize."); |
|
44 ok(isApprox(contentWindow.innerHeight * ZOOM, renderer.height, 1), |
|
45 "The renderer height wasn't set correctly before the resize."); |
|
46 |
|
47 ok(isApprox(contentWindow.innerWidth * ZOOM, arcball.width, 1), |
|
48 "The arcball width wasn't set correctly before the resize."); |
|
49 ok(isApprox(contentWindow.innerHeight * ZOOM, arcball.height, 1), |
|
50 "The arcball height wasn't set correctly before the resize."); |
|
51 |
|
52 |
|
53 window.resizeBy(-RESIZE * ZOOM, -RESIZE * ZOOM); |
|
54 |
|
55 executeSoon(function() { |
|
56 ok(isApprox(contentWindow.innerWidth + RESIZE, initialWidth, 1), |
|
57 "The content window width wasn't set correctly after the resize."); |
|
58 ok(isApprox(contentWindow.innerHeight + RESIZE, initialHeight, 1), |
|
59 "The content window height wasn't set correctly after the resize."); |
|
60 |
|
61 ok(isApprox(contentWindow.innerWidth * ZOOM, renderer.width, 1), |
|
62 "The renderer width wasn't set correctly after the resize."); |
|
63 ok(isApprox(contentWindow.innerHeight * ZOOM, renderer.height, 1), |
|
64 "The renderer height wasn't set correctly after the resize."); |
|
65 |
|
66 ok(isApprox(contentWindow.innerWidth * ZOOM, arcball.width, 1), |
|
67 "The arcball width wasn't set correctly after the resize."); |
|
68 ok(isApprox(contentWindow.innerHeight * ZOOM, arcball.height, 1), |
|
69 "The arcball height wasn't set correctly after the resize."); |
|
70 |
|
71 |
|
72 window.resizeBy(RESIZE * ZOOM, RESIZE * ZOOM); |
|
73 |
|
74 |
|
75 Services.obs.addObserver(cleanup, DESTROYED, false); |
|
76 Tilt.destroy(Tilt.currentWindowId); |
|
77 }); |
|
78 } |
|
79 }, false, function suddenDeath() |
|
80 { |
|
81 info("Tilt could not be initialized properly."); |
|
82 cleanup(); |
|
83 }); |
|
84 }); |
|
85 } |
|
86 |
|
87 function cleanup() { |
|
88 if (tiltOpened) { Services.obs.removeObserver(cleanup, DESTROYED); } |
|
89 gBrowser.removeCurrentTab(); |
|
90 finish(); |
|
91 } |