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