aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/graphics/ext/element_test.html
blob: 293cb34548e0aa65bc4fcbc1805cc542c9669284 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<html>
<!--
Copyright 2008 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.graphics.ext.Element</title>
<script src="../../base.js"></script>
<script>
  goog.require('goog.graphics');
  goog.require('goog.graphics.ext');
  goog.require('goog.testing.StrictMock');
  goog.require('goog.testing.jsunit');
</script>
</head>
<body>
<div id="root" style="display: none"></div>
<script>
  var el, graphics, mockWrapper;

  function setUp() {
    var div = document.getElementById('root');
    graphics = new goog.graphics.ext.Graphics(100, 100, 200, 200);
    div.innerHTML = '';
    graphics.render(div);

    mockWrapper = new goog.testing.StrictMock(goog.graphics.Element);
  }

  function tearDown() {
    mockWrapper.$verify();
  }

  function assertPosition(fn, left, top, opt_width, opt_height) {
    mockWrapper.setTransformation(0, 0, 0, 5, 5);
    mockWrapper.setTransformation(left, top, 0,
        (opt_width || 10) / 2, (opt_height || 10) / 2);
    mockWrapper.$replay();

    el = new goog.graphics.ext.Element(graphics, mockWrapper);
    el.setSize(10, 10);
    fn();
  }

  function testLeft() {
    assertPosition(function() {
      el.setLeft(10);
    }, 10, 0);
    assertFalse(el.isParentDependent());
  }

  function testLeftPercent() {
    assertPosition(function() {
      el.setLeft('10%');
    }, 20, 0);
  }

  function testCenter() {
    assertPosition(function() {
      el.setCenter(0);
    }, 95, 0);
    assertTrue(el.isParentDependent());
  }

  function testCenterPercent() {
    assertPosition(function() {
      el.setCenter('10%');
    }, 115, 0);
  }

  function testRight() {
    assertPosition(function() {
      el.setRight(10);
    }, 180, 0);
    assertTrue(el.isParentDependent());
  }

  function testRightPercent() {
    assertPosition(function() {
      el.setRight('10%');
    }, 170, 0);
    assertTrue(el.isParentDependent());
  }

  function testTop() {
    assertPosition(function() {
      el.setTop(10);
    }, 0, 10);
    assertFalse(el.isParentDependent());
  }

  function testTopPercent() {
    assertPosition(function() {
      el.setTop('10%');
    }, 0, 20);
  }

  function testMiddle() {
    assertPosition(function() {
      el.setMiddle(0);
    }, 0, 95);
    assertTrue(el.isParentDependent());
  }

  function testMiddlePercent() {
    assertPosition(function() {
      el.setMiddle('10%');
    }, 0, 115);
  }

  function testBottom() {
    assertPosition(function() {
      el.setBottom(10);
    }, 0, 180);
    assertTrue(el.isParentDependent());
  }

  function testBottomPercent() {
    assertPosition(function() {
      el.setBottom('10%');
    }, 0, 170);
    assertTrue(el.isParentDependent());
  }

  function testSize() {
    assertPosition(function() {
      el.setSize(100, 100);
    }, 0, 0, 100, 100);
    assertFalse(el.isParentDependent());
  }

  function testSizePercent() {
    assertPosition(function() {
      el.setSize('10%', '20%');
    }, 0, 0, 20, 40);
    assertTrue(el.isParentDependent());
  }
</script>
</body>
</html>