Index: extensions/browser/extension_api_unittest.cc |
diff --git a/extensions/browser/extension_api_unittest.cc b/extensions/browser/extension_api_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0b4dd1f57eca6f0c70a9fc55e5baf30be205b105 |
--- /dev/null |
+++ b/extensions/browser/extension_api_unittest.cc |
@@ -0,0 +1,107 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
James Cook
2014/08/13 16:11:36
Note there are *two* other files in the chrome cod
Yoyo Zhou
2014/08/13 22:53:43
The one in c/c/e/api is actually, as far as I can
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "extensions/browser/extension_api_unittest.h" |
+ |
+#include "base/values.h" |
+#include "components/user_prefs/user_prefs.h" |
+#include "content/public/browser/browser_context.h" |
+#include "content/public/browser/browser_thread.h" |
+#include "content/public/browser/content_browser_client.h" |
+#include "content/public/browser/notification_service.h" |
+#include "content/public/browser/site_instance.h" |
+#include "content/public/browser/web_contents.h" |
+#include "content/public/common/content_client.h" |
+#include "content/public/common/url_constants.h" |
+#include "content/public/test/test_browser_context.h" |
+#include "content/public/test/test_browser_thread_bundle.h" |
+#include "content/public/test/web_contents_tester.h" |
+#include "extensions/browser/api_test_utils.h" |
+#include "extensions/browser/extension_function.h" |
+#include "extensions/browser/test_extensions_browser_client.h" |
+#include "extensions/common/extension.h" |
+#include "extensions/common/extension_builder.h" |
+#include "extensions/common/manifest.h" |
+#include "extensions/common/manifest_handlers/background_info.h" |
+#include "extensions/common/value_builder.h" |
+ |
+namespace utils = extensions::api_test_utils; |
+ |
+namespace extensions { |
+ |
+ExtensionApiUnittest::ExtensionApiUnittest() |
+ : notification_service_(content::NotificationService::Create()) { |
+} |
+ |
+ExtensionApiUnittest::~ExtensionApiUnittest() { |
+} |
+ |
+void ExtensionApiUnittest::SetUp() { |
+ ExtensionsTest::SetUp(); |
+ extensions_browser_client()->set_extension_system_factory( |
+ &extension_system_factory_); |
+ |
+ thread_bundle_.reset(new content::TestBrowserThreadBundle( |
+ content::TestBrowserThreadBundle::DEFAULT)); |
+ user_prefs::UserPrefs::Set(browser_context(), &testing_pref_service_); |
+ |
+ extension_ = ExtensionBuilder() |
James Cook
2014/08/13 16:11:36
I like ExtensionBuilder.
|
+ .SetManifest(DictionaryBuilder().Set("name", "Test").Set( |
+ "version", "1.0")) |
+ .SetLocation(Manifest::UNPACKED) |
+ .Build(); |
+} |
+ |
+scoped_ptr<base::Value> ExtensionApiUnittest::RunFunctionAndReturnValue( |
+ UIThreadExtensionFunction* function, |
+ const std::string& args) { |
+ function->set_extension(extension()); |
+ return scoped_ptr<base::Value>(utils::RunFunctionAndReturnSingleResult( |
+ function, args, browser_context())); |
+} |
+ |
+scoped_ptr<base::DictionaryValue> |
+ExtensionApiUnittest::RunFunctionAndReturnDictionary( |
+ UIThreadExtensionFunction* function, |
+ const std::string& args) { |
+ base::Value* value = RunFunctionAndReturnValue(function, args).release(); |
+ base::DictionaryValue* dict = NULL; |
+ |
+ if (value && !value->GetAsDictionary(&dict)) |
+ delete value; |
+ |
+ // We expect to either have successfuly retrieved a dictionary from the value, |
+ // or the value to have been NULL. |
+ EXPECT_TRUE(dict || !value); |
+ return scoped_ptr<base::DictionaryValue>(dict); |
+} |
+ |
+scoped_ptr<base::ListValue> ExtensionApiUnittest::RunFunctionAndReturnList( |
+ UIThreadExtensionFunction* function, |
+ const std::string& args) { |
+ base::Value* value = RunFunctionAndReturnValue(function, args).release(); |
+ base::ListValue* list = NULL; |
+ |
+ if (value && !value->GetAsList(&list)) |
+ delete value; |
+ |
+ // We expect to either have successfuly retrieved a list from the value, |
+ // or the value to have been NULL. |
+ EXPECT_TRUE(list || !value); |
+ return scoped_ptr<base::ListValue>(list); |
+} |
+ |
+std::string ExtensionApiUnittest::RunFunctionAndReturnError( |
+ UIThreadExtensionFunction* function, |
+ const std::string& args) { |
+ function->set_extension(extension()); |
+ return utils::RunFunctionAndReturnError(function, args, browser_context()); |
+} |
+ |
+void ExtensionApiUnittest::RunFunction(UIThreadExtensionFunction* function, |
+ const std::string& args) { |
+ RunFunctionAndReturnValue(function, args); |
+} |
+ |
+} // namespace extensions |