OLD | NEW |
(Empty) | |
| 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.g
ithub.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/CONTRI
BUTORS.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/PATEN
TS.txt |
| 10 --> |
| 11 <html> |
| 12 <head> |
| 13 <title>iron-image</title> |
| 14 |
| 15 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> |
| 16 <script src="../../web-component-tester/browser.js"></script> |
| 17 <script src="../../test-fixture/test-fixture-mocha.js"></script> |
| 18 |
| 19 <link rel="import" href="../../polymer/polymer.html"> |
| 20 <link rel="import" href="../../test-fixture/test-fixture.html"> |
| 21 <link rel="import" href="../iron-image.html"> |
| 22 |
| 23 <style is="custom-style"> |
| 24 .fixed-width-container { |
| 25 width: 500px; |
| 26 } |
| 27 |
| 28 .fixed-width-container iron-image { |
| 29 width: 100%; |
| 30 --iron-image-width: 100%; |
| 31 } |
| 32 |
| 33 .fixed-height-container { |
| 34 height: 500px; |
| 35 } |
| 36 |
| 37 .fixed-height-container iron-image { |
| 38 height: 100%; |
| 39 --iron-image-height: 100%; |
| 40 } |
| 41 </style> |
| 42 </head> |
| 43 <body> |
| 44 <test-fixture id="TrivialImage"> |
| 45 <template> |
| 46 <iron-image></iron-image> |
| 47 </template> |
| 48 </test-fixture> |
| 49 |
| 50 <test-fixture id="FixedWidthContainer"> |
| 51 <template> |
| 52 <div class="fixed-width-container"> |
| 53 <iron-image></iron-image> |
| 54 </div> |
| 55 </template> |
| 56 </test-fixture> |
| 57 |
| 58 <test-fixture id="FixedHeightContainer"> |
| 59 <template> |
| 60 <div class="fixed-height-container"> |
| 61 <iron-image></iron-image> |
| 62 </div> |
| 63 </template> |
| 64 </test-fixture> |
| 65 |
| 66 <script> |
| 67 suite('<iron-image>', function() { |
| 68 function randomImageUrl () { |
| 69 return '../demo/polymer.svg?' + Math.random(); |
| 70 } |
| 71 |
| 72 var image; |
| 73 |
| 74 suite('basic behavior', function() { |
| 75 setup(function() { |
| 76 image = fixture('TrivialImage'); |
| 77 }); |
| 78 |
| 79 test('can load images given a src', function(done) { |
| 80 image.addEventListener('loaded-changed', function onLoadedChanged()
{ |
| 81 image.removeEventListener('loaded-changed', onLoadedChanged); |
| 82 |
| 83 try { |
| 84 expect(image.loaded).to.be.eql(true); |
| 85 done(); |
| 86 } catch (e) { |
| 87 done(e); |
| 88 } |
| 89 }); |
| 90 image.src = randomImageUrl(); |
| 91 }); |
| 92 |
| 93 test('will reload images when src changes', function(done) { |
| 94 var loadCount = 0; |
| 95 |
| 96 image.addEventListener('loaded-changed', function onLoadedChanged()
{ |
| 97 if (image.loaded === true) { |
| 98 loadCount++; |
| 99 |
| 100 if (loadCount === 2) { |
| 101 done(); |
| 102 } else { |
| 103 image.src = randomImageUrl(); |
| 104 image.removeEventListener('loaded-changed', onLoadedChanged); |
| 105 } |
| 106 } |
| 107 }); |
| 108 |
| 109 image.src = randomImageUrl(); |
| 110 }); |
| 111 }); |
| 112 |
| 113 suite('--iron-image-width, --iron-image-height', function() { |
| 114 var fixedWidthContainer; |
| 115 var fixedWidthIronImage; |
| 116 var fixedHeightContainer; |
| 117 var fixedHeightIronImage; |
| 118 |
| 119 setup(function() { |
| 120 fixedWidthContainer = fixture('FixedWidthContainer'); |
| 121 fixedWidthIronImage = fixedWidthContainer.querySelector('iron-image'
); |
| 122 fixedHeightContainer = fixture('FixedHeightContainer'); |
| 123 fixedHeightIronImage = fixedHeightContainer.querySelector('iron-imag
e'); |
| 124 }); |
| 125 |
| 126 test('100% width image fills container', function(done) { |
| 127 fixedWidthIronImage.$.img.addEventListener('load', function onLoaded
Changed(e) { |
| 128 fixedWidthIronImage.$.img.removeEventListener('load', onLoadedChan
ged); |
| 129 Polymer.updateStyles(); |
| 130 |
| 131 var containerRect = fixedWidthContainer.getBoundingClientRect(); |
| 132 var ironImageRect = fixedWidthIronImage.getBoundingClientRect(); |
| 133 var wrappedImageRect = fixedWidthIronImage.$.img.getBoundingClient
Rect(); |
| 134 |
| 135 expect(containerRect.width).to.be.closeTo(500, 0.5); |
| 136 expect(ironImageRect.width).to.be.closeTo(500, 0.5); |
| 137 expect(wrappedImageRect.width).to.be.closeTo(500, 0.5); |
| 138 |
| 139 done(); |
| 140 }); |
| 141 |
| 142 fixedWidthIronImage.src = randomImageUrl(); |
| 143 }); |
| 144 |
| 145 test('100% height image fills container', function(done) { |
| 146 fixedHeightIronImage.$.img.addEventListener('load', function onLoade
dChanged(e) { |
| 147 fixedHeightIronImage.$.img.removeEventListener('load', onLoadedCha
nged); |
| 148 Polymer.updateStyles(); |
| 149 |
| 150 var containerRect = fixedHeightContainer.getBoundingClientRect(); |
| 151 var ironImageRect = fixedHeightIronImage.getBoundingClientRect(); |
| 152 var wrappedImageRect = fixedHeightIronImage.$.img.getBoundingClien
tRect(); |
| 153 |
| 154 expect(containerRect.height).to.be.closeTo(500, 0.5); |
| 155 expect(ironImageRect.height).to.be.closeTo(500, 0.5); |
| 156 expect(wrappedImageRect.height).to.be.closeTo(500, 0.5); |
| 157 |
| 158 done(); |
| 159 }); |
| 160 |
| 161 fixedHeightIronImage.src = randomImageUrl(); |
| 162 }); |
| 163 }); |
| 164 }); |
| 165 </script> |
| 166 </body> |
| 167 </html> |
OLD | NEW |