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 | |
michael@0 | 3 | <html> |
michael@0 | 4 | |
michael@0 | 5 | <head> |
michael@0 | 6 | <meta charset="utf8"> |
michael@0 | 7 | <title></title> |
michael@0 | 8 | |
michael@0 | 9 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> |
michael@0 | 11 | </head> |
michael@0 | 12 | |
michael@0 | 13 | <div id="root"> |
michael@0 | 14 | <span template='{"type":"textContent","path":"title"}'></span> |
michael@0 | 15 | <span template='{"type":"attribute","name":"title","path":"title"}'></span> |
michael@0 | 16 | <span template='{"type":"localizedContent","paths":["foo2.foo_l10n","foo2.bar_l10n"],"property":"foo2"}'></span> |
michael@0 | 17 | <div template-for='{"path":"mop","childSelector":"#template-for"}'></div> |
michael@0 | 18 | <div template-loop='{"arrayPath":"foo1.bar1","childSelector":"#template-loop"}'></div> |
michael@0 | 19 | </div> |
michael@0 | 20 | |
michael@0 | 21 | <div id="ref0"> |
michael@0 | 22 | <span template='{"type":"textContent","path":"title"}'>ttt</span> |
michael@0 | 23 | <span title="ttt" template='{"type":"attribute","name":"title","path":"title"}'></span> |
michael@0 | 24 | <span template='{"type":"localizedContent","paths":["foo2.foo_l10n","foo2.bar_l10n"],"property":"foo2"}'>foo2:foo_l10n/bar_l10n</span> |
michael@0 | 25 | <div template-for='{"path":"mop","childSelector":"#template-for"}'><span template='{"type":"textContent","path":"name","rootPath":"mop"}'>meh</span></div> |
michael@0 | 26 | <div template-loop='{"arrayPath":"foo1.bar1","childSelector":"#template-loop"}'> |
michael@0 | 27 | <div> |
michael@0 | 28 | <span template='{"type":"textContent","path":"idx","rootPath":"foo1.bar1.0"}'>xx0</span> |
michael@0 | 29 | <span template='{"type":"textContent","path":"a","rootPath":"foo1.bar1.0"}'>a</span> |
michael@0 | 30 | <span template='{"type":"textContent","path":"b","rootPath":"foo1.bar1.0"}'>b</span> |
michael@0 | 31 | </div> |
michael@0 | 32 | <div> |
michael@0 | 33 | <span template='{"type":"textContent","path":"idx","rootPath":"foo1.bar1.1"}'>xx1</span> |
michael@0 | 34 | <span template='{"type":"textContent","path":"a","rootPath":"foo1.bar1.1"}'>a</span> |
michael@0 | 35 | <span template='{"type":"textContent","path":"b","rootPath":"foo1.bar1.1"}'>b</span> |
michael@0 | 36 | </div> |
michael@0 | 37 | </div> |
michael@0 | 38 | </div> |
michael@0 | 39 | |
michael@0 | 40 | |
michael@0 | 41 | <div id="ref1"> |
michael@0 | 42 | <span template='{"type":"textContent","path":"title"}'>xxx</span> |
michael@0 | 43 | <span title="xxx" template='{"type":"attribute","name":"title","path":"title"}'></span> |
michael@0 | 44 | <span template='{"type":"localizedContent","paths":["foo2.foo_l10n","foo2.bar_l10n"],"property":"foo2"}'>foo2:foo2_l10n/bar_l10n</span> |
michael@0 | 45 | <div template-for='{"path":"mop","childSelector":"#template-for"}'><span template='{"type":"textContent","path":"name","rootPath":"mop"}'>meh2</span></div> |
michael@0 | 46 | <div template-loop='{"arrayPath":"foo1.bar1","childSelector":"#template-loop"}'> |
michael@0 | 47 | <div> |
michael@0 | 48 | <span template='{"type":"textContent","path":"idx","rootPath":"foo1.bar1.0"}'>xx0</span> |
michael@0 | 49 | <span template='{"type":"textContent","path":"a","rootPath":"foo1.bar1.0"}'>a</span> |
michael@0 | 50 | <span template='{"type":"textContent","path":"b","rootPath":"foo1.bar1.0"}'>b</span> |
michael@0 | 51 | </div> |
michael@0 | 52 | <div> |
michael@0 | 53 | <span template='{"type":"textContent","path":"idx","rootPath":"foo1.bar1.1"}'>xx1</span> |
michael@0 | 54 | <span template='{"type":"textContent","path":"a","rootPath":"foo1.bar1.1"}'>a</span> |
michael@0 | 55 | <span template='{"type":"textContent","path":"b","rootPath":"foo1.bar1.1"}'>b</span> |
michael@0 | 56 | </div> |
michael@0 | 57 | </div> |
michael@0 | 58 | </div> |
michael@0 | 59 | |
michael@0 | 60 | <div id="ref2"> |
michael@0 | 61 | <span template='{"type":"textContent","path":"title"}'>xxx</span> |
michael@0 | 62 | <span title="xxx" template='{"type":"attribute","name":"title","path":"title"}'></span> |
michael@0 | 63 | <span template='{"type":"localizedContent","paths":["foo2.foo_l10n","foo2.bar_l10n"],"property":"foo2"}'>foo2:yyy/zzz</span> |
michael@0 | 64 | <div template-for='{"path":"","childSelector":"#template-for"}'></div> |
michael@0 | 65 | <div template-loop='{"arrayPath":"foo1.bar1","childSelector":"#template-loop"}'> |
michael@0 | 66 | <div> |
michael@0 | 67 | <span template='{"type":"textContent","path":"idx","rootPath":"foo1.bar1.0"}'>xx0</span> |
michael@0 | 68 | <span template='{"type":"textContent","path":"a","rootPath":"foo1.bar1.0"}'>a</span> |
michael@0 | 69 | <span template='{"type":"textContent","path":"b","rootPath":"foo1.bar1.0"}'>b</span> |
michael@0 | 70 | </div> |
michael@0 | 71 | <div> |
michael@0 | 72 | <span template='{"type":"textContent","path":"idx","rootPath":"foo1.bar1.1"}'>xx1</span> |
michael@0 | 73 | <span template='{"type":"textContent","path":"a","rootPath":"foo1.bar1.1"}'>a</span> |
michael@0 | 74 | <span template='{"type":"textContent","path":"b","rootPath":"foo1.bar1.1"}'>b</span> |
michael@0 | 75 | </div> |
michael@0 | 76 | </div> |
michael@0 | 77 | </div> |
michael@0 | 78 | |
michael@0 | 79 | <div id="ref3"> |
michael@0 | 80 | <span template='{"type":"textContent","path":"title"}'>xxx</span> |
michael@0 | 81 | <span title="xxx" template='{"type":"attribute","name":"title","path":"title"}'></span> |
michael@0 | 82 | <span template='{"type":"localizedContent","paths":["foo2.foo_l10n","foo2.bar_l10n"],"property":"foo2"}'>foo2:yyy/zzz</span> |
michael@0 | 83 | <div template-for='{"path":"","childSelector":"#template-for"}'></div> |
michael@0 | 84 | <div template-loop='{"arrayPath":"foo1.bar1","childSelector":"#template-loop"}'> |
michael@0 | 85 | <div> |
michael@0 | 86 | <span template='{"type":"textContent","path":"idx","rootPath":"foo1.bar1.0"}'>xx0</span> |
michael@0 | 87 | <span template='{"type":"textContent","path":"a","rootPath":"foo1.bar1.0"}'>a</span> |
michael@0 | 88 | <span template='{"type":"textContent","path":"b","rootPath":"foo1.bar1.0"}'>b</span> |
michael@0 | 89 | </div> |
michael@0 | 90 | <div> |
michael@0 | 91 | <span template='{"type":"textContent","path":"idx","rootPath":"foo1.bar1.1"}'>xx1</span> |
michael@0 | 92 | <span template='{"type":"textContent","path":"a","rootPath":"foo1.bar1.1"}'>a</span> |
michael@0 | 93 | <span template='{"type":"textContent","path":"b","rootPath":"foo1.bar1.1"}'>b</span> |
michael@0 | 94 | </div> |
michael@0 | 95 | <div> |
michael@0 | 96 | <span template='{"type":"textContent","path":"idx","rootPath":"foo1.bar1.2"}'>xx2</span> |
michael@0 | 97 | <span template='{"type":"textContent","path":"a","rootPath":"foo1.bar1.2"}'>a</span> |
michael@0 | 98 | <span template='{"type":"textContent","path":"b","rootPath":"foo1.bar1.2"}'>b</span> |
michael@0 | 99 | </div> |
michael@0 | 100 | <div> |
michael@0 | 101 | <span template='{"type":"textContent","path":"idx","rootPath":"foo1.bar1.3"}'>xx3</span> |
michael@0 | 102 | <span template='{"type":"textContent","path":"a","rootPath":"foo1.bar1.3"}'>a</span> |
michael@0 | 103 | <span template='{"type":"textContent","path":"b","rootPath":"foo1.bar1.3"}'>b</span> |
michael@0 | 104 | </div> |
michael@0 | 105 | <div> |
michael@0 | 106 | <span template='{"type":"textContent","path":"idx","rootPath":"foo1.bar1.4"}'>xx4</span> |
michael@0 | 107 | <span template='{"type":"textContent","path":"a","rootPath":"foo1.bar1.4"}'>a</span> |
michael@0 | 108 | <span template='{"type":"textContent","path":"b","rootPath":"foo1.bar1.4"}'>b</span> |
michael@0 | 109 | </div> |
michael@0 | 110 | </div> |
michael@0 | 111 | </div> |
michael@0 | 112 | |
michael@0 | 113 | <div id="ref4"> |
michael@0 | 114 | <span template='{"type":"textContent","path":"title"}'>xxx</span> |
michael@0 | 115 | <span title="xxx" template='{"type":"attribute","name":"title","path":"title"}'></span> |
michael@0 | 116 | <span template='{"type":"localizedContent","paths":["foo2.foo_l10n","foo2.bar_l10n"],"property":"foo2"}'>foo2:yyy/zzz</span> |
michael@0 | 117 | <div template-for='{"path":"","childSelector":"#template-for"}'></div> |
michael@0 | 118 | <div template-loop='{"arrayPath":"foo1.bar1","childSelector":"#template-loop"}'> |
michael@0 | 119 | <div> |
michael@0 | 120 | <span template='{"type":"textContent","path":"idx","rootPath":"foo1.bar1.0"}'>xx0</span> |
michael@0 | 121 | <span template='{"type":"textContent","path":"a","rootPath":"foo1.bar1.0"}'>a</span> |
michael@0 | 122 | <span template='{"type":"textContent","path":"b","rootPath":"foo1.bar1.0"}'>b</span> |
michael@0 | 123 | </div> |
michael@0 | 124 | <div> |
michael@0 | 125 | <span template='{"type":"textContent","path":"idx","rootPath":"foo1.bar1.1"}'>xx1</span> |
michael@0 | 126 | <span template='{"type":"textContent","path":"a","rootPath":"foo1.bar1.1"}'>a</span> |
michael@0 | 127 | <span template='{"type":"textContent","path":"b","rootPath":"foo1.bar1.1"}'>b</span> |
michael@0 | 128 | </div> |
michael@0 | 129 | <div> |
michael@0 | 130 | <span template='{"type":"textContent","path":"idx","rootPath":"foo1.bar1.2"}'>xx2</span> |
michael@0 | 131 | <span template='{"type":"textContent","path":"a","rootPath":"foo1.bar1.2"}'>a</span> |
michael@0 | 132 | <span template='{"type":"textContent","path":"b","rootPath":"foo1.bar1.2"}'>b</span> |
michael@0 | 133 | </div> |
michael@0 | 134 | <div> |
michael@0 | 135 | <span template='{"type":"textContent","path":"idx","rootPath":"foo1.bar1.3"}'>xx3</span> |
michael@0 | 136 | <span template='{"type":"textContent","path":"a","rootPath":"foo1.bar1.3"}'>a</span> |
michael@0 | 137 | <span template='{"type":"textContent","path":"b","rootPath":"foo1.bar1.3"}'>b</span> |
michael@0 | 138 | </div> |
michael@0 | 139 | </div> |
michael@0 | 140 | </div> |
michael@0 | 141 | |
michael@0 | 142 | |
michael@0 | 143 | |
michael@0 | 144 | <template id="template-loop"> |
michael@0 | 145 | <div> |
michael@0 | 146 | <span template='{"type":"textContent","path":"idx"}'></span> |
michael@0 | 147 | <span template='{"type":"textContent","path":"a"}'></span> |
michael@0 | 148 | <span template='{"type":"textContent","path":"b"}'></span> |
michael@0 | 149 | </div> |
michael@0 | 150 | </template> |
michael@0 | 151 | |
michael@0 | 152 | <template id="template-for"> |
michael@0 | 153 | <span template='{"type":"textContent","path":"name"}'></span> |
michael@0 | 154 | </template> |
michael@0 | 155 | |
michael@0 | 156 | <script type="application/javascript;version=1.8" src="chrome://browser/content/devtools/app-manager/template.js"></script> |
michael@0 | 157 | <script type="application/javascript;version=1.8"> |
michael@0 | 158 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 159 | |
michael@0 | 160 | const Cu = Components.utils; |
michael@0 | 161 | Cu.import("resource:///modules/devtools/gDevTools.jsm"); |
michael@0 | 162 | const {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); |
michael@0 | 163 | const {require} = devtools; |
michael@0 | 164 | const ObservableObject = require("devtools/shared/observable-object"); |
michael@0 | 165 | |
michael@0 | 166 | let data = { |
michael@0 | 167 | title: "ttt", |
michael@0 | 168 | mop: { |
michael@0 | 169 | name: "meh", |
michael@0 | 170 | }, |
michael@0 | 171 | foo1: { |
michael@0 | 172 | bar1: [ |
michael@0 | 173 | {idx: "xx0", a: "a", b: "b"}, |
michael@0 | 174 | {idx: "xx1", a: "a", b: "b"}, |
michael@0 | 175 | ], |
michael@0 | 176 | }, |
michael@0 | 177 | foo2: { |
michael@0 | 178 | foo_l10n: "foo_l10n", |
michael@0 | 179 | bar_l10n: "bar_l10n" |
michael@0 | 180 | }, |
michael@0 | 181 | }; |
michael@0 | 182 | |
michael@0 | 183 | let store = new ObservableObject(data); |
michael@0 | 184 | |
michael@0 | 185 | let changes = [ |
michael@0 | 186 | { |
michael@0 | 187 | exec: function() {}, |
michael@0 | 188 | reference: document.querySelector("#ref0") |
michael@0 | 189 | }, |
michael@0 | 190 | { |
michael@0 | 191 | exec: function() { |
michael@0 | 192 | store.object.title = "xxx"; |
michael@0 | 193 | store.object.foo2.foo_l10n = "foo2_l10n"; |
michael@0 | 194 | store.object.mop.name = "meh2"; |
michael@0 | 195 | }, |
michael@0 | 196 | reference: document.querySelector("#ref1") |
michael@0 | 197 | }, |
michael@0 | 198 | { |
michael@0 | 199 | exec: function() { |
michael@0 | 200 | store.object.foo2 = { |
michael@0 | 201 | foo_l10n: "yyy", |
michael@0 | 202 | bar_l10n: "zzz", |
michael@0 | 203 | } |
michael@0 | 204 | let forElt = document.querySelector("#root > [template-for]"); |
michael@0 | 205 | forElt.setAttribute("template-for", '{"path":"","childSelector":"#template-for"}'); |
michael@0 | 206 | t._processFor(forElt); |
michael@0 | 207 | }, |
michael@0 | 208 | reference: document.querySelector("#ref2") |
michael@0 | 209 | }, |
michael@0 | 210 | { |
michael@0 | 211 | exec: function() { |
michael@0 | 212 | let items = []; |
michael@0 | 213 | for (let i = 2; i < 5; i++) { |
michael@0 | 214 | items.push({idx: "xx" + i, a: "a", b: "b"}); |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | store.object.foo1.bar1 = store.object.foo1.bar1.concat(items); |
michael@0 | 218 | }, |
michael@0 | 219 | reference: document.querySelector("#ref3") |
michael@0 | 220 | }, |
michael@0 | 221 | { |
michael@0 | 222 | exec: function() { |
michael@0 | 223 | store.object.foo1.bar1.pop(); |
michael@0 | 224 | }, |
michael@0 | 225 | reference: document.querySelector("#ref4") |
michael@0 | 226 | }, |
michael@0 | 227 | ]; |
michael@0 | 228 | |
michael@0 | 229 | function compare(node1, node2) { |
michael@0 | 230 | let text1 = node1.innerHTML; |
michael@0 | 231 | let text2 = node2.innerHTML; |
michael@0 | 232 | text1 = text1.replace(/\n/g,""); |
michael@0 | 233 | text2 = text2.replace(/\n/g,""); |
michael@0 | 234 | text1 = text1.replace(/\s+/g,""); |
michael@0 | 235 | text2 = text2.replace(/\s+/g,""); |
michael@0 | 236 | return text1 == text2; |
michael@0 | 237 | } |
michael@0 | 238 | |
michael@0 | 239 | |
michael@0 | 240 | let root = document.querySelector("#root"); |
michael@0 | 241 | |
michael@0 | 242 | let t = new Template(root, store, (prop, args) => { |
michael@0 | 243 | return prop + ":" + args.join("/"); |
michael@0 | 244 | }); |
michael@0 | 245 | |
michael@0 | 246 | t.start(); |
michael@0 | 247 | |
michael@0 | 248 | for (let i = 0; i < changes.length; i++) { |
michael@0 | 249 | let change = changes[i]; |
michael@0 | 250 | change.exec(); |
michael@0 | 251 | ok(compare(change.reference, root), "Content " + i + " looks good."); |
michael@0 | 252 | } |
michael@0 | 253 | SimpleTest.finish(); |
michael@0 | 254 | |
michael@0 | 255 | </script> |
michael@0 | 256 | </html> |