public AbstractOsMappingWidget CreateSurface(SystemWindow childSystemWindow)
		{
			AbstractOsMappingWidget newSurface = new WidgetForWindowsFormsBitmap(childSystemWindow);

			((WidgetForWindowsFormsBitmap)newSurface).Init(childSystemWindow);
			return newSurface;
		}
		public void GetWidgetByNameTestNoRegionSingleWindow()
		{
			// single system window
			{
				int leftClickCount = 0;

				Action<AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
				{
					AutomationRunner testRunner = new AutomationRunner();
					testRunner.ClickByName("left");
					testRunner.Wait(.5);

					resultsHarness.AddTestResult(leftClickCount == 1, "Got left button click");
				};

				SystemWindow buttonContainer = new SystemWindow(300, 200);

				Button leftButton = new Button("left", 10, 40);
				leftButton.Name = "left";
				leftButton.Click += (sender, e) => { leftClickCount++; };
				buttonContainer.AddChild(leftButton);

				AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(buttonContainer, testToRun, 10);

				Assert.IsTrue(testHarness.AllTestsPassed);
				Assert.IsTrue(testHarness.TestCount == 1); // make sure we can all our tests
			}
		}
Esempio n. 3
0
 public WindowContentParser GetParser(SystemWindow sw)
 {
     foreach(WindowContentParser p in parsers) {
         if (p.CanParseContent(sw))
             return p;
     }
     return null;
 }
		public static AutomationTesterHarness ShowWindowAndExectueTests(SystemWindow initialSystemWindow, Action<AutomationTesterHarness> functionContainingTests, double secondsToTestFailure)
		{
			StackTrace st = new StackTrace(false);
			Console.WriteLine("\r\nRunning automation test: " + st.GetFrames().Skip(1).First().GetMethod().Name);

			AutomationTesterHarness testHarness = new AutomationTesterHarness(initialSystemWindow, functionContainingTests, secondsToTestFailure);
			return testHarness;
		}
Esempio n. 5
0
 internal AccessibleWindowContent(string name, bool hasMenu, bool hasSysMenu, bool hasClientArea, SystemWindow sw)
 {
     this.name = name;
     this.hasMenu = hasMenu;
     this.hasSysMenu = hasSysMenu;
     this.hasClientArea = hasClientArea;
     this.sw = sw;
 }
Esempio n. 6
0
		public void CreateWidgetAndRunInWindow(SystemWindow.PixelTypes bitDepth = SystemWindow.PixelTypes.Depth32, RenderSurface surfaceType = RenderSurface.Bitmap)
		{
			AppWidgetInfo appWidgetInfo = GetAppParameters();
			SystemWindow systemWindow = new SystemWindow(appWidgetInfo.width, appWidgetInfo.height);
			systemWindow.PixelType = bitDepth;
			systemWindow.Title = appWidgetInfo.title;
			if (surfaceType == RenderSurface.OpenGL)
			{
				systemWindow.UseOpenGL = true;
			}
			systemWindow.AddChild(NewWidget());
			systemWindow.ShowAsSystemWindow();
		}
		public void DoClickButtonInWindow()
		{
			int leftClickCount = 0;
			int rightClickCount = 0;

			Action<AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
			{
				AutomationRunner testRunner = new AutomationRunner();

				// Now do the actions specific to this test. (replace this for new tests)
				testRunner.ClickByName("left", 1);
				testRunner.Wait(.5);

				resultsHarness.AddTestResult(leftClickCount == 1, "Got left button click");

				testRunner.ClickByName("right", 1);
				testRunner.Wait(.5);

				resultsHarness.AddTestResult(rightClickCount == 1, "Got right button click");

				testRunner.DragDropByName("left", "right", offsetDrag: new Point2D(1, 0));
				testRunner.Wait(.5);

				resultsHarness.AddTestResult(leftClickCount == 1, "Mouse down not a click");
			};

			SystemWindow buttonContainer = new SystemWindow(300, 200);

			Button leftButton = new Button("left", 10, 40);
			leftButton.Name = "left";
			leftButton.Click += (sender, e) => { leftClickCount++; };
			buttonContainer.AddChild(leftButton);
			Button rightButton = new Button("right", 110, 40);
			rightButton.Click += (sender, e) => { rightClickCount++; };
			rightButton.Name = "right";
			buttonContainer.AddChild(rightButton);

			AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(buttonContainer, testToRun, 10);

			Assert.IsTrue(testHarness.AllTestsPassed);
			Assert.IsTrue(testHarness.TestCount == 3); // make sure we can all our tests
		}
		private AutomationTesterHarness(SystemWindow initialSystemWindow, Action<AutomationTesterHarness> functionContainingTests, double secondsToTestFailure)
		{
			bool firstDraw = true;
			initialSystemWindow.DrawAfter += (sender, e) =>
			{
				if (firstDraw)
				{
					Task.Run(() => CloseAfterTime(initialSystemWindow, secondsToTestFailure));

					firstDraw = false;
					Task.Run(() =>
					{
						functionContainingTests(this);

						initialSystemWindow.CloseOnIdle();
					});
				}
			};

			initialSystemWindow.ShowAsSystemWindow();
		}
