Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / testing / PrivateScriptTest.js
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 "use strict";
6
7 installClass("PrivateScriptTest", function(PrivateScriptTestPrototype) {
8
9     PrivateScriptTestPrototype.initialize = function() {
10         this.m_shortAttribute = -1;
11         this.m_stringAttribute = "xxx";
12         this.m_nodeAttribute = null;
13         this.m_stringAttributeForPrivateScriptOnly = "yyy";
14     }
15
16     PrivateScriptTestPrototype.doNothing = function() {
17     }
18
19     PrivateScriptTestPrototype.return123 = function() {
20         return 123;
21     }
22
23     PrivateScriptTestPrototype.echoInteger = function(value) {
24         return value;
25     }
26
27     PrivateScriptTestPrototype.echoString = function(value) {
28         return value;
29     }
30
31     PrivateScriptTestPrototype.echoNode = function(value) {
32         return value;
33     }
34
35     PrivateScriptTestPrototype.addValues_ = function(value1, value2) {
36         return value1 + value2;
37     }
38
39     PrivateScriptTestPrototype.addInteger = function(value1, value2) {
40         return this.addValues_(value1, value2);
41     }
42
43     PrivateScriptTestPrototype.addString = function(value1, value2) {
44         return this.addValues_(value1, value2);
45     }
46
47     PrivateScriptTestPrototype.setIntegerToDocument = function(document, value) {
48         document.integer = value;
49     }
50
51     PrivateScriptTestPrototype.getIntegerFromDocument = function(document) {
52         return document.integer;
53     }
54
55     PrivateScriptTestPrototype.setIntegerToPrototype = function(value) {
56         this.integer = value;
57     }
58
59     PrivateScriptTestPrototype.getIntegerFromPrototype = function() {
60         return this.integer;
61     }
62
63     PrivateScriptTestPrototype.createElement = function(document) {
64         return document.createElement("div");
65     }
66
67     PrivateScriptTestPrototype.appendChild = function(node1, node2) {
68         node1.appendChild(node2);
69     }
70
71     PrivateScriptTestPrototype.firstChild = function(node) {
72         return node.firstChild;
73     }
74
75     PrivateScriptTestPrototype.nextSibling = function(node) {
76         return node.nextSibling;
77     }
78
79     PrivateScriptTestPrototype.innerHTML = function(node) {
80         return node.innerHTML;
81     }
82
83     PrivateScriptTestPrototype.setInnerHTML = function(node, string) {
84         node.innerHTML = string;
85     }
86
87     PrivateScriptTestPrototype.addClickListener = function(node) {
88         node.addEventListener("click", function () {
89             node.innerHTML = "clicked";
90         });
91     }
92
93     PrivateScriptTestPrototype.clickNode = function(document, node) {
94         var event = new MouseEvent("click", { bubbles: true, cancelable: true, view: window });
95         node.dispatchEvent(event);
96     }
97
98     Object.defineProperty(PrivateScriptTestPrototype, "readonlyShortAttribute", {
99         get: function() { return 123; }
100     });
101
102     Object.defineProperty(PrivateScriptTestPrototype, "shortAttribute", {
103         get: function() { return this.m_shortAttribute; },
104         set: function(value) { this.m_shortAttribute = value; }
105     });
106
107     Object.defineProperty(PrivateScriptTestPrototype, "stringAttribute", {
108         get: function() { return this.m_stringAttribute; },
109         set: function(value) { this.m_stringAttribute = value; }
110     });
111
112     Object.defineProperty(PrivateScriptTestPrototype, "nodeAttribute", {
113         get: function() { return this.m_nodeAttribute; },
114         set: function(value) { this.m_nodeAttribute = value; }
115     });
116
117     Object.defineProperty(PrivateScriptTestPrototype, "nodeAttributeThrowsIndexSizeError", {
118         get: function() { throw new DOMExceptionInPrivateScript("IndexSizeError", "getter threw error"); },
119         set: function(value) { throw new DOMExceptionInPrivateScript("IndexSizeError", "setter threw error"); }
120     });
121
122     PrivateScriptTestPrototype.voidMethodThrowsDOMSyntaxError = function() {
123         throw new DOMExceptionInPrivateScript("SyntaxError", "method threw error");
124     }
125
126     PrivateScriptTestPrototype.voidMethodThrowsError = function() {
127         throw new Error("method threw Error");
128     }
129
130     PrivateScriptTestPrototype.voidMethodThrowsTypeError = function() {
131         throw new TypeError("method threw TypeError");
132     }
133
134     PrivateScriptTestPrototype.voidMethodThrowsRangeError = function() {
135         throw new RangeError("method threw RangeError");
136     }
137
138     PrivateScriptTestPrototype.voidMethodThrowsSyntaxError = function() {
139         throw new SyntaxError("method threw SyntaxError");
140     }
141
142     PrivateScriptTestPrototype.voidMethodThrowsReferenceError = function() {
143         throw new ReferenceError("method threw ReferenceError");
144     }
145
146     PrivateScriptTestPrototype.voidMethodWithStackOverflow = function() {
147         function f() { f(); }
148         f();
149     }
150
151     PrivateScriptTestPrototype.addIntegerForPrivateScriptOnly = function(value1, value2) {
152         return value1 + value2;
153     }
154
155     Object.defineProperty(PrivateScriptTestPrototype, "stringAttributeForPrivateScriptOnly", {
156         get: function() { return this.m_stringAttributeForPrivateScriptOnly; },
157         set: function(value) { this.m_stringAttributeForPrivateScriptOnly = value; }
158     });
159
160     PrivateScriptTestPrototype.addIntegerImplementedInCPP = function(value1, value2) {
161         return this.addIntegerImplementedInCPPForPrivateScriptOnly(value1, value2);
162     }
163
164     Object.defineProperty(PrivateScriptTestPrototype, "stringAttributeImplementedInCPP", {
165         get: function() { return this.m_stringAttributeImplementedInCPPForPrivateScriptOnly; },
166         set: function(value) { this.m_stringAttributeImplementedInCPPForPrivateScriptOnly = value; }
167     });
168 });