2 // Tests for System.Web.UI.WebControls.ImageMap.cs
5 // Hagit Yidov (hagity@mainsoft.com
7 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using NUnit.Framework;
32 using System.Globalization;
35 using System.Web.UI.WebControls;
36 using MonoTests.stand_alone.WebHarness;
37 using MonoTests.SystemWeb.Framework;
38 using System.Threading;
40 namespace MonoTests.System.Web.UI.WebControls {
41 class PokerTreeNode : TreeNode {
43 public PokerTreeNode () {
47 public object SaveState () {
48 return SaveViewState ();
51 public void LoadState (object o) {
55 public bool IsTrackingViewStateBase { get { return (base.IsTrackingViewState); } }
57 public virtual object CloneBase () {
58 return (base.Clone ());
61 public virtual void RenderPostTextBase (HtmlTextWriter writer) {
62 base.RenderPostText (writer);
65 public virtual void RenderPreTextBase (HtmlTextWriter writer) {
66 base.RenderPreText (writer);
72 public class TreeNodeTest {
75 public void TreeNode_DefaultProperties () {
76 PokerTreeNode tn = new PokerTreeNode ();
77 Assert.AreEqual (false, tn.Checked, "Checked");
78 Assert.AreEqual (0, tn.ChildNodes.Count, "ChildNodes.Count");
79 Assert.AreEqual (false, tn.DataBound, "DataBound");
80 Assert.AreEqual (null, tn.DataItem, "DataItem");
81 Assert.AreEqual (string.Empty, tn.DataPath, "DataPath");
82 Assert.AreEqual (0, tn.Depth, "Depth");
83 Assert.AreEqual (null, tn.Expanded, "Expanded");
84 Assert.AreEqual (string.Empty, tn.ImageToolTip, "ImageToolTip");
85 Assert.AreEqual (string.Empty, tn.ImageUrl, "ImageUrl");
86 Assert.AreEqual (string.Empty, tn.NavigateUrl, "NavigateUrl");
87 Assert.AreEqual (null, tn.Parent, "Parent");
88 Assert.AreEqual (false, tn.PopulateOnDemand, "PopulateOnDemand");
89 Assert.AreEqual (TreeNodeSelectAction.Select, tn.SelectAction, "SelectAction");
90 Assert.AreEqual (false, tn.Selected, "Selected");
91 Assert.AreEqual (null, tn.ShowCheckBox, "ShowCheckBox");
92 Assert.AreEqual (string.Empty, tn.Target, "Target");
93 Assert.AreEqual (string.Empty, tn.Text, "Text");
94 Assert.AreEqual (string.Empty, tn.Value, "Value");
95 Assert.AreEqual (string.Empty, tn.ToolTip, "ToolTip");
96 Assert.AreEqual (string.Empty, tn.ValuePath, "ValuePath");
97 Assert.AreEqual (true, tn.IsTrackingViewStateBase, "IsTrackingViewState");
101 public void TreeNode_AssignToDefaultProperties ()
103 PokerTreeNode tn = new PokerTreeNode ();
105 Assert.AreEqual (false, tn.Checked, "Checked");
106 tn.ChildNodes.Add (new TreeNode ());
107 Assert.AreEqual (1, tn.ChildNodes.Count, "ChildNodes.Count");
109 Assert.AreEqual (false, tn.Expanded, "Expanded");
110 tn.ImageToolTip = string.Empty;
111 Assert.AreEqual (string.Empty, tn.ImageToolTip, "ImageToolTip");
112 tn.ImageUrl = string.Empty;
113 Assert.AreEqual (string.Empty, tn.ImageUrl, "ImageUrl");
114 tn.NavigateUrl = string.Empty;
115 Assert.AreEqual (string.Empty, tn.NavigateUrl, "NavigateUrl");
116 tn.PopulateOnDemand = false;
117 Assert.AreEqual (false, tn.PopulateOnDemand, "PopulateOnDemand");
118 tn.SelectAction = TreeNodeSelectAction.Select;
119 Assert.AreEqual (TreeNodeSelectAction.Select, tn.SelectAction, "SelectAction");
121 Assert.AreEqual (false, tn.Selected, "Selected");
122 tn.ShowCheckBox = false;
123 Assert.AreEqual (false, tn.ShowCheckBox, "ShowCheckBox");
124 tn.Target = string.Empty;
125 Assert.AreEqual (string.Empty, tn.Target, "Target");
126 tn.Text = string.Empty;
127 Assert.AreEqual (string.Empty, tn.Text, "Text");
128 tn.Value = string.Empty;
129 Assert.AreEqual (string.Empty, tn.Value, "Value");
130 tn.ToolTip = string.Empty;
131 Assert.AreEqual (string.Empty, tn.ToolTip, "ToolTip");
135 public void TreeNode_Method_Select () {
136 PokerTreeNode tn = new PokerTreeNode ();
137 Assert.AreEqual (false, tn.Selected, "BeforeSelect");
139 Assert.AreEqual (true, tn.Selected, "AfterSelect");
143 public void TreeNode_Method_Clone () {
144 PokerTreeNode tn1 = new PokerTreeNode ();
145 TreeNode tn2 = new TreeNode ();
146 tn1.Text = "CloneThisNode";
148 Assert.AreEqual (string.Empty, tn2.Text, "BeforeClone1");
149 Assert.AreEqual (string.Empty, tn2.Value, "BeforeClone2");
150 tn2 = (TreeNode) tn1.CloneBase ();
151 Assert.AreEqual ("CloneThisNode", tn2.Text, "AfterClone1");
152 Assert.AreEqual ("111", tn2.Value, "AfterClone2");
156 [Category ("NunitWeb")]
157 public void TreeNode_NavigateUrl () {
158 WebTest t = new WebTest (PageInvoker.CreateOnLoad (pageLoadNavigateUrl));
159 string strTarget = "<a href=\"#treeview1_SkipLink\"><img alt=\"Skip Navigation Links.\" src=\"/NunitWeb/WebResource.axd?d=8VpphgAbakKUC_J8R6hR0Q2&t=634067491135766272\" width=\"0\" height=\"0\" style=\"border-width:0px;\" /></a><div id=\"treeview1\">\r\n\t<table cellpadding=\"0\" cellspacing=\"0\" style=\"border-width:0;\">\r\n\t\t<tr>\r\n\t\t\t<td><img src=\"/NunitWeb/WebResource.axd?d=Me-CdxEHiTTT3lXTDd0I2ilpe6vhhhJjssENmbNkrSY1&t=634067491135766272\" alt=\"\" /></td><td style=\"white-space:nowrap;\"><a class=\"treeview1_0\" href=\"NavigateUrl\" id=\"treeview1t0\">TreeNode1</a></td>\r\n\t\t</tr>\r\n\t</table>\r\n</div><a id=\"treeview1_SkipLink\"></a>";
160 string str = HtmlDiff.GetControlFromPageHtml (t.Run ());
161 HtmlDiff.AssertAreEqual (strTarget, str, "PostbackNavigate");
163 public static void pageLoadNavigateUrl (Page page) {
164 TreeView tv = new TreeView ();
166 PokerTreeNode tn1 = new PokerTreeNode ();
167 tn1.Text = "TreeNode1";
168 tn1.NavigateUrl = "NavigateUrl";
170 LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
171 LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
172 page.Form.Controls.Add (lcb);
173 page.Form.Controls.Add (tv);
174 page.Form.Controls.Add (lce);
177 static void tv_SelectedNodeChanged (object sender, EventArgs e) {
178 TreeView tv = (TreeView) sender;
179 WebTest.CurrentTest.UserData = tv.SelectedNode.Text;
183 [Category ("NunitWeb")]
184 public void TreeNode_Render () {
185 WebTest t = new WebTest (PageInvoker.CreateOnLoad (pageLoadRender));
186 string strTarget = "<a href=\"#treeview1_SkipLink\"><img alt=\"Skip Navigation Links.\" src=\"/NunitWeb/WebResource.axd?d=8VpphgAbakKUC_J8R6hR0Q2&t=634067491135766272\" width=\"0\" height=\"0\" style=\"border-width:0px;\" /></a><div id=\"treeview1\">\r\n\t<table cellpadding=\"0\" cellspacing=\"0\" style=\"border-width:0;\">\r\n\t\t<tr>\r\n\t\t\t<td><a href=\"javascript:__doPostBack('treeview1','tvalue')\"><img src=\"/NunitWeb/WebResource.axd?d=Me-CdxEHiTTT3lXTDd0I2qLe7WfoYyDfWfVSkV5Suzs1&t=634067491135766272\" alt=\"Collapse text\" style=\"border-width:0;\" /></a></td><td><a href=\"navigateUrl\" target=\"target\" title=\"ToolTip\" id=\"treeview1t0i\" tabindex=\"-1\"><img src=\"imageUrl\" alt=\"ImageToolTip\" style=\"border-width:0;\" /></a></td><td style=\"white-space:nowrap;\"><input type=\"checkbox\" name=\"treeview1n0CheckBox\" id=\"treeview1n0CheckBox\" checked=\"checked\" title=\"ToolTip\" /><a class=\"treeview1_0\" href=\"navigateUrl\" target=\"target\" title=\"ToolTip\" id=\"treeview1t0\">text</a></td>\r\n\t\t</tr>\r\n\t</table><table cellpadding=\"0\" cellspacing=\"0\" style=\"border-width:0;\">\r\n\t\t<tr>\r\n\t\t\t<td><div style=\"width:20px;height:1px\"></div></td><td><img src=\"/NunitWeb/WebResource.axd?d=Me-CdxEHiTTT3lXTDd0I2ilpe6vhhhJjssENmbNkrSY1&t=634067491135766272\" alt=\"\" /></td><td style=\"white-space:nowrap;\"><a class=\"treeview1_0\" href=\"javascript:__doPostBack('treeview1','svalue\\\\childenode')\" id=\"treeview1t1\">childenode</a></td>\r\n\t\t</tr>\r\n\t</table>\r\n</div><a id=\"treeview1_SkipLink\"></a>";
187 string str = HtmlDiff.GetControlFromPageHtml (t.Run ());
188 HtmlDiff.AssertAreEqual (strTarget, str, "Render");
190 public static void pageLoadRender (Page page) {
191 TreeView tv = new TreeView ();
192 tv.EnableClientScript = false;
194 TreeNode tn = new TreeNode
195 ("text", "value", "imageUrl", "navigateUrl", "target");
197 tn.ChildNodes.Add (new TreeNode ("childenode"));
199 tn.ImageToolTip = "ImageToolTip";
200 tn.PopulateOnDemand = false;
201 tn.SelectAction = TreeNodeSelectAction.SelectExpand;
203 tn.ShowCheckBox = true;
204 tn.ToolTip = "ToolTip";
207 LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
208 LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
209 page.Form.Controls.Add (lcb);
210 page.Form.Controls.Add (tv);
211 page.Form.Controls.Add (lce);
215 [ExpectedException (typeof (InvalidOperationException))]
216 [Ignore ("Pending more investigation (see FIXME at the top of TreeView.RenderNode)")]
217 public void PopulateOnDemand_With_ChildNodes ()
219 WebTest t = new WebTest (PageInvoker.CreateOnLoad (PopulateOnDemand_With_ChildNodes_OnLoad));
223 protected static void PopulateOnDemand_With_ChildNodes_OnLoad (Page p)
225 TreeView tv = new TreeView ();
226 TreeNode node = new TreeNode ("text", "value", "imageUrl", "navigateUrl", "target");
227 node.PopulateOnDemand = true;
228 node.ChildNodes.Add (new TreeNode ("text", "value", "imageUrl", "navigateUrl", "target"));
231 p.Form.Controls.Add (tv);
235 public void TreeNode_ToggleExpandState ()
237 TreeNode node = new TreeNode ("node");
238 Assert.AreEqual (null, node.Expanded, "TreeNode_ToggleExpandState#1");
239 node.ToggleExpandState ();
240 Assert.AreEqual (true, node.Expanded, "TreeNode_ToggleExpandState#2");
241 node.ToggleExpandState ();
242 Assert.AreEqual (false, node.Expanded, "TreeNode_ToggleExpandState#3");
246 public void TreeNode_TextValue1 ()
248 TreeNode node = new TreeNode ();
250 Assert.AreEqual ("TTT", node.Value, "TreeNode_TextValue1#1");
252 Assert.AreEqual ("", node.Value, "TreeNode_TextValue1#2");
254 Assert.AreEqual ("TTT", node.Value, "TreeNode_TextValue1#3");
258 public void TreeNode_TextValue2 ()
260 TreeNode node = new TreeNode ();
262 Assert.AreEqual ("VVV", node.Text, "TreeNode_TextValue2#1");
264 Assert.AreEqual ("", node.Text, "TreeNode_TextValue2#2");
266 Assert.AreEqual ("VVV", node.Text, "TreeNode_TextValue2#3");