Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: chrome/test/chromedriver/js/call_function_test.html

Issue 2295443003: [chromedriver] Added option to make element references W3C compliant. (Closed)
Patch Set: fix errors introduced during previous rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 function isValidUUID(uuid) {
12 assertEquals(36, uuid.length);
13 var list = uuid.split("-").map(function(x) {return x.length;});
14 assertEquals(5, list.length);
15 assertEquals(8, list[0]);
16 assertEquals(4, list[1]);
17 assertEquals(4, list[2]);
18 assertEquals(4, list[3]);
19 assertEquals(12, list[4]);
20 assert(/[a-z0-9-]{36}/.test(uuid));
21 }
22
23 function testUUID() {
24 var uuids = {}
25 for (var i = 0; i < 100; i++) {
26 var uuid = generateUUID();
27 isValidUUID(uuid);
28 assertEquals(null, uuids[uuid]);
29 uuids[uuid] = 1;
30 }
31 }
32
11 function testCallFunctionNoArgs() { 33 function testCallFunctionNoArgs() {
12 clearCache(); 34 clearCache();
13 35
14 var result = callFunction(null, function() { return 1; }, []); 36 var result = callFunction(null, function() { return 1; }, []);
15 assertEquals(0, result.status); 37 assertEquals(0, result.status);
16 assertEquals(1, result.value); 38 assertEquals(1, result.value);
17 } 39 }
18 40
19 function testCallFunctionThrows() { 41 function testCallFunctionThrows() {
20 clearCache(); 42 clearCache();
(...skipping 25 matching lines...) Expand all
46 var cache = getPageCache(); 68 var cache = getPageCache();
47 assertEquals(document.querySelector('div'), unwrap(result.value[1], cache)); 69 assertEquals(document.querySelector('div'), unwrap(result.value[1], cache));
48 } 70 }
49 71
50 function testCallFunctionArgsUnwrappedReturn() { 72 function testCallFunctionArgsUnwrappedReturn() {
51 clearCache(); 73 clearCache();
52 74
53 function func(elem) { 75 function func(elem) {
54 return elem.querySelector('div'); 76 return elem.querySelector('div');
55 } 77 }
56 var result = callFunction(null, func, [wrap(document)], true); 78 var result = callFunction(null, func, [wrap(document)], false, true);
57 assertEquals(document.querySelector('div'), result); 79 assertEquals(document.querySelector('div'), result);
58 } 80 }
59 81
60 function testCacheWrap() { 82 function testCacheWrap() {
61 clearCache(); 83 clearCache();
62 84
63 assertEquals(1, wrap(1)); 85 assertEquals(1, wrap(1));
64 assertEquals(1, unwrap(1)); 86 assertEquals(1, unwrap(1));
65 assertEquals("1", wrap("1")); 87 assertEquals("1", wrap("1"));
66 assertEquals("1", unwrap("1")); 88 assertEquals("1", unwrap("1"));
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 197
176 var result = callFunction(null, func, [wrappedHost]); 198 var result = callFunction(null, func, [wrappedHost]);
177 assertEquals(0, result.status); 199 assertEquals(0, result.status);
178 assertEquals(wrappedHost['ELEMENT'], result.value['ELEMENT']); 200 assertEquals(wrappedHost['ELEMENT'], result.value['ELEMENT']);
179 var cache = getPageCache(); 201 var cache = getPageCache();
180 assertEquals(host, unwrap(result.value, cache)); 202 assertEquals(host, unwrap(result.value, cache));
181 203
182 document.body.removeChild(host); 204 document.body.removeChild(host);
183 } 205 }
184 206
185 function testCallFunctionWithShadowRoot() { 207 function DISABLED_testCallFunctionWithShadowRoot() {
186 clearCache(); 208 clearCache();
187 209
188 // Set up something in the shadow DOM. 210 // Set up something in the shadow DOM.
189 var host = document.body.appendChild(document.createElement('div')); 211 var host = document.body.appendChild(document.createElement('div'));
190 var root = host.createShadowRoot(); 212 var root = host.createShadowRoot();
191 var shadowDiv = root.appendChild(document.createElement('div')); 213 var shadowDiv = root.appendChild(document.createElement('div'));
192 214
193 function func(element) { 215 function func(element) {
194 return element; 216 return element;
195 } 217 }
196 var wrappedHost = wrap(host); 218 var wrappedHost = wrap(host);
197 var wrappedRoot = wrap(root); 219 var wrappedRoot = wrap(root);
198 220
199 // Trying without setting the shadow_path should fail. 221 // Trying without setting the shadow_path should fail.
200 var result = callFunction(null, func, [wrappedRoot]); 222 var result = callFunction(null, func, [wrappedRoot]);
201 assertEquals(StatusCode.STALE_ELEMENT_REFERENCE, result.status); 223 assertEquals(StatusCode.STALE_ELEMENT_REFERENCE, result.status);
202 // Should succeed with the shadow_path. 224 // Should succeed with the shadow_path.
203 result = callFunction([wrappedHost['ELEMENT']], func, [wrappedRoot]); 225 result = callFunction([wrappedHost['ELEMENT']], func, [wrappedRoot]);
204 assertEquals(0, result.status); 226 assertEquals(0, result.status);
205 assertEquals(wrappedRoot['ELEMENT'], result.value['ELEMENT']); 227 assertEquals(wrappedRoot['ELEMENT'], result.value['ELEMENT']);
206 var cache = getPageCache(root); 228 var cache = getPageCache(root);
207 assertEquals(root, unwrap(result.value, cache)); 229 assertEquals(root, unwrap(result.value, cache));
208 230
209 document.body.removeChild(host); 231 document.body.removeChild(host);
210 } 232 }
211 233
212 function testCacheWithShadowDomAttached() { 234 function DISABLED_testCacheWithShadowDomAttached() {
213 clearCache(); 235 clearCache();
214 var pageCache = getPageCache(); 236 var pageCache = getPageCache();
215 237
216 // Set up something in the shadow DOM. 238 // Set up something in the shadow DOM.
217 var host = document.body.appendChild(document.createElement('div')); 239 var host = document.body.appendChild(document.createElement('div'));
218 var root = host.createShadowRoot(); 240 var root = host.createShadowRoot();
219 var shadowDiv = root.appendChild(document.createElement('div')); 241 var shadowDiv = root.appendChild(document.createElement('div'));
220 242
221 // Test with attached element in shadow DOM. 243 // Test with attached element in shadow DOM.
222 var wrappedDiv = wrap(shadowDiv); 244 var wrappedDiv = wrap(shadowDiv);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 279 }
258 280
259 document.body.removeChild(host); 281 document.body.removeChild(host);
260 } 282 }
261 283
262 </script> 284 </script>
263 <body> 285 <body>
264 <div><span></span></div> 286 <div><span></span></div>
265 </body> 287 </body>
266 </html> 288 </html>
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/js/call_function.js ('k') | chrome/test/chromedriver/session_commands.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698