diff --git a/src/lib/style-transformer.html b/src/lib/style-transformer.html
index 605cabb5d0..74adf086f4 100644
--- a/src/lib/style-transformer.html
+++ b/src/lib/style-transformer.html
@@ -175,6 +175,7 @@
var stop = false;
var hostContext = false;
var self = this;
+ selector = selector.trim();
selector = selector.replace(CONTENT_START, HOST + ' $1');
selector = selector.replace(SIMPLE_SELECTOR_SEP, function(m, c, s) {
if (!stop) {
diff --git a/test/unit/styling-scoped-elements.html b/test/unit/styling-scoped-elements.html
index 14eca30b81..0b291139a2 100644
--- a/test/unit/styling-scoped-elements.html
+++ b/test/unit/styling-scoped-elements.html
@@ -440,8 +440,7 @@
@@ -577,4 +576,26 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/test/unit/styling-scoped.html b/test/unit/styling-scoped.html
index 727ff61242..298aba5a95 100644
--- a/test/unit/styling-scoped.html
+++ b/test/unit/styling-scoped.html
@@ -113,6 +113,49 @@
assertComputed(content2, '14px');
});
+ test('auto ::content selector', function() {
+ var x = document.createElement('x-content');
+ var d1 = document.createElement('div');
+ d1.classList.add('auto-content');
+ d1.textContent = 'auto-content';
+ document.body.appendChild(x);
+ Polymer.dom(x).appendChild(d1);
+ Polymer.dom.flush();
+ assertComputed(d1, '2px');
+ });
+
+ test('::content + descendant in complex selector', function() {
+ var x = document.createElement('x-content');
+ var d1 = document.createElement('div');
+ d1.classList.add('complex-descendant');
+ d1.textContent = 'complex-descendant';
+ document.body.appendChild(x);
+ Polymer.dom(x).appendChild(d1);
+ Polymer.dom.flush();
+ assertComputed(d1, '4px');
+ });
+
+ test('::content + descendant in complex selector does not leak', function() {
+ var x = document.createElement('x-content');
+ var d1 = document.createElement('div');
+ d1.classList.add('complex-descendant');
+ d1.textContent = 'complex-descendant';
+ document.body.appendChild(x);
+ document.body.appendChild(d1);
+ assertComputed(d1, '0px');
+ });
+
+ test('::content + child in complex selector', function() {
+ var x = document.createElement('x-content');
+ var d1 = document.createElement('div');
+ d1.classList.add('complex-child');
+ d1.textContent = 'complex-child';
+ document.body.appendChild(x);
+ Polymer.dom(x).appendChild(d1);
+ Polymer.dom.flush();
+ assertComputed(d1, '6px');
+ });
+
test('::shadow selectors', function() {
assertComputed(styled.$.child.$.shadow, '7px');
});