| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "core/dom/Document.h" |
| 5 #include "core/dom/Element.h" | 6 #include "core/dom/Element.h" |
| 6 #include "core/dom/StyleEngine.h" | 7 #include "core/dom/StyleEngine.h" |
| 7 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
| 8 #include "core/html/HTMLDocument.h" | |
| 9 #include "core/html/HTMLElement.h" | |
| 10 #include "core/layout/LayoutObject.h" | 9 #include "core/layout/LayoutObject.h" |
| 11 #include "core/testing/DummyPageHolder.h" | 10 #include "core/testing/DummyPageHolder.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include <memory> | 12 #include <memory> |
| 14 | 13 |
| 15 namespace blink { | 14 namespace blink { |
| 16 | 15 |
| 17 TEST(DragUpdateTest, AffectedByDragUpdate) | 16 TEST(DragUpdateTest, AffectedByDragUpdate) |
| 18 { | 17 { |
| 19 // Check that when dragging the div in the document below, you only get a | 18 // Check that when dragging the div in the document below, you only get a |
| 20 // single element style recalc. | 19 // single element style recalc. |
| 21 | 20 |
| 22 std::unique_ptr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(I
ntSize(800, 600)); | 21 std::unique_ptr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(I
ntSize(800, 600)); |
| 23 HTMLDocument& document = toHTMLDocument(dummyPageHolder->document()); | 22 Document& document = dummyPageHolder->document(); |
| 24 document.documentElement()->setInnerHTML("<style>div {width:100px;height:100
px} div:-webkit-drag { background-color: green }</style>" | 23 document.documentElement()->setInnerHTML("<style>div {width:100px;height:100
px} div:-webkit-drag { background-color: green }</style>" |
| 25 "<div>" | 24 "<div>" |
| 26 "<span></span>" | 25 "<span></span>" |
| 27 "<span></span>" | 26 "<span></span>" |
| 28 "<span></span>" | 27 "<span></span>" |
| 29 "<span></span>" | 28 "<span></span>" |
| 30 "</div>", ASSERT_NO_EXCEPTION); | 29 "</div>", ASSERT_NO_EXCEPTION); |
| 31 | 30 |
| 32 document.view()->updateAllLifecyclePhases(); | 31 document.view()->updateAllLifecyclePhases(); |
| 33 unsigned startCount = document.styleEngine().styleForElementCount(); | 32 unsigned startCount = document.styleEngine().styleForElementCount(); |
| 34 | 33 |
| 35 document.documentElement()->layoutObject()->updateDragState(true); | 34 document.documentElement()->layoutObject()->updateDragState(true); |
| 36 document.view()->updateAllLifecyclePhases(); | 35 document.view()->updateAllLifecyclePhases(); |
| 37 | 36 |
| 38 unsigned elementCount = document.styleEngine().styleForElementCount() - star
tCount; | 37 unsigned elementCount = document.styleEngine().styleForElementCount() - star
tCount; |
| 39 | 38 |
| 40 ASSERT_EQ(1U, elementCount); | 39 ASSERT_EQ(1U, elementCount); |
| 41 } | 40 } |
| 42 | 41 |
| 43 TEST(DragUpdateTest, ChildAffectedByDragUpdate) | 42 TEST(DragUpdateTest, ChildAffectedByDragUpdate) |
| 44 { | 43 { |
| 45 // Check that when dragging the div in the document below, you get a | 44 // Check that when dragging the div in the document below, you get a |
| 46 // single element style recalc. | 45 // single element style recalc. |
| 47 | 46 |
| 48 std::unique_ptr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(I
ntSize(800, 600)); | 47 std::unique_ptr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(I
ntSize(800, 600)); |
| 49 HTMLDocument& document = toHTMLDocument(dummyPageHolder->document()); | 48 Document& document = dummyPageHolder->document(); |
| 50 document.documentElement()->setInnerHTML("<style>div {width:100px;height:100
px} div:-webkit-drag .drag { background-color: green }</style>" | 49 document.documentElement()->setInnerHTML("<style>div {width:100px;height:100
px} div:-webkit-drag .drag { background-color: green }</style>" |
| 51 "<div>" | 50 "<div>" |
| 52 "<span></span>" | 51 "<span></span>" |
| 53 "<span></span>" | 52 "<span></span>" |
| 54 "<span class='drag'></span>" | 53 "<span class='drag'></span>" |
| 55 "<span></span>" | 54 "<span></span>" |
| 56 "</div>", ASSERT_NO_EXCEPTION); | 55 "</div>", ASSERT_NO_EXCEPTION); |
| 57 | 56 |
| 58 document.updateStyleAndLayout(); | 57 document.updateStyleAndLayout(); |
| 59 unsigned startCount = document.styleEngine().styleForElementCount(); | 58 unsigned startCount = document.styleEngine().styleForElementCount(); |
| 60 | 59 |
| 61 document.documentElement()->layoutObject()->updateDragState(true); | 60 document.documentElement()->layoutObject()->updateDragState(true); |
| 62 document.updateStyleAndLayout(); | 61 document.updateStyleAndLayout(); |
| 63 | 62 |
| 64 unsigned elementCount = document.styleEngine().styleForElementCount() - star
tCount; | 63 unsigned elementCount = document.styleEngine().styleForElementCount() - star
tCount; |
| 65 | 64 |
| 66 ASSERT_EQ(1U, elementCount); | 65 ASSERT_EQ(1U, elementCount); |
| 67 } | 66 } |
| 68 | 67 |
| 69 TEST(DragUpdateTest, SiblingAffectedByDragUpdate) | 68 TEST(DragUpdateTest, SiblingAffectedByDragUpdate) |
| 70 { | 69 { |
| 71 // Check that when dragging the div in the document below, you get a | 70 // Check that when dragging the div in the document below, you get a |
| 72 // single element style recalc. | 71 // single element style recalc. |
| 73 | 72 |
| 74 std::unique_ptr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(I
ntSize(800, 600)); | 73 std::unique_ptr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(I
ntSize(800, 600)); |
| 75 HTMLDocument& document = toHTMLDocument(dummyPageHolder->document()); | 74 Document& document = dummyPageHolder->document(); |
| 76 document.documentElement()->setInnerHTML("<style>div {width:100px;height:100
px} div:-webkit-drag + .drag { background-color: green }</style>" | 75 document.documentElement()->setInnerHTML("<style>div {width:100px;height:100
px} div:-webkit-drag + .drag { background-color: green }</style>" |
| 77 "<div>" | 76 "<div>" |
| 78 "<span></span>" | 77 "<span></span>" |
| 79 "<span></span>" | 78 "<span></span>" |
| 80 "<span></span>" | 79 "<span></span>" |
| 81 "<span></span>" | 80 "<span></span>" |
| 82 "</div>" | 81 "</div>" |
| 83 "<span class='drag'></span>", ASSERT_NO_EXCEPTION); | 82 "<span class='drag'></span>", ASSERT_NO_EXCEPTION); |
| 84 | 83 |
| 85 document.updateStyleAndLayout(); | 84 document.updateStyleAndLayout(); |
| 86 unsigned startCount = document.styleEngine().styleForElementCount(); | 85 unsigned startCount = document.styleEngine().styleForElementCount(); |
| 87 | 86 |
| 88 document.documentElement()->layoutObject()->updateDragState(true); | 87 document.documentElement()->layoutObject()->updateDragState(true); |
| 89 document.updateStyleAndLayout(); | 88 document.updateStyleAndLayout(); |
| 90 | 89 |
| 91 unsigned elementCount = document.styleEngine().styleForElementCount() - star
tCount; | 90 unsigned elementCount = document.styleEngine().styleForElementCount() - star
tCount; |
| 92 | 91 |
| 93 ASSERT_EQ(1U, elementCount); | 92 ASSERT_EQ(1U, elementCount); |
| 94 } | 93 } |
| 95 | 94 |
| 96 } // namespace blink | 95 } // namespace blink |
| OLD | NEW |