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