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

Side by Side Diff: Source/web/PluginPlaceholderImplTest.cpp

Issue 1303233007: Blink Plugins: Remove Shadow DOM plugin placeholder tests. (Closed) 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
OLDNEW
(Empty)
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 "web/PluginPlaceholderImpl.h"
7
8 #include "core/CSSPropertyNames.h"
9 #include "core/CSSValueKeywords.h"
10 #include "core/HTMLNames.h"
11 #include "core/css/CSSPrimitiveValue.h"
12 #include "core/css/CSSValue.h"
13 #include "core/css/StylePropertySet.h"
14 #include "core/dom/DocumentFragment.h"
15 #include "core/dom/TagCollection.h"
16 #include "core/testing/DummyPageHolder.h"
17 #include "public/web/WebPluginPlaceholder.h"
18 #include "wtf/OwnPtr.h"
19 #include "wtf/PassOwnPtr.h"
20 #include "wtf/text/WTFString.h"
21 #include <gmock/gmock.h>
22 #include <gtest/gtest.h>
23
24 using testing::Return;
25
26 namespace blink {
27 namespace {
28
29 using HTMLNames::scriptTag;
30
31 class MockWebPluginPlaceholder : public WebPluginPlaceholder {
32 public:
33 static PassOwnPtr<MockWebPluginPlaceholder> create() { return adoptPtr(new M ockWebPluginPlaceholder); }
34 ~MockWebPluginPlaceholder() override { }
35
36 MOCK_CONST_METHOD0(message, WebString());
37 MOCK_CONST_METHOD0(isCloseable, bool());
38
39 private:
40 MockWebPluginPlaceholder()
41 {
42 ON_CALL(*this, message()).WillByDefault(Return(WebString()));
43 }
44 };
45
46 // Fixture which creates a dummy context for running these this test.
47 // Notably creates a document fragment, since Document returns nothing for
48 // textContent, and mocks out the underlying WebPluginPlaceholder.
49 class PluginPlaceholderImplTest : public ::testing::Test {
50 protected:
51 PluginPlaceholderImplTest()
52 : m_pageHolder(DummyPageHolder::create())
53 , m_documentFragment(m_pageHolder->document().createDocumentFragment())
54 {
55 OwnPtr<MockWebPluginPlaceholder> webPluginPlaceholder = MockWebPluginPla ceholder::create();
56 m_webPluginPlaceholder = webPluginPlaceholder.get();
57 m_pluginPlaceholderImpl = PluginPlaceholderImpl::create(webPluginPlaceho lder.release(), document());
58 }
59
60 Document& document() { return m_pageHolder->document(); }
61 DocumentFragment& documentFragment() { return *m_documentFragment; }
62 MockWebPluginPlaceholder& webPluginPlaceholder() { return *m_webPluginPlaceh older; }
63 PluginPlaceholder& pluginPlaceholder() { return *m_pluginPlaceholderImpl; }
64
65 private:
66 OwnPtr<DummyPageHolder> m_pageHolder;
67 RefPtrWillBePersistent<DocumentFragment> m_documentFragment;
68 MockWebPluginPlaceholder* m_webPluginPlaceholder; // owned by PluginPlacehol derImpl
69 OwnPtrWillBePersistent<PluginPlaceholderImpl> m_pluginPlaceholderImpl;
70 };
71
72 TEST_F(PluginPlaceholderImplTest, MessageIsShown)
73 {
74 String message = "Hello world!";
75 EXPECT_CALL(webPluginPlaceholder(), message()).WillOnce(Return(message));
76 pluginPlaceholder().loadIntoContainer(documentFragment());
77 EXPECT_TRUE(documentFragment().textContent().contains(message));
78 }
79
80 TEST_F(PluginPlaceholderImplTest, MessageDoesNotRunScripts)
81 {
82 String message = "<script>console.log('this should not run');</script>";
83 EXPECT_CALL(webPluginPlaceholder(), message()).WillOnce(Return(message));
84 pluginPlaceholder().loadIntoContainer(documentFragment());
85 EXPECT_TRUE(documentFragment().textContent().contains(message));
86 EXPECT_TRUE(documentFragment().getElementsByTagName(scriptTag.localName())-> isEmpty());
87 }
88
89 TEST_F(PluginPlaceholderImplTest, MessageDoesNotAcceptElements)
90 {
91 String message = "<h1 id='sentinel'>sentinel</h1>";
92 EXPECT_CALL(webPluginPlaceholder(), message()).WillOnce(Return(message));
93 pluginPlaceholder().loadIntoContainer(documentFragment());
94 EXPECT_TRUE(documentFragment().textContent().contains(message));
95 EXPECT_FALSE(documentFragment().getElementById("sentinel"));
96 }
97
98 bool isHiddenWithInlineStyle(Element* element)
99 {
100 if (!element->inlineStyle())
101 return false;
102 RefPtrWillBeRawPtr<CSSValue> value = element->inlineStyle()->getPropertyCSSV alue(CSSPropertyDisplay);
103 return value && value->isPrimitiveValue() && toCSSPrimitiveValue(value.get() )->getValueID() == CSSValueNone;
104 }
105
106 TEST_F(PluginPlaceholderImplTest, Closeable)
107 {
108 // The closing functionality of PluginPlaceholderElement is tested in
109 // LayoutTests/fast/plugins. This test only needs to ensure that the
110 // boolean in WebPluginPlaceholder is respected.
111 EXPECT_CALL(webPluginPlaceholder(), isCloseable()).WillOnce(Return(true));
112 pluginPlaceholder().loadIntoContainer(documentFragment());
113 RefPtrWillBeRawPtr<Element> closeButton = documentFragment().getElementById( "plugin-placeholder-close-button");
114 ASSERT_NE(nullptr, closeButton);
115 EXPECT_FALSE(isHiddenWithInlineStyle(closeButton.get()));
116 }
117
118 TEST_F(PluginPlaceholderImplTest, NotCloseable)
119 {
120 EXPECT_CALL(webPluginPlaceholder(), isCloseable()).WillOnce(Return(false));
121 pluginPlaceholder().loadIntoContainer(documentFragment());
122 RefPtrWillBeRawPtr<Element> closeButton = documentFragment().getElementById( "plugin-placeholder-close-button");
123 EXPECT_NE(nullptr, closeButton);
124 EXPECT_TRUE(isHiddenWithInlineStyle(closeButton.get()));
125 }
126
127 } // namespace
128 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/fast/plugins/plugin-placeholder-structured-expected.html ('k') | Source/web/tests/FrameLoaderClientImplTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698