| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 } catch (e) { | 158 } catch (e) { |
| 159 assertEquals(StatusCode.STALE_ELEMENT_REFERENCE, e.code); | 159 assertEquals(StatusCode.STALE_ELEMENT_REFERENCE, e.code); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 function testCallFunctionWithShadowHost() { | 163 function testCallFunctionWithShadowHost() { |
| 164 clearCache(); | 164 clearCache(); |
| 165 | 165 |
| 166 // Set up something in the shadow DOM. | 166 // Set up something in the shadow DOM. |
| 167 var host = document.body.appendChild(document.createElement('div')); | 167 var host = document.body.appendChild(document.createElement('div')); |
| 168 var root = host.webkitCreateShadowRoot(); | 168 var root = host.createShadowRoot(); |
| 169 var shadowDiv = root.appendChild(document.createElement('div')); | 169 var shadowDiv = root.appendChild(document.createElement('div')); |
| 170 | 170 |
| 171 function func(element) { | 171 function func(element) { |
| 172 return element; | 172 return element; |
| 173 } | 173 } |
| 174 var wrappedHost = wrap(host); | 174 var wrappedHost = wrap(host); |
| 175 | 175 |
| 176 var result = callFunction(null, func, [wrappedHost]); | 176 var result = callFunction(null, func, [wrappedHost]); |
| 177 assertEquals(0, result.status); | 177 assertEquals(0, result.status); |
| 178 assertEquals(wrappedHost['ELEMENT'], result.value['ELEMENT']); | 178 assertEquals(wrappedHost['ELEMENT'], result.value['ELEMENT']); |
| 179 var cache = getPageCache(); | 179 var cache = getPageCache(); |
| 180 assertEquals(host, unwrap(result.value, cache)); | 180 assertEquals(host, unwrap(result.value, cache)); |
| 181 | 181 |
| 182 document.body.removeChild(host); | 182 document.body.removeChild(host); |
| 183 } | 183 } |
| 184 | 184 |
| 185 function testCallFunctionWithShadowRoot() { | 185 function testCallFunctionWithShadowRoot() { |
| 186 clearCache(); | 186 clearCache(); |
| 187 | 187 |
| 188 // Set up something in the shadow DOM. | 188 // Set up something in the shadow DOM. |
| 189 var host = document.body.appendChild(document.createElement('div')); | 189 var host = document.body.appendChild(document.createElement('div')); |
| 190 var root = host.webkitCreateShadowRoot(); | 190 var root = host.createShadowRoot(); |
| 191 var shadowDiv = root.appendChild(document.createElement('div')); | 191 var shadowDiv = root.appendChild(document.createElement('div')); |
| 192 | 192 |
| 193 function func(element) { | 193 function func(element) { |
| 194 return element; | 194 return element; |
| 195 } | 195 } |
| 196 var wrappedHost = wrap(host); | 196 var wrappedHost = wrap(host); |
| 197 var wrappedRoot = wrap(root); | 197 var wrappedRoot = wrap(root); |
| 198 | 198 |
| 199 // Trying without setting the shadow_path should fail. | 199 // Trying without setting the shadow_path should fail. |
| 200 var result = callFunction(null, func, [wrappedRoot]); | 200 var result = callFunction(null, func, [wrappedRoot]); |
| 201 assertEquals(StatusCode.STALE_ELEMENT_REFERENCE, result.status); | 201 assertEquals(StatusCode.STALE_ELEMENT_REFERENCE, result.status); |
| 202 // Should succeed with the shadow_path. | 202 // Should succeed with the shadow_path. |
| 203 result = callFunction([wrappedHost['ELEMENT']], func, [wrappedRoot]); | 203 result = callFunction([wrappedHost['ELEMENT']], func, [wrappedRoot]); |
| 204 assertEquals(0, result.status); | 204 assertEquals(0, result.status); |
| 205 assertEquals(wrappedRoot['ELEMENT'], result.value['ELEMENT']); | 205 assertEquals(wrappedRoot['ELEMENT'], result.value['ELEMENT']); |
| 206 var cache = getPageCache(root); | 206 var cache = getPageCache(root); |
| 207 assertEquals(root, unwrap(result.value, cache)); | 207 assertEquals(root, unwrap(result.value, cache)); |
| 208 | 208 |
| 209 document.body.removeChild(host); | 209 document.body.removeChild(host); |
| 210 } | 210 } |
| 211 | 211 |
| 212 function testCacheWithShadowDomAttached() { | 212 function testCacheWithShadowDomAttached() { |
| 213 clearCache(); | 213 clearCache(); |
| 214 var pageCache = getPageCache(); | 214 var pageCache = getPageCache(); |
| 215 | 215 |
| 216 // Set up something in the shadow DOM. | 216 // Set up something in the shadow DOM. |
| 217 var host = document.body.appendChild(document.createElement('div')); | 217 var host = document.body.appendChild(document.createElement('div')); |
| 218 var root = host.webkitCreateShadowRoot(); | 218 var root = host.createShadowRoot(); |
| 219 var shadowDiv = root.appendChild(document.createElement('div')); | 219 var shadowDiv = root.appendChild(document.createElement('div')); |
| 220 | 220 |
| 221 // Test with attached element in shadow DOM. | 221 // Test with attached element in shadow DOM. |
| 222 var wrappedDiv = wrap(shadowDiv); | 222 var wrappedDiv = wrap(shadowDiv); |
| 223 // It should NOT be in the page cache. | 223 // It should NOT be in the page cache. |
| 224 try { | 224 try { |
| 225 unwrap(wrappedDiv, pageCache); | 225 unwrap(wrappedDiv, pageCache); |
| 226 assert(false); | 226 assert(false); |
| 227 } catch (e) { | 227 } catch (e) { |
| 228 assertEquals(StatusCode.STALE_ELEMENT_REFERENCE, e.code); | 228 assertEquals(StatusCode.STALE_ELEMENT_REFERENCE, e.code); |
| 229 } | 229 } |
| 230 // It should be in the shadow root cache. | 230 // It should be in the shadow root cache. |
| 231 var rootCache = getPageCache(root); | 231 var rootCache = getPageCache(root); |
| 232 rootCache.clearStale(); | 232 rootCache.clearStale(); |
| 233 var unwrappedDiv = unwrap(wrappedDiv, rootCache); | 233 var unwrappedDiv = unwrap(wrappedDiv, rootCache); |
| 234 assertEquals(shadowDiv, unwrappedDiv); | 234 assertEquals(shadowDiv, unwrappedDiv); |
| 235 | 235 |
| 236 document.body.removeChild(host); | 236 document.body.removeChild(host); |
| 237 } | 237 } |
| 238 | 238 |
| 239 function testCacheWithShadowDomDetachedChild() { | 239 function testCacheWithShadowDomDetachedChild() { |
| 240 clearCache(); | 240 clearCache(); |
| 241 | 241 |
| 242 // Set up something in the shadow DOM. | 242 // Set up something in the shadow DOM. |
| 243 var host = document.body.appendChild(document.createElement('div')); | 243 var host = document.body.appendChild(document.createElement('div')); |
| 244 var root = host.webkitCreateShadowRoot(); | 244 var root = host.createShadowRoot(); |
| 245 var shadowDiv = root.appendChild(document.createElement('div')); | 245 var shadowDiv = root.appendChild(document.createElement('div')); |
| 246 | 246 |
| 247 // Test with detached element in shadow DOM. | 247 // Test with detached element in shadow DOM. |
| 248 var wrappedDiv = wrap(shadowDiv); | 248 var wrappedDiv = wrap(shadowDiv); |
| 249 root.removeChild(shadowDiv); | 249 root.removeChild(shadowDiv); |
| 250 var rootCache = getPageCache(root); | 250 var rootCache = getPageCache(root); |
| 251 rootCache.clearStale(); | 251 rootCache.clearStale(); |
| 252 try { | 252 try { |
| 253 unwrap(wrappedDiv, rootCache); | 253 unwrap(wrappedDiv, rootCache); |
| 254 assert(false); | 254 assert(false); |
| 255 } catch (e) { | 255 } catch (e) { |
| 256 assertEquals(StatusCode.STALE_ELEMENT_REFERENCE, e.code); | 256 assertEquals(StatusCode.STALE_ELEMENT_REFERENCE, e.code); |
| 257 } | 257 } |
| 258 | 258 |
| 259 document.body.removeChild(host); | 259 document.body.removeChild(host); |
| 260 } | 260 } |
| 261 | 261 |
| 262 </script> | 262 </script> |
| 263 <body> | 263 <body> |
| 264 <div><span></span></div> | 264 <div><span></span></div> |
| 265 </body> | 265 </body> |
| 266 </html> | 266 </html> |
| OLD | NEW |