Esempio n. 9
0
 internal override bool CanParseContent(SystemWindow sw)
 {
     return TestMenu(sw, AccessibleObjectID.OBJID_MENU) ||
         TestMenu(sw, AccessibleObjectID.OBJID_SYSMENU) ||
         TestClientArea(sw);
 }
Esempio n. 10
0
 private string ParseMenu(SystemWindow sw, AccessibleObjectID accessibleObjectID)
 {
     SystemAccessibleObject sao = SystemAccessibleObject.FromWindow(sw, accessibleObjectID);
     StringBuilder menuitems = new StringBuilder();
     ParseSubMenu(menuitems, sao, 1);
     return menuitems.ToString();
 }
Esempio n. 11
0
 private string ParseClientArea(SystemWindow sw)
 {
     SystemAccessibleObject sao = SystemAccessibleObject.FromWindow(sw, AccessibleObjectID.OBJID_CLIENT);
     StringBuilder sb = new StringBuilder();
     ParseClientAreaElement(sb, sao, 1);
     return sb.ToString();
 }
Esempio n. 12
0
 internal override WindowContent ParseContent(SystemWindow sw)
 {
     SystemAccessibleObject sao = SystemAccessibleObject.FromWindow(sw, AccessibleObjectID.OBJID_CLIENT);
     if (sao.RoleIndex == 35)
     {
         List<string> treeNodes = new List<string>();
         int selected = -1;
         foreach(SystemAccessibleObject n in sao.Children) {
             if (n.RoleIndex == 36)
             {
                 if ((n.State & 0x2) != 0)
                 {
                     selected = treeNodes.Count;
                 }
                 treeNodes.Add(ListContent.Repeat('\t', int.Parse(n.Value)) + n.Name);
             }
         }
         if (treeNodes.Count > 0)
         {
             return new ListContent("TreeView", selected, null, treeNodes.ToArray());
         }
     }
     return new ListContent("EmptyTreeView", -1, null, new string[0]);
 }
Esempio n. 13
0
 internal override bool CanParseContent(SystemWindow sw)
 {
     int cnt = sw.SendGetMessage(TVM_GETCOUNT, 0);
     return cnt != 0;
 }
 internal override WindowContent ParseContent(SystemWindow sw)
 {
     return new TextContent(sw.Title, sw.PasswordCharacter != 0, strict);
 }
Esempio n. 15
0
 private bool TestMenu(SystemWindow sw, AccessibleObjectID accessibleObjectID)
 {
     SystemAccessibleObject sao = SystemAccessibleObject.FromWindow(sw, accessibleObjectID);
     return sao.Children.Length > 0;
 }
Esempio n. 16
0
 internal override WindowContent ParseContent(SystemWindow sw)
 {
     SystemComboBox slb = SystemComboBox.FromSystemWindow(sw);
     int c = slb.Count;
     string[] values = new string[c];
     for (int i = 0; i < c; i++)
     {
         values[i] = slb[i];
     }
     return new ListContent("ComboBox", -1, sw.Title, values);
 }
		// format - see enum pix_format_e {};
		// flip_y - true if you want to have the Y-axis flipped vertically.
		public AbstractOsMappingWidget(SystemWindow childSystemWindow)
			: base(childSystemWindow.Width, childSystemWindow.Height, SizeLimitsToSet.None)
		{
			this.childSystemWindow = childSystemWindow;
		}
 internal abstract WindowContent ParseContent(SystemWindow sw);
 internal abstract bool CanParseContent(SystemWindow sw);
 internal static WindowContent Parse(SystemWindow sw)
 {
     WindowContentParser parser = ContentParserRegistry.Instance.GetParser(sw);
     if (parser == null) return null;
     return parser.ParseContent(sw);
 }
