Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
|
tommi (sloooow) - chröme
2010/12/01 21:51:28
Excellent tests!
| |
| 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> >(); | |
|
tommi (sloooow) - chröme
2010/12/01 21:51:28
indent
| |
| 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> >(); | |
|
grt (UTC plus 2)
2010/12/02 16:27:52
indent
| |
| 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> >(); | |
|
grt (UTC plus 2)
2010/12/02 16:27:52
indent
| |
| 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> >(); | |
|
grt (UTC plus 2)
2010/12/02 16:27:52
indent
| |
| 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 | |
|
tommi (sloooow) - chröme
2010/12/01 21:51:28
remove extra empty line
| |
| 443 | |
| 444 infobar_window.SetHost(host.get()); | |
| 445 | |
| 446 // Used to ensure that GetDesiredSize is only called on an installed | |
| 447 // InfobarContent. | |
| 448 testing::Expectation installed; | |
| 449 | |
| 450 // Will hold the frame given to us in InfobarContent::InstallInFrame. | |
| 451 InfobarContent::Frame* frame = NULL; | |
| 452 | |
| 453 // We could get any number of calls to UpdateLayout. Make sure that, each | |
| 454 // time, the space reserved by the InfobarWindow equals the space offered to | |
| 455 // the InfobarContent. | |
| 456 EXPECT_CALL(*host, CheckReservedSpace(RectAddedToRectXMakesRectY( | |
| 457 ¤t_infobar_dimensions, &natural_dimensions))) | |
| 458 .Times(testing::AnyNumber()) | |
| 459 .WillRepeatedly(ResetFlag(&pending_reserve_space)); | |
| 460 | |
| 461 testing::MockFunction<void(std::string check_point_name)> check; | |
| 462 | |
| 463 { | |
| 464 testing::InSequence s; | |
| 465 // During Show(), we get an InstallInFrame | |
| 466 installed = EXPECT_CALL(*content, InstallInFrame(FrameHwndIs(hwnd))) | |
| 467 .WillOnce(testing::DoAll(testing::SaveArg<0>(&frame), | |
| 468 testing::Return(true))); | |
| 469 | |
| 470 // Allow a call to SetDimensions before InstallInFrame returns. | |
| 471 EXPECT_CALL(*content, SetDimensions(testing::AllOf( | |
| 472 RectIsTopXToYOfRectZ(0, infobar_height / 2 - 1, &natural_dimensions), | |
| 473 RectHeightIsGTEToRectXHeight(¤t_infobar_dimensions)))) | |
| 474 .Times(testing::AnyNumber()).WillRepeatedly(testing::DoAll( | |
| 475 testing::SaveArg<0>(¤t_infobar_dimensions), | |
| 476 CheckSetFlag(&pending_reserve_space))); | |
| 477 | |
| 478 EXPECT_CALL(check, Call("returned from Show")); | |
| 479 | |
| 480 EXPECT_CALL(*content, SetDimensions(testing::AllOf( | |
| 481 RectIsTopXToYOfRectZ(0, infobar_height / 2 - 1, &natural_dimensions), | |
| 482 RectHeightIsGTEToRectXHeight(¤t_infobar_dimensions)))) | |
| 483 .Times(testing::AtLeast(1)).WillRepeatedly(testing::DoAll( | |
| 484 testing::SaveArg<0>(¤t_infobar_dimensions), | |
| 485 CheckSetFlag(&pending_reserve_space))); | |
| 486 EXPECT_CALL(*content, SetDimensions(testing::AllOf( | |
| 487 RectIsTopXToYOfRectZ(infobar_height / 2, | |
| 488 infobar_height - 1, | |
| 489 &natural_dimensions), | |
| 490 RectHeightIsGTEToRectXHeight(¤t_infobar_dimensions)))) | |
| 491 .Times(testing::AtLeast(1)).WillRepeatedly(testing::DoAll( | |
| 492 testing::SaveArg<0>(¤t_infobar_dimensions), | |
| 493 CheckSetFlag(&pending_reserve_space))); | |
| 494 EXPECT_CALL(*content, SetDimensions( | |
| 495 RectIsTopXToYOfRectZ(infobar_height, | |
| 496 infobar_height, | |
| 497 &natural_dimensions))) | |
| 498 .WillOnce(testing::DoAll( | |
| 499 testing::SaveArg<0>(¤t_infobar_dimensions), | |
| 500 CheckSetFlag(&pending_reserve_space), | |
| 501 AsynchronousCloseOnFrame(&message_loop, &frame))); | |
| 502 | |
| 503 EXPECT_CALL(*content, SetDimensions(testing::AllOf( | |
| 504 RectIsTopXToYOfRectZ(infobar_height / 2 + 1, | |
| 505 infobar_height, | |
| 506 &natural_dimensions), | |
| 507 RectHeightIsLTEToRectXHeight(¤t_infobar_dimensions)))) | |
| 508 .Times(testing::AtLeast(1)).WillRepeatedly(testing::DoAll( | |
| 509 testing::SaveArg<0>(¤t_infobar_dimensions), | |
| 510 CheckSetFlag(&pending_reserve_space))); | |
| 511 EXPECT_CALL(*content, SetDimensions(testing::AllOf( | |
| 512 RectIsTopXToYOfRectZ(0, infobar_height / 2, &natural_dimensions), | |
| 513 RectHeightIsLTEToRectXHeight(¤t_infobar_dimensions)))) | |
| 514 .Times(testing::AtLeast(1)).WillRepeatedly(testing::DoAll( | |
| 515 testing::SaveArg<0>(¤t_infobar_dimensions), | |
| 516 CheckSetFlag(&pending_reserve_space))); | |
| 517 | |
| 518 EXPECT_CALL(*content, Die()).WillOnce(QUIT_LOOP(message_loop)); | |
| 519 } | |
| 520 | |
| 521 EXPECT_CALL(*content, GetDesiredSize(80, 0)) | |
| 522 .Times(testing::AnyNumber()).After(installed) | |
| 523 .WillRepeatedly(testing::Return(infobar_height)); | |
| 524 | |
| 525 ASSERT_NO_FATAL_FAILURE(infobar_window.Show(content)); | |
| 526 | |
| 527 ASSERT_NO_FATAL_FAILURE(check.Call("returned from Show")); | |
| 528 | |
| 529 ASSERT_NO_FATAL_FAILURE(message_loop.RunFor(10)); // seconds | |
| 530 | |
| 531 window.DestroyWindow(); | |
| 532 | |
| 533 ASSERT_FALSE(message_loop.WasTimedOut()); | |
| 534 } | |
| 535 | |
| 536 TEST(InfobarsInfobarManagerTest, BasicTest) { | |
| 537 chrome_frame_test::TimedMsgLoop message_loop; | |
| 538 | |
| 539 int infobar_height = 40; | |
| 540 RECT natural_dimensions = {10, 20, 90, 100 + infobar_height}; | |
| 541 | |
| 542 testing::NiceMock<MockTopLevelWindow> window; | |
| 543 ASSERT_TRUE(window.Create(NULL, kInitialParentWindowRect) != NULL); | |
| 544 testing::NiceMock<MockChildWindow> child_window; | |
| 545 ASSERT_TRUE(child_window.Create(window, kInitialChildWindowRect) != NULL); | |
| 546 | |
| 547 HWND parent_hwnd = static_cast<HWND>(window); | |
| 548 HWND child_hwnd = static_cast<HWND>(child_window); | |
| 549 | |
| 550 MockInfobarContent* content = new MockInfobarContent(); | |
| 551 InfobarContent::Frame* frame = NULL; | |
| 552 | |
| 553 InfobarManager *manager = InfobarManager::Get(parent_hwnd); | |
|
grt (UTC plus 2)
2010/12/02 16:27:52
InfobarManager* manager
| |
| 554 ASSERT_FALSE(manager == NULL); | |
| 555 | |
| 556 EXPECT_CALL(*content, GetDesiredSize(80, 0)) | |
| 557 .Times(testing::AnyNumber()) | |
| 558 .WillRepeatedly(testing::Return(infobar_height)); | |
| 559 | |
| 560 EXPECT_CALL(child_window, OnNcCalcSize(true, testing::_)) | |
| 561 .Times(testing::AnyNumber()).WillRepeatedly( | |
| 562 RespondToNcCalcSize(0, &natural_dimensions)); | |
| 563 | |
| 564 EXPECT_CALL(*content, InstallInFrame(FrameHwndIs(parent_hwnd))) | |
| 565 .WillOnce(testing::DoAll(testing::SaveArg<0>(&frame), | |
| 566 testing::Return(true))); | |
| 567 | |
| 568 EXPECT_CALL(*content, SetDimensions(testing::Not( | |
| 569 RectIsTopXToYOfRectZ(infobar_height, | |
| 570 infobar_height, | |
| 571 &natural_dimensions)))).Times(testing::AnyNumber()); | |
| 572 | |
| 573 EXPECT_CALL(*content, SetDimensions( | |
| 574 RectIsTopXToYOfRectZ(infobar_height, | |
| 575 infobar_height, | |
| 576 &natural_dimensions))) | |
| 577 .Times(testing::AnyNumber()) | |
| 578 .WillOnce(AsynchronousHideOnManager(&message_loop, manager)) | |
| 579 .WillRepeatedly(testing::Return()); | |
| 580 | |
| 581 EXPECT_CALL(*content, Die()).WillOnce(QUIT_LOOP(message_loop)); | |
| 582 | |
| 583 ASSERT_TRUE(manager->Show(content, TOP_INFOBAR)); | |
| 584 | |
| 585 message_loop.RunFor(10); // seconds | |
| 586 | |
| 587 window.DestroyWindow(); | |
| 588 | |
| 589 ASSERT_FALSE(message_loop.WasTimedOut()); | |
| 590 } | |
| 591 | |
| 592 // TODO(erikwright): Write test for variations on return from default | |
| 593 // OnNcCalcValidRects | |
| OLD | NEW |