| 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> |   5 #include <vector> | 
|   6  |   6  | 
|   7 #include "base/base64.h" |   7 #include "base/base64.h" | 
 |   8 #include "base/command_line.h" | 
|   8 #include "base/crypto/rsa_private_key.h" |   9 #include "base/crypto/rsa_private_key.h" | 
|   9 #include "base/message_loop.h" |  10 #include "base/message_loop.h" | 
|  10 #include "base/waitable_event.h" |  11 #include "base/waitable_event.h" | 
|  11 #include "chrome/service/service_process.h" |  12 #include "chrome/service/service_process.h" | 
|  12 #include "remoting/host/host_key_pair.h" |  13 #include "remoting/host/host_key_pair.h" | 
|  13 #include "testing/gmock/include/gmock/gmock.h" |  14 #include "testing/gmock/include/gmock/gmock.h" | 
|  14 #include "testing/gtest/include/gtest/gtest.h" |  15 #include "testing/gtest/include/gtest/gtest.h" | 
|  15  |  16  | 
|  16 TEST(ServiceProcessTest, DISABLED_Run) { |  17 TEST(ServiceProcessTest, DISABLED_Run) { | 
|  17   MessageLoopForUI main_message_loop; |  18   MessageLoopForUI main_message_loop; | 
|  18   ServiceProcess process; |  19   ServiceProcess process; | 
|  19   EXPECT_TRUE(process.Initialize(&main_message_loop)); |  20   CommandLine command_line(CommandLine::ARGUMENTS_ONLY); | 
 |  21   EXPECT_TRUE(process.Initialize(&main_message_loop, command_line)); | 
|  20   EXPECT_TRUE(process.Teardown()); |  22   EXPECT_TRUE(process.Teardown()); | 
|  21 } |  23 } | 
|  22  |  24  | 
|  23 #if defined(ENABLE_REMOTING) |  25 #if defined(ENABLE_REMOTING) | 
|  24 // This test seems to break randomly so disabling it. |  26 // This test seems to break randomly so disabling it. | 
|  25 TEST(ServiceProcessTest, DISABLED_RunChromoting) { |  27 TEST(ServiceProcessTest, DISABLED_RunChromoting) { | 
|  26   MessageLoopForUI main_message_loop; |  28   MessageLoopForUI main_message_loop; | 
|  27   ServiceProcess process; |  29   ServiceProcess process; | 
|  28   EXPECT_TRUE(process.Initialize(&main_message_loop)); |  30   CommandLine command_line(CommandLine::ARGUMENTS_ONLY); | 
 |  31   EXPECT_TRUE(process.Initialize(&main_message_loop, command_line)); | 
|  29  |  32  | 
|  30   // Then config the chromoting host and start it. |  33   // Then config the chromoting host and start it. | 
|  31   remoting::HostKeyPair key; |  34   remoting::HostKeyPair key; | 
|  32   key.Generate(); |  35   key.Generate(); | 
|  33   process.SaveChromotingConfig("hello", "world", "it's a", "good day", &key); |  36   process.SaveChromotingConfig("hello", "world", "it's a", "good day", &key); | 
|  34   EXPECT_TRUE(process.StartChromotingHost()); |  37   EXPECT_TRUE(process.StartChromotingHost()); | 
|  35   EXPECT_TRUE(process.ShutdownChromotingHost()); |  38   EXPECT_TRUE(process.ShutdownChromotingHost()); | 
|  36   EXPECT_TRUE(process.Teardown()); |  39   EXPECT_TRUE(process.Teardown()); | 
|  37 } |  40 } | 
|  38  |  41  | 
|  39 class MockServiceProcess : public ServiceProcess { |  42 class MockServiceProcess : public ServiceProcess { | 
|  40  private: |  43  private: | 
|  41   FRIEND_TEST_ALL_PREFIXES(ServiceProcessTest, RunChromotingUntilShutdown); |  44   FRIEND_TEST_ALL_PREFIXES(ServiceProcessTest, RunChromotingUntilShutdown); | 
|  42   MOCK_METHOD0(OnChromotingHostShutdown, void()); |  45   MOCK_METHOD0(OnChromotingHostShutdown, void()); | 
|  43 }; |  46 }; | 
|  44  |  47  | 
|  45 ACTION_P(QuitMessageLoop, message_loop) { |  48 ACTION_P(QuitMessageLoop, message_loop) { | 
|  46   message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |  49   message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 
|  47 } |  50 } | 
|  48  |  51  | 
|  49 TEST(ServiceProcessTest, DISABLED_RunChromotingUntilShutdown) { |  52 TEST(ServiceProcessTest, DISABLED_RunChromotingUntilShutdown) { | 
|  50   MessageLoopForUI main_message_loop; |  53   MessageLoopForUI main_message_loop; | 
|  51   MockServiceProcess process; |  54   MockServiceProcess process; | 
|  52   EXPECT_TRUE(process.Initialize(&main_message_loop)); |  55   CommandLine command_line(CommandLine::ARGUMENTS_ONLY); | 
 |  56   EXPECT_TRUE(process.Initialize(&main_message_loop, command_line)); | 
|  53  |  57  | 
|  54   // Expect chromoting shutdown be called because the login token is invalid. |  58   // Expect chromoting shutdown be called because the login token is invalid. | 
|  55   EXPECT_CALL(process, OnChromotingHostShutdown()) |  59   EXPECT_CALL(process, OnChromotingHostShutdown()) | 
|  56       .WillOnce(QuitMessageLoop(&main_message_loop)); |  60       .WillOnce(QuitMessageLoop(&main_message_loop)); | 
|  57  |  61  | 
|  58   // Then config the chromoting host and start it. |  62   // Then config the chromoting host and start it. | 
|  59   remoting::HostKeyPair key; |  63   remoting::HostKeyPair key; | 
|  60   key.Generate(); |  64   key.Generate(); | 
|  61   process.SaveChromotingConfig("hello", "world", "it's a", "good day", &key); |  65   process.SaveChromotingConfig("hello", "world", "it's a", "good day", &key); | 
|  62   EXPECT_TRUE(process.StartChromotingHost()); |  66   EXPECT_TRUE(process.StartChromotingHost()); | 
|  63   MessageLoop::current()->Run(); |  67   MessageLoop::current()->Run(); | 
|  64  |  68  | 
|  65   EXPECT_TRUE(process.Teardown()); |  69   EXPECT_TRUE(process.Teardown()); | 
|  66 } |  70 } | 
|  67 #endif  // defined(ENABLE_REMOTING) |  71 #endif  // defined(ENABLE_REMOTING) | 
| OLD | NEW |