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.
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>
14 using namespace blink;
18 TEST(DragUpdateTest, AffectedByDragUpdate)
20 // Check that when dragging the div in the document below, you only get a
21 // single element style recalc.
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>"
31 "</div>", ASSERT_NO_EXCEPTION);
33 document.view()->updateLayoutAndStyleIfNeededRecursive();
34 unsigned startCount = document.styleEngine()->resolverAccessCount();
36 document.documentElement()->renderer()->updateDragState(true);
37 document.view()->updateLayoutAndStyleIfNeededRecursive();
39 unsigned accessCount = document.styleEngine()->resolverAccessCount() - startCount;
41 ASSERT_EQ(1U, accessCount);
44 TEST(DragUpdateTest, ChildrenOrSiblingsAffectedByDragUpdate)
46 // Check that when dragging the div in the document below, you get a
47 // full subtree style recalc.
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>"
57 "</div>", ASSERT_NO_EXCEPTION);
59 document.updateLayout();
60 unsigned startCount = document.styleEngine()->resolverAccessCount();
62 document.documentElement()->renderer()->updateDragState(true);
63 document.updateLayout();
65 unsigned accessCount = document.styleEngine()->resolverAccessCount() - startCount;
67 ASSERT_EQ(5U, accessCount);