OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "web/PluginPlaceholderImpl.h" | 6 #include "web/PluginPlaceholderImpl.h" |
7 | 7 |
| 8 #include "core/CSSPropertyNames.h" |
| 9 #include "core/CSSValueKeywords.h" |
8 #include "core/HTMLNames.h" | 10 #include "core/HTMLNames.h" |
| 11 #include "core/css/CSSPrimitiveValue.h" |
| 12 #include "core/css/CSSValue.h" |
| 13 #include "core/css/StylePropertySet.h" |
9 #include "core/dom/DocumentFragment.h" | 14 #include "core/dom/DocumentFragment.h" |
10 #include "core/dom/TagCollection.h" | 15 #include "core/dom/TagCollection.h" |
11 #include "core/testing/DummyPageHolder.h" | 16 #include "core/testing/DummyPageHolder.h" |
12 #include "public/web/WebPluginPlaceholder.h" | 17 #include "public/web/WebPluginPlaceholder.h" |
13 #include "wtf/OwnPtr.h" | 18 #include "wtf/OwnPtr.h" |
14 #include "wtf/PassOwnPtr.h" | 19 #include "wtf/PassOwnPtr.h" |
15 #include "wtf/text/WTFString.h" | 20 #include "wtf/text/WTFString.h" |
16 #include <gmock/gmock.h> | 21 #include <gmock/gmock.h> |
17 #include <gtest/gtest.h> | 22 #include <gtest/gtest.h> |
18 | 23 |
19 using testing::Return; | 24 using testing::Return; |
20 | 25 |
21 namespace blink { | 26 namespace blink { |
22 namespace { | 27 namespace { |
23 | 28 |
24 using HTMLNames::scriptTag; | 29 using HTMLNames::scriptTag; |
25 | 30 |
26 class MockWebPluginPlaceholder : public WebPluginPlaceholder { | 31 class MockWebPluginPlaceholder : public WebPluginPlaceholder { |
27 public: | 32 public: |
28 static PassOwnPtr<MockWebPluginPlaceholder> create() { return adoptPtr(new M
ockWebPluginPlaceholder); } | 33 static PassOwnPtr<MockWebPluginPlaceholder> create() { return adoptPtr(new M
ockWebPluginPlaceholder); } |
29 virtual ~MockWebPluginPlaceholder() { } | 34 virtual ~MockWebPluginPlaceholder() { } |
30 | 35 |
31 MOCK_CONST_METHOD0(message, WebString()); | 36 MOCK_CONST_METHOD0(message, WebString()); |
| 37 MOCK_CONST_METHOD0(isCloseable, bool()); |
32 | 38 |
33 private: | 39 private: |
34 MockWebPluginPlaceholder() { } | 40 MockWebPluginPlaceholder() |
| 41 { |
| 42 ON_CALL(*this, message()).WillByDefault(Return(WebString())); |
| 43 } |
35 }; | 44 }; |
36 | 45 |
37 // Fixture which creates a dummy context for running these this test. | 46 // Fixture which creates a dummy context for running these this test. |
38 // Notably creates a document fragment, since Document returns nothing for | 47 // Notably creates a document fragment, since Document returns nothing for |
39 // textContent, and mocks out the underlying WebPluginPlaceholder. | 48 // textContent, and mocks out the underlying WebPluginPlaceholder. |
40 class PluginPlaceholderImplTest : public ::testing::Test { | 49 class PluginPlaceholderImplTest : public ::testing::Test { |
41 protected: | 50 protected: |
42 PluginPlaceholderImplTest() | 51 PluginPlaceholderImplTest() |
43 : m_pageHolder(DummyPageHolder::create()) | 52 : m_pageHolder(DummyPageHolder::create()) |
44 , m_documentFragment(m_pageHolder->document().createDocumentFragment()) | 53 , m_documentFragment(m_pageHolder->document().createDocumentFragment()) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 88 |
80 TEST_F(PluginPlaceholderImplTest, MessageDoesNotAcceptElements) | 89 TEST_F(PluginPlaceholderImplTest, MessageDoesNotAcceptElements) |
81 { | 90 { |
82 String message = "<h1 id='sentinel'>sentinel</h1>"; | 91 String message = "<h1 id='sentinel'>sentinel</h1>"; |
83 EXPECT_CALL(webPluginPlaceholder(), message()).WillOnce(Return(message)); | 92 EXPECT_CALL(webPluginPlaceholder(), message()).WillOnce(Return(message)); |
84 pluginPlaceholder().loadIntoContainer(documentFragment()); | 93 pluginPlaceholder().loadIntoContainer(documentFragment()); |
85 EXPECT_TRUE(documentFragment().textContent().contains(message)); | 94 EXPECT_TRUE(documentFragment().textContent().contains(message)); |
86 EXPECT_FALSE(documentFragment().getElementById("sentinel")); | 95 EXPECT_FALSE(documentFragment().getElementById("sentinel")); |
87 } | 96 } |
88 | 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 |
89 } // namespace | 127 } // namespace |
90 } // namespace blink | 128 } // namespace blink |
OLD | NEW |