/// <summary> /// Determines the result of a Simian sensation. /// Problems with sensors are not generally logged /// since they are frequently called and most are not /// fatal. /// </summary> /// <param name="sensorRef">A sensor expression in a rule.</param> /// <returns>true if the sensor detected its target.</returns> public bool sensation(EmptyElement sensorRef) { if (sensorRef.getName().Equals("window")) { // is the window showing? string id = sensorRef.getValue("id"); // a VarNode string title = sensorRef.getValue("title"); MarkedNode mn = null; if (Utilities.isGoodStr(id) && Utilities.isGoodStr(title)) { // fetch the title from the model node via id + title mn = m_varNodes.get(id); // bail out if id not defined yet. if (mn == null) return false; if (mn.node != null) title = m_GuiModel.selectToString(mn.node, title, "title"); if (!Utilities.isGoodStr(title)) return false; } else if (id == null && title == null) { // get the main window title from the model title = m_Config.getDataBase()+m_GuiModel.getTitle(); } if (title == null) return false; // model lacks title if (Utilities.isGoodStr(title)) { IntPtr winHand = FindWindow(null, title); if ((int)winHand != 0) { AccessibilityHelper ah = new AccessibilityHelper(winHand); // look for a titlebar GuiPath gPath = new GuiPath("1:NAMELESS"); AccessibilityHelper tah = ah.SearchPath(gPath, this); if (tah == null || !tah.Value.Equals(title)) return false; m_ah = ah; return true; } } } if (sensorRef.getName().Equals("tested")) { string id = sensorRef.getValue("id"); // which controls string control = sensorRef.getValue("control"); // which controls string count = sensorRef.getValue("count"); // indicates how many if (control != null && count == null) return false; if (control == null && count != null) return false; if (control == null && count == null && id == null) return false; if (id != null) { MarkedNode mn = m_varNodes.get(id); if (mn != null) { if (mn.mark == null) return false; return mn.mark.Equals("tested"); } } // if id fails to return a marked node, try a control count if (control != null) { int n = 0; int k = 0; if (control.Equals("view")) { if (m_views == null) m_views = new MarkedList(m_GuiModel, "//*[@role='view']"); n = m_views.Count(); k = m_views.Count("tested"); } if (count.Equals("all") && n == k) return true; if (count.Equals("not-all") && k < n) return true; return false; } return false; } if (sensorRef.getName().Equals("glimpse")) { string id = sensorRef.getValue("id"); // a VarNode string appPath = sensorRef.getValue("on"); // an appPath string guiPath = sensorRef.getValue("at"); // a giuPath string property = sensorRef.getValue("prop"); // an ah property string expect = sensorRef.getValue("expect"); // value expected // Id provides a context ah that must be used to find the rest of the path! // can't just use the appPath from it. What if it's a dialog? XmlNode context = null; MarkedNode mn = null; if (Utilities.isGoodStr(id)) { mn = m_varNodes.get(id); // bail out if id not defined yet. if (mn == null) return false; if (mn.node != null) context = mn.node; } return glimpse(context, appPath, guiPath, property, expect); } return false; }
/// <summary> /// ValueOrChild determines if the ah's value should be macthed or /// if a child should be matched. /// </summary> /// <param name="nextGP">The next path step beyond this ah</param> /// <param name="ah">The accessibility object currently considered</param> /// <param name="visitor">null or the object providing methods that are called when steps are found.</param> /// <returns>An AccessibilityHelper if checking for a value, otherwise null</returns> public AccessibilityHelper ValueOrChild(GuiPath nextGP, AccessibilityHelper ah, IPathVisitor visitor) { bool result = false; if (nextGP.Role == AccessibleRole.Alert) { // check if the name is a regular expression if (nextGP.Name != null && nextGP.Name.StartsWith("rexp#")) { Regex rx = new Regex(nextGP.Name.Substring(5)); result = rx.IsMatch(ah.Value); Log log = Log.getOnly(); log.writeElt("ValueOrChild"); log.writeAttr("pattern", nextGP.Name.Substring(5)); log.writeAttr("to", ah.Value); log.writeAttr("result", result.ToString()); log.endElt(); } else result = nextGP.Name == ah.Value; // match the value to the next path's name if (!result) { // it didn't match, so the search failed if (visitor != null) visitor.notFound(nextGP); return null; } } if (result) return ah; return ah.SearchPath(nextGP, visitor); // continue on the path }