Bug 1322396 - part 1 - report external resources of documents when flushing use counters in tests; r=dholbert

Our use counter tests force reporting of use counters from documents to
make the tests more deterministic: relying on the default
report-at-document-destruction behavior would introduce any number of
intermittents.  However, documents may have any number of external
resource documents, and we have no mechanism for forcing a deterministic
reporting of the use counters from those documents.  Relying on those
external resources to have been destroyed (and thereby reported their
use counters) when we examine the values of the use counters in question
is a recipe for intermittent failures.

Therefore, we introduce an optional report kind for use counter
reporting: if a document is reporting its use counters for the purposes
of a test, we will also report the use counters for the document's
external resource documents.  This change makes everything more
deterministic.
This commit is contained in:
Nathan Froyd 2017-01-09 13:55:31 -05:00
Родитель cdfd99b7c7
Коммит 7c92b7a145
3 изменённых файлов: 31 добавлений и 3 удалений

Просмотреть файл

@ -4026,7 +4026,10 @@ nsDOMWindowUtils::ForceUseCounterFlush(nsIDOMNode *aNode)
mozilla::css::ImageLoader* loader = doc->StyleImageLoader();
loader->FlushUseCounters();
static_cast<nsDocument*>(doc.get())->ReportUseCounters();
// Flush the document and any external documents that it depends on.
const auto reportKind
= nsDocument::UseCounterReportKind::eIncludeExternalResources;
static_cast<nsDocument*>(doc.get())->ReportUseCounters(reportKind);
return NS_OK;
}

Просмотреть файл

@ -12304,8 +12304,17 @@ MightBeAboutOrChromeScheme(nsIURI* aURI)
return isAbout || isChrome;
}
static bool
ReportExternalResourceUseCounters(nsIDocument* aDocument, void* aData)
{
const auto reportKind
= nsDocument::UseCounterReportKind::eIncludeExternalResources;
static_cast<nsDocument*>(aDocument)->ReportUseCounters(reportKind);
return true;
}
void
nsDocument::ReportUseCounters()
nsDocument::ReportUseCounters(UseCounterReportKind aKind)
{
static const bool sDebugUseCounters = false;
if (mReportedUseCounters) {
@ -12314,6 +12323,10 @@ nsDocument::ReportUseCounters()
mReportedUseCounters = true;
if (aKind == UseCounterReportKind::eIncludeExternalResources) {
EnumerateExternalResources(ReportExternalResourceUseCounters, nullptr);
}
if (Telemetry::HistogramUseCounterCount > 0 &&
(IsContentDocument() || IsResourceDoc())) {
nsCOMPtr<nsIURI> uri;

Просмотреть файл

@ -774,7 +774,19 @@ public:
virtual nsViewportInfo GetViewportInfo(const mozilla::ScreenIntSize& aDisplaySize) override;
void ReportUseCounters();
enum class UseCounterReportKind {
// Flush the document's use counters only; the use counters for any
// external resource documents will be flushed when the external
// resource documents themselves are destroyed.
eDefault,
// Flush use counters for the document and for its external resource
// documents. (Should only be necessary for tests, where we need
// flushing to happen synchronously and deterministically.)
eIncludeExternalResources,
};
void ReportUseCounters(UseCounterReportKind aKind = UseCounterReportKind::eDefault);
virtual void AddIntersectionObserver(
mozilla::dom::DOMIntersectionObserver* aObserver) override;