Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / core / layout / LayoutThemeTest.cpp
blobf6afca318f97fadcfb37dd20f3a0f809fccfa3c7
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.
5 #include "config.h"
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>
19 namespace blink {
21 class LayoutThemeTest : public ::testing::Test {
22 protected:
23 void SetUp() override;
24 HTMLDocument& document() const { return *m_document; }
25 void setHtmlInnerHTML(const char* htmlContent);
27 private:
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());
36 ASSERT(m_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));
69 // Do focus.
70 document().page()->focusController().setActive(true);
71 document().page()->focusController().setFocused(true);
72 span->focus();
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));
89 } // namespace blink