| 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/memory/scoped_ptr.h" | 5 #include <memory> |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 6 #include "base/values.h" | 8 #include "base/values.h" |
| 7 #include "chrome/browser/browser_process_impl.h" | 9 #include "chrome/browser/browser_process_impl.h" |
| 8 #include "chrome/browser/extensions/extension_api_unittest.h" | 10 #include "chrome/browser/extensions/extension_api_unittest.h" |
| 9 #include "chrome/browser/extensions/test_extension_system.h" | 11 #include "chrome/browser/extensions/test_extension_system.h" |
| 10 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 11 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
| 12 #include "extensions/browser/api/api_resource_manager.h" | 14 #include "extensions/browser/api/api_resource_manager.h" |
| 13 #include "extensions/browser/api/socket/socket.h" | 15 #include "extensions/browser/api/socket/socket.h" |
| 14 #include "extensions/browser/api/socket/tcp_socket.h" | 16 #include "extensions/browser/api/socket/tcp_socket.h" |
| 15 #include "extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.h" | 17 #include "extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 20 |
| 19 namespace extensions { | 21 namespace extensions { |
| 20 namespace api { | 22 namespace api { |
| 21 | 23 |
| 22 static scoped_ptr<KeyedService> ApiResourceManagerTestFactory( | 24 static std::unique_ptr<KeyedService> ApiResourceManagerTestFactory( |
| 23 content::BrowserContext* context) { | 25 content::BrowserContext* context) { |
| 24 return make_scoped_ptr(new ApiResourceManager<ResumableTCPSocket>(context)); | 26 return base::WrapUnique(new ApiResourceManager<ResumableTCPSocket>(context)); |
| 25 } | 27 } |
| 26 | 28 |
| 27 static scoped_ptr<KeyedService> ApiResourceManagerTestServerFactory( | 29 static std::unique_ptr<KeyedService> ApiResourceManagerTestServerFactory( |
| 28 content::BrowserContext* context) { | 30 content::BrowserContext* context) { |
| 29 return make_scoped_ptr( | 31 return base::WrapUnique( |
| 30 new ApiResourceManager<ResumableTCPServerSocket>(context)); | 32 new ApiResourceManager<ResumableTCPServerSocket>(context)); |
| 31 } | 33 } |
| 32 | 34 |
| 33 class SocketsTcpServerUnitTest : public ExtensionApiUnittest { | 35 class SocketsTcpServerUnitTest : public ExtensionApiUnittest { |
| 34 public: | 36 public: |
| 35 void SetUp() override { | 37 void SetUp() override { |
| 36 ExtensionApiUnittest::SetUp(); | 38 ExtensionApiUnittest::SetUp(); |
| 37 | 39 |
| 38 ApiResourceManager<ResumableTCPSocket>::GetFactoryInstance() | 40 ApiResourceManager<ResumableTCPSocket>::GetFactoryInstance() |
| 39 ->SetTestingFactoryAndUse(browser()->profile(), | 41 ->SetTestingFactoryAndUse(browser()->profile(), |
| 40 ApiResourceManagerTestFactory); | 42 ApiResourceManagerTestFactory); |
| 41 | 43 |
| 42 ApiResourceManager<ResumableTCPServerSocket>::GetFactoryInstance() | 44 ApiResourceManager<ResumableTCPServerSocket>::GetFactoryInstance() |
| 43 ->SetTestingFactoryAndUse(browser()->profile(), | 45 ->SetTestingFactoryAndUse(browser()->profile(), |
| 44 ApiResourceManagerTestServerFactory); | 46 ApiResourceManagerTestServerFactory); |
| 45 } | 47 } |
| 46 }; | 48 }; |
| 47 | 49 |
| 48 TEST_F(SocketsTcpServerUnitTest, Create) { | 50 TEST_F(SocketsTcpServerUnitTest, Create) { |
| 49 // Get BrowserThread | 51 // Get BrowserThread |
| 50 content::BrowserThread::ID id; | 52 content::BrowserThread::ID id; |
| 51 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id)); | 53 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id)); |
| 52 | 54 |
| 53 // Create SocketCreateFunction and put it on BrowserThread | 55 // Create SocketCreateFunction and put it on BrowserThread |
| 54 SocketsTcpServerCreateFunction* function = | 56 SocketsTcpServerCreateFunction* function = |
| 55 new SocketsTcpServerCreateFunction(); | 57 new SocketsTcpServerCreateFunction(); |
| 56 function->set_work_thread_id(id); | 58 function->set_work_thread_id(id); |
| 57 | 59 |
| 58 // Run tests | 60 // Run tests |
| 59 scoped_ptr<base::DictionaryValue> result(RunFunctionAndReturnDictionary( | 61 std::unique_ptr<base::DictionaryValue> result(RunFunctionAndReturnDictionary( |
| 60 function, "[{\"persistent\": true, \"name\": \"foo\"}]")); | 62 function, "[{\"persistent\": true, \"name\": \"foo\"}]")); |
| 61 ASSERT_TRUE(result.get()); | 63 ASSERT_TRUE(result.get()); |
| 62 } | 64 } |
| 63 | 65 |
| 64 } // namespace api | 66 } // namespace api |
| 65 } // namespace extensions | 67 } // namespace extensions |
| OLD | NEW |