Bug 92473 - [CSS] Add tests for :read-only and :read-write
Summary: [CSS] Add tests for :read-only and :read-write
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: KyungTae Kim
URL: http://jsfiddle.net/ZnrQT/
Keywords:
Depends on: 92602
Blocks:
  Show dependency treegraph
 
Reported: 2012-07-27 01:55 PDT by yosin
Modified: 2014-11-02 00:06 PDT (History)
12 users (show)

See Also:


Attachments
Patch (11.19 KB, patch)
2014-01-22 02:57 PST, KyungTae Kim
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from webkit-ews-16 for mac-mountainlion-wk2 (456.97 KB, application/zip)
2014-01-22 04:03 PST, Build Bot
no flags Details
Archive of layout-test-results from webkit-ews-02 for mac-mountainlion (500.64 KB, application/zip)
2014-01-22 04:29 PST, Build Bot
no flags Details
Archive of layout-test-results from webkit-ews-15 for mac-mountainlion-wk2 (452.56 KB, application/zip)
2014-01-22 04:58 PST, Build Bot
no flags Details
Patch (12.77 KB, patch)
2014-01-22 05:16 PST, KyungTae Kim
no flags Details | Formatted Diff | Diff
Patch (20.88 KB, patch)
2014-02-03 21:45 PST, KyungTae Kim
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from webkit-ews-08 for mac-mountainlion (545.27 KB, application/zip)
2014-02-03 23:40 PST, Build Bot
no flags Details
Archive of layout-test-results from webkit-ews-05 for mac-mountainlion (593.39 KB, application/zip)
2014-02-04 00:25 PST, Build Bot
no flags Details
Archive of layout-test-results from webkit-ews-10 for mac-mountainlion-wk2 (556.49 KB, application/zip)
2014-02-04 00:48 PST, Build Bot
no flags Details
Patch (20.95 KB, patch)
2014-02-04 01:37 PST, KyungTae Kim
no flags Details | Formatted Diff | Diff
Patch (23.35 KB, patch)
2014-02-04 21:29 PST, KyungTae Kim
no flags Details | Formatted Diff | Diff
Patch (9.89 KB, patch)
2014-11-01 22:24 PDT, Benjamin Poulain
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description yosin 2012-07-27 01:55:53 PDT
According HTML5 specification[1], :read-only and :read-write selector should match all elements.

Although, current implementation applies only isFormisFormControlElement:

In WebCore/css/SelectorChecker.cpp:

bool SelectorChecker::checkOneSelector(const SelectorCheckingContext& context, PseudoId& dynamicPseudo) const
{
...
        case CSSSelector::PseudoReadWrite:
            if (!element || !element->isFormControlElement())
                return false;
            return element->isTextFormControl() && !element->isReadOnlyFormControl();
...
}

= Browser Behaviors =
Result of http://jsfiddle.net/ZnrQT/
(:read-only: color: red, :read-write: color: green)

Chromium: input and textarea are red
FireFox: all colors are default(black)
IE: all colors are default(black)
Opera: all colors are red except for input type "date".

= References =
[1] http://www.whatwg.org/specs/web-apps/current-work/multipage/selectors.html#pseudo-classes
Comment 1 yosin 2012-07-31 01:12:48 PDT
Definition of "editing host" and "editable" are found in
 "HTML Editing APIs"
 http://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#editing-host
