Home | History | Annotate | Download | only in test
      1 <!doctype html>
      2 <!--
      3 @license
      4 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
      5 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
      6 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
      7 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
      8 Code distributed by Google as part of the polymer project is also
      9 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
     10 -->
     11 <html>
     12 <head>
     13   <meta charset="UTF-8">
     14   <title>paper-icon-button basic tests</title>
     15   <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
     16 
     17   <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
     18   <script src="../../web-component-tester/browser.js"></script>
     19 
     20   <link rel="import" href="../../iron-icons/iron-icons.html">
     21   <link rel="import" href="../paper-icon-button.html">
     22 
     23 </head>
     24 <body>
     25 
     26   <test-fixture id="TrivialIconButton">
     27     <template>
     28       <div style="line-height:30px;">
     29         <paper-icon-button id="fab1" icon="add"></paper-icon-button>
     30       </div>
     31     </template>
     32   </test-fixture>
     33 
     34   <test-fixture id="SrcIconButton">
     35     <template>
     36       <paper-icon-button src="add.png"></paper-icon-button>
     37     </template>
     38   </test-fixture>
     39 
     40   <script>
     41 
     42     var b1;
     43     var b2;
     44 
     45     function centerOf(element) {
     46       var rect = element.getBoundingClientRect();
     47       return {left: rect.left + rect.width / 2, top: rect.top + rect.height / 2};
     48     }
     49 
     50     function approxEqual(p1, p2) {
     51       return Math.abs(p1.left - p2.left) <= 2 && Math.abs(p1.top-p2.top) <= 2;
     52     }
     53 
     54     setup(function() {
     55       b1 = fixture('TrivialIconButton').querySelector('#fab1');
     56       b2 = fixture('SrcIconButton');
     57     });
     58 
     59     test('applies an icon specified by the `icon` attribute', function() {
     60       assert.strictEqual(!!b1.$.icon.src, false);
     61       assert.ok(Polymer.dom(b1.$.icon.root).querySelector('svg'));
     62     });
     63 
     64     test('applies an icon specified by the `src` attribute', function() {
     65 
     66       assert.strictEqual(!!b2.$.icon.src, true);
     67       assert.ok(b2.$.icon.src);
     68     });
     69 
     70     test('renders correctly independent of line height', function() {
     71       assert.ok(approxEqual(centerOf(b1.$.icon), centerOf(b1)));
     72     });
     73   </script>
     74 </body>
     75 </html>
     76