diff options
author | skerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-03 14:25:39 +0000 |
---|---|---|
committer | skerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-03 14:25:39 +0000 |
commit | aaadcd81066a3430b33702288cd56a39986b4326 (patch) | |
tree | 08f2f9e011880015dd47c669f4311f17faa55391 /chrome/common | |
parent | 83e29c010812422515660e4a0b77f1738f238aec (diff) | |
download | chromium_src-aaadcd81066a3430b33702288cd56a39986b4326.zip chromium_src-aaadcd81066a3430b33702288cd56a39986b4326.tar.gz chromium_src-aaadcd81066a3430b33702288cd56a39986b4326.tar.bz2 |
Add unit test that uses V8's JSON.parse() to read extension_api.json .
BUG=18717
TEST=ExtensionApiJsonValidityTest.WithV8
Review URL: http://codereview.chromium.org/661406
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40516 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/extensions/api/extension_api_json_validity_unittest.cc | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/chrome/common/extensions/api/extension_api_json_validity_unittest.cc b/chrome/common/extensions/api/extension_api_json_validity_unittest.cc deleted file mode 100644 index 6746cc7..0000000 --- a/chrome/common/extensions/api/extension_api_json_validity_unittest.cc +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/file_path.h" -#include "base/file_util.h" -#include "base/path_service.h" -#include "base/scoped_ptr.h" -#include "chrome/common/json_value_serializer.h" -#include "chrome/common/chrome_paths.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -// Given a ListValue* of dictionaries, find the first dictionary with -// a property |property| whose string value is |expected_value|. The -// following conditions result in a return value of false, and an -// explanation in |out_error_message|: -// * Any list element is not a dictionary. -// * Any list element does not have a string property |property|. -// * More than one list element has a string property with value -// |expected_value|. -// -// Return true and set |out_matching_dict| if such a dictionary was -// found. If false is returned, |out_message| is set to an explanation. -bool FindDictionaryWithProperyValue(ListValue* list, - const std::string& property, - const std::string& expected_value, - DictionaryValue** out_matching_dict, - std::string* out_error_message) { - bool found = false; - for (ListValue::const_iterator it = list->begin(); it != list->end(); ++it) { - if (!(*it)->IsType(Value::TYPE_DICTIONARY)) { - *out_error_message = "List contains an item taht is not a dictionary."; - return false; - } - - DictionaryValue* dict = static_cast<DictionaryValue*>(*it); - - std::string actual_value; - if (!dict->GetStringASCII(property, &actual_value)) { - *out_error_message = - "Dictionary has no string property \'" + property + "'."; - return false; - } - - if (actual_value != expected_value) - continue; - - if (found) { - *out_error_message = "More than one dictionary matches."; - return false; - } - found = true; - if (out_matching_dict) - *out_matching_dict = dict; - } - if (!found) { - *out_error_message = "No dictionary matches."; - return false; - } - return true; -} - -} - -class ExtensionApiJsonValidityTest : public testing::Test { -}; - -TEST(ExtensionApiJsonValidityTest, Basic) { - // Build the path to extension_api.json, and check that the file exists. - FilePath extension_api_json; - ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &extension_api_json)); - extension_api_json = extension_api_json.AppendASCII("chrome") - .AppendASCII("common") - .AppendASCII("extensions") - .AppendASCII("api") - .AppendASCII("extension_api.json"); - ASSERT_TRUE(file_util::PathExists(extension_api_json)) - << "Failed to find file 'extension_api.json' at the following path: " - << extension_api_json.value(); - - std::string error_message; - - // Check that extension_api.json can be parsed as JSON. - JSONFileValueSerializer serializer(extension_api_json); - scoped_ptr<Value> root(serializer.Deserialize(&error_message)); - ASSERT_TRUE(root.get()) << error_message; - ASSERT_EQ(Value::TYPE_LIST, root->GetType()); - ListValue* root_list = static_cast<ListValue*>(root.get()); - - // As a basic smoke test that the JSON we read is reasonable, find the - // definition of the functions chrome.test.log() and - // chrome.test.notifyPass(). - DictionaryValue* test_namespace_dict; - ASSERT_TRUE(FindDictionaryWithProperyValue( - root_list, "namespace", "test", &test_namespace_dict, &error_message)) - << error_message; - - ListValue* functions_list; - ASSERT_TRUE(test_namespace_dict->GetList(L"functions", &functions_list)) - << "Namespace 'test' should define some functions."; - - EXPECT_TRUE(FindDictionaryWithProperyValue( - functions_list, "name", "log", NULL, &error_message)) - << error_message; - - EXPECT_TRUE(FindDictionaryWithProperyValue( - functions_list, "name", "notifyPass", NULL, &error_message)) - << error_message; -} - -// TODO(skerner): Add a test that parses extension_api.json using v8. |