Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(802)

Unified Diff: third_party/WebKit/Source/core/testing/Internals.cpp

Issue 2680423006: UseCounter: Introduce UseCounter::Observer for layout tests (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/testing/Internals.cpp
diff --git a/third_party/WebKit/Source/core/testing/Internals.cpp b/third_party/WebKit/Source/core/testing/Internals.cpp
index 45599839a2552add0e97821c0110f42d8927dd66..0a1dc3a9512c80dc54698808fff2ba829b4b09b6 100644
--- a/third_party/WebKit/Source/core/testing/Internals.cpp
+++ b/third_party/WebKit/Source/core/testing/Internals.cpp
@@ -172,6 +172,31 @@ class InternalsIterationSource final
}
};
+class UseCounterObserverImpl final : public UseCounter::Observer {
+ WTF_MAKE_NONCOPYABLE(UseCounterObserverImpl);
+
+ public:
+ UseCounterObserverImpl(ScriptPromiseResolver* resolver,
+ UseCounter::Feature feature)
+ : m_resolver(resolver), m_feature(feature) {}
+
+ bool onCountFeature(UseCounter::Feature feature) final {
+ if (m_feature != feature)
+ return false;
+ m_resolver->resolve(feature);
+ return true;
+ }
+
+ DEFINE_INLINE_VIRTUAL_TRACE() {
+ UseCounter::Observer::trace(visitor);
+ visitor->trace(m_resolver);
+ }
+
+ private:
+ Member<ScriptPromiseResolver> m_resolver;
+ UseCounter::Feature m_feature;
+};
+
} // namespace
static WTF::Optional<DocumentMarker::MarkerType> markerTypeFrom(
@@ -3009,6 +3034,26 @@ bool Internals::isCSSPropertyUseCounted(Document* document,
return UseCounter::isCounted(*document, propertyName);
}
+ScriptPromise Internals::observeUseCounter(ScriptState* scriptState,
+ Document* document,
+ uint32_t feature) {
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+ if (feature >= UseCounter::NumberOfFeatures) {
+ resolver->reject();
+ return promise;
+ }
+ UseCounter::Feature useCounterFeature =
+ static_cast<UseCounter::Feature>(feature);
+ if (UseCounter::isCounted(*document, useCounterFeature)) {
+ resolver->resolve();
+ return promise;
+ }
+ UseCounter::addObserver(
+ *document, new UseCounterObserverImpl(resolver, useCounterFeature));
+ return promise;
+}
+
String Internals::unscopableAttribute() {
return "unscopableAttribute";
}

Powered by Google App Engine
This is Rietveld 408576698