4 Copyright (c) 2012 The Chromium Authors. All rights reserved.
5 Use of this source code is governed by a BSD-style license that can be
6 found in the LICENSE file.
9 <script src=
"base.js"></script>
11 base
.require('base.unittest');
12 base
.require('model.layer_tree_host_impl');
13 base
.require('quad_view');
14 base
.require('quad_view_viewport');
21 var QuadView
= ccfv
.QuadView
;
22 var QuadViewViewport
= ccfv
.QuadViewViewport
;
24 function QuadFromXYWH(x
, y
, w
, h
) {
25 return {p1
: {x
: x
, y
: y
},
31 function testInstantiate() {
32 var quadView
= new QuadView();
33 this.addHTMLOutput('test', quadView
);
36 QuadFromXYWH(0, 0, 10, 10),
37 QuadFromXYWH(10, 10, 10, 10),
38 QuadFromXYWH(20, 4, 10, 10),
39 QuadFromXYWH(30, 10, 20, 20),
40 QuadFromXYWH(20, 20, 10, 10),
41 QuadFromXYWH(15, 15, 10, 10)
43 quads
[2].selected
= true;
44 var quadsBBox
= new base
.BBox2();
45 for (var i
= 0; i
< quads
.length
; i
++)
46 quadsBBox
.addQuad(quads
[i
]);
48 quadView
.title
= 'Test Tree';
49 quadView
.quads
= quads
;
50 quadView
.viewport
= new QuadViewViewport(quadsBBox
, 10.0)
51 quadView
.deviceViewportSizeForFrame
= {widht
: 50,
55 function testFindTiles() {
56 var quadView
= new QuadView();
59 QuadFromXYWH(0, 0, 10, 10),
60 QuadFromXYWH(10, 10, 10, 10),
61 QuadFromXYWH(20, 4, 10, 10),
62 QuadFromXYWH(30, 10, 20, 20),
63 QuadFromXYWH(20, 20, 10, 10),
64 QuadFromXYWH(15, 15, 10, 10)
66 var quadsBBox
= new base
.BBox2();
67 for (var i
= 0; i
< quads
.length
; i
++)
68 quadsBBox
.addQuad(quads
[i
]);
70 quadView
.title
= 'Test Tree';
71 quadView
.quads
= quads
;
72 quadView
.viewport
= new QuadViewViewport(quadsBBox
, 10.0, true, 2);
73 quadView
.deviceViewportSizeForFrame
= {widht
: 50,
76 document
.body
.appendChild(quadView
);
78 var rect
= quadView
.canvas_
.getBoundingClientRect();
79 var hitIndices
= quadView
.findQuadsAtCanvasClientPoint(rect
.left
+ 75,
82 document
.body
.removeChild(quadView
);
85 assertEquals(2, hitIndices
.length
);
86 assertArrayEquals(hitIndices
, [1, 5]);