| 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/common/plugin_list.h" | 5 #include "content/common/plugin_list.h" |
| 6 | 6 |
| 7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 base::FilePath(kFooPath), | 45 base::FilePath(kFooPath), |
| 46 base::ASCIIToUTF16("1.2.3"), | 46 base::ASCIIToUTF16("1.2.3"), |
| 47 base::ASCIIToUTF16("foo")), | 47 base::ASCIIToUTF16("foo")), |
| 48 bar_plugin_(base::ASCIIToUTF16("Bar Plugin"), | 48 bar_plugin_(base::ASCIIToUTF16("Bar Plugin"), |
| 49 base::FilePath(kBarPath), | 49 base::FilePath(kBarPath), |
| 50 base::ASCIIToUTF16("2.3.4"), | 50 base::ASCIIToUTF16("2.3.4"), |
| 51 base::ASCIIToUTF16("bar")) { | 51 base::ASCIIToUTF16("bar")) { |
| 52 } | 52 } |
| 53 | 53 |
| 54 void SetUp() override { | 54 void SetUp() override { |
| 55 plugin_list_.DisablePluginsDiscovery(); | |
| 56 plugin_list_.RegisterInternalPlugin(bar_plugin_, false); | 55 plugin_list_.RegisterInternalPlugin(bar_plugin_, false); |
| 57 foo_plugin_.mime_types.push_back( | 56 foo_plugin_.mime_types.push_back( |
| 58 WebPluginMimeType(kFooMimeType, kFooFileType, std::string())); | 57 WebPluginMimeType(kFooMimeType, kFooFileType, std::string())); |
| 59 plugin_list_.RegisterInternalPlugin(foo_plugin_, false); | 58 plugin_list_.RegisterInternalPlugin(foo_plugin_, false); |
| 60 } | 59 } |
| 61 | 60 |
| 62 protected: | 61 protected: |
| 63 PluginList plugin_list_; | 62 PluginList plugin_list_; |
| 64 WebPluginInfo foo_plugin_; | 63 WebPluginInfo foo_plugin_; |
| 65 WebPluginInfo bar_plugin_; | 64 WebPluginInfo bar_plugin_; |
| 66 }; | 65 }; |
| 67 | 66 |
| 68 TEST_F(PluginListTest, GetPlugins) { | 67 TEST_F(PluginListTest, GetPlugins) { |
| 69 std::vector<WebPluginInfo> plugins; | 68 std::vector<WebPluginInfo> plugins; |
| 70 plugin_list_.GetPlugins(&plugins, true); | 69 plugin_list_.GetPlugins(&plugins); |
| 71 EXPECT_EQ(2u, plugins.size()); | 70 EXPECT_EQ(2u, plugins.size()); |
| 72 EXPECT_TRUE(Contains(plugins, foo_plugin_)); | 71 EXPECT_TRUE(Contains(plugins, foo_plugin_)); |
| 73 EXPECT_TRUE(Contains(plugins, bar_plugin_)); | 72 EXPECT_TRUE(Contains(plugins, bar_plugin_)); |
| 74 } | 73 } |
| 75 | 74 |
| 76 TEST_F(PluginListTest, BadPluginDescription) { | 75 TEST_F(PluginListTest, BadPluginDescription) { |
| 77 WebPluginInfo plugin_3043( | 76 WebPluginInfo plugin_3043( |
| 78 base::string16(), base::FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")), | 77 base::string16(), base::FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")), |
| 79 base::string16(), base::string16()); | 78 base::string16(), base::string16()); |
| 80 // Simulate loading of the plugins. | 79 // Simulate loading of the plugins. |
| 81 plugin_list_.RegisterInternalPlugin(plugin_3043, false); | 80 plugin_list_.RegisterInternalPlugin(plugin_3043, false); |
| 82 // Now we should have them in the state we specified above. | 81 // Now we should have them in the state we specified above. |
| 83 plugin_list_.RefreshPlugins(); | 82 plugin_list_.RefreshPlugins(); |
| 84 std::vector<WebPluginInfo> plugins; | 83 std::vector<WebPluginInfo> plugins; |
| 85 plugin_list_.GetPlugins(&plugins, true); | 84 plugin_list_.GetPlugins(&plugins); |
| 86 ASSERT_TRUE(Contains(plugins, plugin_3043)); | 85 ASSERT_TRUE(Contains(plugins, plugin_3043)); |
| 87 } | 86 } |
| 88 | 87 |
| 89 TEST_F(PluginListTest, GetPluginInfoArray) { | 88 TEST_F(PluginListTest, GetPluginInfoArray) { |
| 90 const char kTargetUrl[] = "http://example.com/test.foo"; | 89 const char kTargetUrl[] = "http://example.com/test.foo"; |
| 91 GURL target_url(kTargetUrl); | 90 GURL target_url(kTargetUrl); |
| 92 std::vector<WebPluginInfo> plugins; | 91 std::vector<WebPluginInfo> plugins; |
| 93 std::vector<std::string> actual_mime_types; | 92 std::vector<std::string> actual_mime_types; |
| 94 | 93 |
| 95 // The file type of the URL is supported by foo_plugin_. However, | 94 // The file type of the URL is supported by foo_plugin_. However, |
| 96 // GetPluginInfoArray should not match foo_plugin_ because the MIME type is | 95 // GetPluginInfoArray should not match foo_plugin_ because the MIME type is |
| 97 // application/octet-stream. | 96 // application/octet-stream. |
| 98 plugin_list_.GetPluginInfoArray(target_url, | 97 plugin_list_.GetPluginInfoArray(target_url, |
| 99 "application/octet-stream", | 98 "application/octet-stream", |
| 100 false, // allow_wildcard | 99 false, // allow_wildcard |
| 101 NULL, // use_stale | 100 NULL, // use_stale |
| 102 false, // include_npapi | |
| 103 &plugins, | 101 &plugins, |
| 104 &actual_mime_types); | 102 &actual_mime_types); |
| 105 EXPECT_EQ(0u, plugins.size()); | 103 EXPECT_EQ(0u, plugins.size()); |
| 106 EXPECT_EQ(0u, actual_mime_types.size()); | 104 EXPECT_EQ(0u, actual_mime_types.size()); |
| 107 | 105 |
| 108 // foo_plugin_ matches due to the MIME type. | 106 // foo_plugin_ matches due to the MIME type. |
| 109 plugins.clear(); | 107 plugins.clear(); |
| 110 actual_mime_types.clear(); | 108 actual_mime_types.clear(); |
| 111 plugin_list_.GetPluginInfoArray(target_url, | 109 plugin_list_.GetPluginInfoArray(target_url, |
| 112 kFooMimeType, | 110 kFooMimeType, |
| 113 false, // allow_wildcard | 111 false, // allow_wildcard |
| 114 NULL, // use_stale | 112 NULL, // use_stale |
| 115 false, // include_npapi | |
| 116 &plugins, | 113 &plugins, |
| 117 &actual_mime_types); | 114 &actual_mime_types); |
| 118 EXPECT_EQ(1u, plugins.size()); | 115 EXPECT_EQ(1u, plugins.size()); |
| 119 EXPECT_TRUE(Contains(plugins, foo_plugin_)); | 116 EXPECT_TRUE(Contains(plugins, foo_plugin_)); |
| 120 ASSERT_EQ(1u, actual_mime_types.size()); | 117 ASSERT_EQ(1u, actual_mime_types.size()); |
| 121 EXPECT_EQ(kFooMimeType, actual_mime_types.front()); | 118 EXPECT_EQ(kFooMimeType, actual_mime_types.front()); |
| 122 | 119 |
| 123 // foo_plugin_ matches due to the file type and empty MIME type. | 120 // foo_plugin_ matches due to the file type and empty MIME type. |
| 124 plugins.clear(); | 121 plugins.clear(); |
| 125 actual_mime_types.clear(); | 122 actual_mime_types.clear(); |
| 126 plugin_list_.GetPluginInfoArray(target_url, | 123 plugin_list_.GetPluginInfoArray(target_url, |
| 127 "", | 124 "", |
| 128 false, // allow_wildcard | 125 false, // allow_wildcard |
| 129 NULL, // use_stale | 126 NULL, // use_stale |
| 130 false, // include_npapi | |
| 131 &plugins, | 127 &plugins, |
| 132 &actual_mime_types); | 128 &actual_mime_types); |
| 133 EXPECT_EQ(1u, plugins.size()); | 129 EXPECT_EQ(1u, plugins.size()); |
| 134 EXPECT_TRUE(Contains(plugins, foo_plugin_)); | 130 EXPECT_TRUE(Contains(plugins, foo_plugin_)); |
| 135 ASSERT_EQ(1u, actual_mime_types.size()); | 131 ASSERT_EQ(1u, actual_mime_types.size()); |
| 136 EXPECT_EQ(kFooMimeType, actual_mime_types.front()); | 132 EXPECT_EQ(kFooMimeType, actual_mime_types.front()); |
| 137 } | 133 } |
| 138 | 134 |
| 139 } // namespace content | 135 } // namespace content |
| OLD | NEW |