Changeset 1733
- Timestamp:
- 08/14/08 13:15:20 (4 months ago)
- Files:
-
- honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation.sln (modified) (1 diff)
- honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation.suo (modified) (previous)
- honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/Automation.cs (modified) (3 diffs)
- honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/BrowserAutomation.csproj (modified) (3 diffs)
- honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/IE.cs (modified) (3 diffs)
- honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/bin/Debug/BrowserAutomation.exe (modified) (previous)
- honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/bin/Debug/BrowserAutomation.pdb (modified) (previous)
- honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/bin/Debug/Interop.SHDocVw.dll (modified) (previous)
- honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/obj/Debug/BrowserAutomation.csproj.FileListAbsolute.txt (modified) (1 diff)
- honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/obj/Debug/BrowserAutomation.exe (modified) (previous)
- honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/obj/Debug/BrowserAutomation.pdb (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation.sln
r1675 r1733 6 6 Global 7 7 GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 AutomatedDebug|Any CPU = AutomatedDebug|Any CPU 8 9 Debug|Any CPU = Debug|Any CPU 9 10 Release|Any CPU = Release|Any CPU 10 11 EndGlobalSection 11 12 GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 {2D920B27-1608-408C-8339-68EC491F3A64}.AutomatedDebug|Any CPU.ActiveCfg = Debug|Any CPU 14 {2D920B27-1608-408C-8339-68EC491F3A64}.AutomatedDebug|Any CPU.Build.0 = Debug|Any CPU 12 15 {2D920B27-1608-408C-8339-68EC491F3A64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 16 {2D920B27-1608-408C-8339-68EC491F3A64}.Debug|Any CPU.Build.0 = Debug|Any CPU honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/Automation.cs
r1698 r1733 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Diagnostics; 3 4 using System.Linq; 4 5 using System.Text; … … 14 15 private static IE ie; 15 16 private static Firefox firefox; 17 private static Process[] myOpenFirefoxs; 16 18 17 19 /// <summary> … … 31 33 if (args[0].Equals("firefox")) 32 34 { 35 myOpenFirefoxs = Process.GetProcessesByName("firefox"); 36 foreach (Process myOpenFirefox in myOpenFirefoxs) 37 { 38 myOpenFirefox.Kill(); 39 } 33 40 firefox = new Firefox(args[1]); 34 41 } honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/BrowserAutomation.csproj
r1699 r1733 32 32 </PropertyGroup> 33 33 <ItemGroup> 34 <Reference Include="Interop.SHDocVw, Version=1.1.0.0, Culture=neutral"> 35 <SpecificVersion>False</SpecificVersion> 36 <HintPath>..\References\Interop.SHDocVw.dll</HintPath> 37 </Reference> 34 38 <Reference Include="System" /> 35 39 <Reference Include="System.Core"> … … 44 48 <Reference Include="System.Data" /> 45 49 <Reference Include="System.Xml" /> 50 <Reference Include="WatiN.Core, Version=2.0.0.1000, Culture=neutral, processorArchitecture=MSIL"> 51 <SpecificVersion>False</SpecificVersion> 52 <HintPath>..\References\WatiN.Core.dll</HintPath> 53 </Reference> 46 54 </ItemGroup> 47 55 <ItemGroup> … … 50 58 <Compile Include="Automation.cs" /> 51 59 <Compile Include="Properties\AssemblyInfo.cs" /> 52 </ItemGroup>53 <ItemGroup>54 <COMReference Include="SHDocVw">55 <Guid>{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}</Guid>56 <VersionMajor>1</VersionMajor>57 <VersionMinor>1</VersionMinor>58 <Lcid>0</Lcid>59 <WrapperTool>tlbimp</WrapperTool>60 <Isolated>False</Isolated>61 </COMReference>62 60 </ItemGroup> 63 61 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/IE.cs
r1699 r1733 1 1 using System; 2 using System.Collections.Generic;3 2 using System.Linq; 4 3 using System.Text; 5 4 using System.Threading; 6 using System.Diagnostics; 7 using SHDocVw; 8 9 5 using WatiN.Core; 10 6 11 7 namespace BrowserAutomation 12 8 { 13 /// <summary>14 /// The IE class controls an instance of Internet Explorer15 /// </summary>16 9 class IE 17 10 { 18 private SHDocVw.InternetExplorer internetExplorer; 11 private WatiN.Core.IE ie; 12 private Thread hardTimeoutThread; 19 13 private Thread ieThread; 14 private bool started; 20 15 private String url; 21 private object o;22 private int unfinishedDownloads;23 private int navigateCounter;24 private bool completed;25 16 private DateTime startTime; 26 17 private TimeSpan duration; 27 private Process[] myOpenIEs;28 18 29 19 /// <summary> 30 /// Constructor for an instance of IE20 /// Constructor for an instance of Firefox 31 21 /// </summary> 32 22 /// <param name="url">URL to be navigated to</param> … … 34 24 { 35 25 this.url = url; 26 started = false; 27 hardTimeoutThread = new Thread(new ThreadStart(HardTimeoutCallback)); 36 28 ieThread = new Thread(new ThreadStart(IECallback)); 37 completed = false; 38 navigateCounter = 0; 39 unfinishedDownloads = 0; 40 internetExplorer = new SHDocVw.InternetExplorerClass(); 41 internetExplorer.NavigateError += new DWebBrowserEvents2_NavigateErrorEventHandler(this.navigationError); 42 internetExplorer.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.documentComplete); 43 internetExplorer.DownloadBegin += new DWebBrowserEvents2_DownloadBeginEventHandler(this.downloadBegin); 44 internetExplorer.DownloadComplete += new DWebBrowserEvents2_DownloadCompleteEventHandler(this.downloadComplete); 45 internetExplorer.BeforeNavigate2 += new DWebBrowserEvents2_BeforeNavigate2EventHandler(this.beforeNavigate); 46 internetExplorer.NavigateComplete2 += new DWebBrowserEvents2_NavigateComplete2EventHandler(this.navigateComplete); 29 ieThread.SetApartmentState(ApartmentState.STA); 47 30 ieThread.Start(); 31 hardTimeoutThread.Start(); 48 32 } 49 33 34 private void IECallback() 35 { 36 ie = new WatiN.Core.IE(); 37 38 ie.GoTo(url); 39 Thread.Sleep(1000); 40 ie.Close(); 41 42 hardTimeoutThread.Abort(); 43 ieThread.Abort(); 44 } 45 50 46 /// <summary> 51 /// This method will be called when the thread is started47 /// 52 48 /// </summary> 53 private void IECallback()49 private void HardTimeoutCallback() 54 50 { 55 51 while (true) 56 52 { 57 if ( url != null)53 if (!started) 58 54 { 59 internetExplorer.Visible = true; 60 internetExplorer.Navigate(url, ref o, ref o, ref o, ref o); 61 url = null; 55 started = true; 62 56 startTime = DateTime.Now; 63 57 } … … 65 59 duration = DateTime.Now - startTime; 66 60 67 if (duration.Seconds >= 30)61 if (duration.Seconds >= 30) 68 62 { 69 myOpenIEs = Process.GetProcessesByName("iexplore"); 70 foreach (Process myOpenIE in myOpenIEs) 71 { 72 myOpenIE.Kill(); 73 } 63 ie.Close(); 74 64 ieThread.Abort(); 75 } 76 else 77 { 78 if (completed && (unfinishedDownloads == 0) && !internetExplorer.Busy) 79 { 80 Thread.Sleep(2000); 81 if (completed && (unfinishedDownloads == 0) && !internetExplorer.Busy) 82 { 83 Thread.Sleep(10000); 84 internetExplorer.Quit(); 85 ieThread.Abort(); 86 } 87 } 65 hardTimeoutThread.Abort(); 88 66 } 89 67 } 90 68 } 91 92 /// <summary>93 /// This method is called when a Navigation Error event occurs94 /// </summary>95 /// <param name="pDisp"></param>96 /// <param name="URL">The URL that caused the Navigation Error</param>97 /// <param name="Frame"></param>98 /// <param name="StatusCode">Status code of the Navigation Error (ex. 404, 501)</param>99 /// <param name="Cancel"></param>100 private void navigationError(object pDisp, ref object URL, ref object Frame, ref object StatusCode, ref bool Cancel)101 {102 103 }104 105 /// <summary>106 /// This method is called when a Document Complete event occurs107 /// </summary>108 /// <param name="pDisp"></param>109 /// <param name="URL">URL of the completed document</param>110 private void documentComplete(object pDisp, ref object URL)111 {112 completed = true;113 }114 115 /// <summary>116 /// This method is called when a Download Begins event occurs117 /// Download Begins occurs every time the browser makes a valid118 /// request for content form a server.119 /// </summary>120 private void downloadBegin()121 {122 unfinishedDownloads++;123 }124 125 /// <summary>126 /// This method is called when a Download Complete event occurs127 /// Download Complete occurs everytime the content downloaded after128 /// a Download Begins is completed.129 /// </summary>130 private void downloadComplete()131 {132 unfinishedDownloads--;133 }134 135 /// <summary>136 /// This method is event that is triggered before a URL is navigated to137 /// A web page will usually make multiple requests to Navigate URLs138 /// </summary>139 /// <param name="pDisp"></param>140 /// <param name="URL">URL to be navigated to</param>141 /// <param name="Flags"></param>142 /// <param name="TargetFrameName"></param>143 /// <param name="PostData"></param>144 /// <param name="Headers"></param>145 /// <param name="Cancel"></param>146 private void beforeNavigate(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel)147 {148 if(!((String)URL).Equals("about:blank"))149 {150 navigateCounter++;151 }152 completed = false;153 }154 155 /// <summary>156 /// A Navigation Complete event occurs when the browser has finished navigating to157 /// a URL. It seems that this event is not triggered for each beforeNavigate event.158 /// It also seems that this event can be triggered more than once for each beforeNavigate159 /// event.160 /// </summary>161 /// <param name="pDisp"></param>162 /// <param name="URL">URL of the completed navigation</param>163 private void navigateComplete(object pDisp, ref object URL)164 {165 navigateCounter--;166 }167 69 } 168 70 } honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/obj/Debug/BrowserAutomation.csproj.FileListAbsolute.txt
r1699 r1733 3 3 D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\bin\Debug\Interop.SHDocVw.dll 4 4 D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\obj\Debug\ResolveAssemblyReference.cache 5 D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\obj\Debug\Interop.SHDocVw.dll6 D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\obj\Debug\BrowserAutomation.csproj.ResolveComReference.cache7 5 D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\obj\Debug\BrowserAutomation.exe 8 6 D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\obj\Debug\BrowserAutomation.pdb 7 D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\bin\Debug\WatiN.Core.dll 8 D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\bin\Debug\nunit.framework.dll 9 D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\bin\Debug\WatiN.Core.xml
