| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/browser_process_impl.h" | 6 #include "chrome/browser/browser_process_impl.h" |
| 7 #include "chrome/browser/extensions/api/api_function.h" | |
| 8 #include "chrome/browser/extensions/api/api_resource_manager.h" | 7 #include "chrome/browser/extensions/api/api_resource_manager.h" |
| 9 #include "chrome/browser/extensions/api/socket/socket.h" | 8 #include "chrome/browser/extensions/api/socket/socket.h" |
| 10 #include "chrome/browser/extensions/api/socket/socket_api.h" | 9 #include "chrome/browser/extensions/api/socket/socket_api.h" |
| 11 #include "chrome/browser/extensions/extension_api_unittest.h" | 10 #include "chrome/browser/extensions/extension_api_unittest.h" |
| 12 #include "chrome/browser/extensions/test_extension_system.h" | 11 #include "chrome/browser/extensions/test_extension_system.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 16 |
| 18 namespace extensions { | 17 namespace extensions { |
| 19 | 18 |
| 20 BrowserContextKeyedService* ApiResourceManagerTestFactory( | 19 BrowserContextKeyedService* ApiResourceManagerTestFactory( |
| 21 content::BrowserContext* profile) { | 20 content::BrowserContext* context) { |
| 22 content::BrowserThread::ID id; | 21 content::BrowserThread::ID id; |
| 23 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id)); | 22 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id)); |
| 24 return ApiResourceManager<Socket>::CreateApiResourceManagerForTest( | 23 return ApiResourceManager<Socket>::CreateApiResourceManagerForTest(context, |
| 25 static_cast<Profile*>(profile), id); | 24 id); |
| 26 } | 25 } |
| 27 | 26 |
| 28 class SocketUnitTest : public ExtensionApiUnittest { | 27 class SocketUnitTest : public ExtensionApiUnittest { |
| 29 public: | 28 public: |
| 30 virtual void SetUp() { | 29 virtual void SetUp() { |
| 31 ExtensionApiUnittest::SetUp(); | 30 ExtensionApiUnittest::SetUp(); |
| 32 | 31 |
| 33 ApiResourceManager<Socket>::GetFactoryInstance()->SetTestingFactoryAndUse( | 32 ApiResourceManager<Socket>::GetFactoryInstance()->SetTestingFactoryAndUse( |
| 34 browser()->profile(), ApiResourceManagerTestFactory); | 33 browser()->profile(), ApiResourceManagerTestFactory); |
| 35 } | 34 } |
| 36 }; | 35 }; |
| 37 | 36 |
| 38 TEST_F(SocketUnitTest, Create) { | 37 TEST_F(SocketUnitTest, Create) { |
| 39 // Get BrowserThread | 38 // Get BrowserThread |
| 40 content::BrowserThread::ID id; | 39 content::BrowserThread::ID id; |
| 41 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id)); | 40 CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id)); |
| 42 | 41 |
| 43 // Create SocketCreateFunction and put it on BrowserThread | 42 // Create SocketCreateFunction and put it on BrowserThread |
| 44 SocketCreateFunction *function = new SocketCreateFunction(); | 43 SocketCreateFunction *function = new SocketCreateFunction(); |
| 45 function->set_work_thread_id(id); | 44 function->set_work_thread_id(id); |
| 46 | 45 |
| 47 // Run tests | 46 // Run tests |
| 48 scoped_ptr<base::DictionaryValue> result(RunFunctionAndReturnDictionary( | 47 scoped_ptr<base::DictionaryValue> result(RunFunctionAndReturnDictionary( |
| 49 function, "[\"tcp\"]")); | 48 function, "[\"tcp\"]")); |
| 50 ASSERT_TRUE(result.get()); | 49 ASSERT_TRUE(result.get()); |
| 51 } | 50 } |
| 52 | 51 |
| 53 } // namespace extensions | 52 } // namespace extensions |
| OLD | NEW |