OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <!-- TODO(arv): Check in Closue unit tests and make this run as part of the | 4 <script src="webui_resource_test.js"></script> |
5 tests --> | |
6 <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.j s"></script> | |
7 <script src="../../cr.js"></script> | |
8 <script src="position_util.js"></script> | |
9 <script> | |
10 | |
11 goog.require('goog.testing.PropertyReplacer'); | |
12 goog.require('goog.testing.jsunit'); | |
13 | |
14 </script> | |
15 <style> | 5 <style> |
16 | 6 |
17 html, body { | 7 html, body { |
18 margin: 0; | 8 margin: 0; |
19 width: 100%; | 9 width: 100%; |
20 height: 100%; | 10 height: 100%; |
21 } | 11 } |
22 | 12 |
23 #anchor { | 13 #anchor { |
24 position: absolute; | 14 position: absolute; |
(...skipping 16 matching lines...) Expand all Loading... | |
41 <body> | 31 <body> |
42 | 32 |
43 <div id=anchor></div> | 33 <div id=anchor></div> |
44 <div id=popup></div> | 34 <div id=popup></div> |
45 | 35 |
46 <script> | 36 <script> |
47 | 37 |
48 var anchor = document.getElementById('anchor'); | 38 var anchor = document.getElementById('anchor'); |
49 var popup = document.getElementById('popup'); | 39 var popup = document.getElementById('popup'); |
50 var anchorParent = anchor.offsetParent; | 40 var anchorParent = anchor.offsetParent; |
51 var pr = new goog.testing.PropertyReplacer; | 41 var oldGetBoundingClientRect = anchorParent.getBoundingClientRect; |
Dan Beam
2013/06/20 17:57:46
propertyreplacer is fancier :(
kevers
2013/06/20 18:41:37
Can certainly add it if you'd like. The last of t
Dan Beam
2013/06/20 18:42:20
whatever you'd like, i've just found it handy in t
| |
52 var availRect; | 42 var availRect; |
53 | 43 |
54 function MockRect(w, h) { | 44 function MockRect(w, h) { |
55 this.width = w; | 45 this.width = w; |
56 this.height = h; | 46 this.height = h; |
57 this.right = this.left + w; | 47 this.right = this.left + w; |
58 this.bottom = this.top + h; | 48 this.bottom = this.top + h; |
59 } | 49 } |
60 MockRect.prototype = { | 50 MockRect.prototype = { |
61 left: 0, | 51 left: 0, |
62 top: 0 | 52 top: 0 |
63 }; | 53 }; |
64 | 54 |
65 function setUp() { | 55 function setUp() { |
66 anchor.style.top = '100px'; | 56 anchor.style.top = '100px'; |
67 anchor.style.left = '100px'; | 57 anchor.style.left = '100px'; |
68 availRect = new MockRect(200, 200); | 58 availRect = new MockRect(200, 200); |
69 pr.set(anchorParent, 'getBoundingClientRect', function() { | 59 anchorParent.getBoundingClientRect = function() { |
70 return availRect; | 60 return availRect; |
71 }); | 61 }; |
72 } | 62 } |
73 | 63 |
74 function tearDown() { | 64 function tearDown() { |
75 document.documentElement.dir = 'ltr'; | 65 document.documentElement.dir = 'ltr'; |
76 pr.reset(); | 66 anchorParent.getBoundingClientRect = oldGetBoundingClientRect; |
77 } | 67 } |
78 | 68 |
79 function testAbovePrimary() { | 69 function testAbovePrimary() { |
80 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE); | 70 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE); |
81 | 71 |
82 assertEquals('auto', popup.style.top); | 72 assertEquals('auto', popup.style.top); |
83 assertEquals('100px', popup.style.bottom); | 73 assertEquals('100px', popup.style.bottom); |
84 | 74 |
85 anchor.style.top = '90px'; | 75 anchor.style.top = '90px'; |
86 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE); | 76 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 assertEquals('auto', popup.style.left); | 291 assertEquals('auto', popup.style.left); |
302 assertEquals('auto', popup.style.top); | 292 assertEquals('auto', popup.style.top); |
303 assertEquals('50px', popup.style.right); | 293 assertEquals('50px', popup.style.right); |
304 assertEquals('50px', popup.style.bottom); | 294 assertEquals('50px', popup.style.bottom); |
305 } | 295 } |
306 | 296 |
307 </script> | 297 </script> |
308 | 298 |
309 </body> | 299 </body> |
310 </html> | 300 </html> |
OLD | NEW |