Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / dom / custom / resources / document-register-fuzz.js
1
2 function setupObjectHooks(hooks)
3 {
4     // Wrapper for these object should be materialized before setting hooks.
5     console.log;
6     document.register;
7     HTMLSpanElement.prototype;
8
9     Object.defineProperty(Object.prototype, "prototype", {
10         get: function() { return hooks.prototypeGet(); },
11         set: function(value) { return hooks.prototypeSet(value); }
12     });
13
14     Object.defineProperty(Object.prototype, "constructor", {
15         get: function() { return hooks.constructorGet(); },
16         set: function(value) { return hooks.constructorSet(value); }
17     });
18
19     return hooks;
20 }
21
22 function exerciseDocumentRegister()
23 {
24     register('x-a', {});
25     register('x-b', {prototype: Object.create(HTMLElement.prototype)});
26 }
27
28 function register(name, options)
29 {
30     var myConstructor = null;
31     try {
32         myConstructor = document.registerElement(name, options);
33     } catch (e) { }
34
35     try {
36         if (!myConstructor) {
37             debug("Constructor object isn't created.");
38             return;
39         }
40
41         if (options.prototype !== undefined && myConstructor.prototype != options.prototype) {
42             console.log("FAIL: bad prototype");
43             return;
44          }
45
46         var element = new myConstructor();
47         if (!element)
48             return;
49         if (element.constructor != myConstructor) {
50             console.log("FAIL: bad constructor");
51             return;
52          }
53     } catch (e) { console.log(e); }
54 }