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 "chrome/browser/plugins/plugin_metadata.h" 6 7 #include "base/strings/utf_string_conversions.h" 8 #include "content/public/common/webplugininfo.h" 9 #include "testing/gtest/include/gtest/gtest.h" 10 11 namespace { 12 13 PluginMetadata::SecurityStatus GetSecurityStatus( 14 PluginMetadata* plugin_metadata, 15 const char* version) { 16 content::WebPluginInfo plugin( 17 ASCIIToUTF16("Foo plug-in"), 18 base::FilePath(FILE_PATH_LITERAL("/tmp/plugin.so")), 19 ASCIIToUTF16(version), 20 ASCIIToUTF16("Foo plug-in.")); 21 return plugin_metadata->GetSecurityStatus(plugin); 22 } 23 24 } // namespace 25 26 TEST(PluginMetadataTest, SecurityStatus) { 27 const PluginMetadata::SecurityStatus kUpToDate = 28 PluginMetadata::SECURITY_STATUS_UP_TO_DATE; 29 const PluginMetadata::SecurityStatus kOutOfDate = 30 PluginMetadata::SECURITY_STATUS_OUT_OF_DATE; 31 const PluginMetadata::SecurityStatus kRequiresAuthorization = 32 PluginMetadata::SECURITY_STATUS_REQUIRES_AUTHORIZATION; 33 34 PluginMetadata plugin_metadata("claybrick-writer", 35 ASCIIToUTF16("ClayBrick Writer"), 36 true, 37 GURL(), 38 GURL(), 39 ASCIIToUTF16("ClayBrick"), 40 std::string()); 41 EXPECT_EQ(kRequiresAuthorization, 42 GetSecurityStatus(&plugin_metadata, "1.2.3")); 43 44 plugin_metadata.AddVersion(Version("9.4.1"), kRequiresAuthorization); 45 plugin_metadata.AddVersion(Version("10"), kOutOfDate); 46 plugin_metadata.AddVersion(Version("10.2.1"), kUpToDate); 47 48 // Invalid version. 49 EXPECT_EQ(kOutOfDate, GetSecurityStatus(&plugin_metadata, "foo")); 50 51 EXPECT_EQ(kOutOfDate, GetSecurityStatus(&plugin_metadata, "0")); 52 EXPECT_EQ(kOutOfDate, GetSecurityStatus(&plugin_metadata, "1.2.3")); 53 EXPECT_EQ(kRequiresAuthorization, 54 GetSecurityStatus(&plugin_metadata, "9.4.1")); 55 EXPECT_EQ(kRequiresAuthorization, 56 GetSecurityStatus(&plugin_metadata, "9.4.2")); 57 EXPECT_EQ(kOutOfDate, GetSecurityStatus(&plugin_metadata, "10.2.0")); 58 EXPECT_EQ(kUpToDate, GetSecurityStatus(&plugin_metadata, "10.2.1")); 59 EXPECT_EQ(kUpToDate, GetSecurityStatus(&plugin_metadata, "11")); 60 } 61