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.
33 using System.Collections.Specialized;
36 using System.Web.UI.HtmlControls;
38 using NUnit.Framework;
40 namespace MonoTests.System.Web.UI.HtmlControls {
42 public class TestHtmlInputPassword : HtmlInputPassword {
44 bool value_changed; // true if the "value" is changed in RenderAttributes
45 string new_value; // "value" in ViewState if value_changed is true.
46 bool attr_value_changed; // same but for attributes (instead of viewstate)
47 string attr_new_value;
50 public TestHtmlInputPassword ()
55 public string RenderAttributes ()
57 HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
58 string val = (string) ViewState ["value"];
59 string att = Attributes ["value"];
60 base.RenderAttributes (writer);
61 if (val != (string) ViewState ["value"]) {
63 new_value = (string) ViewState ["value"];
65 if (att != Attributes ["value"]) {
66 attr_value_changed = true;
67 attr_new_value = Attributes ["value"];
69 return writer.InnerWriter.ToString ();
72 public bool ViewStateValueChanged {
73 get { return value_changed; }
76 public string ViewStateNewValue {
77 get { return new_value; }
80 public bool AttributeValueChanged {
81 get { return attr_value_changed; }
84 public string AttributeNewValue {
85 get { return attr_new_value; }
88 public bool LoadPost (string key, NameValueCollection nvc)
90 return base.LoadPostData (key, nvc);
95 base.RaisePostDataChangedEvent ();
101 public class HtmlInputPasswordTest {
103 private const int defaultAttributesCount = 1;
106 public void DefaultProperties ()
108 HtmlInputPassword it = new HtmlInputPassword ();
109 Assert.AreEqual (defaultAttributesCount, it.Attributes.Count, "Attributes.Count");
111 Assert.AreEqual ("password", it.Type, "Type");
112 Assert.AreEqual (String.Empty, it.Value, "Value");
114 Assert.AreEqual ("input", it.TagName, "TagName");
115 Assert.AreEqual (defaultAttributesCount, it.Attributes.Count, "Attributes.Count-2");
119 public void RenderAttributes ()
121 TestHtmlInputPassword it = new TestHtmlInputPassword ();
126 Assert.AreEqual (" name type=\"password\" maxlength=\"4\" size=\"2\" /", it.RenderAttributes ());
127 Assert.IsTrue (it.ViewStateValueChanged, "ViewStateValueChanged");
128 Assert.IsTrue (it.AttributeValueChanged, "AttributeValueChanged");
131 private bool serverChange;
132 private void ServerChange (object sender, EventArgs e)
138 public void IPostBackDataHandler_RaisePostBackEvent ()
140 TestHtmlInputPassword it = new TestHtmlInputPassword ();
141 it.ServerChange += new EventHandler (ServerChange);
142 IPostBackDataHandler pbdh = (it as IPostBackDataHandler);
143 serverChange = false;
144 pbdh.RaisePostDataChangedEvent ();
145 Assert.IsTrue (serverChange, "ServerChange");
149 [ExpectedException (typeof (NullReferenceException))]
150 public void IPostBackDataHandler_LoadPostData_NullCollection ()
152 TestHtmlInputPassword it = new TestHtmlInputPassword ();
153 IPostBackDataHandler pbdh = (it as IPostBackDataHandler);
154 pbdh.LoadPostData ("id1", null);
158 public void IPostBackDataHandler_LoadPostData ()
160 TestHtmlInputPassword it = new TestHtmlInputPassword ();
162 IPostBackDataHandler pbdh = (it as IPostBackDataHandler);
163 NameValueCollection nvc = new NameValueCollection ();
164 nvc.Add ("id1", "mono");
165 Assert.IsTrue (pbdh.LoadPostData ("id1", nvc), "LoadPostData");
166 Assert.AreEqual ("mono", it.Value, "Value");
170 public void RaisePostBackEvent ()
172 TestHtmlInputPassword it = new TestHtmlInputPassword ();
173 it.ServerChange += new EventHandler (ServerChange);
174 serverChange = false;
176 Assert.IsTrue (serverChange, "ServerClick");
180 [ExpectedException (typeof (NullReferenceException))]
181 public void LoadPostData_NullCollection ()
183 TestHtmlInputPassword it = new TestHtmlInputPassword ();
184 it.LoadPost ("id1", null);
188 public void LoadPostData ()
190 TestHtmlInputPassword it = new TestHtmlInputPassword ();
192 NameValueCollection nvc = new NameValueCollection ();
193 nvc.Add ("id1", "mono");
194 Assert.IsTrue (it.LoadPost ("id1", nvc), "LoadPostData");
195 Assert.AreEqual ("mono", it.Value, "Value");