OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/values.h" | 5 #include "base/values.h" |
6 #include "content/public/test/test_browser_context.h" | 6 #include "content/public/test/test_browser_context.h" |
7 #include "extensions/browser/api/api_resource_manager.h" | 7 #include "extensions/browser/api/api_resource_manager.h" |
8 #include "extensions/browser/api/socket/socket.h" | 8 #include "extensions/browser/api/socket/socket.h" |
9 #include "extensions/browser/api/socket/tcp_socket.h" | 9 #include "extensions/browser/api/socket/tcp_socket.h" |
10 #include "extensions/browser/api/sockets_tcp/sockets_tcp_api.h" | 10 #include "extensions/browser/api/sockets_tcp/sockets_tcp_api.h" |
11 #include "extensions/browser/api_unittest.h" | 11 #include "extensions/browser/api_unittest.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace extensions { | 15 namespace extensions { |
16 namespace core_api { | 16 namespace core_api { |
17 | 17 |
18 static KeyedService* ApiResourceManagerTestFactory( | 18 static KeyedService* ApiResourceManagerTestFactory( |
19 content::BrowserContext* context) { | 19 content::BrowserContext* context) { |
20 content::BrowserThread::ID id; | 20 content::BrowserThread::ID id; |
21 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id)); | 21 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id)); |
22 return ApiResourceManager< | 22 return ApiResourceManager< |
23 ResumableTCPSocket>::CreateApiResourceManagerForTest(context, id); | 23 ResumableTCPSocket>::CreateApiResourceManagerForTest(context, id); |
24 } | 24 } |
25 | 25 |
26 class SocketsTcpUnitTest : public ApiUnitTest { | 26 class SocketsTcpUnitTest : public ApiUnitTest { |
27 public: | 27 public: |
28 virtual void SetUp() { | 28 void SetUp() override { |
29 ApiUnitTest::SetUp(); | 29 ApiUnitTest::SetUp(); |
30 | 30 |
31 ApiResourceManager<ResumableTCPSocket>::GetFactoryInstance() | 31 ApiResourceManager<ResumableTCPSocket>::GetFactoryInstance() |
32 ->SetTestingFactoryAndUse(browser_context(), | 32 ->SetTestingFactoryAndUse(browser_context(), |
33 ApiResourceManagerTestFactory); | 33 ApiResourceManagerTestFactory); |
34 } | 34 } |
35 }; | 35 }; |
36 | 36 |
37 TEST_F(SocketsTcpUnitTest, Create) { | 37 TEST_F(SocketsTcpUnitTest, Create) { |
38 // Get BrowserThread | 38 // Get BrowserThread |
39 content::BrowserThread::ID id; | 39 content::BrowserThread::ID id; |
40 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id)); | 40 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id)); |
41 | 41 |
42 // Create SocketCreateFunction and put it on BrowserThread | 42 // Create SocketCreateFunction and put it on BrowserThread |
43 SocketsTcpCreateFunction* function = new SocketsTcpCreateFunction(); | 43 SocketsTcpCreateFunction* function = new SocketsTcpCreateFunction(); |
44 function->set_work_thread_id(id); | 44 function->set_work_thread_id(id); |
45 | 45 |
46 // Run tests | 46 // Run tests |
47 scoped_ptr<base::DictionaryValue> result(RunFunctionAndReturnDictionary( | 47 scoped_ptr<base::DictionaryValue> result(RunFunctionAndReturnDictionary( |
48 function, "[{\"persistent\": true, \"name\": \"foo\"}]")); | 48 function, "[{\"persistent\": true, \"name\": \"foo\"}]")); |
49 ASSERT_TRUE(result.get()); | 49 ASSERT_TRUE(result.get()); |
50 } | 50 } |
51 | 51 |
52 } // namespace core_api | 52 } // namespace core_api |
53 } // namespace extensions | 53 } // namespace extensions |
OLD | NEW |