Bug 1729061 - Introduce cache verification logging. r=Jamie

Differential Revision: https://phabricator.services.mozilla.com/D124486
This commit is contained in:
Eitan Isaacson 2021-09-27 18:46:20 +00:00
parent f287b980e0
commit a5dc06abb2
9 changed files with 109 additions and 11 deletions

View file

@ -63,7 +63,8 @@ static ModuleRep sModuleMap[] = {{"docload", logging::eDocLoad},
{"notifications", logging::eNotifications},
{"stack", logging::eStack},
{"verbose", logging::eVerbose}};
{"verbose", logging::eVerbose},
{"cache", logging::eCache}};
static void EnableLogging(const char* aModulesStr) {
sModules = 0;

View file

@ -52,7 +52,8 @@ enum EModules {
// extras
eStack = 1 << 12,
eVerbose = 1 << 13
eVerbose = 1 << 13,
eCache = 1 << 14,
};
/**

View file

@ -10,6 +10,9 @@
#include "mozilla/StaticPrefs_accessibility.h"
#include "LocalAccessible-inl.h"
#ifdef A11Y_LOG
# include "Logging.h"
#endif
namespace mozilla {
namespace a11y {
@ -97,5 +100,70 @@ void DocAccessibleChildBase::ShowEvent(AccShowEvent* aShowEvent) {
false);
}
mozilla::ipc::IPCResult DocAccessibleChildBase::RecvVerifyCache(
const uint64_t& aID, const uint64_t& aCacheDomain, AccAttributes* aFields) {
#ifdef A11Y_LOG
LocalAccessible* acc = IdToAccessible(aID);
if (!acc) {
return IPC_OK();
}
RefPtr<AccAttributes> localFields =
acc->BundleFieldsForCache(aCacheDomain, CacheUpdateType::Update);
bool mismatches = false;
for (auto prop : *localFields) {
if (prop.Value<DeleteEntry>()) {
if (aFields->HasAttribute(prop.Name())) {
if (!mismatches) {
logging::MsgBegin("Mismatch!", "Local and remote values differ");
logging::AccessibleInfo("", acc);
mismatches = true;
}
nsAutoCString propName;
prop.Name()->ToUTF8String(propName);
nsAutoString val;
aFields->GetAttribute(prop.Name(), val);
logging::MsgEntry(
"Remote value for %s should be empty, but instead it is '%s'",
propName.get(), NS_ConvertUTF16toUTF8(val).get());
}
continue;
}
nsAutoString localVal;
prop.ValueAsString(localVal);
nsAutoString remoteVal;
aFields->GetAttribute(prop.Name(), remoteVal);
if (!localVal.Equals(remoteVal)) {
if (!mismatches) {
logging::MsgBegin("Mismatch!", "");
logging::AccessibleInfo("", acc);
mismatches = true;
}
nsAutoCString propName;
prop.Name()->ToUTF8String(propName);
logging::MsgEntry("Fields differ: %s '%s' != '%s'", propName.get(),
NS_ConvertUTF16toUTF8(remoteVal).get(),
NS_ConvertUTF16toUTF8(localVal).get());
}
}
if (mismatches) {
logging::MsgEnd();
}
#endif // A11Y_LOG
return IPC_OK();
}
LocalAccessible* DocAccessibleChildBase::IdToAccessible(
const uint64_t& aID) const {
if (!aID) return mDoc;
if (!mDoc) return nullptr;
return mDoc->GetAccessibleByUniqueID(reinterpret_cast<void*>(aID));
}
} // namespace a11y
} // namespace mozilla

View file

@ -57,6 +57,10 @@ class DocAccessibleChildBase : public PDocAccessibleChild {
mDoc = nullptr;
}
virtual mozilla::ipc::IPCResult RecvVerifyCache(
const uint64_t& aID, const uint64_t& aCacheDomain,
AccAttributes* aFields) override;
protected:
static void FlattenTree(LocalAccessible* aRoot,
nsTArray<LocalAccessible*>& aTree);
@ -78,6 +82,8 @@ class DocAccessibleChildBase : public PDocAccessibleChild {
bool IsConstructedInParentProcess() const { return mIsRemoteConstructed; }
void SetConstructedInParentProcess() { mIsRemoteConstructed = true; }
LocalAccessible* IdToAccessible(const uint64_t& aID) const;
DocAccessible* mDoc;
bool mIsRemoteConstructed;

View file

@ -17,6 +17,19 @@
#include "RelationType.h"
#include "xpcAccessibleDocument.h"
#ifdef A11Y_LOG
# include "Logging.h"
# define VERIFY_CACHE(domain) \
if (logging::IsEnabled(logging::eCache)) { \
Unused << mDoc->SendVerifyCache(mID, domain, mCachedFields); \
}
#else
# define VERIFY_CACHE(domain) \
do { \
} while (0)
#endif
namespace mozilla {
namespace a11y {
@ -169,6 +182,7 @@ ENameValueFlag RemoteAccessibleBase<Derived>::Name(nsString& aName) const {
if (mCachedFields && mCachedFields->GetAttribute(nsGkAtoms::name, aName)) {
auto nameFlag =
mCachedFields->GetAttribute<int32_t>(nsGkAtoms::explicit_name);
VERIFY_CACHE(CacheDomain::NameAndDescription);
return nameFlag ? static_cast<ENameValueFlag>(*nameFlag) : eNameOK;
}
@ -179,12 +193,14 @@ template <class Derived>
void RemoteAccessibleBase<Derived>::Description(nsString& aDescription) const {
if (mCachedFields) {
mCachedFields->GetAttribute(nsGkAtoms::description, aDescription);
VERIFY_CACHE(CacheDomain::NameAndDescription);
}
}
template <class Derived>
double RemoteAccessibleBase<Derived>::CurValue() const {
if (auto value = mCachedFields->GetAttribute<double>(nsGkAtoms::value)) {
VERIFY_CACHE(CacheDomain::Value);
return *value;
}
@ -194,6 +210,7 @@ double RemoteAccessibleBase<Derived>::CurValue() const {
template <class Derived>
double RemoteAccessibleBase<Derived>::MinValue() const {
if (auto min = mCachedFields->GetAttribute<double>(nsGkAtoms::min)) {
VERIFY_CACHE(CacheDomain::Value);
return *min;
}
@ -203,6 +220,7 @@ double RemoteAccessibleBase<Derived>::MinValue() const {
template <class Derived>
double RemoteAccessibleBase<Derived>::MaxValue() const {
if (auto max = mCachedFields->GetAttribute<double>(nsGkAtoms::max)) {
VERIFY_CACHE(CacheDomain::Value);
return *max;
}
@ -212,6 +230,7 @@ double RemoteAccessibleBase<Derived>::MaxValue() const {
template <class Derived>
double RemoteAccessibleBase<Derived>::Step() const {
if (auto step = mCachedFields->GetAttribute<double>(nsGkAtoms::step)) {
VERIFY_CACHE(CacheDomain::Value);
return *step;
}

View file

@ -27,14 +27,6 @@
namespace mozilla {
namespace a11y {
LocalAccessible* DocAccessibleChild::IdToAccessible(const uint64_t& aID) const {
if (!aID) return mDoc;
if (!mDoc) return nullptr;
return mDoc->GetAccessibleByUniqueID(reinterpret_cast<void*>(aID));
}
LocalAccessible* DocAccessibleChild::IdToAccessibleLink(
const uint64_t& aID) const {
LocalAccessible* acc = IdToAccessible(aID);

View file

@ -485,7 +485,6 @@ class DocAccessibleChild : public DocAccessibleChildBase {
DocAccessiblePlatformExtChild* GetPlatformExtension();
private:
LocalAccessible* IdToAccessible(const uint64_t& aID) const;
LocalAccessible* IdToAccessibleLink(const uint64_t& aID) const;
LocalAccessible* IdToAccessibleSelect(const uint64_t& aID) const;
HyperTextAccessible* IdToHyperTextAccessible(const uint64_t& aID) const;

View file

@ -336,6 +336,12 @@ child:
[Nested=inside_sync] sync ExtentsInCSSPixels(uint64_t aID)
returns(int32_t aX, int32_t aY, int32_t aWidth, int32_t aHeight);
[Nested=inside_sync] sync DOMNodeID(uint64_t aID) returns(nsString aDOMNodeID);
/*
* Verify the cache. Used for testing purposes.
*/
async VerifyCache(uint64_t aID, uint64_t aCacheDomain, AccAttributes aFields);
};
}

View file

@ -17,6 +17,7 @@ using mozilla::a11y::IDispatchHolder from "mozilla/a11y/IPCTypes.h";
using mozilla::a11y::AccType from "mozilla/a11y/IPCTypes.h";
using mozilla::a11y::AccGenericType from "mozilla/a11y/IPCTypes.h";
using mozilla::a11y::CacheUpdateType from "mozilla/a11y/IPCTypes.h";
[RefCounted] using mozilla::a11y::AccAttributes from "mozilla/a11y/IPCTypes.h";
using mozilla::WindowsHandle from "mozilla/ipc/IPCTypes.h";
using mozilla::LayoutDeviceIntRect from "Units.h";
@ -110,6 +111,11 @@ child:
*/
async RestoreFocus();
/*
* Verify the cache. Used for testing purposes.
*/
async VerifyCache(uint64_t aID, uint64_t aCacheDomain, AccAttributes aFields);
async __delete__();
};