Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/layout/LayoutTheme.h" | 6 #include "core/input/EventHandler.h" |
| 7 | 7 |
| 8 #include "core/dom/NodeComputedStyle.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/Range.h" | |
| 10 #include "core/editing/FrameSelection.h" | |
| 9 #include "core/frame/FrameView.h" | 11 #include "core/frame/FrameView.h" |
| 12 #include "core/frame/LocalFrame.h" | |
| 10 #include "core/html/HTMLDocument.h" | 13 #include "core/html/HTMLDocument.h" |
| 11 #include "core/html/HTMLElement.h" | 14 #include "core/page/AutoscrollController.h" |
| 12 #include "core/style/ComputedStyle.h" | |
| 13 #include "core/page/FocusController.h" | |
| 14 #include "core/page/Page.h" | 15 #include "core/page/Page.h" |
| 16 #include "core/testing/CoreTestHelpers.h" | |
| 15 #include "core/testing/DummyPageHolder.h" | 17 #include "core/testing/DummyPageHolder.h" |
| 16 #include "platform/graphics/Color.h" | 18 #include "platform/PlatformMouseEvent.h" |
| 17 #include <gtest/gtest.h> | 19 #include <gtest/gtest.h> |
| 18 | 20 |
| 19 using namespace blink; | 21 namespace blink { |
| 20 | 22 |
| 21 namespace { | 23 class EventHandlerTest : public ::testing::Test { |
| 22 | |
| 23 class LayoutThemeTest : public ::testing::Test { | |
| 24 | |
| 25 protected: | 24 protected: |
| 26 virtual void SetUp() override; | 25 virtual void SetUp() override; |
|
tkent
2015/06/10 01:21:34
Remove |virtual|.
Miyoung Shin(g)
2015/06/10 05:10:47
Done.
| |
| 27 HTMLDocument& document() const { return *m_document; } | 26 |
| 27 Page& page() const { return m_dummyPageHolder->page(); } | |
| 28 Document& document() const { return m_dummyPageHolder->document(); } | |
| 29 | |
| 28 void setHtmlInnerHTML(const char* htmlContent); | 30 void setHtmlInnerHTML(const char* htmlContent); |
| 29 | 31 |
| 30 private: | 32 private: |
| 31 OwnPtr<DummyPageHolder> m_dummyPageHolder; | 33 OwnPtr<DummyPageHolder> m_dummyPageHolder; |
| 32 HTMLDocument* m_document; | |
| 33 }; | 34 }; |
| 34 | 35 |
| 35 void LayoutThemeTest::SetUp() | 36 void EventHandlerTest::SetUp() |
| 36 { | 37 { |
| 37 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); | 38 m_dummyPageHolder = DummyPageHolder::create(IntSize(300, 400)); |
| 38 m_document = toHTMLDocument(&m_dummyPageHolder->document()); | |
| 39 ASSERT(m_document); | |
| 40 } | 39 } |
| 41 | 40 |
| 42 void LayoutThemeTest::setHtmlInnerHTML(const char* htmlContent) | 41 void EventHandlerTest::setHtmlInnerHTML(const char* htmlContent) |
| 43 { | 42 { |
| 44 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent), AS SERT_NO_EXCEPTION); | 43 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent), AS SERT_NO_EXCEPTION); |
| 45 document().view()->updateLayoutAndStyleForPainting(); | 44 document().view()->updateLayoutAndStyleForPainting(); |
| 46 } | 45 } |
| 47 | 46 |
| 48 inline Color outlineColor(Element* element) | 47 TEST_F(EventHandlerTest, dragSelectionAfterScroll) |
| 49 { | 48 { |
| 50 return element->computedStyle()->visitedDependentColor(CSSPropertyOutlineCol or); | 49 setHtmlInnerHTML("<style> body { margin: 0px; } .upper { width: 300px; heigh t: 400px; }" |
| 50 ".lower { margin: 0px; width: 300px; height: 400px; } .line { display: b lock; width: 300px; height: 30px; } </style>" | |
| 51 "<div class=\"upper\"></div>" | |
| 52 "<div class=\"lower\">" | |
| 53 "<span class=\"line\">Line 1</span><span class=\"line\">Line 2</span><sp an class=\"line\">Line 3</span><span class=\"line\">Line 4</span><span class=\"l ine\">Line 5</span>" | |
| 54 "<span class=\"line\">Line 6</span><span class=\"line\">Line 7</span><sp an class=\"line\">Line 8</span><span class=\"line\">Line 9</span><span class=\"l ine\">Line 10</span>" | |
| 55 "</div>"); | |
| 56 | |
| 57 FrameView* frameView = document().view(); | |
| 58 frameView->scrollTo(DoublePoint(0, 400)); | |
| 59 | |
| 60 PlatformMouseEvent mouseDownEvent( | |
| 61 IntPoint(0, 0), | |
| 62 IntPoint(100, 200), | |
| 63 LeftButton, | |
| 64 PlatformEvent::MousePressed, | |
| 65 1, | |
| 66 static_cast<PlatformEvent::Modifiers>(0), | |
| 67 WTF::currentTime()); | |
| 68 document().frame()->eventHandler().handleMousePressEvent(mouseDownEvent); | |
| 69 | |
| 70 PlatformMouseEvent mouseMoveEvent( | |
| 71 IntPoint(100, 50), | |
| 72 IntPoint(200, 250), | |
| 73 LeftButton, | |
| 74 PlatformEvent::MouseMoved, | |
| 75 1, | |
| 76 static_cast<PlatformEvent::Modifiers>(0), | |
| 77 WTF::currentTime()); | |
| 78 document().frame()->eventHandler().handleMouseMoveEvent(mouseMoveEvent); | |
| 79 | |
| 80 page().autoscrollController().animate(WTF::currentTime()); | |
| 81 page().animator().serviceScriptedAnimations(WTF::currentTime()); | |
| 82 | |
| 83 PlatformMouseEvent mouseUpEvent( | |
| 84 IntPoint(100, 50), | |
| 85 IntPoint(200, 250), | |
| 86 LeftButton, | |
| 87 PlatformEvent::MouseReleased, | |
| 88 1, | |
| 89 static_cast<PlatformEvent::Modifiers>(0), | |
| 90 WTF::currentTime()); | |
| 91 document().frame()->eventHandler().handleMouseReleaseEvent(mouseUpEvent); | |
| 92 | |
| 93 FrameSelection& selection = document().frame()->selection(); | |
| 94 ASSERT_TRUE(selection.isRange()); | |
| 95 RefPtrWillBeRawPtr<Range> range = selection.toNormalizedRange(); | |
| 96 ASSERT_TRUE(range.get()); | |
| 97 EXPECT_EQ("Line 1\nLine 2", range->text()); | |
| 51 } | 98 } |
| 52 | 99 |
| 53 inline EBorderStyle outlineStyle(Element* element) | 100 } // namespace blink |
| 54 { | |
| 55 return element->computedStyle()->outlineStyle(); | |
| 56 } | |
| 57 | |
| 58 TEST_F(LayoutThemeTest, 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->layoutObject()); | |
| 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()->updateLayoutAndStyleForPainting(); | |
| 77 | |
| 78 // Checking focused style. | |
| 79 EXPECT_NE(BNONE, outlineStyle(span)); | |
| 80 EXPECT_NE(customColor, outlineColor(span)); | |
| 81 | |
| 82 // Change focus ring color. | |
| 83 LayoutTheme::theme().setCustomFocusRingColor(customColor); | |
| 84 Page::platformColorsChanged(); | |
| 85 document().view()->updateLayoutAndStyleForPainting(); | |
| 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 |