1 // Copyright (c) 2012 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/memory/scoped_ptr.h"
6 #include "base/values.h"
7 #include "chrome/browser/browser_process_impl.h"
8 #include "chrome/browser/extensions/extension_api_unittest.h"
9 #include "chrome/browser/extensions/test_extension_system.h"
10 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/test/base/testing_browser_process.h"
12 #include "extensions/browser/api/api_resource_manager.h"
13 #include "extensions/browser/api/socket/socket.h"
14 #include "extensions/browser/api/socket/socket_api.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace extensions
{
20 scoped_ptr
<KeyedService
> ApiResourceManagerTestFactory(
21 content::BrowserContext
* context
) {
22 content::BrowserThread::ID id
;
23 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id
));
24 return ApiResourceManager
<Socket
>::CreateApiResourceManagerForTest(context
,
28 class SocketUnitTest
: public ExtensionApiUnittest
{
30 void SetUp() override
{
31 ExtensionApiUnittest::SetUp();
33 ApiResourceManager
<Socket
>::GetFactoryInstance()->SetTestingFactoryAndUse(
34 browser()->profile(), ApiResourceManagerTestFactory
);
38 TEST_F(SocketUnitTest
, Create
) {
40 content::BrowserThread::ID id
;
41 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id
));
43 // Create SocketCreateFunction and put it on BrowserThread
44 SocketCreateFunction
* function
= new SocketCreateFunction();
45 function
->set_work_thread_id(id
);
48 scoped_ptr
<base::DictionaryValue
> result(
49 RunFunctionAndReturnDictionary(function
, "[\"tcp\"]"));
50 ASSERT_TRUE(result
.get());
53 } // namespace extensions