Esempio n. 21
0
 internal override WindowContent ParseContent(SystemWindow sw)
 {
     SystemAccessibleObject sao = SystemAccessibleObject.FromWindow(sw, AccessibleObjectID.OBJID_WINDOW);
     bool sysmenu = TestMenu(sw, AccessibleObjectID.OBJID_SYSMENU);
     bool menu = TestMenu(sw, AccessibleObjectID.OBJID_MENU);
     bool clientarea = TestClientArea(sw);
     return new AccessibleWindowContent(sao.Name, menu, sysmenu, clientarea, sw);
 }
Esempio n. 22
0
 private bool TestClientArea(SystemWindow sw)
 {
     try
     {
         SystemAccessibleObject sao = SystemAccessibleObject.FromWindow(sw, AccessibleObjectID.OBJID_CLIENT);
         foreach (SystemAccessibleObject c in sao.Children)
         {
             if (c.Window == sw) return true;
         }
     }
     catch (COMException) { }
     return false;
 }
Esempio n. 23
0
 public SpSystemWindow(SystemWindow window)
 {
     Window = window;
 }
Esempio n. 24
0
 internal override bool CanParseContent(SystemWindow sw)
 {
     return SystemListBox.FromSystemWindow(sw) != null;
 }
 internal override bool CanParseContent(SystemWindow sw)
 {
     if (strict)
     {
         uint EM_GETLINECOUNT = 0xBA;
         return sw.SendGetMessage(EM_GETLINECOUNT) != 0;
     }
     else
     {
         return sw.Title != "";
     }
 }
Esempio n. 26
0
		public static AutomationTesterHarness ShowWindowAndExectueTests(SystemWindow initialSystemWindow, Action<AutomationTesterHarness> functionContainingTests, double secondsToTestFailure)
		{
			AutomationTesterHarness testHarness = new AutomationTesterHarness(initialSystemWindow, functionContainingTests, secondsToTestFailure);
			return testHarness;
		}
Esempio n. 27
0
 internal override WindowContent ParseContent(SystemWindow sw)
 {
     SystemListBox slb = SystemListBox.FromSystemWindow(sw);
     int c = slb.Count;
     string[] values = new string[c];
     for (int i = 0; i < c; i++)
     {
         values[i] = slb[i];
     }
     return new ListContent("ListBox", slb.SelectedIndex, slb.SelectedItem, values);
 }
Esempio n. 28
0
		public static void CloseAfterTime(SystemWindow windowToClose, double timeInSeconds)
		{
			Thread.Sleep((int)(timeInSeconds * 1000));
			windowToClose.CloseOnIdle();
		}
Esempio n. 29
0
 internal override bool CanParseContent(SystemWindow sw)
 {
     uint LVM_GETITEMCOUNT = (0x1000 + 4);
     int cnt = sw.SendGetMessage(LVM_GETITEMCOUNT);
     return cnt != 0;
 }
