1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <atlbase.h>
#include <atlapp.h>
#include <atlcrack.h>
#include <atlmisc.h>
#include <atlwin.h>
#include "base/string_number_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "chrome_frame/infobars/infobar_content.h"
#include "chrome_frame/infobars/internal/displaced_window_manager.h"
#include "chrome_frame/infobars/internal/host_window_manager.h"
#include "chrome_frame/infobars/internal/infobar_window.h"
#include "chrome_frame/infobars/internal/subclassing_window_with_delegate.h"
#include "chrome_frame/test/chrome_frame_test_utils.h"
DISABLE_RUNNABLE_METHOD_REFCOUNT(InfobarContent::Frame);
DISABLE_RUNNABLE_METHOD_REFCOUNT(InfobarManager);
namespace {
RECT kInitialParentWindowRect = {20, 20, 300, 300};
RECT kInitialChildWindowRect = {20, 20, 280, 280};
MATCHER_P(EqualRect, expected, "") {
return ::EqualRect(expected, arg);
}
ACTION_P2(RespondToNcCalcSize, result, rect) {
*reinterpret_cast<RECT*>(arg1) = *rect;
return result;
}
ACTION_P4(RespondToNcCalcSize, result, rect1, rect2, rect3) {
reinterpret_cast<RECT*>(arg1)[0] = rect1;
reinterpret_cast<RECT*>(arg1)[1] = rect2;
reinterpret_cast<RECT*>(arg1)[2] = rect3;
return result;
}
class ParentTraits : public CFrameWinTraits {
public:
static const wchar_t* kClassName;
}; // class ParentTraits
class ChildTraits : public CControlWinTraits {
public:
static const wchar_t* kClassName;
}; // class ChildTraits
const wchar_t* ParentTraits::kClassName = NULL;
const wchar_t* ChildTraits::kClassName = L"Shell DocObject View";
template<typename TRAITS> class MockWindow
: public CWindowImpl<MockWindow<TRAITS>, CWindow, TRAITS> {
public:
virtual ~MockWindow() {
if (IsWindow())
DestroyWindow();
}
MOCK_METHOD1(OnCreate, int(LPCREATESTRUCT lpCreateStruct));
MOCK_METHOD0(OnDestroy, void());
MOCK_METHOD2(OnSize, void(UINT nType, CSize size));
MOCK_METHOD1(OnMove, void(CPoint ptPos));
MOCK_METHOD2(OnNcCalcSize, LRESULT(BOOL bCalcValidRects, LPARAM lParam));
DECLARE_WND_CLASS(TRAITS::kClassName);
BEGIN_MSG_MAP_EX(MockWindow)
MSG_WM_CREATE(OnCreate)
MSG_WM_DESTROY(OnDestroy)
MSG_WM_SIZE(OnSize)
MSG_WM_MOVE(OnMove)
MSG_WM_NCCALCSIZE(OnNcCalcSize)
END_MSG_MAP()
}; // class MockWindow
typedef MockWindow<ParentTraits> MockTopLevelWindow;
typedef MockWindow<ChildTraits> MockChildWindow;
class MockWindowSubclass
: public SubclassingWindowWithDelegate<MockWindowSubclass> {
public:
MOCK_METHOD2(OnNcCalcSize, LRESULT(BOOL bCalcValidRects, LPARAM lParam));
BEGIN_MSG_MAP_EX(MockWindowSubclass)
MSG_WM_NCCALCSIZE(OnNcCalcSize)
CHAIN_MSG_MAP(SubclassingWindowWithDelegate<MockWindowSubclass>)
END_MSG_MAP()
virtual ~MockWindowSubclass() { Die(); }
MOCK_METHOD0(Die, void());
}; // class MockWindowSubclass
template<typename T> class MockDelegate
: public SubclassingWindowWithDelegate<T>::Delegate {
public:
virtual ~MockDelegate() { Die(); }
MOCK_METHOD0(Die, void());
MOCK_METHOD1(AdjustDisplacedWindowDimensions, void(RECT* rect));
}; // clas MockDelegate
template<typename T> T* Initialize(T* t,
HWND hwnd,
typename T::Delegate* delegate) {
if (t->Initialize(hwnd, delegate)) {
return t;
} else {
delete t;
return NULL;
}
}
}; // namespace
TEST(InfobarsSubclassingWindowWithDelegateTest, BasicTest) {
testing::NiceMock<MockTopLevelWindow> window;
ASSERT_TRUE(window.Create(NULL, kInitialParentWindowRect) != NULL);
HWND hwnd = static_cast<HWND>(window);
ASSERT_TRUE(MockWindowSubclass::GetDelegateForHwnd(hwnd) == NULL);
MockDelegate<MockWindowSubclass>* delegate =
new testing::StrictMock<MockDelegate<MockWindowSubclass> >();
MockWindowSubclass* swwd = Initialize(
new testing::StrictMock<MockWindowSubclass>(), hwnd, delegate);
ASSERT_TRUE(swwd != NULL);
ASSERT_EQ(static_cast<MockWindowSubclass::Delegate*>(delegate),
MockWindowSubclass::GetDelegateForHwnd(hwnd));
// Since expectations are only validated upon object destruction, this test
// would normally pass even if the expected deletions never happened.
// By expecting another call, in sequence, after the deletions, we force a
// failure if those deletions don't occur.
testing::MockFunction<void(std::string check_point_name)> check;
{
testing::InSequence s;
EXPECT_CALL(*delegate, Die());
EXPECT_CALL(*swwd, Die());
EXPECT_CALL(check, Call("checkpoint"));
}
window.DestroyWindow();
check.Call("checkpoint");
ASSERT_TRUE(MockWindowSubclass::GetDelegateForHwnd(hwnd) == NULL);
}
TEST(InfobarsSubclassingWindowWithDelegateTest, InvalidHwndTest) {
testing::NiceMock<MockTopLevelWindow> window;
ASSERT_TRUE(window.Create(NULL, kInitialParentWindowRect) != NULL);
HWND hwnd = static_cast<HWND>(window);
window.DestroyWindow();
MockDelegate<MockWindowSubclass>* delegate =
new testing::StrictMock<MockDelegate<MockWindowSubclass> >();
MockWindowSubclass* swwd = new testing::StrictMock<MockWindowSubclass>();
testing::MockFunction<void(std::string check_point_name)> check;
{
testing::InSequence s;
EXPECT_CALL(*delegate, Die());
EXPECT_CALL(check, Call("checkpoint"));
EXPECT_CALL(*swwd, Die());
}
ASSERT_FALSE(swwd->Initialize(hwnd, delegate));
check.Call("checkpoint"); // Make sure the delegate has been deleted
delete swwd;
ASSERT_TRUE(MockWindowSubclass::GetDelegateForHwnd(hwnd) == NULL);
}
template <typename WINDOW, typename DELEGATE> void ExpectNcCalcSizeSequence(
WINDOW* mock_window,
DELEGATE* delegate,
RECT* natural_rect,
RECT* modified_rect) {
testing::InSequence s;
EXPECT_CALL(*mock_window, OnNcCalcSize(true, testing::_)).WillOnce(
RespondToNcCalcSize(0, natural_rect));
EXPECT_CALL(*delegate,
AdjustDisplacedWindowDimensions(EqualRect(natural_rect)))
.WillOnce(testing::SetArgumentPointee<0>(*modified_rect));
EXPECT_CALL(*mock_window, OnMove(CPoint(modified_rect->left,
modified_rect->top)));
EXPECT_CALL(*mock_window,
OnSize(0, CSize(modified_rect->right - modified_rect->left,
modified_rect->bottom - modified_rect->top)));
EXPECT_CALL(*mock_window, OnNcCalcSize(true, testing::_))
.Times(testing::Between(0, 1))
.WillOnce(RespondToNcCalcSize(0, natural_rect));
EXPECT_CALL(*delegate,
AdjustDisplacedWindowDimensions(EqualRect(natural_rect)))
.Times(testing::Between(0, 1))
.WillOnce(testing::SetArgumentPointee<0>(*modified_rect));
EXPECT_CALL(*mock_window, OnMove(CPoint(modified_rect->left,
modified_rect->top)))
.Times(testing::Between(0, 1));
EXPECT_CALL(*mock_window,
OnSize(0, CSize(modified_rect->right - modified_rect->left,
modified_rect->bottom - modified_rect->top)))
.Times(testing::Between(0, 1));
}
template <typename WINDOW, typename DELEGATE, typename MANAGER>
void DoNcCalcSizeSequence(WINDOW* mock_window,
DELEGATE* delegate,
MANAGER* manager) {
RECT natural_rects[] = { {0, 0, 100, 100}, {10, 10, 120, 120} };
RECT modified_rects[] = { {10, 5, 90, 95}, {25, 35, 80, 70} };
ExpectNcCalcSizeSequence(
mock_window, delegate, &natural_rects[0], &natural_rects[0]);
// The first time through, trigger the sizing via the manager.
// This is required for the HostWindowManager, since it only looks up
// and subclasses the displaced window on demand.
manager->UpdateLayout();
testing::Mock::VerifyAndClearExpectations(mock_window);
testing::Mock::VerifyAndClearExpectations(delegate);
ExpectNcCalcSizeSequence(
mock_window, delegate, &natural_rects[1], &natural_rects[1]);
// The second time through, trigger it through the original window.
// By now, we expect to be observing the window in all cases.
::SetWindowPos(static_cast<HWND>(*mock_window),
NULL, 0, 0, 0, 0,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
SWP_FRAMECHANGED);
testing::Mock::VerifyAndClearExpectations(mock_window);
testing::Mock::VerifyAndClearExpectations(delegate);
}
TEST(InfobarsDisplacedWindowManagerTest, BasicTest) {
testing::NiceMock<MockTopLevelWindow> window;
ASSERT_TRUE(window.Create(NULL, kInitialParentWindowRect) != NULL);
MockDelegate<DisplacedWindowManager>* delegate =
new testing::StrictMock<MockDelegate<DisplacedWindowManager> >();
DisplacedWindowManager* dwm = new DisplacedWindowManager();
ASSERT_TRUE(dwm->Initialize(static_cast<HWND>(window), delegate));
ASSERT_NO_FATAL_FAILURE(DoNcCalcSizeSequence(&window, delegate, dwm));
EXPECT_CALL(*delegate, Die());
window.DestroyWindow();
}
TEST(InfobarsHostWindowManagerTest, BasicTest) {
testing::NiceMock<MockTopLevelWindow> window;
ASSERT_TRUE(window.Create(NULL, kInitialParentWindowRect) != NULL);
testing::NiceMock<MockChildWindow> child_window;
ASSERT_TRUE(child_window.Create(window, kInitialChildWindowRect) != NULL);
testing::NiceMock<MockChildWindow> child_window2;
testing::NiceMock<MockChildWindow> child_window3;
MockDelegate<HostWindowManager>* delegate =
new testing::StrictMock<MockDelegate<HostWindowManager> >();
HostWindowManager* hwm = new HostWindowManager();
ASSERT_TRUE(hwm->Initialize(static_cast<HWND>(window), delegate));
ASSERT_NO_FATAL_FAILURE(DoNcCalcSizeSequence(&child_window, delegate, hwm));
// First, destroy window 1 and subsequently create window 2
child_window.DestroyWindow();
ASSERT_TRUE(child_window2.Create(window, kInitialChildWindowRect) != NULL);
ASSERT_NO_FATAL_FAILURE(DoNcCalcSizeSequence(&child_window2, delegate, hwm));
// Next, create window 3 just before destroying window 2
RECT natural_rect = {10, 15, 40, 45};
RECT modified_rect = {15, 20, 35, 40};
ASSERT_TRUE(child_window3.Create(window, kInitialChildWindowRect) != NULL);
ExpectNcCalcSizeSequence(
&child_window3, delegate, &natural_rect, &natural_rect);
child_window2.DestroyWindow();
ASSERT_NO_FATAL_FAILURE(DoNcCalcSizeSequence(&child_window3, delegate, hwm));
EXPECT_CALL(*delegate, Die());
window.DestroyWindow();
}
// Must be declared in same namespace as RECT
void PrintTo(const RECT& rect, ::std::ostream* os) {
*os << "{" << rect.left << ", " << rect.top << ", " << rect.right << ", "
<< rect.bottom << "}";
}
namespace {
class MockHost : public InfobarWindow::Host {
public:
MockHost(InfobarWindow* infobar_window,
const RECT& natural_dimensions,
HWND hwnd)
: infobar_window_(infobar_window),
natural_dimensions_(natural_dimensions),
hwnd_(hwnd) {
}
void SetNaturalDimensions(const RECT& natural_dimensions) {
natural_dimensions_ = natural_dimensions;
UpdateLayout();
}
virtual HWND GetContainerWindow() {
return hwnd_;
}
virtual void UpdateLayout() {
RECT temp(natural_dimensions_);
infobar_window_->ReserveSpace(&temp);
CheckReservedSpace(&temp);
}
MOCK_METHOD0(Die, void(void));
// Convenience method for checking the result of InfobarWindow::ReserveSpace
MOCK_METHOD1(CheckReservedSpace, void(RECT* rect));
private:
InfobarWindow* infobar_window_;
RECT natural_dimensions_;
HWND hwnd_;
}; // class MockHost
class MockInfobarContent : public InfobarContent {
public:
virtual ~MockInfobarContent() { Die(); }
MOCK_METHOD1(InstallInFrame, bool(Frame* frame));
MOCK_METHOD1(SetDimensions, void(const RECT& dimensions));
MOCK_METHOD2(GetDesiredSize, size_t(size_t width, size_t height));
MOCK_METHOD0(Die, void(void));
}; // class MockInfobarContent
MATCHER_P(
RectHeightIsLTEToRectXHeight, rect_x, "height is <= to height of rect x") {
return arg.bottom - arg.top <= rect_x->bottom - rect_x->top;
}
MATCHER_P(
RectHeightIsGTEToRectXHeight, rect_x, "height is >= to height of rect x") {
return arg.bottom - arg.top >= rect_x->bottom - rect_x->top;
}
MATCHER_P3(RectIsTopXToYOfRectZ, x, y, rect_z, "is top x to y of rect z" ) {
return rect_z->top == arg.top &&
rect_z->left == arg.left &&
rect_z->right == arg.right &&
arg.bottom - arg.top >= x &&
arg.bottom - arg.top <= y;
}
MATCHER_P2(RectAddedToRectXMakesRectY,
rect_x,
rect_y,
"rect added to rect x makes rect y") {
if (::IsRectEmpty(rect_x))
return ::EqualRect(arg, rect_y);
if (::IsRectEmpty(arg))
return ::EqualRect(rect_x, rect_y);
// Either they are left and right slices, or top and bottom slices
if (!((rect_x->left == rect_y->left && rect_x->right == rect_y->right &&
arg->left == rect_y->left && arg->right == rect_y->right) ||
(rect_x->top == rect_y->top && rect_x->bottom== rect_y->bottom &&
arg->top == rect_y->top && arg->bottom == rect_y->bottom))) {
return false;
}
RECT expected_arg;
if (!::SubtractRect(&expected_arg, rect_y, rect_x))
return false; // Given above checks, the difference should not be empty
return ::EqualRect(arg, &expected_arg);
}
MATCHER_P(FrameHwndIs, hwnd, "") {
return arg != NULL && arg->GetFrameWindow() == hwnd;
}
ACTION_P(CheckSetFlag, flag) {
ASSERT_FALSE(*flag);
*flag = true;
}
ACTION_P(ResetFlag, flag) {
*flag = false;
}
ACTION_P2(AsynchronousCloseOnFrame, loop, frame) {
loop->PostDelayedTask(
FROM_HERE,
NewRunnableMethod(*frame, &InfobarContent::Frame::CloseInfobar),
0);
}
ACTION_P2(AsynchronousHideOnManager, loop, manager) {
loop->PostDelayedTask(
FROM_HERE,
NewRunnableMethod(manager, &InfobarManager::Hide, TOP_INFOBAR),
0);
}
}; // namespace
// The test ensures that the content is sized at least once in each of the
// following ranges while fully opening and closing:
//
// [0, infobar_height / 2)
// [infobar_height / 2, infobar_height)
// [infobar_height, infobar_height]
// (infobar_height / 2, infobar_height]
// [0, infobar_height / 2]
//
// If the test turns out to be flaky (i.e., because timers are not firing
// frequently enough to hit all the ranges), increasing the infobar_height
// should increase the margin (by increasing the time spent in each range).
TEST(InfobarsInfobarWindowTest, SlidingTest) {
int infobar_height = 40;
chrome_frame_test::TimedMsgLoop message_loop;
RECT natural_dimensions = {10, 20, 90, 100 + infobar_height};
// Used to verify that the last RECT given to SetDimensions is the same RECT
// reserved by ReserveSpace.
RECT current_infobar_dimensions = {0, 0, 0, 0}; // Used to verify that the
// Used to make sure that each SetDimensions is matched by a return from
// ReserveSpace.
bool pending_reserve_space = false;
InfobarWindow infobar_window(TOP_INFOBAR);
testing::NiceMock<MockTopLevelWindow> window;
ASSERT_TRUE(window.Create(NULL, kInitialParentWindowRect));
HWND hwnd = static_cast<HWND>(window);
MockInfobarContent* content = new MockInfobarContent();
scoped_ptr<MockHost> host(new MockHost(&infobar_window,
natural_dimensions,
hwnd));
infobar_window.SetHost(host.get());
// Used to ensure that GetDesiredSize is only called on an installed
// InfobarContent.
testing::Expectation installed;
// Will hold the frame given to us in InfobarContent::InstallInFrame.
InfobarContent::Frame* frame = NULL;
// We could get any number of calls to UpdateLayout. Make sure that, each
// time, the space reserved by the InfobarWindow equals the space offered to
// the InfobarContent.
EXPECT_CALL(*host, CheckReservedSpace(RectAddedToRectXMakesRectY(
¤t_infobar_dimensions, &natural_dimensions)))
.Times(testing::AnyNumber())
.WillRepeatedly(ResetFlag(&pending_reserve_space));
testing::MockFunction<void(std::string check_point_name)> check;
{
testing::InSequence s;
// During Show(), we get an InstallInFrame
installed = EXPECT_CALL(*content, InstallInFrame(FrameHwndIs(hwnd)))
.WillOnce(testing::DoAll(testing::SaveArg<0>(&frame),
testing::Return(true)));
// Allow a call to SetDimensions before InstallInFrame returns.
EXPECT_CALL(*content, SetDimensions(testing::AllOf(
RectIsTopXToYOfRectZ(0, infobar_height / 2 - 1, &natural_dimensions),
RectHeightIsGTEToRectXHeight(¤t_infobar_dimensions))))
.Times(testing::AnyNumber()).WillRepeatedly(testing::DoAll(
testing::SaveArg<0>(¤t_infobar_dimensions),
CheckSetFlag(&pending_reserve_space)));
EXPECT_CALL(check, Call("returned from Show"));
EXPECT_CALL(*content, SetDimensions(testing::AllOf(
RectIsTopXToYOfRectZ(0, infobar_height / 2 - 1, &natural_dimensions),
RectHeightIsGTEToRectXHeight(¤t_infobar_dimensions))))
.Times(testing::AtLeast(1)).WillRepeatedly(testing::DoAll(
testing::SaveArg<0>(¤t_infobar_dimensions),
CheckSetFlag(&pending_reserve_space)));
EXPECT_CALL(*content, SetDimensions(testing::AllOf(
RectIsTopXToYOfRectZ(infobar_height / 2,
infobar_height - 1,
&natural_dimensions),
RectHeightIsGTEToRectXHeight(¤t_infobar_dimensions))))
.Times(testing::AtLeast(1)).WillRepeatedly(testing::DoAll(
testing::SaveArg<0>(¤t_infobar_dimensions),
CheckSetFlag(&pending_reserve_space)));
EXPECT_CALL(*content, SetDimensions(
RectIsTopXToYOfRectZ(infobar_height,
infobar_height,
&natural_dimensions)))
.WillOnce(testing::DoAll(
testing::SaveArg<0>(¤t_infobar_dimensions),
CheckSetFlag(&pending_reserve_space),
AsynchronousCloseOnFrame(&message_loop, &frame)));
EXPECT_CALL(*content, SetDimensions(testing::AllOf(
RectIsTopXToYOfRectZ(infobar_height / 2 + 1,
infobar_height,
&natural_dimensions),
RectHeightIsLTEToRectXHeight(¤t_infobar_dimensions))))
.Times(testing::AtLeast(1)).WillRepeatedly(testing::DoAll(
testing::SaveArg<0>(¤t_infobar_dimensions),
CheckSetFlag(&pending_reserve_space)));
EXPECT_CALL(*content, SetDimensions(testing::AllOf(
RectIsTopXToYOfRectZ(0, infobar_height / 2, &natural_dimensions),
RectHeightIsLTEToRectXHeight(¤t_infobar_dimensions))))
.Times(testing::AtLeast(1)).WillRepeatedly(testing::DoAll(
testing::SaveArg<0>(¤t_infobar_dimensions),
CheckSetFlag(&pending_reserve_space)));
EXPECT_CALL(*content, Die()).WillOnce(QUIT_LOOP(message_loop));
}
EXPECT_CALL(*content, GetDesiredSize(80, 0))
.Times(testing::AnyNumber()).After(installed)
.WillRepeatedly(testing::Return(infobar_height));
ASSERT_NO_FATAL_FAILURE(infobar_window.Show(content));
ASSERT_NO_FATAL_FAILURE(check.Call("returned from Show"));
ASSERT_NO_FATAL_FAILURE(message_loop.RunFor(10)); // seconds
window.DestroyWindow();
ASSERT_FALSE(message_loop.WasTimedOut());
}
TEST(InfobarsInfobarManagerTest, BasicTest) {
chrome_frame_test::TimedMsgLoop message_loop;
int infobar_height = 40;
RECT natural_dimensions = {10, 20, 90, 100 + infobar_height};
testing::NiceMock<MockTopLevelWindow> window;
ASSERT_TRUE(window.Create(NULL, kInitialParentWindowRect) != NULL);
testing::NiceMock<MockChildWindow> child_window;
ASSERT_TRUE(child_window.Create(window, kInitialChildWindowRect) != NULL);
HWND parent_hwnd = static_cast<HWND>(window);
HWND child_hwnd = static_cast<HWND>(child_window);
MockInfobarContent* content = new MockInfobarContent();
InfobarContent::Frame* frame = NULL;
InfobarManager* manager = InfobarManager::Get(parent_hwnd);
ASSERT_FALSE(manager == NULL);
EXPECT_CALL(*content, GetDesiredSize(80, 0))
.Times(testing::AnyNumber())
.WillRepeatedly(testing::Return(infobar_height));
EXPECT_CALL(child_window, OnNcCalcSize(true, testing::_))
.Times(testing::AnyNumber()).WillRepeatedly(
RespondToNcCalcSize(0, &natural_dimensions));
EXPECT_CALL(*content, InstallInFrame(FrameHwndIs(parent_hwnd)))
.WillOnce(testing::DoAll(testing::SaveArg<0>(&frame),
testing::Return(true)));
EXPECT_CALL(*content, SetDimensions(testing::Not(
RectIsTopXToYOfRectZ(infobar_height,
infobar_height,
&natural_dimensions)))).Times(testing::AnyNumber());
EXPECT_CALL(*content, SetDimensions(
RectIsTopXToYOfRectZ(infobar_height,
infobar_height,
&natural_dimensions)))
.Times(testing::AnyNumber())
.WillOnce(AsynchronousHideOnManager(&message_loop, manager))
.WillRepeatedly(testing::Return());
EXPECT_CALL(*content, Die()).WillOnce(QUIT_LOOP(message_loop));
ASSERT_TRUE(manager->Show(content, TOP_INFOBAR));
message_loop.RunFor(10); // seconds
window.DestroyWindow();
ASSERT_FALSE(message_loop.WasTimedOut());
}
// TODO(erikwright): Write test for variations on return from default
// OnNcCalcValidRects
|