| OLD | NEW |
| (Empty) |
| 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 privateScriptController.installClass("PrivateScriptTest", function(PrivateScript
TestPrototype) { | |
| 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, v
iew: 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, "nodeAttributeThrowsIndexS
izeError", { | |
| 118 get: function() { privateScriptController.throwException(privateScriptCo
ntroller.DOMException.IndexSizeError, "getter threw error"); }, | |
| 119 set: function(value) { privateScriptController.throwException(privateScr
iptController.DOMException.IndexSizeError, "setter threw error"); } | |
| 120 }); | |
| 121 | |
| 122 PrivateScriptTestPrototype.voidMethodThrowsDOMSyntaxError = function() { | |
| 123 privateScriptController.throwException(privateScriptController.DOMExcept
ion.SyntaxError, "method threw error"); | |
| 124 } | |
| 125 | |
| 126 PrivateScriptTestPrototype.voidMethodThrowsError = function() { | |
| 127 privateScriptController.throwException(privateScriptController.JSError.E
rror, "method threw Error"); | |
| 128 } | |
| 129 | |
| 130 PrivateScriptTestPrototype.voidMethodThrowsTypeError = function() { | |
| 131 privateScriptController.throwException(privateScriptController.JSError.T
ypeError, "method threw TypeError"); | |
| 132 } | |
| 133 | |
| 134 PrivateScriptTestPrototype.voidMethodThrowsRangeError = function() { | |
| 135 privateScriptController.throwException(privateScriptController.JSError.R
angeError, "method threw RangeError"); | |
| 136 } | |
| 137 | |
| 138 PrivateScriptTestPrototype.voidMethodThrowsSyntaxError = function() { | |
| 139 privateScriptController.throwException(privateScriptController.JSError.S
yntaxError, "method threw SyntaxError"); | |
| 140 } | |
| 141 | |
| 142 PrivateScriptTestPrototype.voidMethodThrowsReferenceError = function() { | |
| 143 privateScriptController.throwException(privateScriptController.JSError.R
eferenceError, "method threw ReferenceError"); | |
| 144 } | |
| 145 | |
| 146 PrivateScriptTestPrototype.voidMethodThrowsStackOverflowError = 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, "stringAttributeForPrivate
ScriptOnly", { | |
| 156 get: function() { return this.m_stringAttributeForPrivateScriptOnly; }, | |
| 157 set: function(value) { this.m_stringAttributeForPrivateScriptOnly = valu
e; } | |
| 158 }); | |
| 159 | |
| 160 PrivateScriptTestPrototype.addIntegerImplementedInCPP = function(value1, val
ue2) { | |
| 161 return this.addIntegerImplementedInCPPForPrivateScriptOnly(value1, value
2); | |
| 162 } | |
| 163 | |
| 164 Object.defineProperty(PrivateScriptTestPrototype, "stringAttributeImplemente
dInCPP", { | |
| 165 get: function() { return this.m_stringAttributeImplementedInCPPForPrivat
eScriptOnly; }, | |
| 166 set: function(value) { this.m_stringAttributeImplementedInCPPForPrivateS
criptOnly = value; } | |
| 167 }); | |
| 168 | |
| 169 PrivateScriptTestPrototype.dispatchDocumentOnload = function(document) { | |
| 170 var event = new Event("load", { bubbles: true, cancelable: true }); | |
| 171 event.valueInPrivateScript = "this should not be visible in user's scrip
t"; | |
| 172 document.dispatchEvent(event); | |
| 173 } | |
| 174 | |
| 175 }); | |
| OLD | NEW |