From 4607cc9b3a899cc792ba9af6eb8e16495645c617 Mon Sep 17 00:00:00 2001 From: Mike Gorse Date: Tue, 20 Apr 2010 21:54:24 +0000 Subject: [PATCH] Do not trust StateSet cache for StateType.Enabled (bug 596801) Also fix NRE in GetText in the test app. svn path=/trunk/at-spi-sharp/; revision=155839 --- at-spi/Accessible.cs | 4 ++-- at-spi/ChangeLog | 5 +++++ at-spi/StateSet.cs | 17 ++++++++++++++++- tests/ChangeLog | 6 ++++++ tests/apps/Document.cs | 6 +++++- tests/at-spi-sharp/AccessibleTest.cs | 10 ++++++++++ 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/at-spi/Accessible.cs b/at-spi/Accessible.cs index 8b280da..be9917a 100644 --- a/at-spi/Accessible.cs +++ b/at-spi/Accessible.cs @@ -259,7 +259,7 @@ namespace Atspi foreach (string iface in e.interfaces) AddInterface (iface); - stateSet = new StateSet (e.states); + stateSet = new StateSet (this, e.states); // Using at-spi StateChanged events to broadcast // changes for now; needed for gail Focused handling UpdateChildren (e.children); @@ -432,7 +432,7 @@ namespace Atspi stateSet.Add (StateType.Defunct); return stateSet; } - stateSet = new StateSet (states); + stateSet = new StateSet (this, states); } return stateSet; } diff --git a/at-spi/ChangeLog b/at-spi/ChangeLog index 31b8ffd..85727f8 100644 --- a/at-spi/ChangeLog +++ b/at-spi/ChangeLog @@ -1,3 +1,8 @@ +2010-04-20 Mike Gorse + + * Accessible.cs, StateSet.cs: Make StateSet cache its accessible and + do not trust cache for StateType.Enabled (bug 596801) + 2010-03-17 Mike Gorse * Accessible.cs: Recognize Application interface, and warn rather diff --git a/at-spi/StateSet.cs b/at-spi/StateSet.cs index 49acfe5..da24bbd 100644 --- a/at-spi/StateSet.cs +++ b/at-spi/StateSet.cs @@ -33,14 +33,17 @@ namespace Atspi public class StateSet { private ulong states; + private Accessible accessible; public StateSet () { + accessible = null; states = 0; } - public StateSet (uint [] states) + public StateSet (Accessible accessible, uint [] states) { + this.accessible = accessible; if (states.Length != 2) throw new ArgumentException ("Expecting int [2]"); this.states = (ulong)(states [1] << (sizeof (int) * 8)) | (ulong)states [0]; @@ -48,12 +51,24 @@ namespace Atspi public bool Contains (StateType state) { + // Do not trust cache for Enabled; see BNC#596801 + // TODO: Eventually remove this work-around + if (accessible != null && state == StateType.Enabled && (states & (ulong)StateType.Defunct) == 0) { + try { + uint [] data = accessible.proxy.GetState (); + states = (ulong)(data [1] << (sizeof (int) * 8)) | (ulong)data [0]; + } catch (System.Exception) { + return false; + } + } return (states & (ulong)state) != 0? true: false; } public void Add (StateType state) { states |= (ulong)state; + if (state == StateType.Defunct) + accessible = null; } public void Remove (StateType state) diff --git a/tests/ChangeLog b/tests/ChangeLog index 2647489..a4770ad 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +2010-04-20 Mike Gorse + + * apps/Document.cs: Fix NRE in GetText. + + * at-spi-sharp/AccessibleTest.cs: Add test for bug 596801. + 2010-03-01 Mike Gorse * at-spi-sharp/Base.cs: Allow a fixture to open multiple apps. diff --git a/tests/apps/Document.cs b/tests/apps/Document.cs index 329d10c..e944201 100644 --- a/tests/apps/Document.cs +++ b/tests/apps/Document.cs @@ -245,7 +245,11 @@ namespace TestDocument { if (end_offset == -1) end_offset = text.Length - start_offset; - return text.Substring (start_offset, end_offset); + if (end_offset > text.Length) + end_offset = text.Length; + if (end_offset < start_offset) + end_offset = start_offset; + return text.Substring (start_offset, end_offset - start_offset); } public string GetTextAfterOffset (int offset, Atk.TextBoundary boundary_type, out int start_offset, out int end_offset) diff --git a/tests/at-spi-sharp/AccessibleTest.cs b/tests/at-spi-sharp/AccessibleTest.cs index e1020f6..bf5dbc1 100644 --- a/tests/at-spi-sharp/AccessibleTest.cs +++ b/tests/at-spi-sharp/AccessibleTest.cs @@ -60,6 +60,16 @@ namespace AtSpiTest ); } + [Test] + public void Bug596801 () + { + EditableText et = documentFrame.QueryEditableText (); + Accessible child = documentFrame.Children [0].Children [0]; + Assert.IsTrue (child.StateSet.Contains (StateType.Enabled), "Enabled"); + et.SetTextContents ("StateChanged"); + Assert.IsFalse (child.StateSet.Contains (StateType.Enabled), "Not enabled after disabling"); + } + [Test] public void Relations () {