Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / sockets_udp / sockets_udp_api_unittest.cc
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.
4
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"
18
19 namespace utils = extension_function_test_utils;
20
21 namespace extensions {
22 namespace core_api {
23
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);
30 }
31
32 class SocketsUdpUnitTest : public ExtensionApiUnittest {
33  public:
34   void SetUp() override {
35     ExtensionApiUnittest::SetUp();
36
37     ApiResourceManager<ResumableUDPSocket>::GetFactoryInstance()
38         ->SetTestingFactoryAndUse(browser()->profile(),
39                                   ApiResourceManagerTestFactory);
40   }
41 };
42
43 TEST_F(SocketsUdpUnitTest, Create) {
44   // Get BrowserThread
45   content::BrowserThread::ID id;
46   CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id));
47
48   // Create SocketCreateFunction and put it on BrowserThread
49   SocketsUdpCreateFunction* function = new SocketsUdpCreateFunction();
50   function->set_work_thread_id(id);
51
52   // Run tests
53   scoped_ptr<base::DictionaryValue> result(RunFunctionAndReturnDictionary(
54       function, "[{\"persistent\": true, \"name\": \"foo\"}]"));
55   ASSERT_TRUE(result.get());
56 }
57
58 }  // namespace core_api
59 }  // namespace extensions