-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
polymer-resin: test and fix handling of orphan text in shadow DOM mode
---- Background: I narrowed down the failure of gr-tooltip-test in https://gerrit-review.googlesource.com/c/106190 The failure only manifests in shadow DOM mode which is why it was not showing up in local runs. https://gerrit.googlesource.com/gerrit/+/master/polygerrit-ui/app/test/index.html#122 for (let file of elements) { file = elementsPath + file; testFiles.push(file); testFiles.push(file + '?dom=shadow'); } takes the cross product of (*.html) x (normal DOM, shadow DOM). When testing locally, I was not appending ?dom=shadow. ---- I. Run tests in shadow DOM mode This adds another wct_test_suite that runs the same tests as the first but with an incantation that causes it to run via shadow DOM. I can't find any docs on settings={"dom": "shadow"}, but it appears in other BUILD files and, until I fixed the test JS files, all the shadow DOM tests were failing. ---- II. Fixup tests to work in shadow DOM mode. The tests used fixture(...) to load a test fixture, but then assumed that DOM searches from that node would reach into the content. That is not the case with the shadow DOM where every custom element has a disconnected fragment that represents its content. The relevant parts of https://www.polymer-project.org/1.0/docs/devguide/local-dom#dom-api that are necessary to understand the test changes are > Work with local DOM > Every Polymer element has a this.root property which is the root of > its local DOM tree. You can manipulate the tree using Polymer.dom > methods: > // Append to local DOM > var toLocal = document.createElement('div'); > Polymer.dom(this.root).appendChild(toLocal); > For locating dynamically-created nodes in your element's local DOM, > the $$ method provides a shorthand for > Polymer.dom(this.root).querySelector(): > this.$$(selector) > $$ returns the first node in the local DOM that matches selector. ---- III. Fixing rootless nodes. When vetting text nodes, Polymer-resin looks at the parent element. In <template> [[foo]] </template> foo specifies a text node that appears at the top level of a custom element's content tree. In shadow DOM mode, the parent of the text node is a document fragment, not an element. I changed polymer-resin to allow text nodes when there is no parent element because in that case there is no direct path from text node addition to parsing as JS, CSS, etc. TODO: I have not yet tested this in the context: <script is="my-custom-element"></script> but custom-builtin elements are deprecated in Polymer2.0. It is unclear that text in a customized-builtin script element's shadow DOM content is JavaScript. Testing: I added the separate shadow DOM tests, ran all tests, and observed that all the new tests were broken, so I concluded that the new test did exercise a different point in the Polymer configuration space. I iteratively reworked test code to get tests green using Polymer.dom and abbreviations. During this I noticed that there was a test that was not installing polymer-resin. I fixed this and `grep -c`ed to check that there were no others. After several rounds of this there were two failing tests that failed in shadow mode: src-attra-as-text, tooltip. I ran both interactively and noted that both involved text nodes with a null parentElement. The tooltip-test was derived from gerrit's gr-tooltip-test so I concluded that fixing these tests would probably address the remaining failure in gerrit's test suite. I tweaked polymer-resin and reran all tests. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=157460289
- Loading branch information
1 parent
0dcd499
commit d625532
Showing
15 changed files
with
52 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters