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