OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/rendering/RenderTheme.h" |
| 7 |
| 8 #include "core/dom/NodeRenderStyle.h" |
| 9 #include "core/frame/FrameView.h" |
| 10 #include "core/html/HTMLDocument.h" |
| 11 #include "core/html/HTMLElement.h" |
| 12 #include "core/page/FocusController.h" |
| 13 #include "core/page/Page.h" |
| 14 #include "core/rendering/style/RenderStyle.h" |
| 15 #include "core/testing/DummyPageHolder.h" |
| 16 #include "platform/graphics/Color.h" |
| 17 #include <gtest/gtest.h> |
| 18 |
| 19 using namespace blink; |
| 20 |
| 21 namespace { |
| 22 |
| 23 class RenderThemeTest : public ::testing::Test { |
| 24 |
| 25 protected: |
| 26 virtual void SetUp() override; |
| 27 HTMLDocument& document() const { return *m_document; } |
| 28 void setHtmlInnerHTML(const char* htmlContent); |
| 29 |
| 30 private: |
| 31 OwnPtr<DummyPageHolder> m_dummyPageHolder; |
| 32 HTMLDocument* m_document; |
| 33 }; |
| 34 |
| 35 void RenderThemeTest::SetUp() |
| 36 { |
| 37 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); |
| 38 m_document = toHTMLDocument(&m_dummyPageHolder->document()); |
| 39 ASSERT(m_document); |
| 40 } |
| 41 |
| 42 void RenderThemeTest::setHtmlInnerHTML(const char* htmlContent) |
| 43 { |
| 44 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent), AS
SERT_NO_EXCEPTION); |
| 45 document().view()->updateLayoutAndStyleIfNeededRecursive(); |
| 46 } |
| 47 |
| 48 inline Color outlineColor(Element* element) |
| 49 { |
| 50 return element->renderStyle()->visitedDependentColor(CSSPropertyOutlineColor
); |
| 51 } |
| 52 |
| 53 inline EBorderStyle outlineStyle(Element* element) |
| 54 { |
| 55 return element->renderStyle()->outlineStyle(); |
| 56 } |
| 57 |
| 58 TEST_F(RenderThemeTest, ChangeFocusRingColor) |
| 59 { |
| 60 setHtmlInnerHTML("<span id=span tabIndex=0>Span</span>"); |
| 61 |
| 62 Element* span = document().getElementById(AtomicString("span")); |
| 63 EXPECT_NE(nullptr, span); |
| 64 EXPECT_NE(nullptr, span->renderer()); |
| 65 |
| 66 Color customColor = makeRGB(123, 145, 167); |
| 67 |
| 68 // Checking unfocused style. |
| 69 EXPECT_EQ(BNONE, outlineStyle(span)); |
| 70 EXPECT_NE(customColor, outlineColor(span)); |
| 71 |
| 72 // Do focus. |
| 73 document().page()->focusController().setActive(true); |
| 74 document().page()->focusController().setFocused(true); |
| 75 span->focus(); |
| 76 document().view()->updateLayoutAndStyleIfNeededRecursive(); |
| 77 |
| 78 // Checking focused style. |
| 79 EXPECT_NE(BNONE, outlineStyle(span)); |
| 80 EXPECT_NE(customColor, outlineColor(span)); |
| 81 |
| 82 // Change focus ring color. |
| 83 RenderTheme::theme().setCustomFocusRingColor(customColor); |
| 84 Page::platformColorsChanged(); |
| 85 document().view()->updateLayoutAndStyleIfNeededRecursive(); |
| 86 |
| 87 // Check that the focus ring color is updated. |
| 88 EXPECT_NE(BNONE, outlineStyle(span)); |
| 89 EXPECT_EQ(customColor, outlineColor(span)); |
| 90 } |
| 91 |
| 92 } |
OLD | NEW |