From 861389e68c23c331a61dd8b42653021295f1f54d Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Fri, 19 Dec 2014 08:02:22 +0100 Subject: [PATCH 01/27] Fix for relative path resolving in css --- src/HTMLImports/path.js | 15 +++++++++------ src/ShadowCSS/ShadowCSS.js | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/HTMLImports/path.js b/src/HTMLImports/path.js index 4dd0d33..98569cb 100644 --- a/src/HTMLImports/path.js +++ b/src/HTMLImports/path.js @@ -16,22 +16,25 @@ var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g; // document. We fixup url's in url() and @import. var path = { - resolveUrlsInStyle: function(style) { + resolveUrlsInStyle: function(style, linkUrl) { var doc = style.ownerDocument; var resolver = doc.createElement('a'); - style.textContent = this.resolveUrlsInCssText(style.textContent, resolver); + style.textContent = this.resolveUrlsInCssText(style.textContent, linkUrl, resolver); return style; }, - resolveUrlsInCssText: function(cssText, urlObj) { - var r = this.replaceUrls(cssText, urlObj, CSS_URL_REGEXP); - r = this.replaceUrls(r, urlObj, CSS_IMPORT_REGEXP); + resolveUrlsInCssText: function(cssText, linkUrl, urlObj) { + var r = this.replaceUrls(cssText, urlObj, linkUrl, CSS_URL_REGEXP); + r = this.replaceUrls(r, urlObj, linkUrl, CSS_IMPORT_REGEXP); return r; }, - replaceUrls: function(text, urlObj, regexp) { + replaceUrls: function(text, urlObj, linkUrl, regexp) { return text.replace(regexp, function(m, pre, url, post) { var urlPath = url.replace(/["']/g, ''); + if (urlPath.substr(0, 3) === '../') { + urlPath = linkUrl.match(/(.*\/)[^\/]+$/)[1] + urlPath; + } urlObj.href = urlPath; urlPath = urlObj.href; return pre + '\'' + urlPath + '\'' + post; diff --git a/src/ShadowCSS/ShadowCSS.js b/src/ShadowCSS/ShadowCSS.js index 9e4b18f..185dc7d 100644 --- a/src/ShadowCSS/ShadowCSS.js +++ b/src/ShadowCSS/ShadowCSS.js @@ -742,7 +742,7 @@ if (window.ShadowDOMPolyfill) { style.textContent = elt.__resource; } // relay on HTMLImports for path fixup - HTMLImports.path.resolveUrlsInStyle(style); + HTMLImports.path.resolveUrlsInStyle(style, elt.href); style.textContent = ShadowCSS.shimStyle(style); style.removeAttribute(SHIM_ATTRIBUTE, ''); style.setAttribute(SHIMMED_ATTRIBUTE, ''); From 34a995f68bbe817d36a1579d99e69031b4bc7331 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Tue, 23 Dec 2014 01:52:42 +0100 Subject: [PATCH 02/27] Fix for relative path resolving in css (complete) --- src/HTMLImports/path.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/HTMLImports/path.js b/src/HTMLImports/path.js index 98569cb..e95ebe0 100644 --- a/src/HTMLImports/path.js +++ b/src/HTMLImports/path.js @@ -11,6 +11,7 @@ HTMLImports.addModule(function(scope) { var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g; var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g; +var CSS_ABSOLUTE_URL_REGEXP = /(http[s]?:)?\/\//i // path fixup: style elements in imports must be made relative to the main // document. We fixup url's in url() and @import. @@ -32,7 +33,7 @@ var path = { replaceUrls: function(text, urlObj, linkUrl, regexp) { return text.replace(regexp, function(m, pre, url, post) { var urlPath = url.replace(/["']/g, ''); - if (urlPath.substr(0, 3) === '../') { + if (!CSS_ABSOLUTE_URL_REGEXP.test(urlPath)) { urlPath = linkUrl.match(/(.*\/)[^\/]+$/)[1] + urlPath; } urlObj.href = urlPath; From 721884ebdb7379c2a2b94a4b2e4a86531195c92c Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Tue, 23 Dec 2014 23:12:44 +0100 Subject: [PATCH 03/27] Better regexp --- src/HTMLImports/path.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HTMLImports/path.js b/src/HTMLImports/path.js index e95ebe0..2b07233 100644 --- a/src/HTMLImports/path.js +++ b/src/HTMLImports/path.js @@ -11,7 +11,7 @@ HTMLImports.addModule(function(scope) { var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g; var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g; -var CSS_ABSOLUTE_URL_REGEXP = /(http[s]?:)?\/\//i +var CSS_ABSOLUTE_URL_REGEXP = /^(http[s]?:)?\/\//i // path fixup: style elements in imports must be made relative to the main // document. We fixup url's in url() and @import. From c21bd3b36a260afcced408889ff478d1ef0c6083 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Fri, 2 Jan 2015 14:00:00 +0100 Subject: [PATCH 04/27] Test for relative path resolving (not actually failing when broken yet) --- .../html/imports/style-import-base-tag.css | 11 ++++++ .../ShadowCSS/html/style-import-base-tag.html | 34 +++++++++++++++++++ tests/ShadowCSS/tests.js | 1 + 3 files changed, 46 insertions(+) create mode 100644 tests/ShadowCSS/html/imports/style-import-base-tag.css create mode 100644 tests/ShadowCSS/html/style-import-base-tag.html diff --git a/tests/ShadowCSS/html/imports/style-import-base-tag.css b/tests/ShadowCSS/html/imports/style-import-base-tag.css new file mode 100644 index 0000000..890db85 --- /dev/null +++ b/tests/ShadowCSS/html/imports/style-import-base-tag.css @@ -0,0 +1,11 @@ +/** + * @license + * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. + * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt + * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt + * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt + * Code distributed by Google as part of the polymer project is also + * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt + */ + +@import "../imports/sheet1.css"; diff --git a/tests/ShadowCSS/html/style-import-base-tag.html b/tests/ShadowCSS/html/style-import-base-tag.html new file mode 100644 index 0000000..0e2c338 --- /dev/null +++ b/tests/ShadowCSS/html/style-import-base-tag.html @@ -0,0 +1,34 @@ + + + + + Imports style loading + + + + + + + + +
red
+ + + diff --git a/tests/ShadowCSS/tests.js b/tests/ShadowCSS/tests.js index d3435ba..121ed1d 100644 --- a/tests/ShadowCSS/tests.js +++ b/tests/ShadowCSS/tests.js @@ -25,5 +25,6 @@ htmlSuite('ShadowCss', function() { htmlTest('html/before-content.html?shadow'); htmlTest('html/before-content.html'); htmlTest('html/style-import.html'); + htmlTest('html/style-import-base-tag.html'); htmlTest('html/css-animation.html'); }); From feef1883d19c80072c411b332cf97e3e99c11941 Mon Sep 17 00:00:00 2001 From: Bouke van der Bijl Date: Wed, 19 Nov 2014 16:18:50 -0500 Subject: [PATCH 05/27] Fix bug in IE10 with MutationObserver There is a difference in behavior between MutationObserver and this shim in IE10, causing the target for a MutationRecord to be different from the expect value. This happens because when you append a node with children in IE10 it'll call the DOMNodeInserted for the node and its children seperately. The test has an if statement because the behavior is different between IE10 and chrome, making both outcomes valid. --- src/MutationObserver/MutationObserver.js | 5 ++--- tests/MutationObservers/childList.js | 21 +++++++++++++++++++++ tests/MutationObservers/runner.html | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/MutationObserver/MutationObserver.js b/src/MutationObserver/MutationObserver.js index f3b5695..44936ca 100644 --- a/src/MutationObserver/MutationObserver.js +++ b/src/MutationObserver/MutationObserver.js @@ -524,7 +524,6 @@ // Fall through. case 'DOMNodeInserted': // http://dom.spec.whatwg.org/#concept-mo-queue-childlist - var target = e.relatedNode; var changedNode = e.target; var addedNodes, removedNodes; if (e.type === 'DOMNodeInserted') { @@ -539,13 +538,13 @@ var nextSibling = changedNode.nextSibling; // 1. - var record = getRecord('childList', target); + var record = getRecord('childList', e.target.parentNode); record.addedNodes = addedNodes; record.removedNodes = removedNodes; record.previousSibling = previousSibling; record.nextSibling = nextSibling; - forEachAncestorAndObserverEnqueueRecord(target, function(options) { + forEachAncestorAndObserverEnqueueRecord(e.relatedNode, function(options) { // 2.1, 3.2 if (!options.childList) return; diff --git a/tests/MutationObservers/childList.js b/tests/MutationObservers/childList.js index a54f915..ab24c37 100644 --- a/tests/MutationObservers/childList.js +++ b/tests/MutationObservers/childList.js @@ -378,4 +378,25 @@ suite('JsMutationObserver childList', function() { }); }); + test('Append child in child', function() { + var div = testDiv.appendChild(document.createElement('div')); + + var observer = new JsMutationObserver(function() {}); + observer.observe(div, { + childList: true, + subtree: true + }); + var div2 = document.createElement('div') + var div3 = div2.appendChild(document.createElement('div')); + div.appendChild(div2); + var records = observer.takeRecords(); + + if(records.length == 1) { + assert.strictEqual(records[0].target, div); + assert.strictEqual(records[0].addedNodes[0].firstChild, div3); + } else { + assert.strictEqual(records[0].target, div); + assert.strictEqual(records[1].target, div2); + } + }); }); diff --git a/tests/MutationObservers/runner.html b/tests/MutationObservers/runner.html index ea8c3bc..d5b0406 100644 --- a/tests/MutationObservers/runner.html +++ b/tests/MutationObservers/runner.html @@ -17,6 +17,7 @@ + + + + + + + + + diff --git a/tests/HTMLImports/html/dynamic-errors-detail.html b/tests/HTMLImports/html/dynamic-errors-detail.html new file mode 100644 index 0000000..c10ce16 --- /dev/null +++ b/tests/HTMLImports/html/dynamic-errors-detail.html @@ -0,0 +1,50 @@ + + + + + HTML Imports Dynamic + + + + + + + + + diff --git a/tests/HTMLImports/html/dynamic-loaded-detail.html b/tests/HTMLImports/html/dynamic-loaded-detail.html new file mode 100644 index 0000000..6d963aa --- /dev/null +++ b/tests/HTMLImports/html/dynamic-loaded-detail.html @@ -0,0 +1,50 @@ + + + + + HTML Imports Dynamic + + + + + + + + + diff --git a/tests/HTMLImports/tests.js b/tests/HTMLImports/tests.js index 83f0879..ee82f91 100644 --- a/tests/HTMLImports/tests.js +++ b/tests/HTMLImports/tests.js @@ -21,6 +21,9 @@ htmlSuite('HTMLImports', function() { htmlTest('html/currentScript.html'); htmlTest('html/dedupe.html'); htmlTest('html/dynamic.html'); + htmlTest('html/dynamic-all-imports-detail.html'); + htmlTest('html/dynamic-errors-detail.html'); + htmlTest('html/dynamic-loaded-detail.html'); htmlTest('html/csp.html'); htmlTest('html/customevent-detail.html'); htmlTest('html/encoding.html'); From 075be28aeadc135a1e7e896c72489f49cd1bcaef Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Tue, 24 Feb 2015 09:27:18 +0100 Subject: [PATCH 24/27] Now fix uses URL object. Also test now fails without patch. --- src/HTMLImports/path.js | 5 ++--- tests/ShadowCSS/html/style-import-base-tag.html | 14 ++++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/HTMLImports/path.js b/src/HTMLImports/path.js index d6b44ac..a53e18b 100644 --- a/src/HTMLImports/path.js +++ b/src/HTMLImports/path.js @@ -11,7 +11,6 @@ HTMLImports.addModule(function(scope) { var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g; var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g; -var CSS_ABSOLUTE_URL_REGEXP = /^([a-z]+:)?\/\/|data:/i; // path fixup: style elements in imports must be made relative to the main // document. We fixup url's in url() and @import. @@ -33,8 +32,8 @@ var path = { replaceUrls: function(text, urlObj, linkUrl, regexp) { return text.replace(regexp, function(m, pre, url, post) { var urlPath = url.replace(/["']/g, ''); - if (!CSS_ABSOLUTE_URL_REGEXP.test(urlPath)) { - urlPath = linkUrl.match(/(.*\/)[^\/]+$/)[1] + urlPath; + if (linkUrl) { + urlPath = (new URL(urlPath, linkUrl)).href; } urlObj.href = urlPath; urlPath = urlObj.href; diff --git a/tests/ShadowCSS/html/style-import-base-tag.html b/tests/ShadowCSS/html/style-import-base-tag.html index 0e2c338..464f350 100644 --- a/tests/ShadowCSS/html/style-import-base-tag.html +++ b/tests/ShadowCSS/html/style-import-base-tag.html @@ -10,7 +10,7 @@ --> - Imports style loading + Imports style loading with base tag @@ -25,9 +25,15 @@ function getComputed(selector) { return getComputedStyle(document.querySelector(selector)); } - - chai.assert.equal(getComputed('#test1').backgroundColor, 'rgb(255, 0, 0)', 'shimmed imported style is loaded'); - done(); + var link = document.querySelector('link[rel=stylesheet]'); + //Tricky interval, because WebComponentsReady is fired before all link[rel=stylesheet] are processed + var interval = setInterval(function () { + if (link.__importParsed) { + clearInterval(interval); + chai.assert.equal(getComputed('#test1').backgroundColor, 'rgb(255, 0, 0)', 'shimmed imported style is loaded'); + done(); + } + }, 50); }); From 13c252ce7ca9e4caff70bca49c3ab45e8c3e25fe Mon Sep 17 00:00:00 2001 From: Steve Orvell Date: Wed, 4 Mar 2015 18:33:47 -0800 Subject: [PATCH 25/27] Store reference on style in import to style that's applied in main document. --- src/HTMLImports/parser.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/HTMLImports/parser.js b/src/HTMLImports/parser.js index 15dfee4..2fd294c 100644 --- a/src/HTMLImports/parser.js +++ b/src/HTMLImports/parser.js @@ -150,6 +150,7 @@ var importParser = { // TODO(sorvell): style element load event can just not fire so clone styles var src = elt; elt = cloneStyle(elt); + src.__appliedElement = elt; elt.__importElement = src; this.parseGeneric(elt); }, From a8ec8d6a4d54d0b4d24795ad49d3ea37dbbede97 Mon Sep 17 00:00:00 2001 From: Steve Orvell Date: Wed, 4 Mar 2015 18:33:06 -0800 Subject: [PATCH 26/27] slightly enhance compatibility with ShadowDOM Conflicts: src/CustomElements/observe.js --- src/CustomElements/observe.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/CustomElements/observe.js b/src/CustomElements/observe.js index 6a3f3b2..a7b1ca2 100644 --- a/src/CustomElements/observe.js +++ b/src/CustomElements/observe.js @@ -163,7 +163,7 @@ function inDocument(element) { if (p == doc) { return true; } - p = p.parentNode || p.host; + p = p.parentNode || ((p.nodeType === Node.DOCUMENT_FRAGMENT_NODE) && p.host); } } @@ -293,7 +293,6 @@ function upgradeDocumentTree(doc) { // undefined to aid feature detection of Shadow DOM. var originalCreateShadowRoot = Element.prototype.createShadowRoot; if (originalCreateShadowRoot) { - // ensure that all ShadowRoots watch for CustomElements. Element.prototype.createShadowRoot = function() { var root = originalCreateShadowRoot.call(this); CustomElements.watchShadow(this); From bc7afc1f1fc8811247eaaa1eb0309c46f2360e47 Mon Sep 17 00:00:00 2001 From: AJ Ortega Date: Thu, 5 Mar 2015 10:48:32 -0800 Subject: [PATCH 27/27] Fix error calling .split on undefined. --- webcomponents.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webcomponents.js b/webcomponents.js index 2d090df..8112c73 100644 --- a/webcomponents.js +++ b/webcomponents.js @@ -34,7 +34,7 @@ } } // log flags - if (flags.log) { + if (flags.log && flags.log.split) { var parts = flags.log.split(','); flags.log = {}; parts.forEach(function(f) {