OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <vector> |
| 6 |
| 7 #include "base/base64.h" |
| 8 #include "base/crypto/rsa_private_key.h" |
| 9 #include "base/message_loop.h" |
| 10 #include "base/waitable_event.h" |
| 11 #include "chrome/service/service_process.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" |
5 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
6 | 14 |
7 TEST(ServiceProcessTest, Run) { | 15 TEST(ServiceProcessTest, Run) { |
8 // TODO(hclam): Implement this test. | 16 MessageLoopForUI main_message_loop; |
| 17 ServiceProcess process; |
| 18 EXPECT_TRUE(process.Initialize(&main_message_loop)); |
| 19 EXPECT_TRUE(process.Teardown()); |
9 } | 20 } |
| 21 |
| 22 #if defined(ENABLE_REMOTING) |
| 23 // TODO(hclam): This method should be made into a util. |
| 24 static std::string GeneratePrivateKey() { |
| 25 scoped_ptr<base::RSAPrivateKey> key(base::RSAPrivateKey::Create(2048)); |
| 26 |
| 27 std::vector<uint8> private_key_buf; |
| 28 key->ExportPrivateKey(&private_key_buf); |
| 29 std::string private_key_str(private_key_buf.begin(), private_key_buf.end()); |
| 30 std::string private_key_base64; |
| 31 base::Base64Encode(private_key_str, &private_key_base64); |
| 32 return private_key_base64; |
| 33 } |
| 34 |
| 35 TEST(ServiceProcessTest, RunChromoting) { |
| 36 MessageLoopForUI main_message_loop; |
| 37 ServiceProcess process; |
| 38 EXPECT_TRUE(process.Initialize(&main_message_loop)); |
| 39 |
| 40 // Then config the chromoting host and start it. |
| 41 process.SaveChromotingConfig("hello", "world", "it's a", "good day", |
| 42 GeneratePrivateKey()); |
| 43 EXPECT_TRUE(process.StartChromotingHost()); |
| 44 EXPECT_TRUE(process.ShutdownChromotingHost()); |
| 45 EXPECT_TRUE(process.Teardown()); |
| 46 } |
| 47 |
| 48 class MockServiceProcess : public ServiceProcess { |
| 49 private: |
| 50 FRIEND_TEST(ServiceProcessTest, RunChromotingUntilShutdown); |
| 51 MOCK_METHOD0(OnChromotingHostShutdown, void()); |
| 52 }; |
| 53 |
| 54 ACTION_P(QuitMessageLoop, message_loop) { |
| 55 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 56 } |
| 57 |
| 58 TEST(ServiceProcessTest, RunChromotingUntilShutdown) { |
| 59 MessageLoopForUI main_message_loop; |
| 60 MockServiceProcess process; |
| 61 EXPECT_TRUE(process.Initialize(&main_message_loop)); |
| 62 |
| 63 // Expect chromoting shutdown be called because the login token is invalid. |
| 64 EXPECT_CALL(process, OnChromotingHostShutdown()) |
| 65 .WillOnce(QuitMessageLoop(&main_message_loop)); |
| 66 |
| 67 // Then config the chromoting host and start it. |
| 68 process.SaveChromotingConfig("hello", "world", "it's a", "good day", |
| 69 GeneratePrivateKey()); |
| 70 EXPECT_TRUE(process.StartChromotingHost()); |
| 71 MessageLoop::current()->Run(); |
| 72 |
| 73 EXPECT_TRUE(process.Teardown()); |
| 74 } |
| 75 #endif // defined(ENABLE_REMOTING) |
OLD | NEW |