| 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 "extensions/browser/api/sockets_tcp/sockets_tcp_api.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/memory/ptr_util.h" |
| 6 #include "base/values.h" | 10 #include "base/values.h" |
| 7 #include "content/public/test/test_browser_context.h" | 11 #include "content/public/test/test_browser_context.h" |
| 8 #include "extensions/browser/api/api_resource_manager.h" | 12 #include "extensions/browser/api/api_resource_manager.h" |
| 9 #include "extensions/browser/api/socket/socket.h" | 13 #include "extensions/browser/api/socket/socket.h" |
| 10 #include "extensions/browser/api/socket/tcp_socket.h" | 14 #include "extensions/browser/api/socket/tcp_socket.h" |
| 11 #include "extensions/browser/api/sockets_tcp/sockets_tcp_api.h" | |
| 12 #include "extensions/browser/api_unittest.h" | 15 #include "extensions/browser/api_unittest.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 18 |
| 16 namespace extensions { | 19 namespace extensions { |
| 17 namespace api { | 20 namespace api { |
| 18 | 21 |
| 19 static scoped_ptr<KeyedService> ApiResourceManagerTestFactory( | 22 static std::unique_ptr<KeyedService> ApiResourceManagerTestFactory( |
| 20 content::BrowserContext* context) { | 23 content::BrowserContext* context) { |
| 21 return make_scoped_ptr(new ApiResourceManager<ResumableTCPSocket>(context)); | 24 return base::WrapUnique(new ApiResourceManager<ResumableTCPSocket>(context)); |
| 22 } | 25 } |
| 23 | 26 |
| 24 class SocketsTcpUnitTest : public ApiUnitTest { | 27 class SocketsTcpUnitTest : public ApiUnitTest { |
| 25 public: | 28 public: |
| 26 void SetUp() override { | 29 void SetUp() override { |
| 27 ApiUnitTest::SetUp(); | 30 ApiUnitTest::SetUp(); |
| 28 | 31 |
| 29 ApiResourceManager<ResumableTCPSocket>::GetFactoryInstance() | 32 ApiResourceManager<ResumableTCPSocket>::GetFactoryInstance() |
| 30 ->SetTestingFactoryAndUse(browser_context(), | 33 ->SetTestingFactoryAndUse(browser_context(), |
| 31 ApiResourceManagerTestFactory); | 34 ApiResourceManagerTestFactory); |
| 32 } | 35 } |
| 33 }; | 36 }; |
| 34 | 37 |
| 35 TEST_F(SocketsTcpUnitTest, Create) { | 38 TEST_F(SocketsTcpUnitTest, Create) { |
| 36 // Get BrowserThread | 39 // Get BrowserThread |
| 37 content::BrowserThread::ID id; | 40 content::BrowserThread::ID id; |
| 38 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id)); | 41 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id)); |
| 39 | 42 |
| 40 // Create SocketCreateFunction and put it on BrowserThread | 43 // Create SocketCreateFunction and put it on BrowserThread |
| 41 SocketsTcpCreateFunction* function = new SocketsTcpCreateFunction(); | 44 SocketsTcpCreateFunction* function = new SocketsTcpCreateFunction(); |
| 42 function->set_work_thread_id(id); | 45 function->set_work_thread_id(id); |
| 43 | 46 |
| 44 // Run tests | 47 // Run tests |
| 45 scoped_ptr<base::DictionaryValue> result(RunFunctionAndReturnDictionary( | 48 std::unique_ptr<base::DictionaryValue> result(RunFunctionAndReturnDictionary( |
| 46 function, "[{\"persistent\": true, \"name\": \"foo\"}]")); | 49 function, "[{\"persistent\": true, \"name\": \"foo\"}]")); |
| 47 ASSERT_TRUE(result.get()); | 50 ASSERT_TRUE(result.get()); |
| 48 } | 51 } |
| 49 | 52 |
| 50 } // namespace api | 53 } // namespace api |
| 51 } // namespace extensions | 54 } // namespace extensions |
| OLD | NEW |