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/extension_function_test_utils.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/udp_socket.h"
15 #include "extensions/browser/api/sockets_udp/sockets_udp_api.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
19 namespace utils
= extension_function_test_utils
;
21 namespace extensions
{
24 static KeyedService
* ApiResourceManagerTestFactory(
25 content::BrowserContext
* context
) {
26 content::BrowserThread::ID id
;
27 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id
));
28 return ApiResourceManager
<
29 ResumableUDPSocket
>::CreateApiResourceManagerForTest(context
, id
);
32 class SocketsUdpUnitTest
: public ExtensionApiUnittest
{
34 virtual void SetUp() {
35 ExtensionApiUnittest::SetUp();
37 ApiResourceManager
<ResumableUDPSocket
>::GetFactoryInstance()
38 ->SetTestingFactoryAndUse(browser()->profile(),
39 ApiResourceManagerTestFactory
);
43 TEST_F(SocketsUdpUnitTest
, Create
) {
45 content::BrowserThread::ID id
;
46 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id
));
48 // Create SocketCreateFunction and put it on BrowserThread
49 SocketsUdpCreateFunction
* function
= new SocketsUdpCreateFunction();
50 function
->set_work_thread_id(id
);
53 scoped_ptr
<base::DictionaryValue
> result(RunFunctionAndReturnDictionary(
54 function
, "[{\"persistent\": true, \"name\": \"foo\"}]"));
55 ASSERT_TRUE(result
.get());
58 } // namespace core_api
59 } // namespace extensions