OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 namespace UnitTests |
| 6 { |
| 7 using System; |
| 8 |
| 9 using EnvDTE; |
| 10 using EnvDTE80; |
| 11 using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 12 |
| 13 using NativeClientVSAddIn; |
| 14 |
| 15 /// <summary> |
| 16 /// This is a test class for WebServerTest and is intended |
| 17 /// to contain all WebServer Unit Tests |
| 18 /// </summary> |
| 19 [TestClass] |
| 20 public class WebServerTest |
| 21 { |
| 22 /// <summary> |
| 23 /// The main visual studio object. |
| 24 /// </summary> |
| 25 private DTE2 dte_; |
| 26 |
| 27 /// <summary> |
| 28 /// Gets or sets the test context which provides |
| 29 /// information about and functionality for the current test run. |
| 30 /// </summary> |
| 31 public TestContext TestContext { get; set; } |
| 32 |
| 33 /// <summary> |
| 34 /// This is run before each test to create test resources. |
| 35 /// </summary> |
| 36 [TestInitialize] |
| 37 public void TestSetup() |
| 38 { |
| 39 dte_ = TestUtilities.StartVisualStudioInstance(); |
| 40 try |
| 41 { |
| 42 TestUtilities.AssertAddinLoaded(dte_, NativeClientVSAddIn.Strings.AddInN
ame); |
| 43 } |
| 44 catch |
| 45 { |
| 46 TestUtilities.CleanUpVisualStudioInstance(dte_); |
| 47 throw; |
| 48 } |
| 49 } |
| 50 |
| 51 /// <summary> |
| 52 /// This is run after each test to clean up things created in TestSetup(). |
| 53 /// </summary> |
| 54 [TestCleanup] |
| 55 public void TestCleanup() |
| 56 { |
| 57 TestUtilities.CleanUpVisualStudioInstance(dte_); |
| 58 } |
| 59 |
| 60 /// <summary> |
| 61 /// A test for WebServer Constructor. Starts the web server. |
| 62 /// </summary> |
| 63 [TestMethod] |
| 64 public void WebServerConstructorTest() |
| 65 { |
| 66 OutputWindowPane outputWindowPane = dte_.ToolWindows.OutputWindow.OutputWi
ndowPanes.Add( |
| 67 Strings.WebServerOutputWindowTitle); |
| 68 |
| 69 // Set up mock property manager to return the desired property values. |
| 70 MockPropertyManager properties = new MockPropertyManager( |
| 71 PropertyManager.ProjectPlatformType.Pepper, |
| 72 delegate(string page, string name) |
| 73 { |
| 74 switch (page) |
| 75 { |
| 76 case "ConfigurationGeneral": |
| 77 switch (name) |
| 78 { |
| 79 case "VSNaClSDKRoot": return System.Environment.GetEnvironmentVa
riable( |
| 80 NativeClientVSAddIn.Strings.SDKPathEnvironmentVariable); |
| 81 case "NaClWebServerPort": return "5105"; |
| 82 } |
| 83 |
| 84 break; |
| 85 case "Property": |
| 86 switch (name) |
| 87 { |
| 88 case "ProjectDirectory": return TestContext.DeploymentDirectory; |
| 89 } |
| 90 |
| 91 break; |
| 92 } |
| 93 |
| 94 return null; |
| 95 }, |
| 96 null); |
| 97 |
| 98 WebServer target = null; |
| 99 try |
| 100 { |
| 101 target = new WebServer(outputWindowPane, properties); |
| 102 |
| 103 TestUtilities.AssertTrueWithTimeout( |
| 104 () => !string.IsNullOrEmpty(TestUtilities.GetPaneText(outputWindowPane
)), |
| 105 TimeSpan.FromMilliseconds(500), |
| 106 20, |
| 107 "Pane text never appeared"); |
| 108 |
| 109 TestUtilities.AssertTrueWithTimeout( |
| 110 () => TestUtilities.DoesProcessExist("python.exe", "5105", "httpd.py
"), |
| 111 TimeSpan.FromMilliseconds(500), |
| 112 20, |
| 113 "Web server failed to start."); |
| 114 |
| 115 target.Dispose(); |
| 116 |
| 117 TestUtilities.AssertTrueWithTimeout( |
| 118 () => !TestUtilities.DoesProcessExist("python.exe", "5105", "httpd.p
y"), |
| 119 TimeSpan.FromMilliseconds(500), |
| 120 20, |
| 121 "Web server failed to shut down."); |
| 122 } |
| 123 finally |
| 124 { |
| 125 if (target != null) |
| 126 { |
| 127 target.Dispose(); |
| 128 } |
| 129 } |
| 130 } |
| 131 } |
| 132 } |
OLD | NEW |