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