OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 // | |
5 // Infobar window implementation unit tests. | |
6 | |
7 // MockWin32 must not be included after atlwin, which is included by some | |
8 // headers in here, so we need to put it at the top: | |
9 #include "ceee/testing/utils/mock_win32.h" // NOLINT | |
10 | |
11 #include "ceee/ie/plugin/bho/infobar_window.h" | |
12 #include "ceee/testing/utils/instance_count_mixin.h" | |
13 #include "ceee/testing/utils/test_utils.h" | |
14 #include "testing/gmock/include/gmock/gmock.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | |
16 | |
17 #include "broker_lib.h" // NOLINT | |
18 | |
19 namespace { | |
20 | |
21 using testing::_; | |
22 using testing::NotNull; | |
23 using testing::Return; | |
24 using testing::SetArgumentPointee; | |
25 using testing::StrEq; | |
26 using testing::StrictMock; | |
27 | |
28 const HWND kGoodWindow = reinterpret_cast<HWND>(42); | |
29 const HWND kParentWindow = reinterpret_cast<HWND>(74); | |
30 const wchar_t* kUrl1 = L"/infobar/test.html"; | |
31 const int kMaxHeight = 25; | |
32 const UINT_PTR timer_id = 19; | |
33 | |
34 class MockInfobarBrowserWindow : public infobar_api::IInfobarBrowserWindow { | |
MAD
2010/11/16 12:58:12
It's highly recommended to use the instance counti
vadimb
2010/11/16 22:46:01
Done.
| |
35 public: | |
36 STDMETHOD_(ULONG, AddRef)() { return 1; } | |
37 STDMETHOD_(ULONG, Release)() { return 1; } | |
38 STDMETHOD(QueryInterface)(REFIID, LPVOID*) { return S_OK; } | |
39 | |
40 MOCK_METHOD1_WITH_CALLTYPE(__stdcall, CreateAndShowWindow, HRESULT(HWND)); | |
41 MOCK_METHOD1_WITH_CALLTYPE(__stdcall, SetUrl, HRESULT(BSTR)); | |
42 MOCK_METHOD2_WITH_CALLTYPE(__stdcall, SetWindowSize, HRESULT(int, int)); | |
43 MOCK_METHOD0_WITH_CALLTYPE(__stdcall, Teardown, HRESULT()); | |
44 }; | |
45 | |
46 class MockInfobarWindowDelegate : public infobar_api::InfobarWindow::Delegate { | |
47 public: | |
48 MOCK_METHOD0(GetContainerWindow, HWND()); | |
49 MOCK_METHOD1(OnWindowClose, void(infobar_api::InfobarType)); | |
50 }; | |
51 | |
52 class TestingInfobarWindow : public infobar_api::InfobarWindow { | |
53 public: | |
54 TestingInfobarWindow(infobar_api::InfobarType type, | |
55 InfobarWindow::Delegate* delegate, | |
56 MockInfobarBrowserWindow* browser_window) | |
57 : infobar_api::InfobarWindow(type, delegate) { | |
58 chrome_frame_host_ = browser_window; | |
59 } | |
60 }; | |
61 | |
62 class InfobarWindowTests : public testing::Test { | |
63 public: | |
64 virtual void SetUp() { | |
65 infobar_window_delegate_.reset(new StrictMock<MockInfobarWindowDelegate>); | |
66 browser_window_.reset(new StrictMock<MockInfobarBrowserWindow>); | |
67 infobar_window_.reset(new StrictMock<TestingInfobarWindow>( | |
68 infobar_api::TOP_INFOBAR, infobar_window_delegate_.get(), | |
69 browser_window_.get())); | |
70 infobar_window_->m_hWnd = kGoodWindow; | |
71 | |
72 EXPECT_CALL(*browser_window_, Teardown()).WillOnce(Return(S_OK)); | |
73 EXPECT_CALL(*infobar_window_delegate_, GetContainerWindow()). | |
74 WillRepeatedly(Return(kParentWindow)); | |
75 | |
76 EXPECT_CALL(user32_, IsWindow(kGoodWindow)).WillRepeatedly(Return(TRUE)); | |
77 EXPECT_CALL(user32_, IsWindow(kParentWindow)).WillRepeatedly(Return(TRUE)); | |
78 EXPECT_CALL(user32_, IsWindow(NULL)).WillRepeatedly(Return(FALSE)); | |
79 EXPECT_CALL(user32_, GetParent(_)).WillRepeatedly(Return(kParentWindow)); | |
80 | |
81 RECT window_rect = {131, 213, 831, 1013}; | |
MAD
2010/11/16 12:58:12
Again, please add a comment stating that these val
vadimb
2010/11/16 22:46:01
Done.
| |
82 EXPECT_CALL(user32_, GetWindowRect(kParentWindow, NotNull())). | |
83 WillRepeatedly(DoAll(SetArgumentPointee<1>(window_rect), Return(TRUE))); | |
84 EXPECT_CALL(user32_, SetWindowPos(_, _, _, _, _, _, _)). | |
85 WillRepeatedly(Return(TRUE)); | |
86 } | |
87 virtual void TearDown() { | |
88 testing::LogDisabler no_dchecks; | |
89 // Infobar window must be deleted before delegate as the destructor will | |
90 // call the delegate member functions. | |
91 infobar_window_.reset(NULL); | |
92 infobar_window_delegate_.reset(NULL); | |
93 | |
94 // Everything should have been relinquished. | |
95 ASSERT_EQ(0, testing::InstanceCountMixinBase::all_instance_count()); | |
96 } | |
97 | |
98 protected: | |
99 StrictMock<testing::MockUser32> user32_; | |
100 scoped_ptr<StrictMock<MockInfobarWindowDelegate>> infobar_window_delegate_; | |
101 scoped_ptr<StrictMock<TestingInfobarWindow>> infobar_window_; | |
102 scoped_ptr<StrictMock<MockInfobarBrowserWindow>> browser_window_; | |
103 }; | |
104 | |
105 TEST_F(InfobarWindowTests, ShowHide) { | |
106 // Show without previous Navigate should fail. | |
107 EXPECT_HRESULT_FAILED(infobar_window_->Show(kMaxHeight, false)); | |
108 | |
109 // Navigate, then Show. | |
110 EXPECT_CALL(*browser_window_, SetUrl(StrEq(kUrl1))).Times(1); | |
111 EXPECT_HRESULT_SUCCEEDED(infobar_window_->Navigate(std::wstring(kUrl1))); | |
112 EXPECT_HRESULT_SUCCEEDED(infobar_window_->Show(kMaxHeight, false)); | |
113 EXPECT_EQ(kMaxHeight, infobar_window_->target_height_); | |
114 EXPECT_EQ(kMaxHeight, infobar_window_->current_height_); | |
115 EXPECT_TRUE(infobar_window_->show_); | |
116 | |
117 EXPECT_HRESULT_SUCCEEDED(infobar_window_->Hide()); | |
118 EXPECT_FALSE(infobar_window_->show_); | |
119 } | |
120 | |
121 TEST_F(InfobarWindowTests, SlidingShow) { | |
122 EXPECT_CALL(*browser_window_, SetUrl(StrEq(kUrl1))).Times(1); | |
123 EXPECT_HRESULT_SUCCEEDED(infobar_window_->Navigate(std::wstring(kUrl1))); | |
124 EXPECT_CALL(user32_, SetTimer(kGoodWindow, _, _, _)). | |
125 WillRepeatedly(Return(timer_id)); | |
126 EXPECT_HRESULT_SUCCEEDED(infobar_window_->Show(kMaxHeight, true)); | |
127 EXPECT_EQ(kMaxHeight, infobar_window_->target_height_); | |
128 // Should not be the target height yet. | |
MAD
2010/11/16 12:58:12
I would add to the comment that we need to call th
vadimb
2010/11/16 22:46:01
Done.
| |
129 EXPECT_LE(infobar_window_->current_height_, kMaxHeight); | |
130 EXPECT_TRUE(infobar_window_->show_); | |
131 EXPECT_TRUE(infobar_window_->sliding_infobar_); | |
132 | |
133 // Call timer callback function until required. | |
134 EXPECT_CALL(user32_, KillTimer(kGoodWindow, timer_id)).WillOnce(Return(TRUE)); | |
135 for (int i = 0; infobar_window_->sliding_infobar_ && i < 100; ++i) { | |
MAD
2010/11/16 12:58:12
Please comment on why you chose to hard code 100 a
vadimb
2010/11/16 22:46:01
Done.
| |
136 infobar_window_->OnTimer(timer_id); | |
137 } | |
138 EXPECT_FALSE(infobar_window_->sliding_infobar_); | |
139 EXPECT_EQ(kMaxHeight, infobar_window_->current_height_); | |
140 EXPECT_TRUE(infobar_window_->show_); | |
141 } | |
142 | |
143 TEST_F(InfobarWindowTests, OnClose) { | |
144 EXPECT_CALL(*infobar_window_delegate_, | |
145 OnWindowClose(infobar_api::TOP_INFOBAR)).Times(1); | |
146 | |
147 infobar_window_->OnBrowserWindowClose(); | |
148 } | |
149 | |
150 TEST_F(InfobarWindowTests, ReserveSpace) { | |
151 CRect rect1(255, 311, 814, 1015); | |
MAD
2010/11/16 12:58:12
Please comment the value choices...
vadimb
2010/11/16 22:46:01
Done.
| |
152 CRect rect0 = rect1; | |
153 infobar_window_->ReserveSpace(&rect1); | |
154 EXPECT_EQ(rect0, rect1); | |
155 | |
156 EXPECT_CALL(*browser_window_, SetUrl(StrEq(kUrl1))).Times(1); | |
157 EXPECT_HRESULT_SUCCEEDED(infobar_window_->Navigate(std::wstring(kUrl1))); | |
158 EXPECT_HRESULT_SUCCEEDED(infobar_window_->Show(kMaxHeight, false)); | |
159 infobar_window_->ReserveSpace(&rect1); | |
160 EXPECT_EQ(rect0.left, rect1.left); | |
161 EXPECT_EQ(rect0.right, rect1.right); | |
162 EXPECT_EQ(rect0.top + kMaxHeight, rect1.top); | |
163 EXPECT_EQ(rect0.bottom, rect1.bottom); | |
164 } | |
165 | |
166 } // namespace | |
OLD | NEW |