1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2008 Novell, Inc.
23 // Andreia Gaita (avidigal@novell.com)
30 using System.Windows.Forms;
31 using NUnit.Framework;
34 namespace MonoTests.System.Windows.Forms
37 public class WebBrowserTest
44 wb = new WebBrowser ();
46 wb.DocumentCompleted += delegate (object sender, WebBrowserDocumentCompletedEventArgs e) {
47 if (e.Url.Equals ("about:blank")) {
55 public string CreateTestPage (string html)
57 io.FileStream f = null;
66 path = io.Path.Combine (io.Path.GetTempPath(), "html" + num.ToString("x") + ".html");
69 f = new io.FileStream (path, io.FileMode.CreateNew, io.FileAccess.ReadWrite, io.FileShare.Read,
70 8192, (io.FileOptions) 1);
72 catch (global::System.Security.SecurityException) {
73 // avoid an endless loop
79 io.StreamWriter s = new io.StreamWriter (f);
87 public void LoadingEventsTest()
89 string html = "<html><head></head><body></body></html>";
90 string url = "file://" + CreateTestPage (html);
91 string events = String.Empty;
93 wb.DocumentCompleted += delegate (object sender, WebBrowserDocumentCompletedEventArgs e) {
94 if (e.Url.Equals (url)) {
96 Assert.AreEqual("navigatingnavigated", events, "#A1");
99 wb.Navigating += delegate (object sender1, WebBrowserNavigatingEventArgs e1) {
100 if (e1.Url.Equals (url))
101 events += "navigating";
103 wb.Navigated += delegate (object sender1, WebBrowserNavigatedEventArgs e1) {
104 if (e1.Url.Equals (url))
105 events += "navigated";
113 public void InnerHtmlTest()
115 string html = "<html><head></head><body><div id=\"testid\"></div></body></html>";
116 string url = "file://" + CreateTestPage (html);
117 string test = "testing inner html";
119 wb.DocumentCompleted += delegate (object sender, WebBrowserDocumentCompletedEventArgs e) {
120 Console.Error.WriteLine (wb.Document.Body.InnerHtml);
121 if (e.Url.Equals (url)) {
123 Assert.IsNotNull (wb.Document, "#A1");
124 HtmlElement elem = wb.Document.GetElementById ("testid");
125 Assert.IsNotNull (elem, "#A2");
126 elem.InnerHtml = test;
127 string ret = elem.InnerHtml;
128 Assert.AreEqual (ret, test, "#A3");