Skip to content

Commit

Permalink
Add internals.isCSSPropertyUseCounted functionality
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
nainar authored and Commit bot committed Feb 26, 2016
1 parent 3f7776e commit 04de728
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>

<style>
div {
padding-left: 100px;
padding-bottom: 100px;
color:green;
background-color: green;
opacity: invalid value;
border: black solid 5px;
border-left: thick dashed lightgreen;
-webkit-border-end-color: pink;
}
</style>

<div id="target"></div>

<script>
test(function() {
assert_true(internals.isCSSPropertyUseCounted(document, "color"));
assert_true(internals.isCSSPropertyUseCounted(document, "background-color"));
assert_true(internals.isCSSPropertyUseCounted(document, "padding-bottom"));
assert_true(internals.isCSSPropertyUseCounted(document, "padding-left"));
assert_true(internals.isCSSPropertyUseCounted(document, "-webkit-border-end-color"));
}, "Test setting and reading css properties");

test(function() {
assert_true(internals.isCSSPropertyUseCounted(document, "border"))
assert_false(internals.isCSSPropertyUseCounted(document, "border-color"));
assert_false(internals.isCSSPropertyUseCounted(document, "border-style"));
assert_false(internals.isCSSPropertyUseCounted(document, "border-width"));

assert_true(internals.isCSSPropertyUseCounted(document, "border-left"))
assert_false(internals.isCSSPropertyUseCounted(document, "border-left-color"));
assert_false(internals.isCSSPropertyUseCounted(document, "border-left-style"));
assert_false(internals.isCSSPropertyUseCounted(document, "border-left-width"));

}, "Test setting a shorthand and reading longhand");

test(function() {
assert_false(internals.isCSSPropertyUseCounted(document, "opacity"));
}, "Test that properties with invalid values aren't counted");

test(function() {
assert_false(internals.isCSSPropertyUseCounted(document, "box-sizing"));
}, "Test that properties specified in UA stylesheet aren't counted");

</script>
21 changes: 21 additions & 0 deletions third_party/WebKit/Source/core/frame/UseCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions third_party/WebKit/Source/core/frame/UseCounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
5 changes: 5 additions & 0 deletions third_party/WebKit/Source/core/testing/Internals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2490,6 +2490,11 @@ bool Internals::isUseCounted(Document* document, int useCounterId)
return UseCounter::isCounted(*document, static_cast<UseCounter::Feature>(useCounterId));
}

bool Internals::isCSSPropertyUseCounted(Document* document, const String& propertyName)
{
return UseCounter::isCounted(*document, propertyName);
}

String Internals::unscopeableAttribute()
{
return "unscopeableAttribute";
Expand Down
1 change: 1 addition & 0 deletions third_party/WebKit/Source/core/testing/Internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ class Internals final : public GarbageCollectedFinalized<Internals>, 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();
Expand Down
1 change: 1 addition & 0 deletions third_party/WebKit/Source/core/testing/Internals.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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<long>;

Expand Down

0 comments on commit 04de728

Please sign in to comment.