| Index: Source/core/style/StyleObserverTest.cpp
|
| diff --git a/Source/core/style/StyleObserverTest.cpp b/Source/core/style/StyleObserverTest.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..604abbaab638af57332435435ac7804b5fd70bd7
|
| --- /dev/null
|
| +++ b/Source/core/style/StyleObserverTest.cpp
|
| @@ -0,0 +1,110 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "config.h"
|
| +#include "core/style/StyleObserver.h"
|
| +
|
| +#include "core/dom/Document.h"
|
| +#include "core/dom/Element.h"
|
| +#include "core/frame/FrameView.h"
|
| +#include "core/style/ComputedStyle.h"
|
| +#include "core/testing/DummyPageHolder.h"
|
| +
|
| +#include <gmock/gmock.h>
|
| +#include <gtest/gtest.h>
|
| +
|
| +using ::testing::_;
|
| +
|
| +namespace blink {
|
| +
|
| +class StyleObserverTest : public ::testing::Test {
|
| +protected:
|
| + StyleObserverTest()
|
| + : pageHolder(DummyPageHolder::create())
|
| + , document(pageHolder->document())
|
| + {
|
| + setHTML("<div id='first'></div><div id='second'></div>");
|
| + layoutAndStyle();
|
| + }
|
| +
|
| + void setHTML(const char* htmlContent)
|
| + {
|
| + document.documentElement()->setInnerHTML(String::fromUTF8(htmlContent), ASSERT_NO_EXCEPTION);
|
| + }
|
| +
|
| + void layoutAndStyle()
|
| + {
|
| + document.view()->updateAllLifecyclePhases();
|
| + }
|
| +
|
| + OwnPtr<DummyPageHolder> pageHolder;
|
| + Document& document;
|
| + TrackExceptionState exceptionState;
|
| +};
|
| +
|
| +class MockStyleObserver: public StyleObserver {
|
| +public:
|
| + MOCK_METHOD3(onStyleChanged, void(const Element*, const ComputedStyle*, const ComputedStyle*));
|
| +};
|
| +
|
| +TEST_F(StyleObserverTest, MultipleObserversSingleChange)
|
| +{
|
| + EXPECT_EQ(false, document.hasStyleObserver());
|
| +
|
| + MockStyleObserver observer1;
|
| + MockStyleObserver observer2;
|
| +
|
| + document.registerStyleObserver(&observer1);
|
| + EXPECT_EQ(true, document.hasStyleObserver());
|
| +
|
| + document.registerStyleObserver(&observer2);
|
| + EXPECT_EQ(true, document.hasStyleObserver());
|
| +
|
| + EXPECT_CALL(observer1, onStyleChanged(_, _, _)).Times(1);
|
| + EXPECT_CALL(observer2, onStyleChanged(_, _, _)).Times(1);
|
| +
|
| + document.getElementById("first")->setAttribute("style", "border: 2px solid;", exceptionState);
|
| + layoutAndStyle();
|
| + ::testing::Mock::VerifyAndClearExpectations(&observer1);
|
| + ::testing::Mock::VerifyAndClearExpectations(&observer2);
|
| +
|
| + document.unregisterStyleObserver(&observer1);
|
| + EXPECT_EQ(true, document.hasStyleObserver());
|
| +
|
| + EXPECT_CALL(observer1, onStyleChanged(_, _, _)).Times(0);
|
| + EXPECT_CALL(observer2, onStyleChanged(_, _, _)).Times(1);
|
| + document.getElementById("first")->setAttribute("style", "border: 5px solid;", exceptionState);
|
| + layoutAndStyle();
|
| + ::testing::Mock::VerifyAndClearExpectations(&observer1);
|
| + ::testing::Mock::VerifyAndClearExpectations(&observer2);
|
| +
|
| + document.unregisterStyleObserver(&observer2);
|
| + EXPECT_EQ(false, document.hasStyleObserver());
|
| +
|
| + EXPECT_CALL(observer1, onStyleChanged(_, _, _)).Times(0);
|
| + EXPECT_CALL(observer2, onStyleChanged(_, _, _)).Times(0);
|
| + document.getElementById("first")->setAttribute("style", "border: 10px solid;", exceptionState);
|
| + layoutAndStyle();
|
| + ::testing::Mock::VerifyAndClearExpectations(&observer1);
|
| + ::testing::Mock::VerifyAndClearExpectations(&observer2);
|
| +}
|
| +
|
| +TEST_F(StyleObserverTest, SingleObserverMultipleChanges)
|
| +{
|
| + MockStyleObserver observer;
|
| + document.registerStyleObserver(&observer);
|
| + const Element* first = document.getElementById("first");
|
| + const Element* second = document.getElementById("second");
|
| +
|
| + EXPECT_CALL(observer, onStyleChanged(first, _, _)).Times(1);
|
| + EXPECT_CALL(observer, onStyleChanged(second, _, _)).Times(1);
|
| +
|
| + document.getElementById("first")->setAttribute("style", "border: 2px solid;", exceptionState);
|
| + document.getElementById("second")->setAttribute("style", "border: 2px solid;", exceptionState);
|
| +
|
| + layoutAndStyle();
|
| + ::testing::Mock::VerifyAndClearExpectations(&observer);
|
| +}
|
| +
|
| +} // namespace blink
|
|
|