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