OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 16 matching lines...) Expand all Loading... |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "public/web/WebPluginContainer.h" | 32 #include "public/web/WebPluginContainer.h" |
33 | 33 |
34 #include "core/dom/Element.h" | 34 #include "core/dom/Element.h" |
35 #include "core/events/KeyboardEvent.h" | 35 #include "core/events/KeyboardEvent.h" |
36 #include "core/testing/URLTestHelpers.h" | 36 #include "core/testing/URLTestHelpers.h" |
| 37 #include "core/testing/UnitTestHelpers.h" |
37 #include "platform/PlatformEvent.h" | 38 #include "platform/PlatformEvent.h" |
38 #include "platform/PlatformKeyboardEvent.h" | 39 #include "platform/PlatformKeyboardEvent.h" |
39 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
40 #include "public/platform/WebClipboard.h" | 41 #include "public/platform/WebClipboard.h" |
41 #include "public/platform/WebThread.h" | 42 #include "public/platform/WebThread.h" |
42 #include "public/platform/WebUnitTestSupport.h" | 43 #include "public/platform/WebUnitTestSupport.h" |
43 #include "public/web/WebDocument.h" | 44 #include "public/web/WebDocument.h" |
44 #include "public/web/WebElement.h" | 45 #include "public/web/WebElement.h" |
45 #include "public/web/WebFrame.h" | 46 #include "public/web/WebFrame.h" |
46 #include "public/web/WebFrameClient.h" | 47 #include "public/web/WebFrameClient.h" |
47 #include "public/web/WebPluginParams.h" | 48 #include "public/web/WebPluginParams.h" |
48 #include "public/web/WebSettings.h" | 49 #include "public/web/WebSettings.h" |
49 #include "public/web/WebView.h" | 50 #include "public/web/WebView.h" |
50 #include "web/WebLocalFrameImpl.h" | 51 #include "web/WebLocalFrameImpl.h" |
51 #include "web/WebPluginContainerImpl.h" | 52 #include "web/WebPluginContainerImpl.h" |
52 #include "web/WebViewImpl.h" | 53 #include "web/WebViewImpl.h" |
53 #include "web/tests/FakeWebPlugin.h" | 54 #include "web/tests/FakeWebPlugin.h" |
54 #include "web/tests/FrameTestHelpers.h" | 55 #include "web/tests/FrameTestHelpers.h" |
55 #include <gtest/gtest.h> | 56 #include <gtest/gtest.h> |
56 | 57 |
| 58 using blink::testing::runPendingTasks; |
57 using namespace blink; | 59 using namespace blink; |
58 | 60 |
59 namespace { | 61 namespace { |
60 | 62 |
61 class WebPluginContainerTest : public testing::Test { | 63 class WebPluginContainerTest : public ::testing::Test { |
62 public: | 64 public: |
63 WebPluginContainerTest() | 65 WebPluginContainerTest() |
64 : m_baseURL("http://www.test.com/") | 66 : m_baseURL("http://www.test.com/") |
65 { | 67 { |
66 } | 68 } |
67 | 69 |
68 virtual void TearDown() | 70 virtual void TearDown() |
69 { | 71 { |
70 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 72 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
71 } | 73 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 106 |
105 TEST_F(WebPluginContainerTest, WindowToLocalPointTest) | 107 TEST_F(WebPluginContainerTest, WindowToLocalPointTest) |
106 { | 108 { |
107 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("plugin_container.html")); | 109 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("plugin_container.html")); |
108 FrameTestHelpers::WebViewHelper webViewHelper; | 110 FrameTestHelpers::WebViewHelper webViewHelper; |
109 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta
iner.html", true, new TestPluginWebFrameClient()); | 111 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta
iner.html", true, new TestPluginWebFrameClient()); |
110 ASSERT(webView); | 112 ASSERT(webView); |
111 webView->settings()->setPluginsEnabled(true); | 113 webView->settings()->setPluginsEnabled(true); |
112 webView->resize(WebSize(300, 300)); | 114 webView->resize(WebSize(300, 300)); |
113 webView->layout(); | 115 webView->layout(); |
114 FrameTestHelpers::runPendingTasks(); | 116 runPendingTasks(); |
115 | 117 |
116 WebPluginContainer* pluginContainerOne = getWebPluginContainer(webView, WebS
tring::fromUTF8("translated-plugin")); | 118 WebPluginContainer* pluginContainerOne = getWebPluginContainer(webView, WebS
tring::fromUTF8("translated-plugin")); |
117 ASSERT(pluginContainerOne); | 119 ASSERT(pluginContainerOne); |
118 WebPoint point1 = pluginContainerOne->windowToLocalPoint(WebPoint(10, 10)); | 120 WebPoint point1 = pluginContainerOne->windowToLocalPoint(WebPoint(10, 10)); |
119 ASSERT_EQ(0, point1.x); | 121 ASSERT_EQ(0, point1.x); |
120 ASSERT_EQ(0, point1.y); | 122 ASSERT_EQ(0, point1.y); |
121 WebPoint point2 = pluginContainerOne->windowToLocalPoint(WebPoint(100, 100))
; | 123 WebPoint point2 = pluginContainerOne->windowToLocalPoint(WebPoint(100, 100))
; |
122 ASSERT_EQ(90, point2.x); | 124 ASSERT_EQ(90, point2.x); |
123 ASSERT_EQ(90, point2.y); | 125 ASSERT_EQ(90, point2.y); |
124 | 126 |
125 WebPluginContainer* pluginContainerTwo = getWebPluginContainer(webView, WebS
tring::fromUTF8("rotated-plugin")); | 127 WebPluginContainer* pluginContainerTwo = getWebPluginContainer(webView, WebS
tring::fromUTF8("rotated-plugin")); |
126 ASSERT(pluginContainerTwo); | 128 ASSERT(pluginContainerTwo); |
127 WebPoint point3 = pluginContainerTwo->windowToLocalPoint(WebPoint(0, 10)); | 129 WebPoint point3 = pluginContainerTwo->windowToLocalPoint(WebPoint(0, 10)); |
128 ASSERT_EQ(10, point3.x); | 130 ASSERT_EQ(10, point3.x); |
129 ASSERT_EQ(0, point3.y); | 131 ASSERT_EQ(0, point3.y); |
130 WebPoint point4 = pluginContainerTwo->windowToLocalPoint(WebPoint(-10, 10)); | 132 WebPoint point4 = pluginContainerTwo->windowToLocalPoint(WebPoint(-10, 10)); |
131 ASSERT_EQ(10, point4.x); | 133 ASSERT_EQ(10, point4.x); |
132 ASSERT_EQ(10, point4.y); | 134 ASSERT_EQ(10, point4.y); |
133 } | 135 } |
134 | 136 |
135 TEST_F(WebPluginContainerTest, LocalToWindowPointTest) | 137 TEST_F(WebPluginContainerTest, LocalToWindowPointTest) |
136 { | 138 { |
137 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("plugin_container.html")); | 139 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("plugin_container.html")); |
138 FrameTestHelpers::WebViewHelper webViewHelper; | 140 FrameTestHelpers::WebViewHelper webViewHelper; |
139 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta
iner.html", true, new TestPluginWebFrameClient()); | 141 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta
iner.html", true, new TestPluginWebFrameClient()); |
140 ASSERT(webView); | 142 ASSERT(webView); |
141 webView->settings()->setPluginsEnabled(true); | 143 webView->settings()->setPluginsEnabled(true); |
142 webView->resize(WebSize(300, 300)); | 144 webView->resize(WebSize(300, 300)); |
143 webView->layout(); | 145 webView->layout(); |
144 FrameTestHelpers::runPendingTasks(); | 146 runPendingTasks(); |
145 | 147 |
146 WebPluginContainer* pluginContainerOne = getWebPluginContainer(webView, WebS
tring::fromUTF8("translated-plugin")); | 148 WebPluginContainer* pluginContainerOne = getWebPluginContainer(webView, WebS
tring::fromUTF8("translated-plugin")); |
147 ASSERT(pluginContainerOne); | 149 ASSERT(pluginContainerOne); |
148 WebPoint point1 = pluginContainerOne->localToWindowPoint(WebPoint(0, 0)); | 150 WebPoint point1 = pluginContainerOne->localToWindowPoint(WebPoint(0, 0)); |
149 ASSERT_EQ(10, point1.x); | 151 ASSERT_EQ(10, point1.x); |
150 ASSERT_EQ(10, point1.y); | 152 ASSERT_EQ(10, point1.y); |
151 WebPoint point2 = pluginContainerOne->localToWindowPoint(WebPoint(90, 90)); | 153 WebPoint point2 = pluginContainerOne->localToWindowPoint(WebPoint(90, 90)); |
152 ASSERT_EQ(100, point2.x); | 154 ASSERT_EQ(100, point2.x); |
153 ASSERT_EQ(100, point2.y); | 155 ASSERT_EQ(100, point2.y); |
154 | 156 |
(...skipping 10 matching lines...) Expand all Loading... |
165 // Verifies executing the command 'Copy' results in copying to the clipboard. | 167 // Verifies executing the command 'Copy' results in copying to the clipboard. |
166 TEST_F(WebPluginContainerTest, Copy) | 168 TEST_F(WebPluginContainerTest, Copy) |
167 { | 169 { |
168 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("plugin_container.html")); | 170 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("plugin_container.html")); |
169 FrameTestHelpers::WebViewHelper webViewHelper; | 171 FrameTestHelpers::WebViewHelper webViewHelper; |
170 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta
iner.html", true, new TestPluginWebFrameClient()); | 172 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta
iner.html", true, new TestPluginWebFrameClient()); |
171 ASSERT(webView); | 173 ASSERT(webView); |
172 webView->settings()->setPluginsEnabled(true); | 174 webView->settings()->setPluginsEnabled(true); |
173 webView->resize(WebSize(300, 300)); | 175 webView->resize(WebSize(300, 300)); |
174 webView->layout(); | 176 webView->layout(); |
175 FrameTestHelpers::runPendingTasks(); | 177 runPendingTasks(); |
176 | 178 |
177 WebElement pluginContainerOneElement = webView->mainFrame()->document().getE
lementById(WebString::fromUTF8("translated-plugin")); | 179 WebElement pluginContainerOneElement = webView->mainFrame()->document().getE
lementById(WebString::fromUTF8("translated-plugin")); |
178 EXPECT_TRUE(webView->mainFrame()->executeCommand("Copy", pluginContainerOne
Element)); | 180 EXPECT_TRUE(webView->mainFrame()->executeCommand("Copy", pluginContainerOne
Element)); |
179 EXPECT_EQ(WebString("x"), Platform::current()->clipboard()->readPlainText(We
bClipboard::Buffer())); | 181 EXPECT_EQ(WebString("x"), Platform::current()->clipboard()->readPlainText(We
bClipboard::Buffer())); |
180 } | 182 } |
181 | 183 |
182 // Verifies |Ctrl-C| and |Ctrl-Insert| keyboard events, results in copying to | 184 // Verifies |Ctrl-C| and |Ctrl-Insert| keyboard events, results in copying to |
183 // the clipboard. | 185 // the clipboard. |
184 TEST_F(WebPluginContainerTest, CopyInsertKeyboardEventsTest) | 186 TEST_F(WebPluginContainerTest, CopyInsertKeyboardEventsTest) |
185 { | 187 { |
186 URLTestHelpers::registerMockedURLFromBaseURL( | 188 URLTestHelpers::registerMockedURLFromBaseURL( |
187 WebString::fromUTF8(m_baseURL.c_str()), | 189 WebString::fromUTF8(m_baseURL.c_str()), |
188 WebString::fromUTF8("plugin_container.html")); | 190 WebString::fromUTF8("plugin_container.html")); |
189 FrameTestHelpers::WebViewHelper webViewHelper; | 191 FrameTestHelpers::WebViewHelper webViewHelper; |
190 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta
iner.html", true, new TestPluginWebFrameClient()); | 192 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_conta
iner.html", true, new TestPluginWebFrameClient()); |
191 ASSERT(webView); | 193 ASSERT(webView); |
192 webView->settings()->setPluginsEnabled(true); | 194 webView->settings()->setPluginsEnabled(true); |
193 webView->resize(WebSize(300, 300)); | 195 webView->resize(WebSize(300, 300)); |
194 webView->layout(); | 196 webView->layout(); |
195 FrameTestHelpers::runPendingTasks(); | 197 runPendingTasks(); |
196 | 198 |
197 WebElement pluginContainerOneElement = webView->mainFrame()->document().getE
lementById(WebString::fromUTF8("translated-plugin")); | 199 WebElement pluginContainerOneElement = webView->mainFrame()->document().getE
lementById(WebString::fromUTF8("translated-plugin")); |
198 PlatformEvent::Modifiers modifierKey = PlatformEvent::CtrlKey; | 200 PlatformEvent::Modifiers modifierKey = PlatformEvent::CtrlKey; |
199 #if OS(MACOSX) | 201 #if OS(MACOSX) |
200 modifierKey = PlatformEvent::MetaKey; | 202 modifierKey = PlatformEvent::MetaKey; |
201 #endif | 203 #endif |
202 PlatformKeyboardEvent platformKeyboardEventC(PlatformEvent::RawKeyDown, "",
"", "67", "", 67, 0, false, false, false, modifierKey, 0.0); | 204 PlatformKeyboardEvent platformKeyboardEventC(PlatformEvent::RawKeyDown, "",
"", "67", "", 67, 0, false, false, false, modifierKey, 0.0); |
203 RefPtrWillBeRawPtr<KeyboardEvent> keyEventC = KeyboardEvent::create(platform
KeyboardEventC, 0); | 205 RefPtrWillBeRawPtr<KeyboardEvent> keyEventC = KeyboardEvent::create(platform
KeyboardEventC, 0); |
204 ((WebPluginContainerImpl*)(pluginContainerOneElement.pluginContainer()))->ha
ndleEvent(keyEventC.get()); | 206 ((WebPluginContainerImpl*)(pluginContainerOneElement.pluginContainer()))->ha
ndleEvent(keyEventC.get()); |
205 EXPECT_EQ(WebString("x"), Platform::current()->clipboard()->readPlainText(We
bClipboard::Buffer())); | 207 EXPECT_EQ(WebString("x"), Platform::current()->clipboard()->readPlainText(We
bClipboard::Buffer())); |
206 | 208 |
207 // Clearing |Clipboard::Buffer()|. | 209 // Clearing |Clipboard::Buffer()|. |
208 Platform::current()->clipboard()->writePlainText(WebString("")); | 210 Platform::current()->clipboard()->writePlainText(WebString("")); |
209 EXPECT_EQ(WebString(""), Platform::current()->clipboard()->readPlainText(Web
Clipboard::Buffer())); | 211 EXPECT_EQ(WebString(""), Platform::current()->clipboard()->readPlainText(Web
Clipboard::Buffer())); |
210 | 212 |
211 PlatformKeyboardEvent platformKeyboardEventInsert(PlatformEvent::RawKeyDown,
"", "", "45", "", 45, 0, false, false, false, modifierKey, 0.0); | 213 PlatformKeyboardEvent platformKeyboardEventInsert(PlatformEvent::RawKeyDown,
"", "", "45", "", 45, 0, false, false, false, modifierKey, 0.0); |
212 RefPtrWillBeRawPtr<KeyboardEvent> keyEventInsert = KeyboardEvent::create(pla
tformKeyboardEventInsert, 0); | 214 RefPtrWillBeRawPtr<KeyboardEvent> keyEventInsert = KeyboardEvent::create(pla
tformKeyboardEventInsert, 0); |
213 ((WebPluginContainerImpl*)(pluginContainerOneElement.pluginContainer()))->ha
ndleEvent(keyEventInsert.get()); | 215 ((WebPluginContainerImpl*)(pluginContainerOneElement.pluginContainer()))->ha
ndleEvent(keyEventInsert.get()); |
214 EXPECT_EQ(WebString("x"), Platform::current()->clipboard()->readPlainText(We
bClipboard::Buffer())); | 216 EXPECT_EQ(WebString("x"), Platform::current()->clipboard()->readPlainText(We
bClipboard::Buffer())); |
215 } | 217 } |
216 } | 218 } |
OLD | NEW |