// // Tests for System.Web.UI.ClientScriptManagerTest.cs // // Author: // Yoni Klein (yonik@mainsoft.com) // // // Copyright (C) 2005 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #if NET_2_0 using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using NUnit.Framework; using MonoTests.stand_alone.WebHarness; using MonoTests.SystemWeb.Framework; using System.Text; using System.Threading; namespace MonoTests.System.Web.UI { public class MyPage : Page, ICallbackEventHandler { #region ICallbackEventHandler Members public string GetCallbackResult () { throw new Exception ("The method or operation is not implemented."); } public void RaiseCallbackEvent (string eventArgument) { throw new Exception ("The method or operation is not implemented."); } #endregion } [TestFixture] public class ClientScriptManagerTest { [TestFixtureSetUp] public void Set_Up () { #if DOT_NET WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.EventValidationTest1.aspx", "EventValidationTest1.aspx"); WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.EventValidationTest2.aspx", "EventValidationTest2.aspx"); #else WebTest.CopyResource (GetType (), "EventValidationTest1.aspx", "EventValidationTest1.aspx"); WebTest.CopyResource (GetType (), "EventValidationTest2.aspx", "EventValidationTest2.aspx"); #endif } [SetUp] public void SetupTestCase () { Thread.Sleep (100); } [Test] public void ClientScriptManager_GetCallbackEventReference_1 () { MyPage p = new MyPage (); ClientScriptManager cs = p.ClientScript; StringBuilder context1 = new StringBuilder (); context1.Append ("function ReceiveServerData1(arg, context)"); context1.Append ("{"); context1.Append ("Message1.innerText = arg;"); context1.Append ("value1 = arg;"); context1.Append ("}"); // Define callback references. String cbReference = cs.GetCallbackEventReference (p, "arg", "ReceiveServerData1", context1.ToString ()); Assert.AreEqual ("WebForm_DoCallback('__Page',arg,ReceiveServerData1,function ReceiveServerData1(arg, context){Message1.innerText = arg;value1 = arg;},null,false)", cbReference, "GetCallbackEventReferenceFail1"); } [Test] public void ClientScriptManager_GetCallbackEventReference_2 () { MyPage p = new MyPage (); ClientScriptManager cs = p.ClientScript; StringBuilder context1 = new StringBuilder (); context1.Append ("function ReceiveServerData1(arg, context)"); context1.Append ("{"); context1.Append ("Message1.innerText = arg;"); context1.Append ("value1 = arg;"); context1.Append ("}"); // Define callback references. String cbReference = cs.GetCallbackEventReference (p, "arg", "ReceiveServerData1", context1.ToString (), true); Assert.AreEqual ("WebForm_DoCallback('__Page',arg,ReceiveServerData1,function ReceiveServerData1(arg, context){Message1.innerText = arg;value1 = arg;},null,true)", cbReference, "GetCallbackEventReferenceFail2"); } [Test] public void ClientScriptManager_GetCallbackEventReference_3 () { MyPage p = new MyPage (); ClientScriptManager cs = p.ClientScript; StringBuilder context1 = new StringBuilder (); context1.Append ("function ReceiveServerData1(arg, context)"); context1.Append ("{"); context1.Append ("Message1.innerText = arg;"); context1.Append ("value1 = arg;"); context1.Append ("}"); // Define callback references. String cbReference = cs.GetCallbackEventReference (p, "arg", "ReceiveServerData1", context1.ToString (), "ErrorCallback", false); Assert.AreEqual ("WebForm_DoCallback('__Page',arg,ReceiveServerData1,function ReceiveServerData1(arg, context){Message1.innerText = arg;value1 = arg;},ErrorCallback,false)", cbReference, "GetCallbackEventReferenceFail3"); } [Test] public void ClientScriptManager_GetPostBackEventReference_1 () { MyPage p = new MyPage (); ClientScriptManager cs = p.ClientScript; String result = cs.GetPostBackEventReference (new PostBackOptions (p, "args")); Assert.AreEqual ("__doPostBack('__Page','args')", result, "GetPostBackEventReference#1"); } [Test] public void ClientScriptManager_GetPostBackEventReference_2 () { MyPage p = new MyPage (); ClientScriptManager cs = p.ClientScript; String result = cs.GetPostBackEventReference (p, "args"); Assert.AreEqual ("__doPostBack('__Page','args')", result, "GetPostBackEventReference#2"); } [Test] public void ClientScriptManager_GetPostBackClientHyperlink () { MyPage p = new MyPage (); ClientScriptManager cs = p.ClientScript; String hyperlink = cs.GetPostBackClientHyperlink (p, "args"); Assert.AreEqual ("javascript:__doPostBack('__Page','args')", hyperlink, "GetPostBackClientHyperlink"); } [Test] [Category("NunitWeb")] public void ClientScriptManager_GetWebResourceUrl () { string html = new WebTest (PageInvoker.CreateOnLoad (GetWebResourceUrlLoad)).Run(); } public static void GetWebResourceUrlLoad (Page p) { ClientScriptManager cs = p.ClientScript; String cbReference = cs.GetWebResourceUrl (typeof (MonoTests.System.Web.UI.ClientScriptManagerTest), "ClientScript.js"); if (cbReference.IndexOf("/NunitWeb/WebResource.axd?")<0) Assert.Fail ("GetWebResourceUrlFail"); } [Test] public void ClientScriptManager_IsClientScriptBlockRegistered () { Page p = new Page (); ClientScriptManager cs = p.ClientScript; String csname2 = "ButtonClickScript"; Type cstype = p.GetType (); StringBuilder cstext2 = new StringBuilder (); cstext2.Append ("