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.
7 installClass("PrivateScriptTest", function(PrivateScriptTestPrototype) {
9 PrivateScriptTestPrototype.initialize = function() {
10 this.m_shortAttribute = -1;
11 this.m_stringAttribute = "xxx";
12 this.m_nodeAttribute = null;
13 this.m_stringAttributeForPrivateScriptOnly = "yyy";
16 PrivateScriptTestPrototype.doNothing = function() {
19 PrivateScriptTestPrototype.return123 = function() {
23 PrivateScriptTestPrototype.echoInteger = function(value) {
27 PrivateScriptTestPrototype.echoString = function(value) {
31 PrivateScriptTestPrototype.echoNode = function(value) {
35 PrivateScriptTestPrototype.addValues_ = function(value1, value2) {
36 return value1 + value2;
39 PrivateScriptTestPrototype.addInteger = function(value1, value2) {
40 return this.addValues_(value1, value2);
43 PrivateScriptTestPrototype.addString = function(value1, value2) {
44 return this.addValues_(value1, value2);
47 PrivateScriptTestPrototype.setIntegerToDocument = function(document, value) {
48 document.integer = value;
51 PrivateScriptTestPrototype.getIntegerFromDocument = function(document) {
52 return document.integer;
55 PrivateScriptTestPrototype.setIntegerToPrototype = function(value) {
59 PrivateScriptTestPrototype.getIntegerFromPrototype = function() {
63 PrivateScriptTestPrototype.createElement = function(document) {
64 return document.createElement("div");
67 PrivateScriptTestPrototype.appendChild = function(node1, node2) {
68 node1.appendChild(node2);
71 PrivateScriptTestPrototype.firstChild = function(node) {
72 return node.firstChild;
75 PrivateScriptTestPrototype.nextSibling = function(node) {
76 return node.nextSibling;
79 PrivateScriptTestPrototype.innerHTML = function(node) {
80 return node.innerHTML;
83 PrivateScriptTestPrototype.setInnerHTML = function(node, string) {
84 node.innerHTML = string;
87 PrivateScriptTestPrototype.addClickListener = function(node) {
88 node.addEventListener("click", function () {
89 node.innerHTML = "clicked";
93 PrivateScriptTestPrototype.clickNode = function(document, node) {
94 var event = new MouseEvent("click", { bubbles: true, cancelable: true, view: window });
95 node.dispatchEvent(event);
98 Object.defineProperty(PrivateScriptTestPrototype, "readonlyShortAttribute", {
99 get: function() { return 123; }
102 Object.defineProperty(PrivateScriptTestPrototype, "shortAttribute", {
103 get: function() { return this.m_shortAttribute; },
104 set: function(value) { this.m_shortAttribute = value; }
107 Object.defineProperty(PrivateScriptTestPrototype, "stringAttribute", {
108 get: function() { return this.m_stringAttribute; },
109 set: function(value) { this.m_stringAttribute = value; }
112 Object.defineProperty(PrivateScriptTestPrototype, "nodeAttribute", {
113 get: function() { return this.m_nodeAttribute; },
114 set: function(value) { this.m_nodeAttribute = value; }
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"); }
122 PrivateScriptTestPrototype.voidMethodThrowsDOMSyntaxError = function() {
123 throw new DOMExceptionInPrivateScript("SyntaxError", "method threw error");
126 PrivateScriptTestPrototype.voidMethodThrowsError = function() {
127 throw new Error("method threw Error");
130 PrivateScriptTestPrototype.voidMethodThrowsTypeError = function() {
131 throw new TypeError("method threw TypeError");
134 PrivateScriptTestPrototype.voidMethodThrowsRangeError = function() {
135 throw new RangeError("method threw RangeError");
138 PrivateScriptTestPrototype.voidMethodThrowsSyntaxError = function() {
139 throw new SyntaxError("method threw SyntaxError");
142 PrivateScriptTestPrototype.voidMethodThrowsReferenceError = function() {
143 throw new ReferenceError("method threw ReferenceError");
146 PrivateScriptTestPrototype.voidMethodWithStackOverflow = function() {
147 function f() { f(); }
151 PrivateScriptTestPrototype.addIntegerForPrivateScriptOnly = function(value1, value2) {
152 return value1 + value2;
155 Object.defineProperty(PrivateScriptTestPrototype, "stringAttributeForPrivateScriptOnly", {
156 get: function() { return this.m_stringAttributeForPrivateScriptOnly; },
157 set: function(value) { this.m_stringAttributeForPrivateScriptOnly = value; }
160 PrivateScriptTestPrototype.addIntegerImplementedInCPP = function(value1, value2) {
161 return this.addIntegerImplementedInCPPForPrivateScriptOnly(value1, value2);
164 Object.defineProperty(PrivateScriptTestPrototype, "stringAttributeImplementedInCPP", {
165 get: function() { return this.m_stringAttributeImplementedInCPPForPrivateScriptOnly; },
166 set: function(value) { this.m_stringAttributeImplementedInCPPForPrivateScriptOnly = value; }