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

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

Issue 2680423006: UseCounter: Introduce UseCounter::Observer for layout tests (Closed)
Patch Set: rebase 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 0b5b0862d491c84491906679415eb55b37de11a9..a35e9e7e75f4a5a5c7be6eabf688082c6309d1ec 100644
--- a/third_party/WebKit/Source/core/testing/Internals.cpp
+++ b/third_party/WebKit/Source/core/testing/Internals.cpp
@@ -157,6 +157,35 @@
namespace blink {
+namespace {
+
+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(
const String& markerType) {
if (equalIgnoringCase(markerType, "Spelling"))
@@ -2986,6 +3015,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