OLD | NEW |
(Empty) | |
| 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 |
| 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/api/socket/socket_api.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/browser_with_test_window_test.h" |
| 12 #include "chrome/test/base/testing_browser_process.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 |
| 16 namespace utils = extension_function_test_utils; |
| 17 |
| 18 namespace extensions { |
| 19 |
| 20 class SocketUnitTest : public BrowserWithTestWindowTest { |
| 21 public: |
| 22 virtual void SetUp() { |
| 23 BrowserWithTestWindowTest::SetUp(); |
| 24 |
| 25 TestExtensionSystem* system = static_cast<TestExtensionSystem*>( |
| 26 ExtensionSystem::Get(browser()->profile())); |
| 27 system->CreateSocketManager(); |
| 28 |
| 29 extension_ = utils::CreateEmptyExtensionWithLocation( |
| 30 extensions::Extension::LOAD); |
| 31 } |
| 32 |
| 33 base::Value* RunFunctionWithExtension( |
| 34 UIThreadExtensionFunction* function, const std::string& args) { |
| 35 function->set_extension(extension_.get()); |
| 36 return utils::RunFunctionAndReturnSingleResult(function, args, browser()); |
| 37 } |
| 38 |
| 39 base::DictionaryValue* RunFunctionAndReturnDict( |
| 40 UIThreadExtensionFunction* function, const std::string& args) { |
| 41 base::Value* result = RunFunctionWithExtension(function, args); |
| 42 return result ? utils::ToDictionary(result) : NULL; |
| 43 } |
| 44 |
| 45 base::ListValue* RunFunctionAndReturnList( |
| 46 UIThreadExtensionFunction* function, const std::string& args) { |
| 47 base::Value* result = RunFunctionWithExtension(function, args); |
| 48 return result ? utils::ToList(result) : NULL; |
| 49 } |
| 50 |
| 51 void RunFunction(UIThreadExtensionFunction* function, |
| 52 const std::string& args) { |
| 53 scoped_ptr<base::Value> result(RunFunctionWithExtension(function, args)); |
| 54 } |
| 55 |
| 56 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, |
| 57 const std::string& args) { |
| 58 function->set_extension(extension_.get()); |
| 59 return utils::RunFunctionAndReturnError(function, args, browser()); |
| 60 } |
| 61 |
| 62 protected: |
| 63 scoped_refptr<extensions::Extension> extension_; |
| 64 }; |
| 65 |
| 66 TEST_F(SocketUnitTest, Create) { |
| 67 // TODO(miket): enable this test. This will require teaching |
| 68 // SocketCreateFunction to do its work on a thread other than IO. Getting |
| 69 // this CL landed was hard enough already, so we're going to save this work |
| 70 // for another day. |
| 71 if (false) { |
| 72 scoped_ptr<base::DictionaryValue> result(RunFunctionAndReturnDict( |
| 73 new SocketCreateFunction(), "[\"tcp\"]")); |
| 74 ASSERT_TRUE(result.get()); |
| 75 } |
| 76 { |
| 77 std::string error = RunFunctionAndReturnError( |
| 78 new SocketCreateFunction(), "[\"nonexistent-socket-type\"]"); |
| 79 ASSERT_FALSE(error.empty()) << "Expected error. Got nothing instead."; |
| 80 } |
| 81 } |
| 82 |
| 83 } // namespace extensions |
OLD | NEW |