Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / core / dom / StyleElementTest.cpp
blob400de285a63b0feec40fa7315a16e7d99ca2fee6
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.
5 #include "config.h"
6 #include "core/dom/StyleElement.h"
8 #include "core/css/StyleSheetContents.h"
9 #include "core/dom/Comment.h"
10 #include "core/html/HTMLStyleElement.h"
11 #include "core/testing/DummyPageHolder.h"
12 #include <gtest/gtest.h>
14 namespace blink {
16 TEST(StyleElementTest, CreateSheetUsesCache)
18 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
19 Document& document = dummyPageHolder->document();
21 document.documentElement()->setInnerHTML("<style id=style>a { top: 0; }</style>", ASSERT_NO_EXCEPTION);
23 HTMLStyleElement& styleElement = toHTMLStyleElement(*document.getElementById("style"));
24 RefPtrWillBeRawPtr<StyleSheetContents> sheet = styleElement.sheet()->contents();
26 RefPtrWillBeRawPtr<Comment> comment = document.createComment("hello!");
27 styleElement.appendChild(comment);
28 EXPECT_EQ(styleElement.sheet()->contents(), sheet);
30 styleElement.removeChild(comment);
31 EXPECT_EQ(styleElement.sheet()->contents(), sheet);
34 } // namespace blink