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.
6 #include "core/layout/LayoutTheme.h"
8 #include "core/dom/NodeComputedStyle.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/style/ComputedStyle.h"
15 #include "core/testing/DummyPageHolder.h"
16 #include "platform/graphics/Color.h"
17 #include <gtest/gtest.h>
21 class LayoutThemeTest
: public ::testing::Test
{
23 void SetUp() override
;
24 HTMLDocument
& document() const { return *m_document
; }
25 void setHtmlInnerHTML(const char* htmlContent
);
28 OwnPtr
<DummyPageHolder
> m_dummyPageHolder
;
29 RefPtrWillBePersistent
<HTMLDocument
> m_document
;
32 void LayoutThemeTest::SetUp()
34 m_dummyPageHolder
= DummyPageHolder::create(IntSize(800, 600));
35 m_document
= toHTMLDocument(&m_dummyPageHolder
->document());
39 void LayoutThemeTest::setHtmlInnerHTML(const char* htmlContent
)
41 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent
), ASSERT_NO_EXCEPTION
);
42 document().view()->updateAllLifecyclePhases();
45 inline Color
outlineColor(Element
* element
)
47 return element
->computedStyle()->visitedDependentColor(CSSPropertyOutlineColor
);
50 inline EBorderStyle
outlineStyle(Element
* element
)
52 return element
->computedStyle()->outlineStyle();
55 TEST_F(LayoutThemeTest
, ChangeFocusRingColor
)
57 setHtmlInnerHTML("<span id=span tabIndex=0>Span</span>");
59 Element
* span
= document().getElementById(AtomicString("span"));
60 EXPECT_NE(nullptr, span
);
61 EXPECT_NE(nullptr, span
->layoutObject());
63 Color customColor
= makeRGB(123, 145, 167);
65 // Checking unfocused style.
66 EXPECT_EQ(BNONE
, outlineStyle(span
));
67 EXPECT_NE(customColor
, outlineColor(span
));
70 document().page()->focusController().setActive(true);
71 document().page()->focusController().setFocused(true);
73 document().view()->updateAllLifecyclePhases();
75 // Checking focused style.
76 EXPECT_NE(BNONE
, outlineStyle(span
));
77 EXPECT_NE(customColor
, outlineColor(span
));
79 // Change focus ring color.
80 LayoutTheme::theme().setCustomFocusRingColor(customColor
);
81 Page::platformColorsChanged();
82 document().view()->updateAllLifecyclePhases();
84 // Check that the focus ring color is updated.
85 EXPECT_NE(BNONE
, outlineStyle(span
));
86 EXPECT_EQ(customColor
, outlineColor(span
));