Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / css / DragUpdateTest.cpp
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.
4
5 #include "config.h"
6 #include "core/dom/Element.h"
7 #include "core/dom/StyleEngine.h"
8 #include "core/frame/FrameView.h"
9 #include "core/html/HTMLDocument.h"
10 #include "core/html/HTMLElement.h"
11 #include "core/testing/DummyPageHolder.h"
12 #include <gtest/gtest.h>
13
14 using namespace blink;
15
16 namespace {
17
18 TEST(DragUpdateTest, AffectedByDragUpdate)
19 {
20     // Check that when dragging the div in the document below, you only get a
21     // single element style recalc.
22
23     OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
24     HTMLDocument& document = toHTMLDocument(dummyPageHolder->document());
25     document.documentElement()->setInnerHTML("<style>div {width:100px;height:100px} div:-webkit-drag { background-color: green }</style>"
26         "<div>"
27         "<span></span>"
28         "<span></span>"
29         "<span></span>"
30         "<span></span>"
31         "</div>", ASSERT_NO_EXCEPTION);
32
33     document.view()->updateLayoutAndStyleIfNeededRecursive();
34     unsigned startCount = document.styleEngine()->resolverAccessCount();
35
36     document.documentElement()->renderer()->updateDragState(true);
37     document.view()->updateLayoutAndStyleIfNeededRecursive();
38
39     unsigned accessCount = document.styleEngine()->resolverAccessCount() - startCount;
40
41     ASSERT_EQ(1U, accessCount);
42 }
43
44 TEST(DragUpdateTest, ChildrenOrSiblingsAffectedByDragUpdate)
45 {
46     // Check that when dragging the div in the document below, you get a
47     // full subtree style recalc.
48
49     OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
50     HTMLDocument& document = toHTMLDocument(dummyPageHolder->document());
51     document.documentElement()->setInnerHTML("<style>div {width:100px;height:100px} div:-webkit-drag span { background-color: green }</style>"
52         "<div>"
53         "<span></span>"
54         "<span></span>"
55         "<span></span>"
56         "<span></span>"
57         "</div>", ASSERT_NO_EXCEPTION);
58
59     document.updateLayout();
60     unsigned startCount = document.styleEngine()->resolverAccessCount();
61
62     document.documentElement()->renderer()->updateDragState(true);
63     document.updateLayout();
64
65     unsigned accessCount = document.styleEngine()->resolverAccessCount() - startCount;
66
67     ASSERT_EQ(5U, accessCount);
68 }
69
70 } // namespace