diff options
author | mad@chromium.org <mad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-31 14:05:18 +0000 |
---|---|---|
committer | mad@chromium.org <mad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-31 14:05:18 +0000 |
commit | 3592d26e1943c0af9627e8e5a6d01ccf79fbb60c (patch) | |
tree | 8314c2e7d9e8e33f70db210a9f7b420e216f0d3f /chrome_frame | |
parent | b9f9935d21ef59f50e46bb4537124a81b840f386 (diff) | |
download | chromium_src-3592d26e1943c0af9627e8e5a6d01ccf79fbb60c.zip chromium_src-3592d26e1943c0af9627e8e5a6d01ccf79fbb60c.tar.gz chromium_src-3592d26e1943c0af9627e8e5a6d01ccf79fbb60c.tar.bz2 |
Test the new code for propagating OnChannelError to Chrome Frame Delegate.
The new code was added in:
http://src.chromium.org/viewvc/chrome?view=rev&revision=42810
More tests are comming.
BUG=0
TEST=none
Review URL: http://codereview.chromium.org/1571005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43211 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame')
-rw-r--r-- | chrome_frame/test/automation_client_mock.cc | 164 | ||||
-rw-r--r-- | chrome_frame/test/automation_client_mock.h | 16 |
2 files changed, 144 insertions, 36 deletions
diff --git a/chrome_frame/test/automation_client_mock.cc b/chrome_frame/test/automation_client_mock.cc index 486f782..26a6732 100644 --- a/chrome_frame/test/automation_client_mock.cc +++ b/chrome_frame/test/automation_client_mock.cc @@ -10,8 +10,9 @@ #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING #include "testing/gmock_mutant.h" -using testing::CreateFunctor; using testing::_; +using testing::CreateFunctor; +using testing::Return; template <> struct RunnableMethodTraits<ProxyFactory::LaunchDelegate> { void RetainCallee(ProxyFactory::LaunchDelegate* obj) {} @@ -41,18 +42,17 @@ void MockProxyFactory::GetServerImpl(ChromeFrameAutomationProxy* pxy, params.automation_server_launch_timeout/2); } -void CFACMockTest::SetAutomationServerOk() { +void CFACMockTest::SetAutomationServerOk(int times) { EXPECT_CALL(factory_, GetAutomationServer(testing::NotNull(), testing::Field(&ChromeFrameLaunchParams::profile_name, testing::StrEq(profile_path_.BaseName().ToWStringHack())), testing::NotNull())) - .Times(1) - .WillOnce(testing::Invoke(CreateFunctor(&factory_, - &MockProxyFactory::GetServerImpl, - get_proxy(), id_, - AUTOMATION_SUCCESS))); + .Times(times) + .WillRepeatedly(testing::Invoke(CreateFunctor(&factory_, + &MockProxyFactory::GetServerImpl, get_proxy(), id_, + AUTOMATION_SUCCESS))); - EXPECT_CALL(factory_, ReleaseAutomationServer(testing::Eq(id_))).Times(1); + EXPECT_CALL(factory_, ReleaseAutomationServer(testing::Eq(id_))).Times(times); } void CFACMockTest::Set_CFD_LaunchFailed(AutomationLaunchResult result) { @@ -120,7 +120,7 @@ TEST(CFACWithChrome, CreateTooFast) { // This test may fail if Chrome take more that 10 seconds (timeout var) to // launch. In this case GMock shall print something like "unexpected call to // OnAutomationServerLaunchFailed". I'm yet to find out how to specify -// that this is an unexpected call, and still to execute and action. +// that this is an unexpected call, and still to execute an action. TEST(CFACWithChrome, CreateNotSoFast) { MockCFDelegate cfd; chrome_frame_test::TimedMsgLoop loop; @@ -262,27 +262,26 @@ TEST(CFACWithChrome, NavigateFailed) { TEST_F(CFACMockTest, MockedCreateTabOk) { int timeout = 500; CreateTab(); - SetAutomationServerOk(); + SetAutomationServerOk(1); - EXPECT_CALL(proxy_, server_version()).Times(testing::AnyNumber()) - .WillRepeatedly(testing::Return("")); + EXPECT_CALL(mock_proxy_, server_version()).Times(testing::AnyNumber()) + .WillRepeatedly(Return("")); // We need some valid HWNDs, when responding to CreateExternalTab HWND h1 = ::GetDesktopWindow(); HWND h2 = ::GetDesktopWindow(); - EXPECT_CALL(proxy_, SendAsAsync(testing::Property(&IPC::SyncMessage::type, - AutomationMsg_CreateExternalTab__ID), - testing::NotNull(), _)) - .Times(1) - .WillOnce(HandleCreateTab(tab_handle_, h1, h2)); + EXPECT_CALL(mock_proxy_, SendAsAsync(testing::Property( + &IPC::SyncMessage::type, AutomationMsg_CreateExternalTab__ID), + testing::NotNull(), _)) + .Times(1).WillOnce(HandleCreateTab(tab_handle_, h1, h2)); - EXPECT_CALL(proxy_, CreateTabProxy(testing::Eq(tab_handle_))) - .WillOnce(testing::Return(tab_)); + EXPECT_CALL(mock_proxy_, CreateTabProxy(testing::Eq(tab_handle_))) + .WillOnce(Return(tab_)); EXPECT_CALL(cfd_, OnAutomationServerReady()) .WillOnce(QUIT_LOOP(loop_)); - EXPECT_CALL(proxy_, CancelAsync(_)).Times(testing::AnyNumber()); + EXPECT_CALL(mock_proxy_, CancelAsync(_)).Times(testing::AnyNumber()); // Here we go! ChromeFrameLaunchParams clp = { @@ -299,26 +298,25 @@ TEST_F(CFACMockTest, MockedCreateTabOk) { EXPECT_TRUE(client_->Initialize(&cfd_, clp)); loop_.RunFor(10); - EXPECT_CALL(proxy_, ReleaseTabProxy(testing::Eq(tab_handle_))).Times(1); + EXPECT_CALL(mock_proxy_, ReleaseTabProxy(testing::Eq(tab_handle_))).Times(1); client_->Uninitialize(); } TEST_F(CFACMockTest, MockedCreateTabFailed) { HWND null_wnd = NULL; - SetAutomationServerOk(); + SetAutomationServerOk(1); - EXPECT_CALL(proxy_, server_version()).Times(testing::AnyNumber()) - .WillRepeatedly(testing::Return("")); + EXPECT_CALL(mock_proxy_, server_version()).Times(testing::AnyNumber()) + .WillRepeatedly(Return("")); - EXPECT_CALL(proxy_, SendAsAsync(testing::Property(&IPC::SyncMessage::type, - AutomationMsg_CreateExternalTab__ID), - testing::NotNull(), _)) - .Times(1) - .WillOnce(HandleCreateTab(tab_handle_, null_wnd, null_wnd)); + EXPECT_CALL(mock_proxy_, SendAsAsync(testing::Property( + &IPC::SyncMessage::type, AutomationMsg_CreateExternalTab__ID), + testing::NotNull(), _)) + .Times(1).WillOnce(HandleCreateTab(tab_handle_, null_wnd, null_wnd)); - EXPECT_CALL(proxy_, CreateTabProxy(_)).Times(0); + EXPECT_CALL(mock_proxy_, CreateTabProxy(_)).Times(0); - EXPECT_CALL(proxy_, CancelAsync(_)).Times(testing::AnyNumber()); + EXPECT_CALL(mock_proxy_, CancelAsync(_)).Times(testing::AnyNumber()); Set_CFD_LaunchFailed(AUTOMATION_CREATE_TAB_FAILED); @@ -339,6 +337,110 @@ TEST_F(CFACMockTest, MockedCreateTabFailed) { client_->Uninitialize(); } +class TestChromeFrameAutomationProxyImpl + : public ChromeFrameAutomationProxyImpl { + public: + TestChromeFrameAutomationProxyImpl() + : ChromeFrameAutomationProxyImpl(1) { // 1 is an unneeded timeout. + } + MOCK_METHOD3(SendAsAsync, void(IPC::SyncMessage* msg, void* callback, + void* key)); + void FakeChannelError() { + reinterpret_cast<IPC::ChannelProxy::MessageFilter*>(message_filter_.get())-> + OnChannelError(); + } +}; + +TEST_F(CFACMockTest, OnChannelErrorEmpty) { + TestChromeFrameAutomationProxyImpl proxy; + + // No tabs should do nothing yet still not fail either. + proxy.FakeChannelError(); +} + TEST_F(CFACMockTest, OnChannelError) { + TestChromeFrameAutomationProxyImpl proxy; + returned_proxy_ = &proxy; + ChromeFrameLaunchParams clp = { + 1, // Unneeded timeout, but can't be 0. + GURL(), + GURL(), + profile_path_, + profile_path_.BaseName().value(), + L"", + false, + false, + false + }; + + HWND h1 = ::GetDesktopWindow(); + HWND h2 = ::GetDesktopWindow(); + EXPECT_CALL(proxy, SendAsAsync(testing::Property( + &IPC::SyncMessage::type, AutomationMsg_CreateExternalTab__ID), + testing::NotNull(), _)).Times(3) + .WillOnce(HandleCreateTab(tab_handle_, h1, h2)) + .WillOnce(HandleCreateTab(tab_handle_ * 2, h1, h2)) + .WillOnce(HandleCreateTab(tab_handle_ * 3, h1, h2)); + + SetAutomationServerOk(3); + + // First, try a single tab and make sure the notification find its way to the + // Chrome Frame Delegate. + StrictMock<MockCFDelegate> cfd1; + scoped_refptr<ChromeFrameAutomationClient> client1; + client1 = new ChromeFrameAutomationClient; + client1->set_proxy_factory(&factory_); + + EXPECT_CALL(cfd1, OnAutomationServerReady()).WillOnce(QUIT_LOOP(loop_)); + EXPECT_TRUE(client1->Initialize(&cfd1, clp)); + // Wait for OnAutomationServerReady to be called in the UI thread. + loop_.RunFor(11); + + proxy.FakeChannelError(); + EXPECT_CALL(cfd1, OnChannelError()).WillOnce(QUIT_LOOP(loop_)); + // Wait for OnChannelError to be propagated to delegate from the UI thread. + loop_.RunFor(11); + + // Add a second tab using a different delegate. + StrictMock<MockCFDelegate> cfd2; + scoped_refptr<ChromeFrameAutomationClient> client2; + client2 = new ChromeFrameAutomationClient; + client2->set_proxy_factory(&factory_); + + EXPECT_CALL(cfd2, OnAutomationServerReady()).WillOnce(QUIT_LOOP(loop_)); + EXPECT_TRUE(client2->Initialize(&cfd2, clp)); + // Wait for OnAutomationServerReady to be called in the UI thread. + loop_.RunFor(11); + + EXPECT_CALL(cfd1, OnChannelError()).Times(1); + EXPECT_CALL(cfd2, OnChannelError()).WillOnce(QUIT_LOOP(loop_)); + proxy.FakeChannelError(); + // Wait for OnChannelError to be propagated to delegate from the UI thread. + loop_.RunFor(11); + + // And now a 3rd tab using the first delegate. + scoped_refptr<ChromeFrameAutomationClient> client3; + client3 = new ChromeFrameAutomationClient; + client3->set_proxy_factory(&factory_); + + EXPECT_CALL(cfd1, OnAutomationServerReady()).WillOnce(QUIT_LOOP(loop_)); + EXPECT_TRUE(client3->Initialize(&cfd1, clp)); + // Wait for OnAutomationServerReady to be called in the UI thread. + loop_.RunFor(11); + + EXPECT_CALL(cfd2, OnChannelError()).Times(1); + EXPECT_CALL(cfd1, OnChannelError()).Times(2).WillOnce(Return()) + .WillOnce(QUIT_LOOP(loop_)); + proxy.FakeChannelError(); + // Wait for OnChannelError to be propagated to delegate from the UI thread. + loop_.RunFor(11); + + // Cleanup. + client1->Uninitialize(); + client2->Uninitialize(); + client3->Uninitialize(); + client1 = NULL; + client2 = NULL; + client3 = NULL; } diff --git a/chrome_frame/test/automation_client_mock.h b/chrome_frame/test/automation_client_mock.h index 1d187f3..54f9d5e 100644 --- a/chrome_frame/test/automation_client_mock.h +++ b/chrome_frame/test/automation_client_mock.h @@ -32,6 +32,7 @@ struct MockCFDelegate : public ChromeFrameDelegateImpl { // to the following methods (which we mock) // MOCK_METHOD1(OnMessageReceived, void(const IPC::Message&)); + MOCK_METHOD0(OnChannelError, void(void)); MOCK_METHOD2(OnNavigationStateChanged, void(int tab_handle, int flags)); MOCK_METHOD2(OnUpdateTargetUrl, void(int tab_handle, const std::wstring& new_target_url)); @@ -103,7 +104,6 @@ class MockAutomationProxy : public ChromeFrameAutomationProxy { struct MockAutomationMessageSender : public AutomationMessageSender { MOCK_METHOD1(Send, bool(IPC::Message*)); - MOCK_METHOD3(SendWithTimeout, bool(IPC::Message* , int , bool*)); void ForwardTo(StrictMock<MockAutomationProxy> *p) { proxy_ = p; @@ -133,7 +133,12 @@ class CFACMockTest : public testing::Test { MockProxyFactory factory_; MockCFDelegate cfd_; chrome_frame_test::TimedMsgLoop loop_; - StrictMock<MockAutomationProxy> proxy_; + // Most of the test uses the mocked proxy, but some tests need + // to validate the functionality of the real proxy object. + // So we have a mock that is used as the default for the returned_proxy_ + // pointer, but tests can set their own pointer in there as needed. + StrictMock<MockAutomationProxy> mock_proxy_; + ChromeFrameAutomationProxy* returned_proxy_; scoped_ptr<AutomationHandleTracker> tracker_; MockAutomationMessageSender dummy_sender_; scoped_refptr<TabProxy> tab_; @@ -146,7 +151,7 @@ class CFACMockTest : public testing::Test { int tab_handle_; // Tab handle. Any non-zero value is Ok. inline ChromeFrameAutomationProxy* get_proxy() { - return static_cast<ChromeFrameAutomationProxy*>(&proxy_); + return returned_proxy_; } inline void CreateTab() { @@ -155,12 +160,13 @@ class CFACMockTest : public testing::Test { } // Easy methods to set expectations. - void SetAutomationServerOk(); + void SetAutomationServerOk(int times); void Set_CFD_LaunchFailed(AutomationLaunchResult result); protected: CFACMockTest() : tracker_(NULL), timeout_(500), + returned_proxy_(static_cast<ChromeFrameAutomationProxy*>(&mock_proxy_)), profile_path_( chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter")) { id_ = reinterpret_cast<void*>(5); @@ -168,7 +174,7 @@ class CFACMockTest : public testing::Test { } virtual void SetUp() { - dummy_sender_.ForwardTo(&proxy_); + dummy_sender_.ForwardTo(&mock_proxy_); tracker_.reset(new AutomationHandleTracker()); client_ = new ChromeFrameAutomationClient; |