Index: tools/cc-frame-viewer/src/quad_view_viewport_test.html |
diff --git a/tools/cc-frame-viewer/src/quad_view_viewport_test.html b/tools/cc-frame-viewer/src/quad_view_viewport_test.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cf82fc74bafd191dbbfdfbac6fd3584a1017bfb8 |
--- /dev/null |
+++ b/tools/cc-frame-viewer/src/quad_view_viewport_test.html |
@@ -0,0 +1,79 @@ |
+<!DOCTYPE HTML> |
+<html> |
+<!-- |
+Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+Use of this source code is governed by a BSD-style license that can be |
+found in the LICENSE file. |
+--> |
+<head> |
+<script src="base.js"></script> |
+<script> |
+ base.require('base.unittest'); |
+ base.require('base.bbox2'); |
+ base.require('quad_view_viewport'); |
+</script> |
+</head> |
+<body> |
+<script> |
+ 'use strict'; |
+ |
+ var QuadViewViewport = ccfv.QuadViewViewport; |
+ |
+ function testBasicsHighDPI() { |
+ var bbox = new base.BBox2(); |
+ bbox.addXY(0, 0); |
+ bbox.addXY(4000, 2000); |
+ |
+ var vp = new QuadViewViewport(bbox, 0.125, true, 2); |
+ assertEquals(500, vp.deviceWidth); |
+ assertEquals(250, vp.deviceHeight); |
+ |
+ assertEquals(250, vp.layoutWidth); |
+ assertEquals(125, vp.layoutHeight); |
+ |
+ // Top left. |
+ var tmp = vp.layoutPixelsToWorldPixels2(vec2.createXY(0, 0)) |
+ assertEquals(0, tmp[0]); |
+ assertEquals(0, tmp[1]); |
+ |
+ // World center. |
+ var tmp = vp.layoutPixelsToWorldPixels2(vec2.createXY(125, 62.5)) |
+ assertEquals(2000, tmp[0]); |
+ assertEquals(1000, tmp[1]); |
+ |
+ // Bottom right. |
+ var tmp = vp.layoutPixelsToWorldPixels2(vec2.createXY(250, 125)) |
+ assertEquals(4000, tmp[0]); |
+ assertEquals(2000, tmp[1]); |
+ } |
+ |
+ function testBasicsHighDPIUnpadded() { |
+ var bbox = new base.BBox2(); |
+ bbox.addXY(0, 0); |
+ bbox.addXY(4000, 2000); |
+ |
+ var vp = new QuadViewViewport(bbox, 0.125, false, 2); |
+ assertEquals(550, vp.deviceWidth); |
+ assertEquals(300, vp.deviceHeight); |
+ |
+ assertEquals(275, vp.layoutWidth); |
+ assertEquals(150, vp.layoutHeight); |
+ |
+ // Top left. |
+ var tmp = vp.layoutPixelsToWorldPixels2(vec2.createXY(0, 0)) |
+ assertEquals(-200, tmp[0]); |
+ assertEquals(-200, tmp[1]); |
+ |
+ // World center. |
+ var tmp = vp.layoutPixelsToWorldPixels2(vec2.createXY(137.5, 75)) |
+ assertEquals(2000, tmp[0]); |
+ assertEquals(1000, tmp[1]); |
+ |
+ // Bottom right. |
+ var tmp = vp.layoutPixelsToWorldPixels2(vec2.createXY(275, 150)) |
+ assertEquals(4200, tmp[0]); |
+ assertEquals(2200, tmp[1]); |
+ } |
+</script> |
+</body> |
+</html> |