Suppression for crbug/241044.
[chromium-blink-merge.git] / chrome / test / chromedriver / js / call_function_test.html
blobc11bc6cf45f4ed6499f32b46401b617bf6c8623f
1 <!DOCTYPE HTML>
2 <html>
3 <script src='test.js'></script>
4 <script src='call_function.js'></script>
5 <script>
7 function clearCache() {
8 getPageCache().cache_ = {};
11 function testCallFunctionNoArgs() {
12 clearCache();
14 var result = callFunction(function() { return 1; }, []);
15 assertEquals(0, result.status);
16 assertEquals(1, result.value);
19 function testCallFunctionThrows() {
20 clearCache();
22 var result = callFunction(function() { throw new Error('fake error'); }, []);
23 assertEquals(StatusCode.UNKNOWN_ERROR, result.status);
24 assertEquals('fake error', result.value);
26 result = callFunction(function() {
27 var e = new Error('fake error');
28 e.code = 77;
29 e.message = 'CUSTOM';
30 throw e;
31 }, []);
32 assertEquals(77, result.status);
33 assertEquals('CUSTOM', result.value);
36 function testCallFunctionArgs() {
37 clearCache();
39 function func(primitive, elem) {
40 return [primitive, elem.querySelector('div')];
42 var result = callFunction(func, [1, wrap(document)]);
43 assertEquals(0, result.status);
44 assertEquals(1, result.value[0]);
45 var cache = getPageCache();
46 assertEquals(document.querySelector('div'), unwrap(result.value[1], cache));
49 function testCallFunctionArgsUnwrappedReturn() {
50 clearCache();
52 function func(elem) {
53 return elem.querySelector('div');
55 var result = callFunction(func, [wrap(document)], true);
56 assertEquals(document.querySelector('div'), result);
59 function testCacheWrap() {
60 clearCache();
62 assertEquals(1, wrap(1));
63 assertEquals(1, unwrap(1));
64 assertEquals("1", wrap("1"));
65 assertEquals("1", unwrap("1"));
66 assertEquals(false, wrap(false));
67 assertEquals(false, unwrap(false));
68 assertEquals(null, wrap(null));
69 assertEquals(null, unwrap(null));
70 assertEquals(undefined, wrap(undefined));
71 assertEquals(undefined, unwrap(undefined));
72 function func() {}
73 assertEquals(func, wrap(func));
74 assertEquals(func, unwrap(func));
76 var cache = getPageCache();
77 var arr = [1, new Array(1, new Object({a: 1, b: {a: 1, b: {}, c: 3}}), 3)];
78 var originalJson = JSON.stringify(arr);
79 arr[1][1].b.b[ELEMENT_KEY] = cache.idPrefix_ + ':' + cache.nextId_;
80 var wrappedJson = JSON.stringify(arr);
81 arr[1][1].b.b = document;
82 assertEquals(wrappedJson, JSON.stringify(wrap(arr)));
83 var unwrapped = unwrap(JSON.parse(wrappedJson), cache);
84 assertEquals(document, unwrapped[1][1].b.b);
85 unwrapped[1][1].b.b = {};
86 assertEquals(originalJson, JSON.stringify(unwrapped));
89 function testCacheDoubleWrap() {
90 clearCache();
92 assertEquals(wrap(document)[ELEMENT_KEY], wrap(document)[ELEMENT_KEY]);
95 function testCacheUnwrapThrows() {
96 clearCache();
98 try {
99 var wrapped = {};
100 wrapped[ELEMENT_KEY] = '1';
101 unwrap(wrapped, getPageCache());
102 assert(false);
103 } catch (e) {
107 function testClearStale() {
108 clearCache();
110 var doc = document;
111 var div = doc.querySelector('div');
112 var span = doc.querySelector('span');
114 var wrappedDoc = wrap(doc);
115 var wrappedDiv = wrap(div);
116 var wrappedSpan = wrap(span);
118 var cache = getPageCache();
119 cache.clearStale();
120 assertEquals(doc, unwrap(wrappedDoc, cache));
121 assertEquals(div, unwrap(wrappedDiv, cache));
122 assertEquals(span, unwrap(wrappedSpan, cache));
124 div.removeChild(span);
125 cache.clearStale();
126 assertEquals(doc, unwrap(wrappedDoc, cache));
127 assertEquals(div, unwrap(wrappedDiv, cache));
128 try {
129 unwrap(wrappedSpan, cache);
130 assert(false);
131 } catch (e) {
135 function testCacheQuerySelector() {
136 clearCache();
138 var cache = getPageCache();
139 assertEquals(document.querySelector('div'),
140 unwrap(wrap(document.querySelector('div')), cache));
141 assertEquals(document.querySelectorAll('div')[0],
142 unwrap(wrap(document.querySelectorAll('div')), cache)[0]);
145 function testCacheStaleRef() {
146 clearCache();
148 var cache = getPageCache();
149 var img = document.createElement('img');
150 document.body.appendChild(img);
151 var wrappedImg = wrap(img);
152 document.body.removeChild(img);
153 cache.clearStale();
154 try {
155 unwrap(wrappedImg, cache);
156 assert(false);
157 } catch (e) {
158 assertEquals(StatusCode.STALE_ELEMENT_REFERENCE, e.code);
162 </script>
163 <body>
164 <div><span></span></div>
165 </body>
166 </html>