| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/compiler_specific.h" |
| 5 #include "base/synchronization/waitable_event.h" | 6 #include "base/synchronization/waitable_event.h" |
| 7 #include "chrome/common/chrome_paths_internal.h" |
| 6 #include "chrome_frame/crash_reporting/crash_metrics.h" | 8 #include "chrome_frame/crash_reporting/crash_metrics.h" |
| 9 #include "chrome_frame/test/chrome_frame_test_utils.h" |
| 7 #include "chrome_frame/test/proxy_factory_mock.h" | 10 #include "chrome_frame/test/proxy_factory_mock.h" |
| 11 #include "chrome_frame/test/test_scrubber.h" |
| 8 | 12 |
| 9 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING | 13 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING |
| 10 #include "testing/gmock_mutant.h" | 14 #include "testing/gmock_mutant.h" |
| 11 | 15 |
| 12 using testing::CreateFunctor; | 16 using testing::CreateFunctor; |
| 13 using testing::_; | 17 using testing::_; |
| 14 | 18 |
| 15 TEST(ProxyFactoryTest, CreateDestroy) { | 19 class ProxyFactoryTest : public testing::Test { |
| 20 protected: |
| 21 virtual void SetUp() OVERRIDE; |
| 22 |
| 23 ChromeFrameLaunchParams* MakeLaunchParams(const wchar_t* profile_name); |
| 24 |
| 25 ProxyFactory proxy_factory_; |
| 26 LaunchDelegateMock launch_delegate_mock_; |
| 27 }; |
| 28 |
| 29 void ProxyFactoryTest::SetUp() { |
| 16 CrashMetricsReporter::GetInstance()->set_active(true); | 30 CrashMetricsReporter::GetInstance()->set_active(true); |
| 31 } |
| 17 | 32 |
| 18 ProxyFactory f; | 33 ChromeFrameLaunchParams* ProxyFactoryTest::MakeLaunchParams( |
| 19 LaunchDelegateMock d; | 34 const wchar_t* profile_name) { |
| 20 EXPECT_CALL(d, LaunchComplete(testing::NotNull(), testing::_)).Times(1); | |
| 21 | |
| 22 GURL empty; | 35 GURL empty; |
| 23 FilePath profile_path; | 36 FilePath profile_path(chrome_frame_test::GetProfilePath(profile_name)); |
| 24 scoped_refptr<ChromeFrameLaunchParams> params( | 37 chrome_frame_test::OverrideDataDirectoryForThisTest(profile_path.value()); |
| 38 ChromeFrameLaunchParams* params = |
| 25 new ChromeFrameLaunchParams(empty, empty, profile_path, | 39 new ChromeFrameLaunchParams(empty, empty, profile_path, |
| 26 L"Adam.N.Epilinter", L"", false, false, false)); | 40 profile_path.BaseName().value(), L"", false, |
| 41 false, false); |
| 27 params->set_launch_timeout(0); | 42 params->set_launch_timeout(0); |
| 28 params->set_version_check(false); | 43 params->set_version_check(false); |
| 44 return params; |
| 45 } |
| 46 |
| 47 TEST_F(ProxyFactoryTest, CreateDestroy) { |
| 48 EXPECT_CALL(launch_delegate_mock_, |
| 49 LaunchComplete(testing::NotNull(), testing::_)).Times(1); |
| 50 |
| 51 scoped_refptr<ChromeFrameLaunchParams> params( |
| 52 MakeLaunchParams(L"Adam.N.Epilinter")); |
| 29 | 53 |
| 30 void* id = NULL; | 54 void* id = NULL; |
| 31 f.GetAutomationServer(&d, params, &id); | 55 proxy_factory_.GetAutomationServer(&launch_delegate_mock_, params, &id); |
| 32 f.ReleaseAutomationServer(id, &d); | 56 proxy_factory_.ReleaseAutomationServer(id, &launch_delegate_mock_); |
| 33 } | 57 } |
| 34 | 58 |
| 35 TEST(ProxyFactoryTest, CreateSameProfile) { | 59 TEST_F(ProxyFactoryTest, CreateSameProfile) { |
| 36 CrashMetricsReporter::GetInstance()->set_active(true); | |
| 37 ProxyFactory f; | |
| 38 LaunchDelegateMock d; | |
| 39 LaunchDelegateMock d2; | 60 LaunchDelegateMock d2; |
| 40 EXPECT_CALL(d, LaunchComplete(testing::NotNull(), testing::_)).Times(1); | 61 EXPECT_CALL(launch_delegate_mock_, |
| 62 LaunchComplete(testing::NotNull(), testing::_)).Times(1); |
| 41 EXPECT_CALL(d2, LaunchComplete(testing::NotNull(), testing::_)).Times(1); | 63 EXPECT_CALL(d2, LaunchComplete(testing::NotNull(), testing::_)).Times(1); |
| 42 | 64 |
| 43 GURL empty; | |
| 44 FilePath profile_path; | |
| 45 scoped_refptr<ChromeFrameLaunchParams> params( | 65 scoped_refptr<ChromeFrameLaunchParams> params( |
| 46 new ChromeFrameLaunchParams(empty, empty, profile_path, | 66 MakeLaunchParams(L"Dr. Gratiano Forbeson")); |
| 47 L"Dr. Gratiano Forbeson", L"", false, false, false)); | |
| 48 params->set_launch_timeout(0); | |
| 49 params->set_version_check(false); | |
| 50 | 67 |
| 51 void* i1 = NULL; | 68 void* i1 = NULL; |
| 52 void* i2 = NULL; | 69 void* i2 = NULL; |
| 53 | 70 |
| 54 f.GetAutomationServer(&d, params, &i1); | 71 proxy_factory_.GetAutomationServer(&launch_delegate_mock_, params, &i1); |
| 55 f.GetAutomationServer(&d2, params, &i2); | 72 proxy_factory_.GetAutomationServer(&d2, params, &i2); |
| 56 | 73 |
| 57 EXPECT_EQ(i1, i2); | 74 EXPECT_EQ(i1, i2); |
| 58 f.ReleaseAutomationServer(i2, &d2); | 75 proxy_factory_.ReleaseAutomationServer(i2, &d2); |
| 59 f.ReleaseAutomationServer(i1, &d); | 76 proxy_factory_.ReleaseAutomationServer(i1, &launch_delegate_mock_); |
| 60 } | 77 } |
| 61 | 78 |
| 62 TEST(ProxyFactoryTest, CreateDifferentProfiles) { | 79 TEST_F(ProxyFactoryTest, CreateDifferentProfiles) { |
| 63 CrashMetricsReporter::GetInstance()->set_active(true); | 80 EXPECT_CALL(launch_delegate_mock_, |
| 64 ProxyFactory f; | 81 LaunchComplete(testing::NotNull(), testing::_)).Times(2); |
| 65 LaunchDelegateMock d; | |
| 66 EXPECT_CALL(d, LaunchComplete(testing::NotNull(), testing::_)).Times(2); | |
| 67 | 82 |
| 68 GURL empty; | |
| 69 FilePath profile_path; | |
| 70 scoped_refptr<ChromeFrameLaunchParams> params1( | 83 scoped_refptr<ChromeFrameLaunchParams> params1( |
| 71 new ChromeFrameLaunchParams(empty, empty, profile_path, | 84 MakeLaunchParams(L"Adam.N.Epilinter")); |
| 72 L"Adam.N.Epilinter", L"", false, false, false)); | |
| 73 params1->set_launch_timeout(0); | |
| 74 params1->set_version_check(false); | |
| 75 | |
| 76 scoped_refptr<ChromeFrameLaunchParams> params2( | 85 scoped_refptr<ChromeFrameLaunchParams> params2( |
| 77 new ChromeFrameLaunchParams(empty, empty, profile_path, | 86 MakeLaunchParams(L"Dr. Gratiano Forbeson")); |
| 78 L"Dr. Gratiano Forbeson", L"", false, false, false)); | |
| 79 params2->set_launch_timeout(0); | |
| 80 params2->set_version_check(false); | |
| 81 | 87 |
| 82 void* i1 = NULL; | 88 void* i1 = NULL; |
| 83 void* i2 = NULL; | 89 void* i2 = NULL; |
| 84 | 90 |
| 85 f.GetAutomationServer(&d, params1, &i1); | 91 proxy_factory_.GetAutomationServer(&launch_delegate_mock_, params1, &i1); |
| 86 f.GetAutomationServer(&d, params2, &i2); | 92 proxy_factory_.GetAutomationServer(&launch_delegate_mock_, params2, &i2); |
| 87 | 93 |
| 88 EXPECT_NE(i1, i2); | 94 EXPECT_NE(i1, i2); |
| 89 f.ReleaseAutomationServer(i2, &d); | 95 proxy_factory_.ReleaseAutomationServer(i2, &launch_delegate_mock_); |
| 90 f.ReleaseAutomationServer(i1, &d); | 96 proxy_factory_.ReleaseAutomationServer(i1, &launch_delegate_mock_); |
| 91 } | 97 } |
| 92 | 98 |
| 93 // This test has been disabled because it crashes randomly on the builders. | 99 // This test has been disabled because it crashes randomly on the builders. |
| 94 // http://code.google.com/p/chromium/issues/detail?id=81039 | 100 // http://code.google.com/p/chromium/issues/detail?id=81039 |
| 95 TEST(ProxyFactoryTest, DISABLED_FastCreateDestroy) { | 101 TEST_F(ProxyFactoryTest, DISABLED_FastCreateDestroy) { |
| 96 CrashMetricsReporter::GetInstance()->set_active(true); | 102 LaunchDelegateMock* d1 = &launch_delegate_mock_; |
| 97 ProxyFactory f; | |
| 98 LaunchDelegateMock* d1 = new LaunchDelegateMock(); | |
| 99 LaunchDelegateMock* d2 = new LaunchDelegateMock(); | 103 LaunchDelegateMock* d2 = new LaunchDelegateMock(); |
| 100 | 104 |
| 101 GURL empty; | |
| 102 FilePath profile_path; | |
| 103 scoped_refptr<ChromeFrameLaunchParams> params( | 105 scoped_refptr<ChromeFrameLaunchParams> params( |
| 104 new ChromeFrameLaunchParams(empty, empty, profile_path, | 106 MakeLaunchParams(L"Dr. Gratiano Forbeson")); |
| 105 L"Dr. Gratiano Forbeson", L"", false, false, false)); | |
| 106 params->set_launch_timeout(10000); | 107 params->set_launch_timeout(10000); |
| 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 proxy_factory_.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 proxy_factory_.GetAutomationServer(d2, params, &i2); |
| 127 EXPECT_EQ(i1, i2); | 127 EXPECT_EQ(i1, i2); |
| 128 f.ReleaseAutomationServer(i2, d2); | 128 proxy_factory_.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 proxy_factory_.ReleaseAutomationServer(i1, d1); |
| 133 delete d1; | |
| 134 } | 133 } |
| OLD | NEW |