Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // 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
| |
| 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 "extensions/browser/extension_api_unittest.h" | |
| 6 | |
| 7 #include "base/values.h" | |
| 8 #include "components/user_prefs/user_prefs.h" | |
| 9 #include "content/public/browser/browser_context.h" | |
| 10 #include "content/public/browser/browser_thread.h" | |
| 11 #include "content/public/browser/content_browser_client.h" | |
| 12 #include "content/public/browser/notification_service.h" | |
| 13 #include "content/public/browser/site_instance.h" | |
| 14 #include "content/public/browser/web_contents.h" | |
| 15 #include "content/public/common/content_client.h" | |
| 16 #include "content/public/common/url_constants.h" | |
| 17 #include "content/public/test/test_browser_context.h" | |
| 18 #include "content/public/test/test_browser_thread_bundle.h" | |
| 19 #include "content/public/test/web_contents_tester.h" | |
| 20 #include "extensions/browser/api_test_utils.h" | |
| 21 #include "extensions/browser/extension_function.h" | |
| 22 #include "extensions/browser/test_extensions_browser_client.h" | |
| 23 #include "extensions/common/extension.h" | |
| 24 #include "extensions/common/extension_builder.h" | |
| 25 #include "extensions/common/manifest.h" | |
| 26 #include "extensions/common/manifest_handlers/background_info.h" | |
| 27 #include "extensions/common/value_builder.h" | |
| 28 | |
| 29 namespace utils = extensions::api_test_utils; | |
| 30 | |
| 31 namespace extensions { | |
| 32 | |
| 33 ExtensionApiUnittest::ExtensionApiUnittest() | |
| 34 : notification_service_(content::NotificationService::Create()) { | |
| 35 } | |
| 36 | |
| 37 ExtensionApiUnittest::~ExtensionApiUnittest() { | |
| 38 } | |
| 39 | |
| 40 void ExtensionApiUnittest::SetUp() { | |
| 41 ExtensionsTest::SetUp(); | |
| 42 extensions_browser_client()->set_extension_system_factory( | |
| 43 &extension_system_factory_); | |
| 44 | |
| 45 thread_bundle_.reset(new content::TestBrowserThreadBundle( | |
| 46 content::TestBrowserThreadBundle::DEFAULT)); | |
| 47 user_prefs::UserPrefs::Set(browser_context(), &testing_pref_service_); | |
| 48 | |
| 49 extension_ = ExtensionBuilder() | |
|
James Cook
2014/08/13 16:11:36
I like ExtensionBuilder.
| |
| 50 .SetManifest(DictionaryBuilder().Set("name", "Test").Set( | |
| 51 "version", "1.0")) | |
| 52 .SetLocation(Manifest::UNPACKED) | |
| 53 .Build(); | |
| 54 } | |
| 55 | |
| 56 scoped_ptr<base::Value> ExtensionApiUnittest::RunFunctionAndReturnValue( | |
| 57 UIThreadExtensionFunction* function, | |
| 58 const std::string& args) { | |
| 59 function->set_extension(extension()); | |
| 60 return scoped_ptr<base::Value>(utils::RunFunctionAndReturnSingleResult( | |
| 61 function, args, browser_context())); | |
| 62 } | |
| 63 | |
| 64 scoped_ptr<base::DictionaryValue> | |
| 65 ExtensionApiUnittest::RunFunctionAndReturnDictionary( | |
| 66 UIThreadExtensionFunction* function, | |
| 67 const std::string& args) { | |
| 68 base::Value* value = RunFunctionAndReturnValue(function, args).release(); | |
| 69 base::DictionaryValue* dict = NULL; | |
| 70 | |
| 71 if (value && !value->GetAsDictionary(&dict)) | |
| 72 delete value; | |
| 73 | |
| 74 // We expect to either have successfuly retrieved a dictionary from the value, | |
| 75 // or the value to have been NULL. | |
| 76 EXPECT_TRUE(dict || !value); | |
| 77 return scoped_ptr<base::DictionaryValue>(dict); | |
| 78 } | |
| 79 | |
| 80 scoped_ptr<base::ListValue> ExtensionApiUnittest::RunFunctionAndReturnList( | |
| 81 UIThreadExtensionFunction* function, | |
| 82 const std::string& args) { | |
| 83 base::Value* value = RunFunctionAndReturnValue(function, args).release(); | |
| 84 base::ListValue* list = NULL; | |
| 85 | |
| 86 if (value && !value->GetAsList(&list)) | |
| 87 delete value; | |
| 88 | |
| 89 // We expect to either have successfuly retrieved a list from the value, | |
| 90 // or the value to have been NULL. | |
| 91 EXPECT_TRUE(list || !value); | |
| 92 return scoped_ptr<base::ListValue>(list); | |
| 93 } | |
| 94 | |
| 95 std::string ExtensionApiUnittest::RunFunctionAndReturnError( | |
| 96 UIThreadExtensionFunction* function, | |
| 97 const std::string& args) { | |
| 98 function->set_extension(extension()); | |
| 99 return utils::RunFunctionAndReturnError(function, args, browser_context()); | |
| 100 } | |
| 101 | |
| 102 void ExtensionApiUnittest::RunFunction(UIThreadExtensionFunction* function, | |
| 103 const std::string& args) { | |
| 104 RunFunctionAndReturnValue(function, args); | |
| 105 } | |
| 106 | |
| 107 } // namespace extensions | |
| OLD | NEW |