Files
polymer/test/html/styling/host.html
T
2013-05-13 18:07:25 -07:00

115 lines
3.7 KiB
HTML

<!DOCTYPE html>
<!--
Copyright 2013 The Polymer-Project Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<html>
<head>
<meta name="viewport" content="initial-scale=1.0">
<title>Using @host styling</title>
<script src="../../../polymer.js"></script>
<script src="../../../tools/test/htmltest.js"></script>
<script src="../../../node_modules/chai/chai.js"></script>
</head>
<body>
<h4>Expected: red background</h4>
<x-foo></x-foo>
<h4>Expected: red background with white text</h4>
<x-bar></x-bar>
<h4>Expected: red background with black text and orange border</h4>
<x-zot></x-zot>
<h4>Expected: red background with black text and orange border and 20px padding</h4>
<x-zim></x-zim>
<script>
document.addEventListener('WebComponentsReady', function() {
var foo = document.querySelector('x-foo');
chai.assert.equal(getComputedStyle(foo).backgroundColor, 'rgb(255, 0, 0)',
'@host styles are applied (backgroundColor)');
var bar = document.querySelector('x-bar');
var barStyle = getComputedStyle(bar);
chai.assert.equal(barStyle.backgroundColor, 'rgb(255, 0, 0)',
'@host styles are inherited (backgroundColor)');
chai.assert.equal(barStyle.color, 'rgb(255, 255, 255)',
'@host styles are combined with inherited @host styles (color)');
var zot = document.querySelector('x-zot');
var zotStyle = getComputedStyle(zot);
chai.assert.equal(zotStyle.backgroundColor, 'rgb(255, 0, 0)',
'@host styles are inherited (backgroundColor)');
chai.assert.equal(zotStyle.borderTopColor, 'rgb(255, 165, 0)',
'@host styles are combined with inherited @host styles (borderTopColor)');
chai.assert.equal(zotStyle.color, 'rgb(0, 0, 0)',
'@host styles are applied to given selector (color)');
var zim = document.querySelector('x-zim');
var zimStyle = getComputedStyle(zim);
chai.assert.equal(zimStyle.backgroundColor, 'rgb(255, 0, 0)',
'@host styles are inherited (backgroundColor)');
chai.assert.equal(zimStyle.borderTopColor, 'rgb(255, 165, 0)',
'@host styles are combined with inherited @host styles (borderTopColor)');
chai.assert.equal(zimStyle.borderBottomColor, 'rgb(255, 165, 0)',
'@host styles are combined with inherited @host styles (borderBottomColor)');
chai.assert.equal(zimStyle.color, 'rgb(0, 0, 0)',
'@host styles are applied to given selector (color)');
chai.assert.equal(zimStyle.paddingTop, '20px',
'@host styles are loaded via external sheet in import (paddingTop)');
chai.assert.equal(zimStyle.paddingLeft, '20px',
'@host styles are loaded via external sheet in import (paddingLeft)');
done();
});
</script>
<element name="x-foo">
<template>
<style>
@host {
* {
display: block;
background: red;
}
}
</style>
<div>red background</div>
</template>
<script>Polymer.register(this)</script>
</element>
<element name="x-bar" extends="x-foo">
<template>
<style>
@host {
x-bar {
color: white;
}
}
</style>
<shadow></shadow>
<div>white text</div>
</template>
<script>Polymer.register(this)</script>
</element>
<element name="x-zot" extends="x-bar">
<template>
<style>
@host {
* {
border: 5px solid orange;
}
}
</style>
<shadow></shadow>
<div>orange border & gray background</div>
</template>
<script>Polymer.register(this)</script>
</element>
<link rel="import" href="zim.html">
</body>
</html>