Comment 2 KyungTae Kim 2014-01-22 02:57:19 PST
Created attachment 221847 [details]
Patch
Comment 3 KyungTae Kim 2014-01-22 03:01:07 PST
By the spec (http://www.w3.org/TR/css3-ui/),
most elements are :read-only but if a element with contenteditable attribute, it is :read-write.
Additionally, children of contenteditable elements seems not :read-write, because their contents are not user-alterable.

4.1.7. :read-only and :read-write
An element whose contents are not user-alterable is :read-only. However, elements whose contents are user-alterable (such as text input fields) are considered to be in a :read-write state. In typical documents, most elements are :read-only. However it may be possible (e.g. in the context of an editor) for any element to become :read-write.
Comment 4 Build Bot 2014-01-22 04:03:45 PST
Comment on attachment 221847 [details]
Patch

Attachment 221847 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/4814773833170944

New failing tests:
fast/forms/select-live-pseudo-selectors.html
Comment 5 Build Bot 2014-01-22 04:03:48 PST
Created attachment 221856 [details]
Archive of layout-test-results from webkit-ews-16 for mac-mountainlion-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: webkit-ews-16  Port: mac-mountainlion-wk2  Platform: Mac OS X 10.8.5
Comment 6 Build Bot 2014-01-22 04:29:31 PST
Comment on attachment 221847 [details]
Patch

Attachment 221847 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.appspot.com/results/6751327879168000

New failing tests:
fast/forms/select-live-pseudo-selectors.html
platform/mac/fast/objc/dom-html-select-live-pseudo-selectors.html
Comment 7 Build Bot 2014-01-22 04:29:33 PST
Created attachment 221857 [details]
Archive of layout-test-results from webkit-ews-02 for mac-mountainlion

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: webkit-ews-02  Port: mac-mountainlion  Platform: Mac OS X 10.8.5
Comment 8 Build Bot 2014-01-22 04:58:12 PST
Comment on attachment 221847 [details]
Patch

Attachment 221847 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/5336707922657280

New failing tests:
fast/forms/select-live-pseudo-selectors.html
Comment 9 Build Bot 2014-01-22 04:58:15 PST
Created attachment 221860 [details]
Archive of layout-test-results from webkit-ews-15 for mac-mountainlion-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: webkit-ews-15  Port: mac-mountainlion-wk2  Platform: Mac OS X 10.8.5
Comment 10 KyungTae Kim 2014-01-22 05:16:33 PST
Created attachment 221861 [details]
Patch
Comment 11 Darin Adler 2014-02-02 23:37:34 PST
Comment on attachment 221861 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=221861&action=review

A good start, but test and implementation both need more work.

We need more test coverage on elements that are not editable, including non-HTML elements. Doing all the tests with <div> is not OK.

> Source/WebCore/html/HTMLElement.cpp:1110
> +bool HTMLElement::matchesReadOnlyPseudoClass() const
> +{
> +    return !matchesReadWritePseudoClass();
> +}

I think that Element::matchesReadOnlyPseudoClass needs to also return true; a test case that would cover that would be any non-HTML element that is styled with ::read-only. I’m thinking that we should get rid of the virtual matchesReadOnlyPseudoClass function entirely and just have Element::matchesReadOnlyPseudoClass be an inline non-virtual member function that returns !matchesReadWritePseudoClass().

While this change is OK for CSS purposes, I think it also changes the behavior of RenderTheme::isReadOnlyControl, causing it to return true for many renderers where it used to return false. It will return for many renderers for elements are not controls at all. Did you test to make sure that’s OK? I’m particularly concerned about the use in RenderThemeSafari::determineState, but also I am not sure if RenderThemeSafari is still live code or not.

> Source/WebCore/html/HTMLElement.h:103
> +    virtual bool matchesReadOnlyPseudoClass() const;
> +    virtual bool matchesReadWritePseudoClass() const;

These should both be marked "override". I also suggest making them private rather than public, because no code should be calling this directly on an HTMLElement.

> LayoutTests/fast/css/readwrite-pseudoclass-editable.html:9
> +                shouldBeEqualToString("window.getComputedStyle(document.getElementById('editable1'),null).getPropertyValue('background-color')","rgb(255, 0, 0)");

To make the test more readable I suggest the following simplification:

1) Don’t use "window."; we can just use “getComputedStyle”.
2) Don’t pass “null” explicitly. I think we can just omit the second argument to getComputedStyle.
3) Use a helper function:

    function backgroundColor(identifier)
    {
        return getComputedStyle(document.getElementById(identifier)).getPropertyValue("background-color");
    }

    shouldBeEqualToString("backgroundColor('editable1')", "rgb(255, 0, 0)");

By using the named helper function the test itself and the test output are more readable.

> LayoutTests/fast/css/readwrite-pseudoclass-editable.html:16
> +                isSuccessfullyParsed();

I don’t think this is the right place for that function call. How do we do this in other tests.

> LayoutTests/fast/css/readwrite-pseudoclass-editable.html:22
> +            :read-write {
> +                background-color: red;
> +            }

This test case covers :read-write only. We need to test :read-only too.

> LayoutTests/fast/css/readwrite-pseudoclass-editable.html:33
> +        <div id="editable1" contenteditable>
> +            <div id="div_in_editable"></div>
> +            <input type="text" readonly id="readonly_in_editable"/>
> +            <input type="text" disabled id="disabled_in_editable"/>
> +        </div>
> +        <div id="editable2" contenteditable="true"></div>
> +        <div id="editable3" contenteditable="plaintext-only"></div>
> +        <div id="non_editable" contenteditable="false"></div>

Where’s the test case for contenteditable=""? That’s specially handled in the code above, and so it needs a test case.
Comment 12 KyungTae Kim 2014-02-03 21:45:20 PST
Created attachment 223072 [details]
Patch
Comment 13 Build Bot 2014-02-03 23:40:34 PST
Comment on attachment 223072 [details]
Patch

Attachment 223072 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.appspot.com/results/6446230313893888

