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 "extensions/browser/api/api_resource_manager.h"
7 #include "extensions/browser/api/socket/socket.h"
8 #include "extensions/browser/api/socket/udp_socket.h"
9 #include "extensions/browser/api/sockets_udp/sockets_udp_api.h"
10 #include "extensions/browser/api_unittest.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace extensions
{
17 static KeyedService
* ApiResourceManagerTestFactory(
18 content::BrowserContext
* context
) {
19 content::BrowserThread::ID id
;
20 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id
));
21 return ApiResourceManager
<
22 ResumableUDPSocket
>::CreateApiResourceManagerForTest(context
, id
);
25 class SocketsUdpUnitTest
: public ApiUnitTest
{
27 void SetUp() override
{
30 ApiResourceManager
<ResumableUDPSocket
>::GetFactoryInstance()
31 ->SetTestingFactoryAndUse(browser_context(),
32 ApiResourceManagerTestFactory
);
36 TEST_F(SocketsUdpUnitTest
, Create
) {
38 content::BrowserThread::ID id
;
39 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id
));
41 // Create SocketCreateFunction and put it on BrowserThread
42 SocketsUdpCreateFunction
* function
= new SocketsUdpCreateFunction();
43 function
->set_work_thread_id(id
);
46 scoped_ptr
<base::DictionaryValue
> result(RunFunctionAndReturnDictionary(
47 function
, "[{\"persistent\": true, \"name\": \"foo\"}]"));
48 ASSERT_TRUE(result
.get());
51 } // namespace core_api
52 } // namespace extensions