From 76c94be4e77bfef6ee3642cb175ff34ba6c694db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Boris=20Du=C5=A1ek?= Date: Tue, 17 Mar 2015 23:10:07 +0100 Subject: OS X Accessibility: Make checkboxes etc. checkable with VoiceOver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NSAccessibility has no explicit analog for QAccessibleActionInterface::toggleAction(), checking checkboxes/radio buttons is handled by NSAccessibilityPressAction. So ensure exposing the action properly on OS X so that VoiceOver users can check/uncheck checkboxes, select radio buttons etc. Change-Id: Idc8b048de2313a3e875a929516baf3dded9c68cc Task-number: QTBUG-44852 Reviewed-by: Jan Arve Sæther --- .../qaccessibilitymac/tst_qaccessibilitymac.cpp | 15 ++++++ .../tst_qaccessibilitymac_helpers.h | 1 + .../tst_qaccessibilitymac_helpers.mm | 59 ++++++++++++++++++++++ 3 files changed, 75 insertions(+) (limited to 'tests') diff --git a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.cpp b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.cpp index 8e439a61cf..92af5a0757 100644 --- a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.cpp +++ b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.cpp @@ -75,6 +75,7 @@ private slots: void lineEditTest(); void hierarchyTest(); void notificationsTest(); + void checkBoxTest(); private: AccessibleTestWindow *m_window; @@ -151,5 +152,19 @@ void tst_QAccessibilityMac::notificationsTest() QVERIFY(notifications(m_window)); } +void tst_QAccessibilityMac::checkBoxTest() +{ + if (!macNativeAccessibilityEnabled()) + return; + + QCheckBox *cb = new QCheckBox(m_window); + cb->setText("Great option"); + m_window->addWidget(cb); + QVERIFY(QTest::qWaitForWindowExposed(m_window)); + QCoreApplication::processEvents(); + + QVERIFY(testCheckBox()); +} + QTEST_MAIN(tst_QAccessibilityMac) #include "tst_qaccessibilitymac.moc" diff --git a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.h b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.h index 78615fa9cd..cdf12489a6 100644 --- a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.h +++ b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.h @@ -44,3 +44,4 @@ bool testLineEdit(); bool testHierarchy(QWidget *w); bool singleWidget(); bool notifications(QWidget *w); +bool testCheckBox(); diff --git a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm index a182fc27d5..d0ff6af640 100644 --- a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm +++ b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm @@ -114,6 +114,7 @@ QDebug operator<<(QDebug dbg, AXErrorTag err) @property (readonly) NSString *description; @property (readonly) NSString *value; @property (readonly) CGRect rect; + @property (readonly) NSArray *actions; @end @implementation TestAXObject @@ -329,10 +330,34 @@ QDebug operator<<(QDebug dbg, AXErrorTag err) return value; } +- (NSArray*)actions +{ + AXError err; + CFArrayRef actions; + + if (kAXErrorSuccess != (err = AXUIElementCopyActionNames(reference, &actions))) + { + qDebug() << "AXUIElementCopyActionNames(...) returned error = " << AXErrorTag(err); + } + + return (NSArray*)actions; +} + +- (void)performAction:(CFStringRef)action +{ + AXError err; + + if (kAXErrorSuccess != (err = AXUIElementPerformAction(reference, action))) + { + qDebug() << "AXUIElementPerformAction(" << QString::fromCFString(action) << ") returned error = " << AXErrorTag(err); + } +} + - (NSString*) role { return [self _stringAttributeValue:kAXRoleAttribute]; } - (NSString*) title { return [self _stringAttributeValue:kAXTitleAttribute]; } - (NSString*) description { return [self _stringAttributeValue:kAXDescriptionAttribute]; } - (NSString*) value { return [self _stringAttributeValue:kAXValueAttribute]; } +- (NSInteger) valueNumber { return [self _numberAttributeValue:kAXValueAttribute]; } - (NSRect) rect { NSRect rect; @@ -563,3 +588,37 @@ bool notifications(QWidget *w) return true; } + +bool testCheckBox() +{ + TestAXObject *appObject = [TestAXObject getApplicationAXObject]; + EXPECT(appObject); + + NSArray *windowList = [appObject windowList]; + // one window + EXPECT([windowList count] == 1); + AXUIElementRef windowRef = (AXUIElementRef) [windowList objectAtIndex: 0]; + EXPECT(windowRef != nil); + TestAXObject *window = [[TestAXObject alloc] initWithAXUIElementRef: windowRef]; + + // children of window: + AXUIElementRef checkBox = [window findDirectChildByRole: kAXCheckBoxRole]; + EXPECT(checkBox != nil); + + TestAXObject *cb = [[TestAXObject alloc] initWithAXUIElementRef: checkBox]; + + // here start actual checkbox tests + EXPECT([cb valueNumber] == 0); + EXPECT([cb.title isEqualToString:@"Great option"]); + // EXPECT(cb.description == nil); // currently returns "" instead of nil + + EXPECT([cb.actions containsObject:(NSString*)kAXPressAction]); + + [cb performAction:kAXPressAction]; + EXPECT([cb valueNumber] == 1); + + [cb performAction:kAXPressAction]; + EXPECT([cb valueNumber] == 0); + + return true; +} -- cgit v1.2.3