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.
5 #include "base/compiler_specific.h"
6 #include "base/synchronization/waitable_event.h"
7 #include "chrome/common/chrome_paths_internal.h"
8 #include "chrome_frame/crash_reporting/crash_metrics.h"
9 #include "chrome_frame/test/chrome_frame_test_utils.h"
10 #include "chrome_frame/test/proxy_factory_mock.h"
11 #include "chrome_frame/test/test_scrubber.h"
12 #include "chrome_frame/utils.h"
14 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING
15 #include "testing/gmock_mutant.h"
17 using testing::CreateFunctor
;
20 class ProxyFactoryTest
: public testing::Test
{
22 virtual void SetUp() OVERRIDE
;
24 ChromeFrameLaunchParams
* MakeLaunchParams(const wchar_t* profile_name
);
26 ProxyFactory proxy_factory_
;
27 LaunchDelegateMock launch_delegate_mock_
;
30 void ProxyFactoryTest::SetUp() {
31 CrashMetricsReporter::GetInstance()->set_active(true);
34 ChromeFrameLaunchParams
* ProxyFactoryTest::MakeLaunchParams(
35 const wchar_t* profile_name
) {
37 base::FilePath profile_path
;
38 GetChromeFrameProfilePath(profile_name
, &profile_path
);
39 chrome_frame_test::OverrideDataDirectoryForThisTest(profile_path
.value());
40 ChromeFrameLaunchParams
* params
=
41 new ChromeFrameLaunchParams(empty
, empty
, profile_path
,
42 profile_path
.BaseName().value(), L
"", false,
44 params
->set_launch_timeout(0);
45 params
->set_version_check(false);
49 TEST_F(ProxyFactoryTest
, CreateDestroy
) {
50 EXPECT_CALL(launch_delegate_mock_
,
51 LaunchComplete(testing::NotNull(), testing::_
)).Times(1);
53 scoped_refptr
<ChromeFrameLaunchParams
> params(
54 MakeLaunchParams(L
"Adam.N.Epilinter"));
57 proxy_factory_
.GetAutomationServer(&launch_delegate_mock_
, params
, &id
);
58 proxy_factory_
.ReleaseAutomationServer(id
, &launch_delegate_mock_
);
61 TEST_F(ProxyFactoryTest
, CreateSameProfile
) {
62 LaunchDelegateMock d2
;
63 EXPECT_CALL(launch_delegate_mock_
,
64 LaunchComplete(testing::NotNull(), testing::_
)).Times(1);
65 EXPECT_CALL(d2
, LaunchComplete(testing::NotNull(), testing::_
)).Times(1);
67 scoped_refptr
<ChromeFrameLaunchParams
> params(
68 MakeLaunchParams(L
"Dr. Gratiano Forbeson"));
73 proxy_factory_
.GetAutomationServer(&launch_delegate_mock_
, params
, &i1
);
74 proxy_factory_
.GetAutomationServer(&d2
, params
, &i2
);
77 proxy_factory_
.ReleaseAutomationServer(i2
, &d2
);
78 proxy_factory_
.ReleaseAutomationServer(i1
, &launch_delegate_mock_
);
81 TEST_F(ProxyFactoryTest
, CreateDifferentProfiles
) {
82 LaunchDelegateMock d2
;
84 EXPECT_CALL(launch_delegate_mock_
,
85 LaunchComplete(testing::NotNull(), testing::_
));
86 EXPECT_CALL(d2
, LaunchComplete(testing::NotNull(), testing::_
));
88 scoped_refptr
<ChromeFrameLaunchParams
> params1(
89 MakeLaunchParams(L
"Adam.N.Epilinter"));
90 scoped_refptr
<ChromeFrameLaunchParams
> params2(
91 MakeLaunchParams(L
"Dr. Gratiano Forbeson"));
96 proxy_factory_
.GetAutomationServer(&launch_delegate_mock_
, params1
, &i1
);
97 proxy_factory_
.GetAutomationServer(&d2
, params2
, &i2
);
100 proxy_factory_
.ReleaseAutomationServer(i2
, &d2
);
101 proxy_factory_
.ReleaseAutomationServer(i1
, &launch_delegate_mock_
);
104 // This test has been disabled because it crashes randomly on the builders.
105 // http://code.google.com/p/chromium/issues/detail?id=81039
106 TEST_F(ProxyFactoryTest
, DISABLED_FastCreateDestroy
) {
107 LaunchDelegateMock
* d1
= &launch_delegate_mock_
;
108 LaunchDelegateMock
* d2
= new LaunchDelegateMock();
110 scoped_refptr
<ChromeFrameLaunchParams
> params(
111 MakeLaunchParams(L
"Dr. Gratiano Forbeson"));
112 params
->set_launch_timeout(10000);
115 base::WaitableEvent
launched(true, false);
116 EXPECT_CALL(*d1
, LaunchComplete(testing::NotNull(), AUTOMATION_SUCCESS
))
117 .WillOnce(testing::InvokeWithoutArgs(&launched
,
118 &base::WaitableEvent::Signal
));
119 proxy_factory_
.GetAutomationServer(d1
, params
, &i1
);
121 ASSERT_TRUE(launched
.TimedWait(base::TimeDelta::FromSeconds(10)));
123 // Expect second launch to succeed too
124 EXPECT_CALL(*d2
, LaunchComplete(testing::NotNull(), AUTOMATION_SUCCESS
))
127 // Boost thread priority so we call ReleaseAutomationServer before
128 // LaunchComplete callback have a chance to be executed.
129 ::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_HIGHEST
);
131 proxy_factory_
.GetAutomationServer(d2
, params
, &i2
);
133 proxy_factory_
.ReleaseAutomationServer(i2
, d2
);
136 ::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_NORMAL
);
137 proxy_factory_
.ReleaseAutomationServer(i1
, d1
);