Commit 904eb665 authored by dhnishi@chromium.org's avatar dhnishi@chromium.org

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
parent 459a22a5
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "base/path_service.h" #include "base/path_service.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_function_test_utils.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_test_message_listener.h" #include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
...@@ -20,10 +19,6 @@ ...@@ -20,10 +19,6 @@
#include "net/dns/mock_host_resolver.h" #include "net/dns/mock_host_resolver.h"
#include "net/test/spawned_test_server/spawned_test_server.h" #include "net/test/spawned_test_server/spawned_test_server.h"
using extensions::Extension;
namespace utils = extension_function_test_utils;
namespace { namespace {
// TODO(jschuh): Hanging plugin tests. crbug.com/244653 // TODO(jschuh): Hanging plugin tests. crbug.com/244653
...@@ -64,25 +59,6 @@ class SocketsTcpApiTest : public ExtensionApiTest { ...@@ -64,25 +59,6 @@ class SocketsTcpApiTest : public ExtensionApiTest {
} // namespace } // namespace
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(utils::CreateEmptyExtension());
socket_create_function->set_extension(empty_extension.get());
socket_create_function->set_has_callback(true);
scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
socket_create_function.get(), "[]", browser(), utils::NONE));
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);
}
IN_PROC_BROWSER_TEST_F(SocketsTcpApiTest, SocketTcpExtension) { IN_PROC_BROWSER_TEST_F(SocketsTcpApiTest, SocketTcpExtension) {
scoped_ptr<net::SpawnedTestServer> test_server( scoped_ptr<net::SpawnedTestServer> test_server(
new net::SpawnedTestServer( new net::SpawnedTestServer(
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/values.h" #include "base/values.h"
...@@ -10,9 +9,8 @@ ...@@ -10,9 +9,8 @@
#include "extensions/browser/api/dns/host_resolver_wrapper.h" #include "extensions/browser/api/dns/host_resolver_wrapper.h"
#include "extensions/browser/api/dns/mock_host_resolver_creator.h" #include "extensions/browser/api/dns/mock_host_resolver_creator.h"
#include "extensions/browser/api_test_utils.h" #include "extensions/browser/api_test_utils.h"
#include "extensions/browser/extension_function_dispatcher.h"
#include "extensions/common/extension.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 "extensions/shell/test/shell_test.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
...@@ -20,21 +18,6 @@ using extensions::api_test_utils::RunFunctionAndReturnSingleResult; ...@@ -20,21 +18,6 @@ using extensions::api_test_utils::RunFunctionAndReturnSingleResult;
namespace extensions { 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 { class DnsApiTest : public AppShellTest {
public: public:
DnsApiTest() : resolver_creator_(new MockHostResolverCreator()) {} DnsApiTest() : resolver_creator_(new MockHostResolverCreator()) {}
...@@ -60,24 +43,13 @@ class DnsApiTest : public AppShellTest { ...@@ -60,24 +43,13 @@ class DnsApiTest : public AppShellTest {
IN_PROC_BROWSER_TEST_F(DnsApiTest, DnsResolveIPLiteral) { IN_PROC_BROWSER_TEST_F(DnsApiTest, DnsResolveIPLiteral) {
scoped_refptr<DnsResolveFunction> resolve_function(new DnsResolveFunction()); scoped_refptr<DnsResolveFunction> resolve_function(new DnsResolveFunction());
scoped_refptr<Extension> empty_extension( scoped_refptr<Extension> empty_extension = test_util::CreateEmptyExtension();
ExtensionBuilder()
.SetManifest(
DictionaryBuilder().Set("name", "Test").Set("version", "1.0"))
.Build());
resolve_function->set_extension(empty_extension.get()); resolve_function->set_extension(empty_extension.get());
resolve_function->set_has_callback(true); resolve_function->set_has_callback(true);
TestFunctionDispatcherDelegate delegate; scoped_ptr<base::Value> result(RunFunctionAndReturnSingleResult(
scoped_ptr<ExtensionFunctionDispatcher> dispatcher( resolve_function.get(), "[\"127.0.0.1\"]", browser_context()));
new ExtensionFunctionDispatcher(browser_context(), &delegate));
scoped_ptr<base::Value> result(
RunFunctionAndReturnSingleResult(resolve_function.get(),
"[\"127.0.0.1\"]",
browser_context(),
dispatcher.Pass()));
base::DictionaryValue* dict = NULL; base::DictionaryValue* dict = NULL;
ASSERT_TRUE(result->GetAsDictionary(&dict)); ASSERT_TRUE(result->GetAsDictionary(&dict));
...@@ -92,27 +64,16 @@ IN_PROC_BROWSER_TEST_F(DnsApiTest, DnsResolveIPLiteral) { ...@@ -92,27 +64,16 @@ IN_PROC_BROWSER_TEST_F(DnsApiTest, DnsResolveIPLiteral) {
IN_PROC_BROWSER_TEST_F(DnsApiTest, DnsResolveHostname) { IN_PROC_BROWSER_TEST_F(DnsApiTest, DnsResolveHostname) {
scoped_refptr<DnsResolveFunction> resolve_function(new DnsResolveFunction()); scoped_refptr<DnsResolveFunction> resolve_function(new DnsResolveFunction());
scoped_refptr<Extension> empty_extension( scoped_refptr<Extension> empty_extension = test_util::CreateEmptyExtension();
ExtensionBuilder()
.SetManifest(
DictionaryBuilder().Set("name", "Test").Set("version", "1.0"))
.Build());
resolve_function->set_extension(empty_extension.get()); resolve_function->set_extension(empty_extension.get());
resolve_function->set_has_callback(true); resolve_function->set_has_callback(true);
TestFunctionDispatcherDelegate delegate;
scoped_ptr<ExtensionFunctionDispatcher> dispatcher(
new ExtensionFunctionDispatcher(browser_context(), &delegate));
std::string function_arguments("[\""); std::string function_arguments("[\"");
function_arguments += MockHostResolverCreator::kHostname; function_arguments += MockHostResolverCreator::kHostname;
function_arguments += "\"]"; function_arguments += "\"]";
scoped_ptr<base::Value> result( scoped_ptr<base::Value> result(RunFunctionAndReturnSingleResult(
RunFunctionAndReturnSingleResult(resolve_function.get(), resolve_function.get(), function_arguments, browser_context()));
function_arguments,
browser_context(),
dispatcher.Pass()));
base::DictionaryValue* dict = NULL; base::DictionaryValue* dict = NULL;
ASSERT_TRUE(result->GetAsDictionary(&dict)); ASSERT_TRUE(result->GetAsDictionary(&dict));
......
// 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
...@@ -11,10 +11,24 @@ ...@@ -11,10 +11,24 @@
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "extensions/browser/extension_function.h" #include "extensions/browser/extension_function.h"
#include "extensions/browser/extension_function_dispatcher.h" #include "extensions/browser/extension_function_dispatcher.h"
#include "extensions/common/extension_builder.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using extensions::ExtensionFunctionDispatcher;
namespace { 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) { base::Value* ParseJSON(const std::string& data) {
return base::JSONReader::Read(data); return base::JSONReader::Read(data);
} }
...@@ -69,16 +83,16 @@ namespace extensions { ...@@ -69,16 +83,16 @@ namespace extensions {
namespace api_test_utils { namespace api_test_utils {
base::Value* RunFunctionAndReturnSingleResult( base::Value* RunFunctionWithDelegateAndReturnSingleResult(
UIThreadExtensionFunction* function, UIThreadExtensionFunction* function,
const std::string& args, const std::string& args,
content::BrowserContext* context, content::BrowserContext* context,
scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher) { scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher) {
return RunFunctionAndReturnSingleResult( return RunFunctionWithDelegateAndReturnSingleResult(
function, args, context, dispatcher.Pass(), NONE); function, args, context, dispatcher.Pass(), NONE);
} }
base::Value* RunFunctionAndReturnSingleResult( base::Value* RunFunctionWithDelegateAndReturnSingleResult(
UIThreadExtensionFunction* function, UIThreadExtensionFunction* function,
const std::string& args, const std::string& args,
content::BrowserContext* context, content::BrowserContext* context,
...@@ -98,6 +112,26 @@ base::Value* RunFunctionAndReturnSingleResult( ...@@ -98,6 +112,26 @@ base::Value* RunFunctionAndReturnSingleResult(
return NULL; 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, bool RunFunction(UIThreadExtensionFunction* function,
const std::string& args, const std::string& args,
content::BrowserContext* context, content::BrowserContext* context,
......
...@@ -31,18 +31,30 @@ enum RunFunctionFlags { NONE = 0, INCLUDE_INCOGNITO = 1 << 0 }; ...@@ -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 // Run |function| with |args| and return the result. Adds an error to the
// current test if |function| returns an error. Takes ownership of // current test if |function| returns an error. Takes ownership of
// |function|. The caller takes ownership of the result. // |function|. The caller takes ownership of the result.
base::Value* RunFunctionAndReturnSingleResult( base::Value* RunFunctionWithDelegateAndReturnSingleResult(
UIThreadExtensionFunction* function, UIThreadExtensionFunction* function,
const std::string& args, const std::string& args,
content::BrowserContext* context, content::BrowserContext* context,
scoped_ptr<ExtensionFunctionDispatcher> dispatcher); scoped_ptr<ExtensionFunctionDispatcher> dispatcher);
base::Value* RunFunctionAndReturnSingleResult( base::Value* RunFunctionWithDelegateAndReturnSingleResult(
UIThreadExtensionFunction* function, UIThreadExtensionFunction* function,
const std::string& args, const std::string& args,
content::BrowserContext* context, content::BrowserContext* context,
scoped_ptr<ExtensionFunctionDispatcher> dispatcher, scoped_ptr<ExtensionFunctionDispatcher> dispatcher,
RunFunctionFlags flags); 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 // Create and run |function| with |args|. Works with both synchronous and async
// functions. Ownership of |function| remains with the caller. // functions. Ownership of |function| remains with the caller.
// //
......
...@@ -22,6 +22,15 @@ ExtensionBuilder& BuildExtension(ExtensionBuilder& builder) { ...@@ -22,6 +22,15 @@ ExtensionBuilder& BuildExtension(ExtensionBuilder& builder) {
.Set("manifest_version", 2)); .Set("manifest_version", 2));
} }
scoped_refptr<Extension> CreateEmptyExtension() {
scoped_refptr<Extension> empty_extension(
ExtensionBuilder()
.SetManifest(
DictionaryBuilder().Set("name", "Test").Set("version", "1.0"))
.Build());
return empty_extension;
}
scoped_refptr<Extension> CreateExtensionWithID(const std::string& id) { scoped_refptr<Extension> CreateExtensionWithID(const std::string& id) {
return ExtensionBuilder() return ExtensionBuilder()
.SetManifest( .SetManifest(
......
...@@ -23,6 +23,10 @@ namespace test_util { ...@@ -23,6 +23,10 @@ namespace test_util {
// Adds an extension manifest to a builder. // Adds an extension manifest to a builder.
ExtensionBuilder& BuildExtension(ExtensionBuilder& builder); ExtensionBuilder& BuildExtension(ExtensionBuilder& builder);
// Creates an extension instance that can be attached to an ExtensionFunction
// before running it.
scoped_refptr<Extension> CreateEmptyExtension();
// Return a very simple extension with a given |id|. // Return a very simple extension with a given |id|.
scoped_refptr<Extension> CreateExtensionWithID(const std::string& id); scoped_refptr<Extension> CreateExtensionWithID(const std::string& id);
......
...@@ -157,6 +157,7 @@ ...@@ -157,6 +157,7 @@
# TODO(yoz): Something is off here; should this .gyp file be # TODO(yoz): Something is off here; should this .gyp file be
# in the parent directory? Test target extensions_browsertests? # in the parent directory? Test target extensions_browsertests?
'../browser/api/dns/dns_apitest.cc', '../browser/api/dns/dns_apitest.cc',
'../browser/api/sockets_tcp/sockets_tcp_apitest.cc',
'browser/shell_browsertest.cc', 'browser/shell_browsertest.cc',
'test/shell_test.h', 'test/shell_test.h',
'test/shell_test.cc', 'test/shell_test.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment