2 // HtmlInputPasswordTest.cs
3 // - Unit tests for System.Web.UI.HtmlControls.HtmlInputPassword
6 // Chris Toshok <toshok@ximian.com>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections.Specialized;
34 using System.Web.UI.HtmlControls;
36 using NUnit.Framework;
39 namespace MonoTests.System.Web.UI.HtmlControls {
41 public class TestHtmlInputPassword : HtmlInputPassword {
43 bool value_changed; // true if the "value" is changed in RenderAttributes
44 string new_value; // "value" in ViewState if value_changed is true.
45 bool attr_value_changed; // same but for attributes (instead of viewstate)
46 string attr_new_value;
49 public TestHtmlInputPassword ()
54 public TestHtmlInputPassword (string type)
59 public string RenderAttributes ()
61 HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
62 string val = (string) ViewState ["value"];
63 string att = Attributes ["value"];
64 base.RenderAttributes (writer);
65 if (val != (string) ViewState ["value"]) {
67 new_value = (string) ViewState ["value"];
69 if (att != Attributes ["value"]) {
70 attr_value_changed = true;
71 attr_new_value = Attributes ["value"];
73 return writer.InnerWriter.ToString ();
76 public bool ViewStateValueChanged {
77 get { return value_changed; }
80 public string ViewStateNewValue {
81 get { return new_value; }
84 public bool AttributeValueChanged {
85 get { return attr_value_changed; }
88 public string AttributeNewValue {
89 get { return attr_new_value; }
92 public bool LoadPost (string key, NameValueCollection nvc)
94 return base.LoadPostData (key, nvc);
99 base.RaisePostDataChangedEvent ();
106 public class HtmlInputPasswordTest {
107 private const int defaultAttributesCount = 0;
110 public void ConstructorType ()
112 HtmlInputPassword it = new HtmlInputPassword ("mono");
113 Assert.AreEqual ("mono", it.Type, "Type");
117 public void DefaultProperties ()
119 HtmlInputPassword it = new HtmlInputPassword ();
120 Assert.AreEqual (defaultAttributesCount, it.Attributes.Count, "Attributes.Count");
122 Assert.AreEqual ("password", it.Type, "Type");
123 Assert.AreEqual (String.Empty, it.Value, "Value");
125 Assert.AreEqual ("input", it.TagName, "TagName");
126 Assert.AreEqual (defaultAttributesCount, it.Attributes.Count, "Attributes.Count-2");
130 public void RenderAttributes ()
132 TestHtmlInputPassword it = new TestHtmlInputPassword ();
137 Assert.AreEqual (" name type=\"password\" maxlength=\"4\" size=\"2\" /", it.RenderAttributes ());
138 Assert.IsTrue (it.ViewStateValueChanged, "ViewStateValueChanged");
139 Assert.IsTrue (it.AttributeValueChanged, "AttributeValueChanged");
142 private bool serverChange;
143 private void ServerChange (object sender, EventArgs e)
149 public void IPostBackDataHandler_RaisePostBackEvent ()
151 TestHtmlInputPassword it = new TestHtmlInputPassword ();
152 it.ServerChange += new EventHandler (ServerChange);
153 IPostBackDataHandler pbdh = (it as IPostBackDataHandler);
154 serverChange = false;
155 pbdh.RaisePostDataChangedEvent ();
156 Assert.IsTrue (serverChange, "ServerChange");
160 [ExpectedException (typeof (NullReferenceException))]
161 public void IPostBackDataHandler_LoadPostData_NullCollection ()
163 TestHtmlInputPassword it = new TestHtmlInputPassword ();
164 IPostBackDataHandler pbdh = (it as IPostBackDataHandler);
165 pbdh.LoadPostData ("id1", null);
169 public void IPostBackDataHandler_LoadPostData ()
171 TestHtmlInputPassword it = new TestHtmlInputPassword ();
173 IPostBackDataHandler pbdh = (it as IPostBackDataHandler);
174 NameValueCollection nvc = new NameValueCollection ();
175 nvc.Add ("id1", "mono");
176 Assert.IsTrue (pbdh.LoadPostData ("id1", nvc), "LoadPostData");
177 Assert.AreEqual ("mono", it.Value, "Value");
181 public void RaisePostBackEvent ()
183 TestHtmlInputPassword it = new TestHtmlInputPassword ();
184 it.ServerChange += new EventHandler (ServerChange);
185 serverChange = false;
187 Assert.IsTrue (serverChange, "ServerClick");
191 [ExpectedException (typeof (NullReferenceException))]
192 public void LoadPostData_NullCollection ()
194 TestHtmlInputPassword it = new TestHtmlInputPassword ();
195 it.LoadPost ("id1", null);
199 public void LoadPostData ()
201 TestHtmlInputPassword it = new TestHtmlInputPassword ();
203 NameValueCollection nvc = new NameValueCollection ();
204 nvc.Add ("id1", "mono");
205 Assert.IsTrue (it.LoadPost ("id1", nvc), "LoadPostData");
206 Assert.AreEqual ("mono", it.Value, "Value");