diff options
Diffstat (limited to 'tests/auto/other')
3 files changed, 75 insertions, 0 deletions
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; +} |