From 04de728dedc272262c320c5d24f5df8df2a0db7e Mon Sep 17 00:00:00 2001 From: nainar Date: Fri, 26 Feb 2016 00:13:42 -0800 Subject: [PATCH] Add internals.isCSSPropertyUseCounted functionality This patch adds the functionality of internals.isCSSPropertyUseCounted to test whether a particular CSSProperty is in use in a file. This function is being added to help improve testing for improvements made to UseCounter methods for counting CSSProperty. There is a currently a internals.isUseCounted that is used for testing whether a current feature is UseCounted. BUG=589343 Review URL: https://codereview.chromium.org/1711703002 Cr-Commit-Position: refs/heads/master@{#377846} --- ...dow-internals-isCSSPropertyUseCounted.html | 50 +++++++++++++++++++ .../WebKit/Source/core/frame/UseCounter.cpp | 21 ++++++++ .../WebKit/Source/core/frame/UseCounter.h | 4 ++ .../WebKit/Source/core/testing/Internals.cpp | 5 ++ .../WebKit/Source/core/testing/Internals.h | 1 + .../WebKit/Source/core/testing/Internals.idl | 1 + 6 files changed, 82 insertions(+) create mode 100644 third_party/WebKit/LayoutTests/fast/css/window-internals-isCSSPropertyUseCounted.html diff --git a/third_party/WebKit/LayoutTests/fast/css/window-internals-isCSSPropertyUseCounted.html b/third_party/WebKit/LayoutTests/fast/css/window-internals-isCSSPropertyUseCounted.html new file mode 100644 index 00000000000000..5abe8501e79669 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/css/window-internals-isCSSPropertyUseCounted.html @@ -0,0 +1,50 @@ + + + + + + +
+ + \ No newline at end of file diff --git a/third_party/WebKit/Source/core/frame/UseCounter.cpp b/third_party/WebKit/Source/core/frame/UseCounter.cpp index 15eb00c980c79d..022799f0e88213 100644 --- a/third_party/WebKit/Source/core/frame/UseCounter.cpp +++ b/third_party/WebKit/Source/core/frame/UseCounter.cpp @@ -680,6 +680,27 @@ bool UseCounter::isCounted(Document& document, Feature feature) return host->useCounter().hasRecordedMeasurement(feature); } +bool UseCounter::isCounted(CSSPropertyID unresolvedProperty) +{ + return m_CSSFeatureBits.quickGet(unresolvedProperty); +} + + +bool UseCounter::isCounted(Document& document, const String& string) +{ + Frame* frame = document.frame(); + if (!frame) + return false; + FrameHost* host = frame->host(); + if (!host) + return false; + + CSSPropertyID propertyID = cssPropertyID(string); + if (propertyID == CSSPropertyInvalid) + return false; + return host->useCounter().isCounted(propertyID); +} + void UseCounter::count(const ExecutionContext* context, Feature feature) { if (!context) diff --git a/third_party/WebKit/Source/core/frame/UseCounter.h b/third_party/WebKit/Source/core/frame/UseCounter.h index 89239e6af9ab0e..8ad6600228d92d 100644 --- a/third_party/WebKit/Source/core/frame/UseCounter.h +++ b/third_party/WebKit/Source/core/frame/UseCounter.h @@ -1117,6 +1117,10 @@ class CORE_EXPORT UseCounter { // Return whether the Feature was previously counted for this document. // NOTE: only for use in testing. static bool isCounted(Document&, Feature); + // Return whether the CSSPropertyID was previously counted for this document. + // NOTE: only for use in testing. + static bool isCounted(Document&, const String&); + bool isCounted(CSSPropertyID); void didCommitLoad(); diff --git a/third_party/WebKit/Source/core/testing/Internals.cpp b/third_party/WebKit/Source/core/testing/Internals.cpp index 8ce2a51274397c..b71d2ff1aa4fe3 100644 --- a/third_party/WebKit/Source/core/testing/Internals.cpp +++ b/third_party/WebKit/Source/core/testing/Internals.cpp @@ -2490,6 +2490,11 @@ bool Internals::isUseCounted(Document* document, int useCounterId) return UseCounter::isCounted(*document, static_cast(useCounterId)); } +bool Internals::isCSSPropertyUseCounted(Document* document, const String& propertyName) +{ + return UseCounter::isCounted(*document, propertyName); +} + String Internals::unscopeableAttribute() { return "unscopeableAttribute"; diff --git a/third_party/WebKit/Source/core/testing/Internals.h b/third_party/WebKit/Source/core/testing/Internals.h index 65de0437a1e57f..126d15692a2046 100644 --- a/third_party/WebKit/Source/core/testing/Internals.h +++ b/third_party/WebKit/Source/core/testing/Internals.h @@ -374,6 +374,7 @@ class Internals final : public GarbageCollectedFinalized, public Scri // Return true if the given use counter exists for the given document. // |useCounterId| must be one of the values from the UseCounter::Feature enum. bool isUseCounted(Document*, int useCounterId); + bool isCSSPropertyUseCounted(Document*, const String&); String unscopeableAttribute(); String unscopeableMethod(); diff --git a/third_party/WebKit/Source/core/testing/Internals.idl b/third_party/WebKit/Source/core/testing/Internals.idl index 65ec824edac13e..dc692028d53ebb 100644 --- a/third_party/WebKit/Source/core/testing/Internals.idl +++ b/third_party/WebKit/Source/core/testing/Internals.idl @@ -335,6 +335,7 @@ bool magnifyScaleAroundAnchor(float offset, float x, float y); boolean isUseCounted(Document document, long useCounterId); + boolean isCSSPropertyUseCounted(Document document, DOMString propertyName); iterable;