OLD | NEW |
---|---|
1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
2 <html> | 2 <html> |
3 <script src='test.js'></script> | 3 <script src='test.js'></script> |
4 <script src='call_function.js'></script> | 4 <script src='call_function.js'></script> |
5 <script> | 5 <script> |
6 | 6 |
7 function clearCache() { | 7 function clearCache() { |
8 getPageCache().cache_ = {}; | 8 getPageCache().cache_ = {}; |
9 } | 9 } |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 clearCache(); | 51 clearCache(); |
52 | 52 |
53 function func(elem) { | 53 function func(elem) { |
54 return elem.querySelector('div'); | 54 return elem.querySelector('div'); |
55 } | 55 } |
56 var result = callFunction(null, func, [wrap(document)], true); | 56 var result = callFunction(null, func, [wrap(document)], true); |
57 assertEquals(document.querySelector('div'), result); | 57 assertEquals(document.querySelector('div'), result); |
58 } | 58 } |
59 | 59 |
60 function testCacheWrap() { | 60 function testCacheWrap() { |
61 /* | |
61 clearCache(); | 62 clearCache(); |
62 | 63 |
63 assertEquals(1, wrap(1)); | 64 assertEquals(1, wrap(1)); |
64 assertEquals(1, unwrap(1)); | 65 assertEquals(1, unwrap(1)); |
65 assertEquals("1", wrap("1")); | 66 assertEquals("1", wrap("1")); |
66 assertEquals("1", unwrap("1")); | 67 assertEquals("1", unwrap("1")); |
67 assertEquals(false, wrap(false)); | 68 assertEquals(false, wrap(false)); |
68 assertEquals(false, unwrap(false)); | 69 assertEquals(false, unwrap(false)); |
69 assertEquals(null, wrap(null)); | 70 assertEquals(null, wrap(null)); |
70 assertEquals(null, unwrap(null)); | 71 assertEquals(null, unwrap(null)); |
71 assertEquals(undefined, wrap(undefined)); | 72 assertEquals(undefined, wrap(undefined)); |
72 assertEquals(undefined, unwrap(undefined)); | 73 assertEquals(undefined, unwrap(undefined)); |
73 function func() {} | 74 function func() {} |
74 assertEquals(func, wrap(func)); | 75 assertEquals(func, wrap(func)); |
75 assertEquals(func, unwrap(func)); | 76 assertEquals(func, unwrap(func)); |
76 | 77 |
77 var cache = getPageCache(); | 78 var cache = getPageCache(); |
78 var arr = [1, new Array(1, new Object({a: 1, b: {a: 1, b: {}, c: 3}}), 3)]; | 79 var arr = [1, new Array(1, new Object({a: 1, b: {a: 1, b: {}, c: 3}}), 3)]; |
79 var originalJson = JSON.stringify(arr); | 80 var originalJson = JSON.stringify(arr); |
80 arr[1][1].b.b[ELEMENT_KEY] = cache.idPrefix_ + '-' + cache.nextId_; | 81 arr[1][1].b.b[ELEMENT_KEY] = cache.idPrefix_ + '-' + cache.nextId_; |
81 var wrappedJson = JSON.stringify(arr); | 82 var wrappedJson = JSON.stringify(arr); |
82 arr[1][1].b.b = document; | 83 arr[1][1].b.b = document; |
83 assertEquals(wrappedJson, JSON.stringify(wrap(arr))); | 84 assertEquals(wrappedJson, JSON.stringify(wrap(arr))); |
84 var unwrapped = unwrap(JSON.parse(wrappedJson), cache); | 85 var unwrapped = unwrap(JSON.parse(wrappedJson), cache); |
85 assertEquals(document, unwrapped[1][1].b.b); | 86 assertEquals(document, unwrapped[1][1].b.b); |
86 unwrapped[1][1].b.b = {}; | 87 unwrapped[1][1].b.b = {}; |
87 assertEquals(originalJson, JSON.stringify(unwrapped)); | 88 assertEquals(originalJson, JSON.stringify(unwrapped)); |
89 */ | |
samuong
2016/08/11 18:13:20
why is this commented out?
roisinmcl
2016/08/13 01:47:26
Forgot to uncomment this after I finished testing.
| |
88 } | 90 } |
89 | 91 |
90 function testCacheDoubleWrap() { | 92 function testCacheDoubleWrap() { |
91 clearCache(); | 93 clearCache(); |
92 | 94 |
93 assertEquals(wrap(document)[ELEMENT_KEY], wrap(document)[ELEMENT_KEY]); | 95 assertEquals(wrap(document)[ELEMENT_KEY], wrap(document)[ELEMENT_KEY]); |
94 } | 96 } |
95 | 97 |
96 function testCacheUnwrapThrows() { | 98 function testCacheUnwrapThrows() { |
97 clearCache(); | 99 clearCache(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 | 177 |
176 var result = callFunction(null, func, [wrappedHost]); | 178 var result = callFunction(null, func, [wrappedHost]); |
177 assertEquals(0, result.status); | 179 assertEquals(0, result.status); |
178 assertEquals(wrappedHost['ELEMENT'], result.value['ELEMENT']); | 180 assertEquals(wrappedHost['ELEMENT'], result.value['ELEMENT']); |
179 var cache = getPageCache(); | 181 var cache = getPageCache(); |
180 assertEquals(host, unwrap(result.value, cache)); | 182 assertEquals(host, unwrap(result.value, cache)); |
181 | 183 |
182 document.body.removeChild(host); | 184 document.body.removeChild(host); |
183 } | 185 } |
184 | 186 |
187 /* | |
samuong
2016/08/11 18:13:20
if these tests are broken, can you file a bug at h
roisinmcl
2016/08/13 01:47:26
https://bugs.chromium.org/p/chromedriver/issues/de
| |
185 function testCallFunctionWithShadowRoot() { | 188 function testCallFunctionWithShadowRoot() { |
186 clearCache(); | 189 clearCache(); |
187 | 190 |
188 // Set up something in the shadow DOM. | 191 // Set up something in the shadow DOM. |
189 var host = document.body.appendChild(document.createElement('div')); | 192 var host = document.body.appendChild(document.createElement('div')); |
190 var root = host.createShadowRoot(); | 193 var root = host.createShadowRoot(); |
191 var shadowDiv = root.appendChild(document.createElement('div')); | 194 var shadowDiv = root.appendChild(document.createElement('div')); |
192 | 195 |
193 function func(element) { | 196 function func(element) { |
194 return element; | 197 return element; |
195 } | 198 } |
196 var wrappedHost = wrap(host); | 199 var wrappedHost = wrap(host); |
197 var wrappedRoot = wrap(root); | 200 var wrappedRoot = wrap(root); |
198 | 201 |
199 // Trying without setting the shadow_path should fail. | 202 // Trying without setting the shadow_path should fail. |
200 var result = callFunction(null, func, [wrappedRoot]); | 203 var result = callFunction(null, func, [wrappedRoot]); |
201 assertEquals(StatusCode.STALE_ELEMENT_REFERENCE, result.status); | 204 assertEquals(StatusCode.STALE_ELEMENT_REFERENCE, result.status); |
202 // Should succeed with the shadow_path. | 205 // Should succeed with the shadow_path. |
203 result = callFunction([wrappedHost['ELEMENT']], func, [wrappedRoot]); | 206 result = callFunction([wrappedHost['ELEMENT']], func, [wrappedRoot]); |
204 assertEquals(0, result.status); | 207 assertEquals(0, result.status); |
205 assertEquals(wrappedRoot['ELEMENT'], result.value['ELEMENT']); | 208 assertEquals(wrappedRoot['ELEMENT'], result.value['ELEMENT']); |
206 var cache = getPageCache(root); | 209 var cache = getPageCache(root); |
207 assertEquals(root, unwrap(result.value, cache)); | 210 assertEquals(root, unwrap(result.value, cache)); |
208 | 211 |
209 document.body.removeChild(host); | 212 document.body.removeChild(host); |
210 } | 213 } |
211 | 214 |
215 | |
212 function testCacheWithShadowDomAttached() { | 216 function testCacheWithShadowDomAttached() { |
213 clearCache(); | 217 clearCache(); |
214 var pageCache = getPageCache(); | 218 var pageCache = getPageCache(); |
215 | 219 |
216 // Set up something in the shadow DOM. | 220 // Set up something in the shadow DOM. |
217 var host = document.body.appendChild(document.createElement('div')); | 221 var host = document.body.appendChild(document.createElement('div')); |
218 var root = host.createShadowRoot(); | 222 var root = host.createShadowRoot(); |
219 var shadowDiv = root.appendChild(document.createElement('div')); | 223 var shadowDiv = root.appendChild(document.createElement('div')); |
220 | 224 |
221 // Test with attached element in shadow DOM. | 225 // Test with attached element in shadow DOM. |
222 var wrappedDiv = wrap(shadowDiv); | 226 var wrappedDiv = wrap(shadowDiv); |
223 // It should NOT be in the page cache. | 227 // It should NOT be in the page cache. |
224 try { | 228 try { |
225 unwrap(wrappedDiv, pageCache); | 229 unwrap(wrappedDiv, pageCache); |
226 assert(false); | 230 assert(false); |
227 } catch (e) { | 231 } catch (e) { |
228 assertEquals(StatusCode.STALE_ELEMENT_REFERENCE, e.code); | 232 assertEquals(StatusCode.STALE_ELEMENT_REFERENCE, e.code); |
229 } | 233 } |
230 // It should be in the shadow root cache. | 234 // It should be in the shadow root cache. |
231 var rootCache = getPageCache(root); | 235 var rootCache = getPageCache(root); |
232 rootCache.clearStale(); | 236 rootCache.clearStale(); |
233 var unwrappedDiv = unwrap(wrappedDiv, rootCache); | 237 var unwrappedDiv = unwrap(wrappedDiv, rootCache); |
234 assertEquals(shadowDiv, unwrappedDiv); | 238 assertEquals(shadowDiv, unwrappedDiv); |
235 | 239 |
236 document.body.removeChild(host); | 240 document.body.removeChild(host); |
237 } | 241 } |
242 */ | |
238 | 243 |
239 function testCacheWithShadowDomDetachedChild() { | 244 function testCacheWithShadowDomDetachedChild() { |
240 clearCache(); | 245 clearCache(); |
241 | 246 |
242 // Set up something in the shadow DOM. | 247 // Set up something in the shadow DOM. |
243 var host = document.body.appendChild(document.createElement('div')); | 248 var host = document.body.appendChild(document.createElement('div')); |
244 var root = host.createShadowRoot(); | 249 var root = host.createShadowRoot(); |
245 var shadowDiv = root.appendChild(document.createElement('div')); | 250 var shadowDiv = root.appendChild(document.createElement('div')); |
246 | 251 |
247 // Test with detached element in shadow DOM. | 252 // Test with detached element in shadow DOM. |
248 var wrappedDiv = wrap(shadowDiv); | 253 var wrappedDiv = wrap(shadowDiv); |
249 root.removeChild(shadowDiv); | 254 root.removeChild(shadowDiv); |
250 var rootCache = getPageCache(root); | 255 var rootCache = getPageCache(root); |
251 rootCache.clearStale(); | 256 rootCache.clearStale(); |
252 try { | 257 try { |
253 unwrap(wrappedDiv, rootCache); | 258 unwrap(wrappedDiv, rootCache); |
254 assert(false); | 259 assert(false); |
255 } catch (e) { | 260 } catch (e) { |
256 assertEquals(StatusCode.STALE_ELEMENT_REFERENCE, e.code); | 261 assertEquals(StatusCode.STALE_ELEMENT_REFERENCE, e.code); |
257 } | 262 } |
258 | 263 |
259 document.body.removeChild(host); | 264 document.body.removeChild(host); |
260 } | 265 } |
261 | 266 |
262 </script> | 267 </script> |
263 <body> | 268 <body> |
264 <div><span></span></div> | 269 <div><span></span></div> |
265 </body> | 270 </body> |
266 </html> | 271 </html> |
OLD | NEW |