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_finder.h" 6 7 #include "base/values.h" 8 #include "chrome/browser/plugins/plugin_metadata.h" 9 #include "testing/gtest/include/gtest/gtest.h" 10 11 using base::DictionaryValue; 12 using base::ListValue; 13 14 TEST(PluginFinderTest, JsonSyntax) { 15 scoped_ptr<base::DictionaryValue> plugin_list( 16 PluginFinder::LoadBuiltInPluginList()); 17 ASSERT_TRUE(plugin_list.get()); 18 scoped_ptr<base::Value> version; 19 ASSERT_TRUE(plugin_list->Remove("x-version", &version)); 20 EXPECT_EQ(base::Value::TYPE_INTEGER, version->GetType()); 21 22 for (base::DictionaryValue::Iterator plugin_it(*plugin_list); 23 !plugin_it.IsAtEnd(); plugin_it.Advance()) { 24 const base::DictionaryValue* plugin = NULL; 25 ASSERT_TRUE(plugin_it.value().GetAsDictionary(&plugin)); 26 std::string dummy_str; 27 bool dummy_bool; 28 if (plugin->HasKey("lang")) 29 EXPECT_TRUE(plugin->GetString("lang", &dummy_str)); 30 if (plugin->HasKey("url")) 31 EXPECT_TRUE(plugin->GetString("url", &dummy_str)); 32 EXPECT_TRUE(plugin->GetString("name", &dummy_str)); 33 if (plugin->HasKey("help_url")) 34 EXPECT_TRUE(plugin->GetString("help_url", &dummy_str)); 35 if (plugin->HasKey("displayurl")) 36 EXPECT_TRUE(plugin->GetBoolean("displayurl", &dummy_bool)); 37 if (plugin->HasKey("requires_authorization")) 38 EXPECT_TRUE(plugin->GetBoolean("requires_authorization", &dummy_bool)); 39 const base::ListValue* mime_types = NULL; 40 if (plugin->GetList("mime_types", &mime_types)) { 41 for (base::ListValue::const_iterator mime_type_it = mime_types->begin(); 42 mime_type_it != mime_types->end(); ++mime_type_it) { 43 EXPECT_TRUE((*mime_type_it)->GetAsString(&dummy_str)); 44 } 45 } 46 47 const base::ListValue* matching_mime_types = NULL; 48 if (plugin->GetList("matching_mime_types", &matching_mime_types)) { 49 for (base::ListValue::const_iterator it = matching_mime_types->begin(); 50 it != matching_mime_types->end(); ++it) { 51 EXPECT_TRUE((*it)->GetAsString(&dummy_str)); 52 } 53 } 54 55 const base::ListValue* versions = NULL; 56 if (!plugin->GetList("versions", &versions)) 57 continue; 58 59 for (base::ListValue::const_iterator it = versions->begin(); 60 it != versions->end(); ++it) { 61 base::DictionaryValue* version_dict = NULL; 62 ASSERT_TRUE((*it)->GetAsDictionary(&version_dict)); 63 EXPECT_TRUE(version_dict->GetString("version", &dummy_str)); 64 std::string status_str; 65 EXPECT_TRUE(version_dict->GetString("status", &status_str)); 66 PluginMetadata::SecurityStatus status = 67 PluginMetadata::SECURITY_STATUS_UP_TO_DATE; 68 EXPECT_TRUE(PluginMetadata::ParseSecurityStatus(status_str, &status)) 69 << "Invalid security status \"" << status_str << "\""; 70 } 71 } 72 } 73