Bug 1416893 - Added getConsumers method to nsIAccessibilityService. r=surkov

MozReview-Commit-ID: EoBdYSxqEGz
This commit is contained in:
Yura Zenevich 2017-11-13 16:36:37 -05:00
parent 16b17057eb
commit 3898a0e472
6 changed files with 50 additions and 9 deletions

View File

@ -1876,6 +1876,19 @@ nsAccessibilityService::UnsetConsumers(uint32_t aConsumers) {
NotifyOfConsumersChange();
}
void
nsAccessibilityService::GetConsumers(nsAString& aString)
{
const char16_t* kJSONFmt =
u"{ \"XPCOM\": %s, \"MainProcess\": %s, \"PlatformAPI\": %s }";
nsString json;
nsTextFormatter::ssprintf(json, kJSONFmt,
gConsumers & eXPCOM ? "true" : "false",
gConsumers & eMainProcess ? "true" : "false",
gConsumers & ePlatformAPI ? "true" : "false");
aString.Assign(json);
}
void
nsAccessibilityService::NotifyOfConsumersChange()
{
@ -1886,15 +1899,10 @@ nsAccessibilityService::NotifyOfConsumersChange()
return;
}
const char16_t* kJSONFmt =
u"{ \"XPCOM\": %s, \"MainProcess\": %s, \"PlatformAPI\": %s }";
nsString json;
nsTextFormatter::ssprintf(json, kJSONFmt,
gConsumers & eXPCOM ? "true" : "false",
gConsumers & eMainProcess ? "true" : "false",
gConsumers & ePlatformAPI ? "true" : "false");
nsAutoString consumers;
GetConsumers(consumers);
observerService->NotifyObservers(
nullptr, "a11y-consumers-changed", json.get());
nullptr, "a11y-consumers-changed", consumers.get());
}
nsAccessibilityService*

View File

@ -309,6 +309,11 @@ private:
*/
void NotifyOfConsumersChange();
/**
* Get a JSON string representing the accessibility service consumers.
*/
void GetConsumers(nsAString& aString);
/**
* Set accessibility service consumers.
*/

View File

@ -16,7 +16,7 @@ interface nsIAccessiblePivot;
* nsIAccessible for a given DOM node. More documentation at:
* http://www.mozilla.org/projects/ui/accessibility
*/
[scriptable, builtinclass, uuid(9a6f80fe-25cc-405c-9f8f-25869bc9f94e)]
[scriptable, builtinclass, uuid(2188e3a0-c88e-11e7-8f1a-0800200c9a66)]
interface nsIAccessibilityService : nsISupports
{
/**
@ -97,4 +97,10 @@ interface nsIAccessibilityService : nsISupports
* Return true if the given module is logged.
*/
boolean isLogged(in AString aModule);
/**
* Get the current accessibility service consumers.
* @returns a JSON string representing the accessibility service consumers.
*/
AString getConsumers();
};

View File

@ -39,6 +39,10 @@ add_task(async function() {
XPCOM: false, MainProcess: true, PlatformAPI: false
}, "Accessibility service consumers in content are correct."));
Assert.deepEqual(JSON.parse(accService.getConsumers()), {
XPCOM: true, MainProcess: false, PlatformAPI: false
}, "Accessibility service consumers in parent are correct.");
info("Removing a service in parent and waiting for service to be shut " +
"down in content");
// Remove a11y service reference in the main process.

View File

@ -47,6 +47,12 @@ add_task(async function() {
XPCOM: true, MainProcess: true, PlatformAPI: false
}, "Accessibility service consumers in content are correct."));
const contentConsumers = await ContentTask.spawn(browser, {}, () =>
accService.getConsumers());
Assert.deepEqual(JSON.parse(contentConsumers), {
XPCOM: true, MainProcess: true, PlatformAPI: false
}, "Accessibility service consumers in parent are correct.");
info("Shutting down a service in parent and making sure the one in " +
"content stays alive");
let contentCanShutdown = false;

View File

@ -258,6 +258,18 @@ xpcAccessibilityService::IsLogged(const nsAString& aModule, bool* aIsLogged)
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibilityService::GetConsumers(nsAString& aString)
{
nsAccessibilityService* accService = GetAccService();
if (!accService) {
return NS_ERROR_SERVICE_NOT_AVAILABLE;
}
accService->GetConsumers(aString);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// NS_GetAccessibilityService
////////////////////////////////////////////////////////////////////////////////