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

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

Issue 2680423006: UseCounter: Introduce UseCounter::Observer for layout tests (Closed)
Patch Set: instance method 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..3b798ec93b6e4f0519db810ffddef6c3e5ec2560 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,34 @@ 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;
+ }
+
+ Frame* frame = document->frame();
+ if (!frame || !frame->host()) {
+ resolver->reject();
+ return promise;
+ }
+
+ frame->host()->useCounter().addObserver(
+ new UseCounterObserverImpl(resolver, useCounterFeature));
+ return promise;
+}
+
String Internals::unscopableAttribute() {
return "unscopableAttribute";
}
« no previous file with comments | « third_party/WebKit/Source/core/testing/Internals.h ('k') | third_party/WebKit/Source/core/testing/Internals.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698