Esempio n. 30
0
 internal override WindowContent ParseContent(SystemWindow sw)
 {
     uint LVM_GETITEMCOUNT = (0x1000 + 4);
     int cnt = sw.SendGetMessage(LVM_GETITEMCOUNT);
     if (cnt == 0) throw new Exception();
     SystemAccessibleObject o = SystemAccessibleObject.FromWindow(sw, AccessibleObjectID.OBJID_CLIENT);
     if (o.RoleIndex == 33)
     {
         // are there column headers?
         int cs = o.Children.Length;
         string[] hdr = null;
         if (cs > 0)
         {
             SystemAccessibleObject headers = o.Children[cs - 1];
             if (headers.RoleIndex == 9 && headers.Window != sw)
             {
                 SystemAccessibleObject hdrL = SystemAccessibleObject.FromWindow(headers.Window, AccessibleObjectID.OBJID_CLIENT);
                 hdr = new string[hdrL.Children.Length];
                 for (int i = 0; i < hdr.Length; i++)
                 {
                     if (hdrL.Children[i].RoleIndex != 25)
                     {
                         hdr = null;
                         break;
                     }
                     hdr[i] = hdrL.Children[i].Name;
                 }
                 if (hdr != null)
                 {
                     cs--;
                 }
             }
         }
         List<string> values = new List<string>();
         for (int i = 0; i < cs; i++)
         {
             if (o.Children[i].RoleIndex == 34)
             {
                 string name = o.Children[i].Name;
                 if (hdr != null)
                 {
                     try
                     {
                         string cols = o.Children[i].Description;
                         if (cols == null && values.Count == 0) { hdr = null; }
                         else
                         {
                             string tmpCols = "; " + cols;
                             List<string> usedHdr = new List<string>();
                             foreach (string header in hdr)
                             {
                                 string h = "; " + header + ": ";
                                 if (tmpCols.Contains(h))
                                 {
                                     usedHdr.Add(header);
                                     tmpCols = tmpCols.Substring(tmpCols.IndexOf(h) + h.Length);
                                 }
                             }
                             foreach (string header in hdr)
                             {
                                 name += "\t";
                                 if (usedHdr.Count > 0 && usedHdr[0] == header)
                                 {
                                     if (!cols.StartsWith(header + ": "))
                                         throw new Exception();
                                     cols = cols.Substring(header.Length + 1);
                                     string elem;
                                     if (usedHdr.Count > 1)
                                     {
                                         int pos = cols.IndexOf("; " + usedHdr[1] + ": ");
                                         elem = cols.Substring(0, pos);
                                         cols = cols.Substring(pos + 2);
                                     }
                                     else
                                     {
                                         elem = cols;
                                         cols = "";
                                     }
                                     name += elem;
                                     usedHdr.RemoveAt(0);
                                 }
                             }
                         }
                     }
                     catch (COMException ex)
                     {
                         if (ex.ErrorCode == -2147352573 && values.Count == 0)
                         {
                             hdr = null;
                         }
                         else
                         {
                             throw ex;
                         }
                     }
                 }
                 values.Add(name);
             }
         }
         if (hdr != null)
         {
             string lines = "", headers = "";
             foreach (string h in hdr)
             {
                 if (lines.Length > 0) lines += "\t";
                 if (headers.Length > 0) headers += "\t";
                 headers += h;
                 lines += ListContent.Repeat('~', h.Length);
             }
             values.Insert(0, lines);
             values.Insert(0, headers);
             return new ListContent("DetailsListView", -1, null, values.ToArray());
         }
         else
         {
             return new ListContent("ListView", -1, null, values.ToArray());
         }
     }
     else
     {
         return new ListContent("EmptyListView", -1, null, new string[0]);
     }
 }
Esempio n. 31
0
        public static void ResetKeyState(SystemWindow targetWindow, params Keys[] keys)
        {
            if (keys == null || keys.Length == 0)
            {
                return;
            }

            var shieldWindow               = new NativeWindow();
            List <KeyboardKey> keyList     = new List <KeyboardKey>(keys.Select(k => new KeyboardKey(k)));
            List <KeyboardKey> failureList = new List <KeyboardKey>(keyList);

            try
            {
                shieldWindow.CreateHandle(new CreateParams()
                {
                    ExStyle = (int)(WindowExStyleFlags.TOOLWINDOW | WindowExStyleFlags.LAYERED)
                });

                InputSimulator simulator = new InputSimulator();
                SystemWindow.ForegroundWindow = new SystemWindow(shieldWindow.Handle)
                {
                    WindowState = FormWindowState.Normal
                };

                for (int i = 0; i < keys.Length; i++)
                {
                    if (!Enum.IsDefined(typeof(VirtualKeyCode), keys[i].GetHashCode()))
                    {
                        continue;
                    }
                    simulator.Keyboard.KeyUp((VirtualKeyCode)keys[i]).Sleep(10);

                    if (keyList[i].IsGloballyPressed)
                    {
                        keyList[i].Release();
                        Thread.Sleep(10);
                        if (!keyList[i].IsGloballyPressed)
                        {
                            failureList.Remove(keyList[i]);
                        }
                    }
                    else
                    {
                        failureList.Remove(keyList[i]);
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                SystemWindow.ForegroundWindow = targetWindow;
                shieldWindow.DestroyHandle();

                string keysName = null;
                foreach (var k in keyList)
                {
                    if (keysName == null)
                    {
                        keysName = k.KeyName;
                    }
                    else
                    {
                        keysName = keysName + " + " + k.KeyName;
                    }
                }
                string failurekeysName = null;
                foreach (var k in failureList)
                {
                    if (failurekeysName == null)
                    {
                        failurekeysName = k.KeyName;
                    }
                    else
                    {
                        failurekeysName = failurekeysName + " + " + k.KeyName;
                    }
                }
                string message = string.Format(LocalizationProvider.Instance.GetTextValue("CorePlugins.HotKey.FailureMessage"), keysName);
                if (failurekeysName != null)
                {
                    message += "\r\n" + string.Format(LocalizationProvider.Instance.GetTextValue("CorePlugins.HotKey.ResetFailure"), failurekeysName);
                }

                MessageBox.Show(message, LocalizationProvider.Instance.GetTextValue("Messages.Error"),
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
            }
        }