summaryrefslogtreecommitdiffstats
path: root/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm')
-rw-r--r--tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm83
1 files changed, 71 insertions, 12 deletions
diff --git a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm
index 8620b7dd2f..bc89ac858b 100644
--- a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm
+++ b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm
@@ -43,8 +43,10 @@
#define QT_NO_KEYWORDS
#include "tst_qaccessibilitymac_helpers.h"
-#include <QApplication>
-#include <QDebug>
+#include <QtWidgets/qapplication.h>
+#include <QtWidgets/qlineedit.h>
+#include <QtWidgets/qpushbutton.h>
+#include <QtTest>
#include <unistd.h>
#import <Cocoa/Cocoa.h>
@@ -148,9 +150,41 @@ bool trusted()
return p;
}
++ (TestAXObject *) getApplicationAXObject
+{
+ pid_t pid = getpid();
+ AXUIElementRef appRef = AXUIElementCreateApplication(pid);
+ TestAXObject *appObject = [[TestAXObject alloc] initWithAXUIElementRef: appRef];
+ return appObject;
+}
+
@end
+bool singleWidget()
+{
+ QLineEdit le;
+ le.setText("button");
+ le.show();
+ EXPECT(QTest::qWaitForWindowExposed(&le));
+ QCoreApplication::processEvents();
+
+ TestAXObject *appObject = [TestAXObject getApplicationAXObject];
+ EXPECT(appObject);
+
+ NSArray *windows = [appObject windowList];
+ EXPECT([windows count] == 1);
+
+ AXUIElementRef windowRef = (AXUIElementRef) [windows objectAtIndex: 0];
+ EXPECT(windowRef != nil);
+ TestAXObject *window = [[TestAXObject alloc] initWithAXUIElementRef: windowRef];
+
+ AXUIElementRef lineEdit = [window findDirectChildByRole: kAXTextFieldRole];
+ EXPECT(lineEdit != nil);
+
+ return true;
+}
+
bool testLineEdit()
{
// not sure if this is needed. on my machine the calls succeed.
@@ -159,10 +193,8 @@ bool testLineEdit()
// AXError e = AXMakeProcessTrusted((CFStringRef) path);
// NSLog(@"error: %i", e);
- pid_t pid = getpid();
- AXUIElementRef app = AXUIElementCreateApplication(pid);
- EXPECT(app != nil);
- TestAXObject *appObject = [[TestAXObject alloc] initWithAXUIElementRef: app];
+ TestAXObject *appObject = [TestAXObject getApplicationAXObject];
+ EXPECT(appObject);
NSArray *windowList = [appObject windowList];
// one window
@@ -184,12 +216,10 @@ bool testLineEdit()
return true;
}
-bool testHierarchy()
+bool testHierarchy(QWidget *w)
{
- pid_t pid = getpid();
- AXUIElementRef app = AXUIElementCreateApplication(pid);
- EXPECT(app != nil);
- TestAXObject *appObject = [[TestAXObject alloc] initWithAXUIElementRef: app];
+ TestAXObject *appObject = [TestAXObject getApplicationAXObject];
+ EXPECT(appObject);
NSArray *windowList = [appObject windowList];
// one window
@@ -207,7 +237,36 @@ bool testHierarchy()
TestAXObject *parentObject = [[TestAXObject alloc] initWithAXUIElementRef: [buttonObject parent]];
// check that the parent is a window
- EXPECT([[parentObject role] isEqualToString: (NSString *)kAXWindowRole]);
+ EXPECT([[parentObject role] isEqualToString: NSAccessibilityWindowRole]);
+
+ // test the focus
+ // child 0 is the layout, then button1 and 2
+ QPushButton *button1 = qobject_cast<QPushButton*>(w->children().at(1));
+ EXPECT(button1);
+ QPushButton *button2 = qobject_cast<QPushButton*>(w->children().at(2));
+ EXPECT(button2);
+ button2->setFocus();
+
+ AXUIElementRef systemWideElement = AXUIElementCreateSystemWide();
+ AXUIElementRef focussedElement = NULL;
+ AXError error = AXUIElementCopyAttributeValue(systemWideElement,
+ (CFStringRef)NSAccessibilityFocusedUIElementAttribute, (CFTypeRef*)&focussedElement);
+ EXPECT(!error);
+ EXPECT(focussedElement);
+ TestAXObject *focusButton2 = [[TestAXObject alloc] initWithAXUIElementRef: focussedElement];
+
+ EXPECT([[focusButton2 role] isEqualToString: NSAccessibilityButtonRole]);
+ EXPECT([[focusButton2 description] isEqualToString: @"Button 2"]);
+
+
+ button1->setFocus();
+ error = AXUIElementCopyAttributeValue(systemWideElement,
+ (CFStringRef)NSAccessibilityFocusedUIElementAttribute, (CFTypeRef*)&focussedElement);
+ EXPECT(!error);
+ EXPECT(focussedElement);
+ TestAXObject *focusButton1 = [[TestAXObject alloc] initWithAXUIElementRef: focussedElement];
+ EXPECT([[focusButton1 role] isEqualToString: NSAccessibilityButtonRole]);
+ EXPECT([[focusButton1 description] isEqualToString: @"I am a button"]);
return true;
}