Home | History | Annotate | Download | only in plugins
      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_installer.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 PluginInstaller::SecurityStatus GetSecurityStatus(PluginInstaller* installer,
     14                                                   const char* version) {
     15   content:: WebPluginInfo plugin(
     16       ASCIIToUTF16("Foo plug-in"),
     17       base::FilePath(FILE_PATH_LITERAL("/tmp/plugin.so")),
     18       ASCIIToUTF16(version),
     19       ASCIIToUTF16("Foo plug-in."));
     20   return installer->GetSecurityStatus(plugin);
     21 }
     22 
     23 }  // namespace
     24 
     25 TEST(PluginInstallerTest, SecurityStatus) {
     26   const PluginInstaller::SecurityStatus kUpToDate =
     27       PluginInstaller::SECURITY_STATUS_UP_TO_DATE;
     28   const PluginInstaller::SecurityStatus kOutOfDate =
     29       PluginInstaller::SECURITY_STATUS_OUT_OF_DATE;
     30   const PluginInstaller::SecurityStatus kRequiresAuthorization =
     31       PluginInstaller::SECURITY_STATUS_REQUIRES_AUTHORIZATION;
     32 
     33   PluginInstaller installer("claybrick-writer",
     34                             ASCIIToUTF16("ClayBrick Writer"),
     35                             true, GURL(), GURL(), ASCIIToUTF16("ClayBrick"));
     36 
     37 #if defined(OS_LINUX)
     38   EXPECT_EQ(kRequiresAuthorization, GetSecurityStatus(&installer, "1.2.3"));
     39 #else
     40   EXPECT_EQ(kUpToDate, GetSecurityStatus(&installer, "1.2.3"));
     41 #endif
     42 
     43   installer.AddVersion(Version("9.4.1"), kRequiresAuthorization);
     44   installer.AddVersion(Version("10"), kOutOfDate);
     45   installer.AddVersion(Version("10.2.1"), kUpToDate);
     46 
     47   // Invalid version.
     48   EXPECT_EQ(kOutOfDate, GetSecurityStatus(&installer, "foo"));
     49 
     50   EXPECT_EQ(kOutOfDate, GetSecurityStatus(&installer, "0"));
     51   EXPECT_EQ(kOutOfDate, GetSecurityStatus(&installer, "1.2.3"));
     52   EXPECT_EQ(kRequiresAuthorization, GetSecurityStatus(&installer, "9.4.1"));
     53   EXPECT_EQ(kRequiresAuthorization, GetSecurityStatus(&installer, "9.4.2"));
     54   EXPECT_EQ(kOutOfDate, GetSecurityStatus(&installer, "10.2.0"));
     55   EXPECT_EQ(kUpToDate, GetSecurityStatus(&installer, "10.2.1"));
     56   EXPECT_EQ(kUpToDate, GetSecurityStatus(&installer, "11"));
     57 }
     58