OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "webkit/glue/plugins/plugin_lib.h" | 5 #include "webkit/glue/plugins/plugin_lib.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 // Test the unloading of plugin libs. Bug http://crbug.com/46526 showed that | 12 // Test the unloading of plugin libs. Bug http://crbug.com/46526 showed that |
13 // if UnloadAllPlugins() simply iterates through the g_loaded_libs global | 13 // if UnloadAllPlugins() simply iterates through the g_loaded_libs global |
14 // variable, we can get a crash if no plugin libs were marked as always loaded. | 14 // variable, we can get a crash if no plugin libs were marked as always loaded. |
15 class PluginLibTest : public NPAPI::PluginLib { | 15 class PluginLibTest : public NPAPI::PluginLib { |
16 public: | 16 public: |
17 PluginLibTest() : NPAPI::PluginLib(WebPluginInfo(), NULL) { | 17 PluginLibTest() : NPAPI::PluginLib(WebPluginInfo(), NULL) { |
18 } | 18 } |
19 using NPAPI::PluginLib::Unload; | 19 using NPAPI::PluginLib::Unload; |
20 }; | 20 }; |
21 | 21 |
22 TEST(PluginLibLoading, UnloadAllPlugins) { | 22 TEST(PluginLibLoading, UnloadAllPlugins) { |
23 // For the creation of the g_loaded_libs global variable. | 23 // For the creation of the g_loaded_libs global variable. |
24 ASSERT_EQ(static_cast<PluginLibTest*>(NULL), | 24 ASSERT_EQ(static_cast<PluginLibTest*>(NULL), |
25 PluginLibTest::CreatePluginLib(FilePath())); | 25 PluginLibTest::CreatePluginLib(FilePath())); |
26 | 26 |
27 // Try with a single plugin lib. | 27 // Try with a single plugin lib. |
28 scoped_refptr<PluginLibTest> plugin_lib1 = new PluginLibTest(); | 28 scoped_refptr<PluginLibTest> plugin_lib1(new PluginLibTest()); |
29 NPAPI::PluginLib::UnloadAllPlugins(); | 29 NPAPI::PluginLib::UnloadAllPlugins(); |
30 | 30 |
31 // Need to create it again, it should have been destroyed above. | 31 // Need to create it again, it should have been destroyed above. |
32 ASSERT_EQ(static_cast<PluginLibTest*>(NULL), | 32 ASSERT_EQ(static_cast<PluginLibTest*>(NULL), |
33 PluginLibTest::CreatePluginLib(FilePath())); | 33 PluginLibTest::CreatePluginLib(FilePath())); |
34 | 34 |
35 // Try with two plugin libs. | 35 // Try with two plugin libs. |
36 plugin_lib1 = new PluginLibTest(); | 36 plugin_lib1 = new PluginLibTest(); |
37 scoped_refptr<PluginLibTest> plugin_lib2 = new PluginLibTest(); | 37 scoped_refptr<PluginLibTest> plugin_lib2(new PluginLibTest()); |
38 NPAPI::PluginLib::UnloadAllPlugins(); | 38 NPAPI::PluginLib::UnloadAllPlugins(); |
39 | 39 |
40 // Need to create it again, it should have been destroyed above. | 40 // Need to create it again, it should have been destroyed above. |
41 ASSERT_EQ(static_cast<PluginLibTest*>(NULL), | 41 ASSERT_EQ(static_cast<PluginLibTest*>(NULL), |
42 PluginLibTest::CreatePluginLib(FilePath())); | 42 PluginLibTest::CreatePluginLib(FilePath())); |
43 | 43 |
44 // Now try to manually Unload one and then UnloadAll. | 44 // Now try to manually Unload one and then UnloadAll. |
45 plugin_lib1 = new PluginLibTest(); | 45 plugin_lib1 = new PluginLibTest(); |
46 plugin_lib2 = new PluginLibTest(); | 46 plugin_lib2 = new PluginLibTest(); |
47 plugin_lib1->Unload(); | 47 plugin_lib1->Unload(); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 143 |
144 ASSERT_EQ(12U, types.size()); | 144 ASSERT_EQ(12U, types.size()); |
145 for (size_t i = 0; i < types.size(); ++i) | 145 for (size_t i = 0; i < types.size(); ++i) |
146 EXPECT_EQ(ASCIIToUTF16("IcedTea"), types[i].description); | 146 EXPECT_EQ(ASCIIToUTF16("IcedTea"), types[i].description); |
147 | 147 |
148 // Verify that the mime types with semis are coming through ok. | 148 // Verify that the mime types with semis are coming through ok. |
149 EXPECT_TRUE(types[4].mime_type.find(';') != std::string::npos); | 149 EXPECT_TRUE(types[4].mime_type.find(';') != std::string::npos); |
150 } | 150 } |
151 | 151 |
152 #endif // defined(OS_LINUX) | 152 #endif // defined(OS_LINUX) |
OLD | NEW |