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.
32 using System.Collections.Specialized;
35 using System.Web.UI.HtmlControls;
37 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 string RenderAttributes ()
56 HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
57 string val = (string) ViewState ["value"];
58 string att = Attributes ["value"];
59 base.RenderAttributes (writer);
60 if (val != (string) ViewState ["value"]) {
62 new_value = (string) ViewState ["value"];
64 if (att != Attributes ["value"]) {
65 attr_value_changed = true;
66 attr_new_value = Attributes ["value"];
68 return writer.InnerWriter.ToString ();
71 public bool ViewStateValueChanged {
72 get { return value_changed; }
75 public string ViewStateNewValue {
76 get { return new_value; }
79 public bool AttributeValueChanged {
80 get { return attr_value_changed; }
83 public string AttributeNewValue {
84 get { return attr_new_value; }
87 public bool LoadPost (string key, NameValueCollection nvc)
89 return base.LoadPostData (key, nvc);
94 base.RaisePostDataChangedEvent ();
100 public class HtmlInputPasswordTest {
102 private const int defaultAttributesCount = 1;
105 public void DefaultProperties ()
107 HtmlInputPassword it = new HtmlInputPassword ();
108 Assert.AreEqual (defaultAttributesCount, it.Attributes.Count, "Attributes.Count");
110 Assert.AreEqual ("password", it.Type, "Type");
111 Assert.AreEqual (String.Empty, it.Value, "Value");
113 Assert.AreEqual ("input", it.TagName, "TagName");
114 Assert.AreEqual (defaultAttributesCount, it.Attributes.Count, "Attributes.Count-2");
118 public void RenderAttributes ()
120 TestHtmlInputPassword it = new TestHtmlInputPassword ();
125 Assert.AreEqual (" name type=\"password\" maxlength=\"4\" size=\"2\" /", it.RenderAttributes ());
126 Assert.IsTrue (it.ViewStateValueChanged, "ViewStateValueChanged");
127 Assert.IsTrue (it.AttributeValueChanged, "AttributeValueChanged");
130 private bool serverChange;
131 private void ServerChange (object sender, EventArgs e)
137 public void IPostBackDataHandler_RaisePostBackEvent ()
139 TestHtmlInputPassword it = new TestHtmlInputPassword ();
140 it.ServerChange += new EventHandler (ServerChange);
141 IPostBackDataHandler pbdh = (it as IPostBackDataHandler);
142 serverChange = false;
143 pbdh.RaisePostDataChangedEvent ();
144 Assert.IsTrue (serverChange, "ServerChange");
148 [ExpectedException (typeof (NullReferenceException))]
149 public void IPostBackDataHandler_LoadPostData_NullCollection ()
151 TestHtmlInputPassword it = new TestHtmlInputPassword ();
152 IPostBackDataHandler pbdh = (it as IPostBackDataHandler);
153 pbdh.LoadPostData ("id1", null);
157 public void IPostBackDataHandler_LoadPostData ()
159 TestHtmlInputPassword it = new TestHtmlInputPassword ();
161 IPostBackDataHandler pbdh = (it as IPostBackDataHandler);
162 NameValueCollection nvc = new NameValueCollection ();
163 nvc.Add ("id1", "mono");
164 Assert.IsTrue (pbdh.LoadPostData ("id1", nvc), "LoadPostData");
165 Assert.AreEqual ("mono", it.Value, "Value");
169 public void RaisePostBackEvent ()
171 TestHtmlInputPassword it = new TestHtmlInputPassword ();
172 it.ServerChange += new EventHandler (ServerChange);
173 serverChange = false;
175 Assert.IsTrue (serverChange, "ServerClick");
179 [ExpectedException (typeof (NullReferenceException))]
180 public void LoadPostData_NullCollection ()
182 TestHtmlInputPassword it = new TestHtmlInputPassword ();
183 it.LoadPost ("id1", null);
187 public void LoadPostData ()
189 TestHtmlInputPassword it = new TestHtmlInputPassword ();
191 NameValueCollection nvc = new NameValueCollection ();
192 nvc.Add ("id1", "mono");
193 Assert.IsTrue (it.LoadPost ("id1", nvc), "LoadPostData");
194 Assert.AreEqual ("mono", it.Value, "Value");