This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: branches/1.3.1/src/Core/IE.cs | |
=================================================================== | |
--- branches/1.3.1/src/Core/IE.cs (revision 1091) | |
+++ branches/1.3.1/src/Core/IE.cs (working copy) | |
@@ -20,6 +20,7 @@ | |
using System.Collections; | |
using System.Diagnostics; | |
using System.Drawing; | |
+using System.Net; | |
using System.Runtime.InteropServices; | |
using System.Threading; | |
using System.Windows.Forms; | |
@@ -600,6 +601,8 @@ | |
} | |
InitIEAndStartDialogWatcher(internetExplorer); | |
+ | |
+ AttachEventHandlers(); | |
} | |
private void CreateNewIEAndGoToUri(Uri uri, LogonDialogHandler logonDialogHandler, bool createInNewProcess) | |
@@ -629,6 +632,8 @@ | |
DialogWatcher.Add(logonDialogHandler); | |
} | |
+ AttachEventHandlers(); | |
+ | |
WaitForComplete(); | |
} | |
@@ -706,7 +711,7 @@ | |
throw new IENotFoundException(findBy.ConstraintToString(), timeout); | |
} | |
- private static SHDocVw.InternetExplorer findInternetExplorer(BaseConstraint findBy, int timeout) | |
+ protected static SHDocVw.InternetExplorer findInternetExplorer(BaseConstraint findBy, int timeout) | |
{ | |
Logger.LogAction("Busy finding Internet Explorer matching constriant " + findBy.ConstraintToString()); | |
@@ -907,6 +912,27 @@ | |
get { return ie; } | |
} | |
+ protected void AttachEventHandlers() | |
+ { | |
+ ie.BeforeNavigate2 += (object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel) => | |
+ { | |
+ ErrorCode = null; | |
+ }; | |
+ ie.NavigateError += (object pDisp, ref object URL, ref object Frame, ref object StatusCode, ref bool Cancel) => | |
+ { | |
+ ErrorCode = (HttpStatusCode)StatusCode; | |
+ }; | |
+ } | |
+ | |
+ /// <summary> | |
+ /// HTTP Status Code of last error, or null if the last request was successful | |
+ /// </summary> | |
+ public HttpStatusCode? ErrorCode | |
+ { | |
+ get; | |
+ private set; | |
+ } | |
+ | |
/// <summary> | |
/// Navigates the browser back to the previously displayed Url (like the back | |
/// button in Internet Explorer). | |
Index: branches/1.3.1/src/UnitTests/IETests.cs | |
=================================================================== | |
--- branches/1.3.1/src/UnitTests/IETests.cs (revision 1091) | |
+++ branches/1.3.1/src/UnitTests/IETests.cs (working copy) | |
@@ -19,6 +19,7 @@ | |
using System; | |
using System.Diagnostics; | |
using System.Drawing; | |
+using System.Net; | |
using System.Runtime.InteropServices; | |
using System.Threading; | |
using System.Web; | |
@@ -88,6 +89,68 @@ | |
} | |
} | |
+ [Test, Category("InternetConnectionNeeded")] | |
+ public void RealUrlHasNullErrorCode() | |
+ { | |
+ using (IE ie = new IE(GoogleUrl)) | |
+ { | |
+ Assert.That(ie.ErrorCode, Is.Null); | |
+ } | |
+ } | |
+ | |
+ [Test, Category("InternetConnectionNeeded")] | |
+ public void FakeUrlHasErrorCodeNotFound() | |
+ { | |
+ using (IE ie = new IE(GoogleUrl + "/thisdoesnotexist")) | |
+ { | |
+ Assert.That(ie.ErrorCode, Is.EqualTo(HttpStatusCode.NotFound)); | |
+ } | |
+ } | |
+ | |
+ [Test, Category("InternetConnectionNeeded")] | |
+ public void RealUrlAfterFakeUrlHasStatusCodeNotFound() | |
+ { | |
+ using (IE ie = new IE("http://www.google.com/thisdoesnotexist")) | |
+ { | |
+ ie.GoTo(GoogleUrl); | |
+ Assert.That(ie.ErrorCode, Is.Null); | |
+ } | |
+ } | |
+ | |
+ [Test, Category("InternetConnectionNeeded")] | |
+ public void RealUrlHasNullErrorCode_Attached() | |
+ { | |
+ using (new IE(MainURI)) | |
+ using (var ie = IE.AttachToIE(Find.ByUrl(MainURI))) | |
+ { | |
+ ie.GoTo(GoogleUrl); | |
+ Assert.That(ie.ErrorCode, Is.Null); | |
+ } | |
+ } | |
+ | |
+ [Test, Category("InternetConnectionNeeded")] | |
+ public void FakeUrlHasErrorCodeNotFound_Attached() | |
+ { | |
+ using (new IE(MainURI)) | |
+ using (var ie = IE.AttachToIE(Find.ByUrl(MainURI))) | |
+ { | |
+ ie.GoTo(GoogleUrl + "/thisdoesnotexist"); | |
+ Assert.That(ie.ErrorCode, Is.EqualTo(HttpStatusCode.NotFound)); | |
+ } | |
+ } | |
+ | |
+ [Test, Category("InternetConnectionNeeded")] | |
+ public void RealUrlAfterFakeUrlHasStatusCodeNotFound_Attached() | |
+ { | |
+ using (new IE(MainURI)) | |
+ using (var ie = IE.AttachToIE(Find.ByUrl(MainURI))) | |
+ { | |
+ ie.GoTo("http://www.google.com/thisdoesnotexist"); | |
+ ie.GoTo(GoogleUrl); | |
+ Assert.That(ie.ErrorCode, Is.Null); | |
+ } | |
+ } | |
+ | |
[Test, Category("InternetConnectionNeeded")] | |
public void GoogleSearchWithEncodedQueryString() | |
{ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment