OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/browser_plugin/browser_plugin_browsertest.h" | 5 #include "content/renderer/browser_plugin/browser_plugin_browsertest.h" |
6 | 6 |
7 #include "base/debug/leak_annotations.h" | 7 #include "base/debug/leak_annotations.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "third_party/WebKit/public/web/WebScriptSource.h" | 24 #include "third_party/WebKit/public/web/WebScriptSource.h" |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 namespace { | 28 namespace { |
29 const char kHTMLForBrowserPluginObject[] = | 29 const char kHTMLForBrowserPluginObject[] = |
30 "<object id='browserplugin' width='640px' height='480px'" | 30 "<object id='browserplugin' width='640px' height='480px'" |
31 " src='foo' type='%s'></object>" | 31 " src='foo' type='%s'></object>" |
32 "<script>document.querySelector('object').nonExistentAttribute;</script>"; | 32 "<script>document.querySelector('object').nonExistentAttribute;</script>"; |
33 | 33 |
34 const char kHTMLForSourcelessPluginObject[] = | |
35 "<object id='browserplugin' width='640px' height='480px' type='%s'>"; | |
36 | |
37 std::string GetHTMLForBrowserPluginObject() { | 34 std::string GetHTMLForBrowserPluginObject() { |
38 return base::StringPrintf(kHTMLForBrowserPluginObject, | 35 return base::StringPrintf(kHTMLForBrowserPluginObject, |
39 kBrowserPluginMimeType); | 36 kBrowserPluginMimeType); |
40 } | 37 } |
41 | 38 |
42 } // namespace | 39 } // namespace |
43 | 40 |
44 // Test factory for creating test instances of BrowserPluginManager. | 41 // Test factory for creating test instances of BrowserPluginManager. |
45 class TestBrowserPluginManagerFactory : public BrowserPluginManagerFactory { | 42 class TestBrowserPluginManagerFactory : public BrowserPluginManagerFactory { |
46 public: | 43 public: |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 163 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
167 // Verify that the information in Attach is correct. | 164 // Verify that the information in Attach is correct. |
168 BrowserPluginHostMsg_Attach_Params params; | 165 BrowserPluginHostMsg_Attach_Params params; |
169 MockBrowserPlugin* browser_plugin = GetCurrentPluginWithAttachParams(¶ms); | 166 MockBrowserPlugin* browser_plugin = GetCurrentPluginWithAttachParams(¶ms); |
170 | 167 |
171 EXPECT_EQ(640, params.resize_guest_params.view_size.width()); | 168 EXPECT_EQ(640, params.resize_guest_params.view_size.width()); |
172 EXPECT_EQ(480, params.resize_guest_params.view_size.height()); | 169 EXPECT_EQ(480, params.resize_guest_params.view_size.height()); |
173 ASSERT_TRUE(browser_plugin); | 170 ASSERT_TRUE(browser_plugin); |
174 } | 171 } |
175 | 172 |
176 TEST_F(BrowserPluginTest, RemovePlugin) { | |
177 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | |
178 MockBrowserPlugin* browser_plugin = GetCurrentPlugin(); | |
179 ASSERT_TRUE(browser_plugin); | |
180 | |
181 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | |
182 BrowserPluginHostMsg_PluginDestroyed::ID)); | |
183 ExecuteJavaScript("x = document.getElementById('browserplugin'); " | |
184 "x.parentNode.removeChild(x);"); | |
185 ProcessPendingMessages(); | |
186 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | |
187 BrowserPluginHostMsg_PluginDestroyed::ID)); | |
188 } | |
189 | |
190 // This test verifies that PluginDestroyed messages do not get sent from a | |
191 // BrowserPlugin that has never navigated. | |
192 TEST_F(BrowserPluginTest, RemovePluginBeforeNavigation) { | |
193 std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject, | |
194 kBrowserPluginMimeType); | |
195 LoadHTML(html.c_str()); | |
196 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | |
197 BrowserPluginHostMsg_PluginDestroyed::ID)); | |
198 ExecuteJavaScript("x = document.getElementById('browserplugin'); " | |
199 "x.parentNode.removeChild(x);"); | |
200 ProcessPendingMessages(); | |
201 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | |
202 BrowserPluginHostMsg_PluginDestroyed::ID)); | |
203 } | |
204 | |
205 } // namespace content | 173 } // namespace content |
OLD | NEW |