diff options
author | dhnishi@chromium.org <dhnishi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-09 02:53:32 +0000 |
---|---|---|
committer | dhnishi@chromium.org <dhnishi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-09 02:54:30 +0000 |
commit | 904eb66575fc98086e1a8b90b21a6e5ebc6afc2c (patch) | |
tree | 7064cc28fda091fa231806e1a6777bd60ee96408 /extensions/browser | |
parent | 459a22a5e7e580f888faa4ef0cbc1f37d624a810 (diff) | |
download | chromium_src-904eb66575fc98086e1a8b90b21a6e5ebc6afc2c.zip chromium_src-904eb66575fc98086e1a8b90b21a6e5ebc6afc2c.tar.gz chromium_src-904eb66575fc98086e1a8b90b21a6e5ebc6afc2c.tar.bz2 |
Move SocketsTcpApiTest.SocketsTcpCreateGood to app_shell_browsertests.
BUG=388893
Review URL: https://codereview.chromium.org/449303002
Cr-Commit-Position: refs/heads/master@{#288495}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288495 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/browser')
-rw-r--r-- | extensions/browser/api/dns/dns_apitest.cc | 53 | ||||
-rw-r--r-- | extensions/browser/api/sockets_tcp/sockets_tcp_apitest.cc | 37 | ||||
-rw-r--r-- | extensions/browser/api_test_utils.cc | 40 | ||||
-rw-r--r-- | extensions/browser/api_test_utils.h | 16 |
4 files changed, 95 insertions, 51 deletions
diff --git a/extensions/browser/api/dns/dns_apitest.cc b/extensions/browser/api/dns/dns_apitest.cc index fa2ec2f..9d41503 100644 --- a/extensions/browser/api/dns/dns_apitest.cc +++ b/extensions/browser/api/dns/dns_apitest.cc @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/values.h" @@ -10,9 +9,8 @@ #include "extensions/browser/api/dns/host_resolver_wrapper.h" #include "extensions/browser/api/dns/mock_host_resolver_creator.h" #include "extensions/browser/api_test_utils.h" -#include "extensions/browser/extension_function_dispatcher.h" #include "extensions/common/extension.h" -#include "extensions/common/extension_builder.h" +#include "extensions/common/test_util.h" #include "extensions/shell/test/shell_test.h" #include "net/base/net_errors.h" @@ -20,21 +18,6 @@ using extensions::api_test_utils::RunFunctionAndReturnSingleResult; namespace extensions { -namespace { - -class TestFunctionDispatcherDelegate - : public ExtensionFunctionDispatcher::Delegate { - public: - TestFunctionDispatcherDelegate() {} - virtual ~TestFunctionDispatcherDelegate() {} - - // NULL implementation. - private: - DISALLOW_COPY_AND_ASSIGN(TestFunctionDispatcherDelegate); -}; - -} // namespace - class DnsApiTest : public AppShellTest { public: DnsApiTest() : resolver_creator_(new MockHostResolverCreator()) {} @@ -60,24 +43,13 @@ class DnsApiTest : public AppShellTest { IN_PROC_BROWSER_TEST_F(DnsApiTest, DnsResolveIPLiteral) { scoped_refptr<DnsResolveFunction> resolve_function(new DnsResolveFunction()); - scoped_refptr<Extension> empty_extension( - ExtensionBuilder() - .SetManifest( - DictionaryBuilder().Set("name", "Test").Set("version", "1.0")) - .Build()); + scoped_refptr<Extension> empty_extension = test_util::CreateEmptyExtension(); resolve_function->set_extension(empty_extension.get()); resolve_function->set_has_callback(true); - TestFunctionDispatcherDelegate delegate; - scoped_ptr<ExtensionFunctionDispatcher> dispatcher( - new ExtensionFunctionDispatcher(browser_context(), &delegate)); - - scoped_ptr<base::Value> result( - RunFunctionAndReturnSingleResult(resolve_function.get(), - "[\"127.0.0.1\"]", - browser_context(), - dispatcher.Pass())); + scoped_ptr<base::Value> result(RunFunctionAndReturnSingleResult( + resolve_function.get(), "[\"127.0.0.1\"]", browser_context())); base::DictionaryValue* dict = NULL; ASSERT_TRUE(result->GetAsDictionary(&dict)); @@ -92,27 +64,16 @@ IN_PROC_BROWSER_TEST_F(DnsApiTest, DnsResolveIPLiteral) { IN_PROC_BROWSER_TEST_F(DnsApiTest, DnsResolveHostname) { scoped_refptr<DnsResolveFunction> resolve_function(new DnsResolveFunction()); - scoped_refptr<Extension> empty_extension( - ExtensionBuilder() - .SetManifest( - DictionaryBuilder().Set("name", "Test").Set("version", "1.0")) - .Build()); + scoped_refptr<Extension> empty_extension = test_util::CreateEmptyExtension(); resolve_function->set_extension(empty_extension.get()); resolve_function->set_has_callback(true); - TestFunctionDispatcherDelegate delegate; - scoped_ptr<ExtensionFunctionDispatcher> dispatcher( - new ExtensionFunctionDispatcher(browser_context(), &delegate)); - std::string function_arguments("[\""); function_arguments += MockHostResolverCreator::kHostname; function_arguments += "\"]"; - scoped_ptr<base::Value> result( - RunFunctionAndReturnSingleResult(resolve_function.get(), - function_arguments, - browser_context(), - dispatcher.Pass())); + scoped_ptr<base::Value> result(RunFunctionAndReturnSingleResult( + resolve_function.get(), function_arguments, browser_context())); base::DictionaryValue* dict = NULL; ASSERT_TRUE(result->GetAsDictionary(&dict)); diff --git a/extensions/browser/api/sockets_tcp/sockets_tcp_apitest.cc b/extensions/browser/api/sockets_tcp/sockets_tcp_apitest.cc new file mode 100644 index 0000000..df0ddea --- /dev/null +++ b/extensions/browser/api/sockets_tcp/sockets_tcp_apitest.cc @@ -0,0 +1,37 @@ +// Copyright 2014 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 "extensions/browser/api/sockets_tcp/sockets_tcp_api.h" +#include "extensions/browser/api_test_utils.h" +#include "extensions/common/extension.h" +#include "extensions/common/test_util.h" +#include "extensions/shell/test/shell_test.h" + +using extensions::api_test_utils::RunFunctionAndReturnSingleResult; + +namespace extensions { + +class SocketsTcpApiTest : public AppShellTest {}; + +IN_PROC_BROWSER_TEST_F(SocketsTcpApiTest, SocketsTcpCreateGood) { + scoped_refptr<extensions::core_api::SocketsTcpCreateFunction> + socket_create_function( + new extensions::core_api::SocketsTcpCreateFunction()); + scoped_refptr<Extension> empty_extension = test_util::CreateEmptyExtension(); + + socket_create_function->set_extension(empty_extension.get()); + socket_create_function->set_has_callback(true); + + scoped_ptr<base::Value> result(RunFunctionAndReturnSingleResult( + socket_create_function.get(), "[]", browser_context())); + + ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType()); + base::DictionaryValue* value = + static_cast<base::DictionaryValue*>(result.get()); + int socketId = -1; + EXPECT_TRUE(value->GetInteger("socketId", &socketId)); + ASSERT_TRUE(socketId > 0); +} + +} // namespace extensions diff --git a/extensions/browser/api_test_utils.cc b/extensions/browser/api_test_utils.cc index 4c9a58b..b18b249 100644 --- a/extensions/browser/api_test_utils.cc +++ b/extensions/browser/api_test_utils.cc @@ -11,10 +11,24 @@ #include "content/public/test/test_utils.h" #include "extensions/browser/extension_function.h" #include "extensions/browser/extension_function_dispatcher.h" +#include "extensions/common/extension_builder.h" #include "testing/gtest/include/gtest/gtest.h" +using extensions::ExtensionFunctionDispatcher; + namespace { +class TestFunctionDispatcherDelegate + : public ExtensionFunctionDispatcher::Delegate { + public: + TestFunctionDispatcherDelegate() {} + virtual ~TestFunctionDispatcherDelegate() {} + + // NULL implementation. + private: + DISALLOW_COPY_AND_ASSIGN(TestFunctionDispatcherDelegate); +}; + base::Value* ParseJSON(const std::string& data) { return base::JSONReader::Read(data); } @@ -69,16 +83,16 @@ namespace extensions { namespace api_test_utils { -base::Value* RunFunctionAndReturnSingleResult( +base::Value* RunFunctionWithDelegateAndReturnSingleResult( UIThreadExtensionFunction* function, const std::string& args, content::BrowserContext* context, scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher) { - return RunFunctionAndReturnSingleResult( + return RunFunctionWithDelegateAndReturnSingleResult( function, args, context, dispatcher.Pass(), NONE); } -base::Value* RunFunctionAndReturnSingleResult( +base::Value* RunFunctionWithDelegateAndReturnSingleResult( UIThreadExtensionFunction* function, const std::string& args, content::BrowserContext* context, @@ -98,6 +112,26 @@ base::Value* RunFunctionAndReturnSingleResult( return NULL; } +base::Value* RunFunctionAndReturnSingleResult( + UIThreadExtensionFunction* function, + const std::string& args, + content::BrowserContext* context) { + return RunFunctionAndReturnSingleResult(function, args, context, NONE); +} + +base::Value* RunFunctionAndReturnSingleResult( + UIThreadExtensionFunction* function, + const std::string& args, + content::BrowserContext* context, + RunFunctionFlags flags) { + TestFunctionDispatcherDelegate delegate; + scoped_ptr<ExtensionFunctionDispatcher> dispatcher( + new ExtensionFunctionDispatcher(context, &delegate)); + + return RunFunctionWithDelegateAndReturnSingleResult( + function, args, context, dispatcher.Pass(), flags); +} + bool RunFunction(UIThreadExtensionFunction* function, const std::string& args, content::BrowserContext* context, diff --git a/extensions/browser/api_test_utils.h b/extensions/browser/api_test_utils.h index 119b090..19af352 100644 --- a/extensions/browser/api_test_utils.h +++ b/extensions/browser/api_test_utils.h @@ -31,18 +31,30 @@ enum RunFunctionFlags { NONE = 0, INCLUDE_INCOGNITO = 1 << 0 }; // Run |function| with |args| and return the result. Adds an error to the // current test if |function| returns an error. Takes ownership of // |function|. The caller takes ownership of the result. -base::Value* RunFunctionAndReturnSingleResult( +base::Value* RunFunctionWithDelegateAndReturnSingleResult( UIThreadExtensionFunction* function, const std::string& args, content::BrowserContext* context, scoped_ptr<ExtensionFunctionDispatcher> dispatcher); -base::Value* RunFunctionAndReturnSingleResult( +base::Value* RunFunctionWithDelegateAndReturnSingleResult( UIThreadExtensionFunction* function, const std::string& args, content::BrowserContext* context, scoped_ptr<ExtensionFunctionDispatcher> dispatcher, RunFunctionFlags flags); +// RunFunctionWithDelegateAndReturnSingleResult, except with a NULL +// implementation of the Delegate. +base::Value* RunFunctionAndReturnSingleResult( + UIThreadExtensionFunction* function, + const std::string& args, + content::BrowserContext* context); +base::Value* RunFunctionAndReturnSingleResult( + UIThreadExtensionFunction* function, + const std::string& args, + content::BrowserContext* context, + RunFunctionFlags flags); + // Create and run |function| with |args|. Works with both synchronous and async // functions. Ownership of |function| remains with the caller. // |