Skip to content

Commit

Permalink
fix 'Should perform 'isShadowUIElement' checking for 'Node.nextSiblin…
Browse files Browse the repository at this point in the history
…g' when Node is TEXT_NODE' close (#1465) (#1466)

* fix 'Should perform 'isShadowUIElement' checking for 'Node.nextSibling' when Node is TEXT_NODE' close (#1465)

* fix tests

* fix tests (2)
  • Loading branch information
miherlosev authored Feb 1, 2018
1 parent e2d51e6 commit b3e6f94
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
19 changes: 13 additions & 6 deletions src/client/sandbox/code-instrumentation/properties/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,15 +408,22 @@ export default class PropertyAccessorsInstrumentation extends SandboxBase {
},

nextElementSibling: {
condition: node => node.nextElementSibling && domUtils.isDomElement(node) && domUtils.isDomElement(node.nextElementSibling),
get: node => domUtils.isShadowUIElement(node.nextElementSibling) ? null : node.nextElementSibling,
set: () => void 0
condition: node => node.nextElementSibling && domUtils.isDomElement(node) &&
domUtils.isDomElement(node.nextElementSibling),

get: node => domUtils.isShadowUIElement(node.nextElementSibling) ? null : node.nextElementSibling,
set: () => void 0
},

nextSibling: {
condition: node => node.nextSibling && domUtils.isDomElement(node) && domUtils.isDomElement(node.nextSibling),
get: node => domUtils.isShadowUIElement(node.nextSibling) ? null : node.nextSibling,
set: () => void 0
// NOTE: This property instrumentation needs only for body and head element children
condition: node => node.nextSibling &&
domUtils.isDomElement(node.nextSibling) &&
domUtils.isDomElement(node) || domUtils.isTextNode(node) ||
domUtils.isProcessingInstructionNode(node) || domUtils.isCommentNode(node),

get: node => domUtils.isShadowUIElement(node.nextSibling) ? null : node.nextSibling,
set: () => void 0
},

outerHTML: {
Expand Down
39 changes: 35 additions & 4 deletions test/client/fixtures/sandbox/shadow-ui-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,37 @@ test('Node.nextSibling, NonDocumentTypeChildNode.nextElementSibling', function (
strictEqual(getProperty(previous, 'nextElementSibling'), null);
});

test('Node.nextSibling when Node is not ELEMENT_NODE (GH-1465)', function () {
var supportCreationProcessingInstructionForHtmlDoc = (function () {
try {
document.createProcessingInstruction('x', 'x');

return true;
}
catch (err) {
return false;
}
})();

var notElementNodes = [
document.createTextNode(''),
document.createComment('')
];

if (supportCreationProcessingInstructionForHtmlDoc)
notElementNodes.push(document.createProcessingInstruction('x', 'x'));

for (var i = 0; i < notElementNodes.length; i++) {
var notElementNode = notElementNodes[i];

document.body.appendChild(notElementNode);
strictEqual(getProperty(notElementNode, 'nextSibling'), null);
strictEqual(notElementNode.nextSibling, shadowUI.getRoot());

notElementNode.parentNode.removeChild(notElementNode);
}
});

module('element methods');

test('Node.childElementCount', function () {
Expand Down Expand Up @@ -575,8 +606,8 @@ test('querySelectorAll', function () {
module('ui stylesheet');

test('stylesheets are restored after the document is cleaned', function () {
var link1 = document.createElement('link');
var link2 = document.createElement('link');
var link1 = document.createElement('link');
var link2 = document.createElement('link');

link1.className = SHADOW_UI_CLASSNAME.uiStylesheet;
link2.className = SHADOW_UI_CLASSNAME.uiStylesheet;
Expand Down Expand Up @@ -613,8 +644,8 @@ test('stylesheets are restored after the document is cleaned', function () {
});

test('append stylesheets to the iframe on initialization', function () {
var link1 = document.createElement('link');
var link2 = document.createElement('link');
var link1 = document.createElement('link');
var link2 = document.createElement('link');

link1.className = SHADOW_UI_CLASSNAME.uiStylesheet;
link2.className = SHADOW_UI_CLASSNAME.uiStylesheet;
Expand Down

0 comments on commit b3e6f94

Please sign in to comment.