1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/waitable_event.h"
#include "chrome_frame/test/proxy_factory_mock.h"
#define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING
#include "testing/gmock_mutant.h"
using testing::CreateFunctor;
using testing::_;
DISABLE_RUNNABLE_METHOD_REFCOUNT(MockProxyFactory);
TEST(ProxyFactoryTest, CreateDestroy) {
ProxyFactory f;
LaunchDelegateMock d;
EXPECT_CALL(d, LaunchComplete(testing::NotNull(), testing::_)).Times(1);
GURL empty;
FilePath profile_path;
scoped_refptr<ChromeFrameLaunchParams> params(
new ChromeFrameLaunchParams(empty, empty, profile_path,
L"Adam.N.Epilinter", L"", false, false));
params->set_launch_timeout(0);
params->set_version_check(false);
void* id = NULL;
f.GetAutomationServer(&d, params, &id);
f.ReleaseAutomationServer(id, &d);
}
TEST(ProxyFactoryTest, CreateSameProfile) {
ProxyFactory f;
LaunchDelegateMock d;
LaunchDelegateMock d2;
EXPECT_CALL(d, LaunchComplete(testing::NotNull(), testing::_)).Times(1);
EXPECT_CALL(d2, LaunchComplete(testing::NotNull(), testing::_)).Times(1);
GURL empty;
FilePath profile_path;
scoped_refptr<ChromeFrameLaunchParams> params(
new ChromeFrameLaunchParams(empty, empty, profile_path,
L"Dr. Gratiano Forbeson", L"", false, false));
params->set_launch_timeout(0);
params->set_version_check(false);
void* i1 = NULL;
void* i2 = NULL;
f.GetAutomationServer(&d, params, &i1);
f.GetAutomationServer(&d2, params, &i2);
EXPECT_EQ(i1, i2);
f.ReleaseAutomationServer(i2, &d2);
f.ReleaseAutomationServer(i1, &d);
}
TEST(ProxyFactoryTest, CreateDifferentProfiles) {
ProxyFactory f;
LaunchDelegateMock d;
EXPECT_CALL(d, LaunchComplete(testing::NotNull(), testing::_)).Times(2);
GURL empty;
FilePath profile_path;
scoped_refptr<ChromeFrameLaunchParams> params1(
new ChromeFrameLaunchParams(empty, empty, profile_path,
L"Adam.N.Epilinter", L"", false, false));
params1->set_launch_timeout(0);
params1->set_version_check(false);
scoped_refptr<ChromeFrameLaunchParams> params2(
new ChromeFrameLaunchParams(empty, empty, profile_path,
L"Dr. Gratiano Forbeson", L"", false, false));
params2->set_launch_timeout(0);
params2->set_version_check(false);
void* i1 = NULL;
void* i2 = NULL;
f.GetAutomationServer(&d, params1, &i1);
f.GetAutomationServer(&d, params2, &i2);
EXPECT_NE(i1, i2);
f.ReleaseAutomationServer(i2, &d);
f.ReleaseAutomationServer(i1, &d);
}
TEST(ProxyFactoryTest, FastCreateDestroy) {
ProxyFactory f;
LaunchDelegateMock* d1 = new LaunchDelegateMock();
LaunchDelegateMock* d2 = new LaunchDelegateMock();
GURL empty;
FilePath profile_path;
scoped_refptr<ChromeFrameLaunchParams> params(
new ChromeFrameLaunchParams(empty, empty, profile_path,
L"Dr. Gratiano Forbeson", L"", false, false));
params->set_launch_timeout(10000);
params->set_version_check(false);
void* i1 = NULL;
base::WaitableEvent launched(true, false);
EXPECT_CALL(*d1, LaunchComplete(testing::NotNull(), AUTOMATION_SUCCESS))
.WillOnce(testing::InvokeWithoutArgs(&launched,
&base::WaitableEvent::Signal));
f.GetAutomationServer(d1, params, &i1);
// Wait for launch
ASSERT_TRUE(launched.TimedWait(base::TimeDelta::FromSeconds(10)));
// Expect second launch to succeed too
EXPECT_CALL(*d2, LaunchComplete(testing::NotNull(), AUTOMATION_SUCCESS))
.Times(1);
// Boost thread priority so we call ReleaseAutomationServer before
// LaunchComplete callback have a chance to be executed.
::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
void* i2 = NULL;
f.GetAutomationServer(d2, params, &i2);
EXPECT_EQ(i1, i2);
f.ReleaseAutomationServer(i2, d2);
delete d2;
::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_NORMAL);
f.ReleaseAutomationServer(i1, d1);
delete d1;
}
|