Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Side by Side Diff: Source/core/style/StyleObserverTest.cpp

Issue 1323243002: WIP - Rough draft of style observation in style of apply hooks. Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/style/StyleObserver.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/style/StyleObserver.h"
7
8 #include "core/dom/Document.h"
9 #include "core/dom/Element.h"
10 #include "core/frame/FrameView.h"
11 #include "core/style/ComputedStyle.h"
12 #include "core/testing/DummyPageHolder.h"
13
14 #include <gmock/gmock.h>
15 #include <gtest/gtest.h>
16
17 using ::testing::_;
18
19 namespace blink {
20
21 class StyleObserverTest : public ::testing::Test {
22 protected:
23 StyleObserverTest()
24 : pageHolder(DummyPageHolder::create())
25 , document(pageHolder->document())
26 {
27 setHTML("<div id='first'></div><div id='second'></div>");
28 layoutAndStyle();
29 }
30
31 void setHTML(const char* htmlContent)
32 {
33 document.documentElement()->setInnerHTML(String::fromUTF8(htmlContent), ASSERT_NO_EXCEPTION);
34 }
35
36 void layoutAndStyle()
37 {
38 document.view()->updateAllLifecyclePhases();
39 }
40
41 OwnPtr<DummyPageHolder> pageHolder;
42 Document& document;
43 TrackExceptionState exceptionState;
44 };
45
46 class MockStyleObserver: public StyleObserver {
47 public:
48 MOCK_METHOD3(onStyleChanged, void(const Element*, const ComputedStyle*, cons t ComputedStyle*));
49 };
50
51 TEST_F(StyleObserverTest, MultipleObserversSingleChange)
52 {
53 EXPECT_EQ(false, document.hasStyleObserver());
54
55 MockStyleObserver observer1;
56 MockStyleObserver observer2;
57
58 document.registerStyleObserver(&observer1);
59 EXPECT_EQ(true, document.hasStyleObserver());
60
61 document.registerStyleObserver(&observer2);
62 EXPECT_EQ(true, document.hasStyleObserver());
63
64 EXPECT_CALL(observer1, onStyleChanged(_, _, _)).Times(1);
65 EXPECT_CALL(observer2, onStyleChanged(_, _, _)).Times(1);
66
67 document.getElementById("first")->setAttribute("style", "border: 2px solid;" , exceptionState);
68 layoutAndStyle();
69 ::testing::Mock::VerifyAndClearExpectations(&observer1);
70 ::testing::Mock::VerifyAndClearExpectations(&observer2);
71
72 document.unregisterStyleObserver(&observer1);
73 EXPECT_EQ(true, document.hasStyleObserver());
74
75 EXPECT_CALL(observer1, onStyleChanged(_, _, _)).Times(0);
76 EXPECT_CALL(observer2, onStyleChanged(_, _, _)).Times(1);
77 document.getElementById("first")->setAttribute("style", "border: 5px solid;" , exceptionState);
78 layoutAndStyle();
79 ::testing::Mock::VerifyAndClearExpectations(&observer1);
80 ::testing::Mock::VerifyAndClearExpectations(&observer2);
81
82 document.unregisterStyleObserver(&observer2);
83 EXPECT_EQ(false, document.hasStyleObserver());
84
85 EXPECT_CALL(observer1, onStyleChanged(_, _, _)).Times(0);
86 EXPECT_CALL(observer2, onStyleChanged(_, _, _)).Times(0);
87 document.getElementById("first")->setAttribute("style", "border: 10px solid; ", exceptionState);
88 layoutAndStyle();
89 ::testing::Mock::VerifyAndClearExpectations(&observer1);
90 ::testing::Mock::VerifyAndClearExpectations(&observer2);
91 }
92
93 TEST_F(StyleObserverTest, SingleObserverMultipleChanges)
94 {
95 MockStyleObserver observer;
96 document.registerStyleObserver(&observer);
97 const Element* first = document.getElementById("first");
98 const Element* second = document.getElementById("second");
99
100 EXPECT_CALL(observer, onStyleChanged(first, _, _)).Times(1);
101 EXPECT_CALL(observer, onStyleChanged(second, _, _)).Times(1);
102
103 document.getElementById("first")->setAttribute("style", "border: 2px solid;" , exceptionState);
104 document.getElementById("second")->setAttribute("style", "border: 2px solid; ", exceptionState);
105
106 layoutAndStyle();
107 ::testing::Mock::VerifyAndClearExpectations(&observer);
108 }
109
110 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/style/StyleObserver.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698