1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/values.h"
6 #include "chrome/browser/browser_process_impl.h"
7 #include "chrome/browser/extensions/extension_api_unittest.h"
8 #include "chrome/browser/extensions/test_extension_system.h"
9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/test/base/testing_browser_process.h"
11 #include "extensions/browser/api/api_resource_manager.h"
12 #include "extensions/browser/api/socket/socket.h"
13 #include "extensions/browser/api/socket/tcp_socket.h"
14 #include "extensions/browser/api/sockets_tcp/sockets_tcp_api.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace extensions {
21 static KeyedService* ApiResourceManagerTestFactory(
22 content::BrowserContext* context) {
23 content::BrowserThread::ID id;
24 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id));
25 return ApiResourceManager<
26 ResumableTCPSocket>::CreateApiResourceManagerForTest(context, id);
29 class SocketsTcpUnitTest : public ExtensionApiUnittest {
31 virtual void SetUp() {
32 ExtensionApiUnittest::SetUp();
34 ApiResourceManager<ResumableTCPSocket>::GetFactoryInstance()
35 ->SetTestingFactoryAndUse(browser()->profile(),
36 ApiResourceManagerTestFactory);
40 TEST_F(SocketsTcpUnitTest, Create) {
42 content::BrowserThread::ID id;
43 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id));
45 // Create SocketCreateFunction and put it on BrowserThread
46 SocketsTcpCreateFunction* function = new SocketsTcpCreateFunction();
47 function->set_work_thread_id(id);
50 scoped_ptr<base::DictionaryValue> result(RunFunctionAndReturnDictionary(
51 function, "[{\"persistent\": true, \"name\": \"foo\"}]"));
52 ASSERT_TRUE(result.get());
55 } // namespace core_api
56 } // namespace extensions