benjamin@webkit.org | ff47a36 | 2014-08-15 04:06:27 +0000 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <script src="../../resources/js-test-pre.js"></script> |
| 5 | <style> |
| 6 | testcase { |
| 7 | background-color: white; |
| 8 | } |
| 9 | testcase:empty { |
| 10 | background-color: rgb(1, 2, 3); |
| 11 | } |
| 12 | </style> |
| 13 | </head> |
| 14 | <body> |
| 15 | <div> |
| 16 | <testcase id="with-renderer"></testcase> |
| 17 | </div> |
| 18 | <div style="display:none;"> |
| 19 | <testcase id="without-renderer"></testcase> |
| 20 | </div> |
| 21 | </body> |
| 22 | <script> |
| 23 | description('Test the style update with the :empty pseudo class.'); |
| 24 | |
| 25 | var testCaseWithRender = document.getElementById("with-renderer"); |
| 26 | var testCaseWithoutRenderer = document.getElementById("without-renderer"); |
| 27 | |
benjamin@webkit.org | 53da953 | 2014-08-18 20:52:04 +0000 | [diff] [blame] | 28 | debug("Initial state is empty."); |
benjamin@webkit.org | ff47a36 | 2014-08-15 04:06:27 +0000 | [diff] [blame] | 29 | shouldBeEqualToString('getComputedStyle(document.getElementById("with-renderer")).backgroundColor', 'rgb(1, 2, 3)'); |
| 30 | shouldBeEqualToString('getComputedStyle(document.getElementById("without-renderer")).backgroundColor', 'rgb(1, 2, 3)'); |
| 31 | |
| 32 | debug("Adding a comment does not change the :empty state."); |
| 33 | testCaseWithRender.appendChild(document.createComment("WebKit!")); |
| 34 | testCaseWithoutRenderer.appendChild(document.createComment("WebKit!")); |
| 35 | shouldBeEqualToString('getComputedStyle(document.getElementById("with-renderer")).backgroundColor', 'rgb(1, 2, 3)'); |
| 36 | shouldBeEqualToString('getComputedStyle(document.getElementById("without-renderer")).backgroundColor', 'rgb(1, 2, 3)'); |
| 37 | |
| 38 | debug("Add an element as child make updates :empty."); |
| 39 | var elementForCaseWithRenderer = document.createElement('div'); |
| 40 | var elementForCaseWithoutRenderer = document.createElement('div'); |
| 41 | testCaseWithRender.appendChild(elementForCaseWithRenderer); |
| 42 | testCaseWithoutRenderer.appendChild(elementForCaseWithoutRenderer); |
| 43 | shouldBeEqualToString('getComputedStyle(document.getElementById("with-renderer")).backgroundColor', 'rgb(255, 255, 255)'); |
| 44 | shouldBeEqualToString('getComputedStyle(document.getElementById("without-renderer")).backgroundColor', 'rgb(255, 255, 255)'); |
| 45 | |
| 46 | debug("Adding an empty text node, this is still not empty because of the element."); |
| 47 | testCaseWithRender.appendChild(document.createTextNode('')); |
| 48 | testCaseWithoutRenderer.appendChild(document.createTextNode('')); |
| 49 | shouldBeEqualToString('getComputedStyle(document.getElementById("with-renderer")).backgroundColor', 'rgb(255, 255, 255)'); |
| 50 | shouldBeEqualToString('getComputedStyle(document.getElementById("without-renderer")).backgroundColor', 'rgb(255, 255, 255)'); |
| 51 | |
| 52 | debug("Removing the elements previously added should restore the :empty state."); |
| 53 | testCaseWithRender.removeChild(elementForCaseWithRenderer); |
| 54 | testCaseWithoutRenderer.removeChild(elementForCaseWithoutRenderer); |
| 55 | shouldBeEqualToString('getComputedStyle(document.getElementById("with-renderer")).backgroundColor', 'rgb(1, 2, 3)'); |
| 56 | shouldBeEqualToString('getComputedStyle(document.getElementById("without-renderer")).backgroundColor', 'rgb(1, 2, 3)'); |
| 57 | |
| 58 | debug("Adding a non empty text node makes the state non empty."); |
| 59 | testCaseWithRender.appendChild(document.createTextNode('WebKit!')); |
| 60 | testCaseWithoutRenderer.appendChild(document.createTextNode('WebKit!')); |
| 61 | shouldBeEqualToString('getComputedStyle(document.getElementById("with-renderer")).backgroundColor', 'rgb(255, 255, 255)'); |
| 62 | shouldBeEqualToString('getComputedStyle(document.getElementById("without-renderer")).backgroundColor', 'rgb(255, 255, 255)'); |
| 63 | |
| 64 | debug("Removing the last text child, back to being empty."); |
| 65 | testCaseWithRender.removeChild(testCaseWithRender.lastChild); |
| 66 | testCaseWithoutRenderer.removeChild(testCaseWithoutRenderer.lastChild); |
| 67 | shouldBeEqualToString('getComputedStyle(document.getElementById("with-renderer")).backgroundColor', 'rgb(1, 2, 3)'); |
| 68 | shouldBeEqualToString('getComputedStyle(document.getElementById("without-renderer")).backgroundColor', 'rgb(1, 2, 3)'); |
| 69 | </script> |
| 70 | <script src="../../resources/js-test-post.js"></script> |
| 71 | </html> |