Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE html> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=338679 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Bug 338679: correct reporting of newValue/prevValue in |
michael@0 | 8 | DOMAttrModified events</title> |
michael@0 | 9 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <a target="_blank" |
michael@0 | 14 | href="https://bugzilla.mozilla.org/show_bug.cgi?id=338679">Bug |
michael@0 | 15 | 338679: correct reporting of newValue/prevValue in |
michael@0 | 16 | DOMAttrModified events</a> |
michael@0 | 17 | |
michael@0 | 18 | <div id="test" style="width:20em"></div> |
michael@0 | 19 | |
michael@0 | 20 | <script> |
michael@0 | 21 | var testDiv = document.getElementById("test"); |
michael@0 | 22 | var e_new, e_prev = testDiv.getAttribute("style"); |
michael@0 | 23 | var phase, recursive = false; |
michael@0 | 24 | |
michael@0 | 25 | /* driver */ |
michael@0 | 26 | var tests = [ test_1, test_2, test_3 ]; |
michael@0 | 27 | var i = 0; |
michael@0 | 28 | function nextTest() { |
michael@0 | 29 | if (i < tests.length) { |
michael@0 | 30 | phase = tests[i]; |
michael@0 | 31 | i++; |
michael@0 | 32 | phase(); |
michael@0 | 33 | } else { |
michael@0 | 34 | SimpleTest.finish(); |
michael@0 | 35 | } |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 39 | testDiv.addEventListener("DOMAttrModified", attr_modified, false); |
michael@0 | 40 | nextTest(); |
michael@0 | 41 | |
michael@0 | 42 | /* event handler */ |
michael@0 | 43 | function attr_modified(ev) { |
michael@0 | 44 | is(ev.newValue, e_new, |
michael@0 | 45 | phase.name + (recursive ? " recursive" : "") + ": newValue"); |
michael@0 | 46 | is(ev.prevValue, e_prev, |
michael@0 | 47 | phase.name + (recursive ? " recursive" : "") + ": prevValue"); |
michael@0 | 48 | |
michael@0 | 49 | e_prev = e_new; |
michael@0 | 50 | if (!recursive) { |
michael@0 | 51 | recursive = true; |
michael@0 | 52 | e_new = "width: 0px;"; |
michael@0 | 53 | testDiv.style.width = "0"; |
michael@0 | 54 | } else { |
michael@0 | 55 | recursive = false; |
michael@0 | 56 | setTimeout(nextTest, 0); |
michael@0 | 57 | } |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | /* tests */ |
michael@0 | 61 | function test_1() { |
michael@0 | 62 | e_new = "width: auto;"; |
michael@0 | 63 | testDiv.style.width = "auto"; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function test_2() { |
michael@0 | 67 | e_new = "width: 15%;"; |
michael@0 | 68 | testDiv.style.width = "15%"; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | function test_3() { |
michael@0 | 72 | window.getComputedStyle(testDiv, null).width; // force style resolution |
michael@0 | 73 | e_new = "width: inherit;"; |
michael@0 | 74 | testDiv.style.width = "inherit"; |
michael@0 | 75 | } |
michael@0 | 76 | </script> |
michael@0 | 77 | </body> |
michael@0 | 78 | </html> |