| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/plugins/npapi/plugin_lib.h" | |
| 6 | |
| 7 #include "base/strings/string_util.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "build/build_config.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 namespace webkit { | |
| 13 namespace npapi { | |
| 14 | |
| 15 // Test the unloading of plugin libs. Bug http://crbug.com/46526 showed that | |
| 16 // if UnloadAllPlugins() simply iterates through the g_loaded_libs global | |
| 17 // variable, we can get a crash if no plugin libs were marked as always loaded. | |
| 18 class PluginLibTest : public PluginLib { | |
| 19 public: | |
| 20 PluginLibTest() : PluginLib(WebPluginInfo()) {} | |
| 21 using PluginLib::Unload; | |
| 22 | |
| 23 protected: | |
| 24 virtual ~PluginLibTest() {} | |
| 25 }; | |
| 26 | |
| 27 TEST(PluginLibLoading, UnloadAllPlugins) { | |
| 28 // For the creation of the g_loaded_libs global variable. | |
| 29 ASSERT_EQ(static_cast<PluginLibTest*>(NULL), | |
| 30 PluginLibTest::CreatePluginLib(base::FilePath())); | |
| 31 | |
| 32 // Try with a single plugin lib. | |
| 33 scoped_refptr<PluginLibTest> plugin_lib1(new PluginLibTest()); | |
| 34 PluginLib::UnloadAllPlugins(); | |
| 35 | |
| 36 // Need to create it again, it should have been destroyed above. | |
| 37 ASSERT_EQ(static_cast<PluginLibTest*>(NULL), | |
| 38 PluginLibTest::CreatePluginLib(base::FilePath())); | |
| 39 | |
| 40 // Try with two plugin libs. | |
| 41 plugin_lib1 = new PluginLibTest(); | |
| 42 scoped_refptr<PluginLibTest> plugin_lib2(new PluginLibTest()); | |
| 43 PluginLib::UnloadAllPlugins(); | |
| 44 | |
| 45 // Need to create it again, it should have been destroyed above. | |
| 46 ASSERT_EQ(static_cast<PluginLibTest*>(NULL), | |
| 47 PluginLibTest::CreatePluginLib(base::FilePath())); | |
| 48 | |
| 49 // Now try to manually Unload one and then UnloadAll. | |
| 50 plugin_lib1 = new PluginLibTest(); | |
| 51 plugin_lib2 = new PluginLibTest(); | |
| 52 plugin_lib1->Unload(); | |
| 53 PluginLib::UnloadAllPlugins(); | |
| 54 | |
| 55 // Need to create it again, it should have been destroyed above. | |
| 56 ASSERT_EQ(static_cast<PluginLibTest*>(NULL), | |
| 57 PluginLibTest::CreatePluginLib(base::FilePath())); | |
| 58 | |
| 59 // Now try to manually Unload the only one and then UnloadAll. | |
| 60 plugin_lib1 = new PluginLibTest(); | |
| 61 plugin_lib1->Unload(); | |
| 62 PluginLib::UnloadAllPlugins(); | |
| 63 } | |
| 64 | |
| 65 } // namespace npapi | |
| 66 } // namespace webkit | |
| OLD | NEW |