Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: ceee/ie/plugin/bho/infobar_window_unittest.cc

Issue 4991002: New unittests for infobar. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ceee/ie/plugin/bho/infobar_window.cc ('k') | ceee/testing/utils/mock_win32.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 {
35 public:
36 MockInfobarBrowserWindow() : ref_count(0) {}
37 ~MockInfobarBrowserWindow() { EXPECT_EQ(0, ref_count); }
38 STDMETHOD_(ULONG, AddRef)() { return ++ref_count; }
39 STDMETHOD_(ULONG, Release)() { return --ref_count; }
40 STDMETHOD(QueryInterface)(REFIID, LPVOID*) { return S_OK; }
41
42 MOCK_METHOD1_WITH_CALLTYPE(__stdcall, CreateAndShowWindow, HRESULT(HWND));
43 MOCK_METHOD1_WITH_CALLTYPE(__stdcall, SetUrl, HRESULT(BSTR));
44 MOCK_METHOD2_WITH_CALLTYPE(__stdcall, SetWindowSize, HRESULT(int, int));
45 MOCK_METHOD0_WITH_CALLTYPE(__stdcall, Teardown, HRESULT());
46
47 ULONG ref_count;
MAD 2010/11/17 16:34:32 Note that you can also use the InstanceCountMixin
48 };
49
50 class MockInfobarWindowDelegate : public infobar_api::InfobarWindow::Delegate {
51 public:
52 MOCK_METHOD0(GetContainerWindow, HWND());
53 MOCK_METHOD1(OnWindowClose, void(infobar_api::InfobarType));
54 };
55
56 class TestingInfobarWindow : public infobar_api::InfobarWindow {
57 public:
58 TestingInfobarWindow(infobar_api::InfobarType type,
59 InfobarWindow::Delegate* delegate,
60 MockInfobarBrowserWindow* browser_window)
61 : infobar_api::InfobarWindow(type, delegate) {
62 chrome_frame_host_ = browser_window;
63 }
64 };
65
66 class InfobarWindowTests : public testing::Test {
67 public:
68 virtual void SetUp() {
69 infobar_window_delegate_.reset(new StrictMock<MockInfobarWindowDelegate>);
70 browser_window_.reset(new StrictMock<MockInfobarBrowserWindow>);
71 infobar_window_.reset(new StrictMock<TestingInfobarWindow>(
72 infobar_api::TOP_INFOBAR, infobar_window_delegate_.get(),
73 browser_window_.get()));
74 infobar_window_->m_hWnd = kGoodWindow;
75
76 EXPECT_CALL(*browser_window_, Teardown()).WillOnce(Return(S_OK));
77 EXPECT_CALL(*infobar_window_delegate_, GetContainerWindow()).
78 WillRepeatedly(Return(kParentWindow));
79
80 EXPECT_CALL(user32_, IsWindow(kGoodWindow)).WillRepeatedly(Return(TRUE));
81 EXPECT_CALL(user32_, IsWindow(kParentWindow)).WillRepeatedly(Return(TRUE));
82 EXPECT_CALL(user32_, IsWindow(NULL)).WillRepeatedly(Return(FALSE));
83 EXPECT_CALL(user32_, GetParent(_)).WillRepeatedly(Return(kParentWindow));
84
85 // Arbitrary number to return from GetWindowRect. Unique to make it easier
86 // to trace in the debugger or to add in future tests dependent on return
87 // values.
88 RECT window_rect = {131, 213, 831, 1013};
89 EXPECT_CALL(user32_, GetWindowRect(kParentWindow, NotNull())).
90 WillRepeatedly(DoAll(SetArgumentPointee<1>(window_rect), Return(TRUE)));
91 EXPECT_CALL(user32_, SetWindowPos(_, _, _, _, _, _, _)).
92 WillRepeatedly(Return(TRUE));
93 }
94 virtual void TearDown() {
95 testing::LogDisabler no_dchecks;
96 // Infobar window must be deleted before delegate as the destructor will
97 // call the delegate member functions.
98 infobar_window_.reset(NULL);
99 infobar_window_delegate_.reset(NULL);
100
101 // Everything should have been relinquished.
102 ASSERT_EQ(0, testing::InstanceCountMixinBase::all_instance_count());
103 }
104
105 protected:
106 StrictMock<testing::MockUser32> user32_;
107 scoped_ptr<StrictMock<MockInfobarWindowDelegate>> infobar_window_delegate_;
108 scoped_ptr<StrictMock<TestingInfobarWindow>> infobar_window_;
109 scoped_ptr<StrictMock<MockInfobarBrowserWindow>> browser_window_;
110 };
111
112 TEST_F(InfobarWindowTests, ShowHide) {
113 // Show without previous Navigate should fail.
114 EXPECT_HRESULT_FAILED(infobar_window_->Show(kMaxHeight, false));
115
116 // Navigate, then Show.
117 EXPECT_CALL(*browser_window_, SetUrl(StrEq(kUrl1))).Times(1);
118 EXPECT_HRESULT_SUCCEEDED(infobar_window_->Navigate(std::wstring(kUrl1)));
119 EXPECT_HRESULT_SUCCEEDED(infobar_window_->Show(kMaxHeight, false));
120 EXPECT_EQ(kMaxHeight, infobar_window_->target_height_);
121 EXPECT_EQ(kMaxHeight, infobar_window_->current_height_);
122 EXPECT_TRUE(infobar_window_->show_);
123
124 EXPECT_HRESULT_SUCCEEDED(infobar_window_->Hide());
125 EXPECT_FALSE(infobar_window_->show_);
126 }
127
128 TEST_F(InfobarWindowTests, SlidingShow) {
129 EXPECT_CALL(*browser_window_, SetUrl(StrEq(kUrl1))).Times(1);
130 EXPECT_HRESULT_SUCCEEDED(infobar_window_->Navigate(std::wstring(kUrl1)));
131 EXPECT_CALL(user32_, SetTimer(kGoodWindow, _, _, _)).
132 WillRepeatedly(Return(timer_id));
133 EXPECT_HRESULT_SUCCEEDED(infobar_window_->Show(kMaxHeight, true));
134 EXPECT_EQ(kMaxHeight, infobar_window_->target_height_);
135 // With sliding enabled, the hight of the infobar should not be the target
MAD 2010/11/17 16:34:32 hight -> height
136 // height immediately - it increases on each timer tick until reaches target.
137 EXPECT_LE(infobar_window_->current_height_, kMaxHeight);
138 EXPECT_TRUE(infobar_window_->show_);
139 EXPECT_TRUE(infobar_window_->sliding_infobar_);
140
141 // Call timer callback function until required.
142 EXPECT_CALL(user32_, KillTimer(kGoodWindow, timer_id)).WillOnce(Return(TRUE));
143 // Restrict the maximum number of times the loop can run so the test does not
144 // hang if infobar_window_->sliding_infobar_ is not set. Normally it should
145 // run just a few times (3 times if kMaxHeight is 25 and sliding step is 10).
146 for (int i = 0; infobar_window_->sliding_infobar_ && i < 100; ++i) {
147 infobar_window_->OnTimer(timer_id);
148 }
149 // Check that the loop is exited because of sliding_infobar_ condition and not
150 // the counter saturation.
151 EXPECT_FALSE(infobar_window_->sliding_infobar_);
152 EXPECT_EQ(kMaxHeight, infobar_window_->current_height_);
153 EXPECT_TRUE(infobar_window_->show_);
154 }
155
156 TEST_F(InfobarWindowTests, OnClose) {
157 EXPECT_CALL(*infobar_window_delegate_,
158 OnWindowClose(infobar_api::TOP_INFOBAR)).Times(1);
159
160 infobar_window_->OnBrowserWindowClose();
161 }
162
163 TEST_F(InfobarWindowTests, ReserveSpace) {
164 // Arbitrary number to return from GetWindowRect. Unique to make it easier
165 // to trace in the debugger.
166 CRect rect1(255, 311, 814, 1015);
167 CRect rect0 = rect1;
168 infobar_window_->ReserveSpace(&rect1);
169 EXPECT_EQ(rect0, rect1);
170
171 EXPECT_CALL(*browser_window_, SetUrl(StrEq(kUrl1))).Times(1);
172 EXPECT_HRESULT_SUCCEEDED(infobar_window_->Navigate(std::wstring(kUrl1)));
173 EXPECT_HRESULT_SUCCEEDED(infobar_window_->Show(kMaxHeight, false));
174 infobar_window_->ReserveSpace(&rect1);
175 EXPECT_EQ(rect0.left, rect1.left);
176 EXPECT_EQ(rect0.right, rect1.right);
177 EXPECT_EQ(rect0.top + kMaxHeight, rect1.top);
178 EXPECT_EQ(rect0.bottom, rect1.bottom);
179 }
180
181 } // namespace
OLDNEW
« no previous file with comments | « ceee/ie/plugin/bho/infobar_window.cc ('k') | ceee/testing/utils/mock_win32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698