| 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 "webkit/plugins/npapi/plugin_list.h" | 5 #include "webkit/plugins/npapi/plugin_list.h" | 
| 6 | 6 | 
| 7 #include "base/string16.h" | 7 #include "base/string16.h" | 
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" | 
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" | 
| 10 #include "webkit/plugins/npapi/mock_plugin_list.h" | 10 #include "webkit/plugins/npapi/mock_plugin_list.h" | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 26   for (std::vector<WebPluginInfo>::const_iterator it = list.begin(); | 26   for (std::vector<WebPluginInfo>::const_iterator it = list.begin(); | 
| 27        it != list.end(); ++it) { | 27        it != list.end(); ++it) { | 
| 28     if (Equals(*it, plugin)) | 28     if (Equals(*it, plugin)) | 
| 29       return true; | 29       return true; | 
| 30   } | 30   } | 
| 31   return false; | 31   return false; | 
| 32 } | 32 } | 
| 33 | 33 | 
| 34 FilePath::CharType kFooPath[] = FILE_PATH_LITERAL("/plugins/foo.plugin"); | 34 FilePath::CharType kFooPath[] = FILE_PATH_LITERAL("/plugins/foo.plugin"); | 
| 35 FilePath::CharType kBarPath[] = FILE_PATH_LITERAL("/plugins/bar.plugin"); | 35 FilePath::CharType kBarPath[] = FILE_PATH_LITERAL("/plugins/bar.plugin"); | 
| 36 const char* kFooIdentifier = "foo"; |  | 
| 37 const char* kFooGroupName = "Foo"; |  | 
| 38 const char* kFooName = "Foo Plugin"; | 36 const char* kFooName = "Foo Plugin"; | 
| 39 const PluginGroupDefinition kPluginDefinitions[] = { |  | 
| 40   { kFooIdentifier, kFooGroupName, kFooName }, |  | 
| 41 }; |  | 
| 42 | 37 | 
| 43 }  // namespace | 38 }  // namespace | 
| 44 | 39 | 
| 45 class PluginListTest : public testing::Test { | 40 class PluginListTest : public testing::Test { | 
| 46  public: | 41  public: | 
| 47   PluginListTest() | 42   PluginListTest() | 
| 48       : plugin_list_(kPluginDefinitions, arraysize(kPluginDefinitions)), | 43       : foo_plugin_(ASCIIToUTF16(kFooName), | 
| 49         foo_plugin_(ASCIIToUTF16(kFooName), |  | 
| 50                     FilePath(kFooPath), | 44                     FilePath(kFooPath), | 
| 51                     ASCIIToUTF16("1.2.3"), | 45                     ASCIIToUTF16("1.2.3"), | 
| 52                     ASCIIToUTF16("foo")), | 46                     ASCIIToUTF16("foo")), | 
| 53         bar_plugin_(ASCIIToUTF16("Bar Plugin"), | 47         bar_plugin_(ASCIIToUTF16("Bar Plugin"), | 
| 54                     FilePath(kBarPath), | 48                     FilePath(kBarPath), | 
| 55                     ASCIIToUTF16("2.3.4"), | 49                     ASCIIToUTF16("2.3.4"), | 
| 56                     ASCIIToUTF16("bar")) { | 50                     ASCIIToUTF16("bar")) { | 
| 57   } | 51   } | 
| 58 | 52 | 
| 59   virtual void SetUp() { | 53   virtual void SetUp() { | 
| 60     plugin_list_.AddPluginToLoad(bar_plugin_); | 54     plugin_list_.AddPluginToLoad(bar_plugin_); | 
| 61     plugin_list_.AddPluginToLoad(foo_plugin_); | 55     plugin_list_.AddPluginToLoad(foo_plugin_); | 
| 62   } | 56   } | 
| 63 | 57 | 
| 64   PluginGroup* AddToPluginGroups(const WebPluginInfo& plugin) { |  | 
| 65     return plugin_list_.AddToPluginGroups(plugin, &plugin_list_.plugin_groups_); |  | 
| 66   } |  | 
| 67 |  | 
| 68  protected: | 58  protected: | 
| 69   MockPluginList plugin_list_; | 59   MockPluginList plugin_list_; | 
| 70   WebPluginInfo foo_plugin_; | 60   WebPluginInfo foo_plugin_; | 
| 71   WebPluginInfo bar_plugin_; | 61   WebPluginInfo bar_plugin_; | 
| 72 }; | 62 }; | 
| 73 | 63 | 
| 74 TEST_F(PluginListTest, GetPlugins) { | 64 TEST_F(PluginListTest, GetPlugins) { | 
| 75   std::vector<WebPluginInfo> plugins; | 65   std::vector<WebPluginInfo> plugins; | 
| 76   plugin_list_.GetPlugins(&plugins); | 66   plugin_list_.GetPlugins(&plugins); | 
| 77   EXPECT_EQ(2u, plugins.size()); | 67   EXPECT_EQ(2u, plugins.size()); | 
| 78   EXPECT_TRUE(Contains(plugins, foo_plugin_)); | 68   EXPECT_TRUE(Contains(plugins, foo_plugin_)); | 
| 79   EXPECT_TRUE(Contains(plugins, bar_plugin_)); | 69   EXPECT_TRUE(Contains(plugins, bar_plugin_)); | 
| 80 } | 70 } | 
| 81 | 71 | 
| 82 TEST_F(PluginListTest, GetPluginGroup) { |  | 
| 83   PluginGroup* foo_group = AddToPluginGroups(foo_plugin_); |  | 
| 84   EXPECT_EQ(ASCIIToUTF16(kFooGroupName), foo_group->GetGroupName()); |  | 
| 85 |  | 
| 86   scoped_ptr<PluginGroup> foo_group_copy( |  | 
| 87       plugin_list_.GetPluginGroup(foo_plugin_)); |  | 
| 88   EXPECT_EQ(ASCIIToUTF16(kFooGroupName), foo_group_copy->GetGroupName()); |  | 
| 89 } |  | 
| 90 |  | 
| 91 TEST_F(PluginListTest, EmptyGroup) { |  | 
| 92   std::vector<PluginGroup> groups; |  | 
| 93   plugin_list_.GetPluginGroups(false, &groups); |  | 
| 94   for (size_t i = 0; i < groups.size(); ++i) |  | 
| 95     EXPECT_GE(1U, groups[i].web_plugin_infos().size()); |  | 
| 96 } |  | 
| 97 |  | 
| 98 TEST_F(PluginListTest, BadPluginDescription) { | 72 TEST_F(PluginListTest, BadPluginDescription) { | 
| 99   WebPluginInfo plugin_3043( | 73   WebPluginInfo plugin_3043( | 
| 100       string16(), FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")), | 74       string16(), FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")), | 
| 101       string16(), string16()); | 75       string16(), string16()); | 
| 102   // Simulate loading of the plugins. | 76   // Simulate loading of the plugins. | 
| 103   plugin_list_.ClearPluginsToLoad(); | 77   plugin_list_.ClearPluginsToLoad(); | 
| 104   plugin_list_.AddPluginToLoad(plugin_3043); | 78   plugin_list_.AddPluginToLoad(plugin_3043); | 
| 105   // Now we should have them in the state we specified above. | 79   // Now we should have them in the state we specified above. | 
| 106   plugin_list_.RefreshPlugins(); | 80   plugin_list_.RefreshPlugins(); | 
| 107   std::vector<WebPluginInfo> plugins; | 81   std::vector<WebPluginInfo> plugins; | 
| 108   plugin_list_.GetPlugins(&plugins); | 82   plugin_list_.GetPlugins(&plugins); | 
| 109   ASSERT_TRUE(Contains(plugins, plugin_3043)); | 83   ASSERT_TRUE(Contains(plugins, plugin_3043)); | 
| 110 } | 84 } | 
| 111 | 85 | 
| 112 TEST_F(PluginListTest, HardcodedGroups) { |  | 
| 113   std::vector<PluginGroup> groups; |  | 
| 114   plugin_list_.GetPluginGroups(true, &groups); |  | 
| 115   ASSERT_EQ(2u, groups.size()); |  | 
| 116   EXPECT_EQ(1u, groups[0].web_plugin_infos().size()); |  | 
| 117   EXPECT_TRUE(groups[0].ContainsPlugin(FilePath(kBarPath))); |  | 
| 118   EXPECT_EQ("bar.plugin", groups[0].identifier()); |  | 
| 119   EXPECT_EQ(1u, groups[1].web_plugin_infos().size()); |  | 
| 120   EXPECT_TRUE(groups[1].ContainsPlugin(FilePath(kFooPath))); |  | 
| 121   EXPECT_EQ(kFooIdentifier, groups[1].identifier()); |  | 
| 122 } |  | 
| 123 |  | 
| 124 }  // namespace npapi | 86 }  // namespace npapi | 
| 125 }  // namespace webkit | 87 }  // namespace webkit | 
| OLD | NEW | 
|---|