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