Debian Codegraph @

closure-library/closure/goog/graphics/ext/element_test.js

raw
1 // Copyright 2008 The Closure Library Authors. All Rights Reserved.
2 // Use of this source code is governed by the Apache License, Version 2.0.
3
4 goog.provide('goog.graphics.ext.ElementTest');
5 goog.setTestOnly('goog.graphics.ext.ElementTest');
6
7 goog.require('goog.graphics');
8 goog.require('goog.graphics.ext');
9 goog.require('goog.testing.StrictMock');
10 goog.require('goog.testing.jsunit');
11
12 var el, graphics, mockWrapper;
13
14 function setUp() {
15 var div = document.getElementById('root');
16 graphics = new goog.graphics.ext.Graphics(100, 100, 200, 200);
17 div.innerHTML = '';
18 graphics.render(div);
19
20 mockWrapper = new goog.testing.StrictMock(goog.graphics.Element);
21 }
22
23 function tearDown() {
24 mockWrapper.$verify();
25 }
26
27 function assertPosition(fn, left, top, opt_width, opt_height) {
28 mockWrapper.setTransformation(0, 0, 0, 5, 5);
29 mockWrapper.setTransformation(
30 left, top, 0, (opt_width || 10) / 2, (opt_height || 10) / 2);
31 mockWrapper.$replay();
32
33 el = new goog.graphics.ext.Element(graphics, mockWrapper);
34 el.setSize(10, 10);
35 fn();
36 }
37
38 function testLeft() {
39 assertPosition(function() {
40 el.setLeft(10);
41 }, 10, 0);
42 assertFalse(el.isParentDependent());
43 }
44
45 function testLeftPercent() {
46 assertPosition(function() {
47 el.setLeft('10%');
48 }, 20, 0);
49 }
50
51 function testCenter() {
52 assertPosition(function() {
53 el.setCenter(0);
54 }, 95, 0);
55 assertTrue(el.isParentDependent());
56 }
57
58 function testCenterPercent() {
59 assertPosition(function() {
60 el.setCenter('10%');
61 }, 115, 0);
62 }
63
64 function testRight() {
65 assertPosition(function() {
66 el.setRight(10);
67 }, 180, 0);
68 assertTrue(el.isParentDependent());
69 }
70
71 function testRightPercent() {
72 assertPosition(function() {
73 el.setRight('10%');
74 }, 170, 0);
75 assertTrue(el.isParentDependent());
76 }
77
78 function testTop() {
79 assertPosition(function() {
80 el.setTop(10);
81 }, 0, 10);
82 assertFalse(el.isParentDependent());
83 }
84
85 function testTopPercent() {
86 assertPosition(function() {
87 el.setTop('10%');
88 }, 0, 20);
89 }
90
91 function testMiddle() {
92 assertPosition(function() {
93 el.setMiddle(0);
94 }, 0, 95);
95 assertTrue(el.isParentDependent());
96 }
97
98 function testMiddlePercent() {
99 assertPosition(function() {
100 el.setMiddle('10%');
101 }, 0, 115);
102 }
103
104 function testBottom() {
105 assertPosition(function() {
106 el.setBottom(10);
107 }, 0, 180);
108 assertTrue(el.isParentDependent());
109 }
110
111 function testBottomPercent() {
112 assertPosition(function() {
113 el.setBottom('10%');
114 }, 0, 170);
115 assertTrue(el.isParentDependent());
116 }
117
118 function testSize() {
119 assertPosition(function() {
120 el.setSize(100, 100);
121 }, 0, 0, 100, 100);
122 assertFalse(el.isParentDependent());
123 }
124
125 function testSizePercent() {
126 assertPosition(function() {
127 el.setSize('10%', '20%');
128 }, 0, 0, 20, 40);
129 assertTrue(el.isParentDependent());
130 }