New failing tests:
fast/css/readwrite-pseudoclass-editable.html
Comment 14 Build Bot 2014-02-03 23:40:37 PST
Created attachment 223076 [details]
Archive of layout-test-results from webkit-ews-08 for mac-mountainlion

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: webkit-ews-08  Port: mac-mountainlion  Platform: Mac OS X 10.8.5
Comment 15 Build Bot 2014-02-04 00:25:05 PST
Comment on attachment 223072 [details]
Patch

Attachment 223072 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.appspot.com/results/6245221952126976

New failing tests:
fast/css/readwrite-pseudoclass-editable.html
Comment 16 Build Bot 2014-02-04 00:25:09 PST
Created attachment 223079 [details]
Archive of layout-test-results from webkit-ews-05 for mac-mountainlion

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: webkit-ews-05  Port: mac-mountainlion  Platform: Mac OS X 10.8.5
Comment 17 Build Bot 2014-02-04 00:48:25 PST
Comment on attachment 223072 [details]
Patch

Attachment 223072 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/6577233661526016

New failing tests:
fast/css/readwrite-pseudoclass-editable.html
Comment 18 Build Bot 2014-02-04 00:48:29 PST
Created attachment 223083 [details]
Archive of layout-test-results from webkit-ews-10 for mac-mountainlion-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: webkit-ews-10  Port: mac-mountainlion-wk2  Platform: Mac OS X 10.8.5
Comment 19 KyungTae Kim 2014-02-04 01:37:42 PST
Created attachment 223086 [details]
Patch
Comment 20 KyungTae Kim 2014-02-04 04:11:21 PST
(In reply to comment #11)
> (From update of attachment 221861 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=221861&action=review
> We need more test coverage on elements that are not editable, including non-HTML elements. Doing all the tests with <div> is not OK.
I changed the test case to use many types, but I'm confused how the test coverage should be. Should it include all sort of elements?

> I’m thinking that we should get rid of the virtual matchesReadOnlyPseudoClass function entirely and just have Element::matchesReadOnlyPseudoClass be an inline non-virtual member function that returns !matchesReadWritePseudoClass().
I modified as your comment, and removed each element's matchesReadOnlyPseudoClass methods.
I think a disabled input is also :read-only because it's not user-alterable.

> While this change is OK for CSS purposes, I think it also changes the behavior of RenderTheme::isReadOnlyControl, causing it to return true for many renderers where it used to return false. It will return for many renderers for elements are not controls at all. Did you test to make sure that’s OK? I’m particularly concerned about the use in RenderThemeSafari::determineState, but also I am not sure if RenderThemeSafari is still live code or not.

isReadOnlyControl means isControl && isReadOnly, and I changed that function like it. However, I could not sure it yet because I couldn't find the test case for that.

The newly added test cases are readonly-pseudoclass-common-element.html and readwrite-pseudoclass-editable.html.
I modified the test cases as your comment.
Comment 21 Darin Adler 2014-02-04 20:51:00 PST
(In reply to comment #20)
> (In reply to comment #11)
> > We need more test coverage on elements that are not editable, including non-HTML elements. Doing all the tests with <div> is not OK.
> I changed the test case to use many types, but I'm confused how the test coverage should be. Should it include all sort of elements?

I think we want at least one SVG element and at least one MathML element; probably not important to have a big variety of HTML elements, although it would be good to cover any that have special rules.
Comment 22 KyungTae Kim 2014-02-04 21:29:25 PST
Created attachment 223208 [details]
Patch
Comment 23 KyungTae Kim 2014-02-16 23:08:36 PST
(In reply to comment #21)
> (In reply to comment #20)
> > (In reply to comment #11)
> > > We need more test coverage on elements that are not editable, including non-HTML elements. Doing all the tests with <div> is not OK.
> > I changed the test case to use many types, but I'm confused how the test coverage should be. Should it include all sort of elements?
> 
> I think we want at least one SVG element and at least one MathML element; probably not important to have a big variety of HTML elements, although it would be good to cover any that have special rules.
I added  SVG & MathML case on the updated patch.
Comment 24 Benjamin Poulain 2014-11-01 22:24:12 PDT
Created attachment 240806 [details]
Patch
Comment 25 Benjamin Poulain 2014-11-01 22:25:50 PDT
I fixed this bug a month ago, I was unaware you had a fix for it. :(

Your tests are still interesting by themselves, let's land that if the bots are green.
Comment 26 WebKit Commit Bot 2014-11-02 00:06:21 PDT
Comment on attachment 240806 [details]
Patch

Clearing flags on attachment: 240806

Committed r175461: <http://trac.webkit.org/changeset/175461>
Comment 27 WebKit Commit Bot 2014-11-02 00:06:28 PDT
All reviewed patches have been landed.  Closing bug.