Home | History | Annotate | Download | only in ui
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 'use strict';
      6 
      7 base.require('base.bbox2');
      8 base.require('ui.quad_view_viewport');
      9 
     10 base.unittest.testSuite('ui.quad_view_viewport', function() {
     11   var QuadViewViewport = ui.QuadViewViewport;
     12 
     13   test('basicsHighDPIUnpadded', function() {
     14     var bbox = new base.BBox2();
     15     bbox.addXY(0, 0);
     16     bbox.addXY(4000, 2000);
     17 
     18     var vp = new QuadViewViewport(bbox.asRect(), 0.125, 0, 2);
     19 
     20     assertEquals(500, vp.worldWidthInDevicePixels_);
     21     assertEquals(250, vp.worldHeightInDevicePixels_);
     22 
     23     assertEquals(250, vp.layoutRect_.width);
     24     assertEquals(125, vp.layoutRect_.height);
     25 
     26     // Top left.
     27     var tmp = vp.layoutPixelsToWorldPixels(vec2.createXY(0, 0));
     28     assertEquals(0, tmp[0]);
     29     assertEquals(0, tmp[1]);
     30 
     31     // World center.
     32     var tmp = vp.layoutPixelsToWorldPixels(vec2.createXY(125, 62.5));
     33     assertEquals(2000, tmp[0]);
     34     assertEquals(1000, tmp[1]);
     35 
     36     // Bottom right.
     37     var tmp = vp.layoutPixelsToWorldPixels(vec2.createXY(250, 125));
     38     assertEquals(4000, tmp[0]);
     39     assertEquals(2000, tmp[1]);
     40 
     41     assertRectEquals(bbox.asRect(), vp.unpaddedWorldRect);
     42   });
     43 
     44   test('basicsHighDPI', function() {
     45     var bbox = new base.BBox2();
     46     bbox.addXY(0, 0);
     47     bbox.addXY(4000, 2000);
     48 
     49     var vp = new QuadViewViewport(bbox.asRect(), 0.125, 0.1, 2);
     50     assertEquals(550, vp.worldWidthInDevicePixels_);
     51     assertEquals(300, vp.worldHeightInDevicePixels_);
     52 
     53     assertEquals(275, vp.layoutRect_.width);
     54     assertEquals(150, vp.layoutRect_.height);
     55 
     56     // Top left.
     57     var tmp = vp.layoutPixelsToWorldPixels(vec2.createXY(0, 0));
     58     assertEquals(-200, tmp[0]);
     59     assertEquals(-200, tmp[1]);
     60 
     61     // World center.
     62     var tmp = vp.layoutPixelsToWorldPixels(vec2.createXY(137.5, 75));
     63     assertEquals(2000, tmp[0]);
     64     assertEquals(1000, tmp[1]);
     65 
     66     // Bottom right.
     67     var tmp = vp.layoutPixelsToWorldPixels(vec2.createXY(275, 150));
     68     assertEquals(4200, tmp[0]);
     69     assertEquals(2200, tmp[1]);
     70 
     71     assertRectEquals(bbox.asRect(), vp.unpaddedWorldRect);
     72   });
     73 });
     74