From 7dc95e485bc44c7d4736df11bda08d8bf0eb816b Mon Sep 17 00:00:00 2001 From: "aa@chromium.org" Date: Fri, 30 Sep 2011 21:55:36 +0000 Subject: Revert 103536 - Add ExtensionFunctionTest base class and a test for GetWindowFunction using it. Review URL: http://codereview.chromium.org/8065027 TBR=aa@chromium.org Review URL: http://codereview.chromium.org/8102011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103552 0039d316-1c4b-4281-b951-d872f2087c98 --- .../extensions/extension_function_test_utils.cc | 108 --------------------- 1 file changed, 108 deletions(-) delete mode 100644 chrome/browser/extensions/extension_function_test_utils.cc (limited to 'chrome/browser/extensions/extension_function_test_utils.cc') diff --git a/chrome/browser/extensions/extension_function_test_utils.cc b/chrome/browser/extensions/extension_function_test_utils.cc deleted file mode 100644 index 4f5b8ae..0000000 --- a/chrome/browser/extensions/extension_function_test_utils.cc +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (c) 2011 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 "chrome/browser/extensions/extension_function_test_utils.h" - -#include - -#include "base/json/json_reader.h" -#include "base/values.h" -#include "chrome/browser/ui/browser.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace extension_function_test_utils { - -base::Value* ParseJSON(const std::string& data) { - const bool kAllowTrailingComma = false; - return base::JSONReader::Read(data, kAllowTrailingComma); -} - -base::ListValue* ParseList(const std::string& data) { - scoped_ptr result(ParseJSON(data)); - if (result.get() && result->IsType(base::Value::TYPE_LIST)) - return static_cast(result.release()); - else - return NULL; -} - -base::DictionaryValue* ParseDictionary( - const std::string& data) { - scoped_ptr result(ParseJSON(data)); - if (result.get() && result->IsType(base::Value::TYPE_DICTIONARY)) - return static_cast(result.release()); - else - return NULL; -} - -bool GetBoolean(base::DictionaryValue* val, const std::string& key) { - bool result = false; - if (!val->GetBoolean(key, &result)) - ADD_FAILURE() << key << " does not exist or is not a boolean."; - return result; -} - -int GetInteger(base::DictionaryValue* val, const std::string& key) { - int result = 0; - if (!val->GetInteger(key, &result)) - ADD_FAILURE() << key << " does not exist or is not an integer."; - return result; -} - -std::string GetString(base::DictionaryValue* val, const std::string& key) { - std::string result; - if (!val->GetString(key, &result)) - ADD_FAILURE() << key << " does not exist or is not a string."; - return result; -} - -base::DictionaryValue* ToDictionary(base::Value* val) { - if (!val || !val->IsType(base::Value::TYPE_DICTIONARY)) - ADD_FAILURE() << "value is null or not a dictionary."; - return static_cast(val); -} - -std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, - const std::string& args, - Browser* browser) { - return RunFunctionAndReturnError(function, args, browser, NONE); -} -std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, - const std::string& args, - Browser* browser, - RunFunctionFlags flags) { - scoped_refptr function_owner(function); - RunFunction(function, args, browser, flags); - if (function->GetResultValue()) - ADD_FAILURE() << function->GetResult(); - return function->GetError(); -} - -base::Value* RunFunctionAndReturnResult(UIThreadExtensionFunction* function, - const std::string& args, - Browser* browser) { - return RunFunctionAndReturnResult(function, args, browser, NONE); -} -base::Value* RunFunctionAndReturnResult(UIThreadExtensionFunction* function, - const std::string& args, - Browser* browser, - RunFunctionFlags flags) { - scoped_refptr function_owner(function); - RunFunction(function, args, browser, flags); - if (!function->GetError().empty()) - ADD_FAILURE() << function->GetError(); - return function->GetResultValue()->DeepCopy(); -} - -void RunFunction(UIThreadExtensionFunction* function, - const std::string& args, - Browser* browser, - RunFunctionFlags flags) { - scoped_ptr parsed_args(ParseList(args)); - function->SetArgs(parsed_args.get()); - function->set_profile(browser->profile()); - function->set_include_incognito(flags & INCLUDE_INCOGNITO); - function->Run(); -} - -} // namespace extension_function_test_utils -- cgit v1.1