OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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/command_line.h" | |
6 #include "chrome/browser/extensions/extension_apitest.h" | |
7 #include "chrome/browser/extensions/extension_function_test_utils.h" | |
8 #include "chrome/browser/extensions/socket_api.h" | |
9 #include "chrome/common/chrome_switches.h" | |
10 #include "chrome/test/base/in_process_browser_test.h" | |
11 #include "chrome/test/base/ui_test_utils.h" | |
12 | |
13 using namespace extension_function_test_utils; | |
14 | |
15 namespace { | |
16 | |
17 class SocketApiTest : public InProcessBrowserTest { | |
18 }; | |
19 | |
20 } | |
21 | |
22 IN_PROC_BROWSER_TEST_F(SocketApiTest, SocketCreateGood) { | |
23 CommandLine::ForCurrentProcess()->AppendSwitch( | |
24 switches::kEnableExperimentalExtensionApis); | |
25 CommandLine::ForCurrentProcess()->AppendSwitch( | |
26 switches::kEnablePlatformApps); | |
27 scoped_refptr<extensions::SocketCreateFunction> socket_create_function( | |
28 new extensions::SocketCreateFunction()); | |
29 scoped_refptr<Extension> empty_extension(CreateEmptyExtension()); | |
30 | |
31 socket_create_function->set_extension(empty_extension.get()); | |
32 socket_create_function->set_has_callback(true); | |
33 | |
34 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | |
35 socket_create_function, "[\"udp\"]", browser(), NONE)); | |
36 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType()); | |
37 DictionaryValue *value = static_cast<DictionaryValue*>(result.get()); | |
38 int socketId = -1; | |
39 EXPECT_TRUE(value->GetInteger("socketId", &socketId)); | |
40 EXPECT_EQ(42, socketId); | |
41 } | |
42 | |
43 IN_PROC_BROWSER_TEST_F(SocketApiTest, SocketCreateBad) { | |
44 CommandLine::ForCurrentProcess()->AppendSwitch( | |
45 switches::kEnableExperimentalExtensionApis); | |
46 CommandLine::ForCurrentProcess()->AppendSwitch( | |
47 switches::kEnablePlatformApps); | |
48 scoped_refptr<extensions::SocketCreateFunction> socket_create_function( | |
49 new extensions::SocketCreateFunction()); | |
50 scoped_refptr<Extension> empty_extension(CreateEmptyExtension()); | |
51 | |
52 socket_create_function->set_extension(empty_extension.get()); | |
53 socket_create_function->set_has_callback(true); | |
54 | |
55 // TODO(miket): this test currently passes only because of artificial code | |
56 // that doesn't run in production. Fix this when we're able to. | |
57 RunFunctionAndReturnError(socket_create_function, "[\"xxxx\"]", browser(), | |
58 NONE); | |
59 } | |
60 | |
61 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, SocketExtension) { | |
62 CommandLine::ForCurrentProcess()->AppendSwitch( | |
63 switches::kEnableExperimentalExtensionApis); | |
64 CommandLine::ForCurrentProcess()->AppendSwitch( | |
65 switches::kEnablePlatformApps); | |
66 | |
67 ASSERT_TRUE(RunExtensionTest("socket/api")) << message_; | |
68 } | |
OLD | NEW |