Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 local_state_.reset(new ScopedTestingLocalState( | 280 local_state_.reset(new ScopedTestingLocalState( |
| 281 TestingBrowserProcess::GetGlobal())); | 281 TestingBrowserProcess::GetGlobal())); |
| 282 model_->ClearStore(); | 282 model_->ClearStore(); |
| 283 | 283 |
| 284 bb_view_.reset(new BookmarkBarView(browser_.get(), NULL)); | 284 bb_view_.reset(new BookmarkBarView(browser_.get(), NULL)); |
| 285 bb_view_->set_owned_by_client(); | 285 bb_view_->set_owned_by_client(); |
| 286 bb_view_->SetPageNavigator(&navigator_); | 286 bb_view_->SetPageNavigator(&navigator_); |
| 287 | 287 |
| 288 AddTestData(CreateBigMenu()); | 288 AddTestData(CreateBigMenu()); |
| 289 | 289 |
| 290 // Calculate the preferred size so that one button doesn't fit, which | 290 // Create the Widget. Note the initial size is given by GetPreferredSize() |
| 291 // triggers the overflow button to appear. We have to do this incrementally | 291 // during initialization. This occurs after the WidgetDelegate provides |
| 292 // as there isn't a good way to determine the point at which the overflow | 292 // |bb_view_| as the contents view and adds it to the hierarchy. |
| 293 // button is shown. | 293 ViewEventTestBase::SetUp(); |
| 294 // | |
| 295 // This code looks a bit hacky, but I've written it so that it shouldn't | |
| 296 // be dependant upon any of the layout code in BookmarkBarView. Instead | |
| 297 // we brute force search for a size that triggers the overflow button. | |
| 298 bb_view_pref_ = bb_view_->GetPreferredSize(); | |
| 299 bb_view_pref_.set_width(1000); | |
| 300 do { | |
| 301 bb_view_pref_.set_width(bb_view_pref_.width() - 25); | |
| 302 bb_view_->SetBounds(0, 0, bb_view_pref_.width(), bb_view_pref_.height()); | |
| 303 bb_view_->Layout(); | |
| 304 } while (GetBookmarkButton(6)->visible()); | |
| 305 | 294 |
| 306 ViewEventTestBase::SetUp(); | 295 // Verify the layout triggered by the initial size preserves the overflow |
| 296 // state calculated in GetPreferredSize(). | |
| 297 EXPECT_TRUE(GetBookmarkButton(5)->visible()); | |
| 298 EXPECT_FALSE(GetBookmarkButton(6)->visible()); | |
| 307 } | 299 } |
| 308 | 300 |
| 309 void TearDown() override { | 301 void TearDown() override { |
| 310 // Destroy everything, then run the message loop to ensure we delete all | 302 // Destroy everything, then run the message loop to ensure we delete all |
| 311 // Tasks and fully shut down. | 303 // Tasks and fully shut down. |
| 312 browser_->tab_strip_model()->CloseAllTabs(); | 304 browser_->tab_strip_model()->CloseAllTabs(); |
| 313 bb_view_.reset(); | 305 bb_view_.reset(); |
| 314 browser_.reset(); | 306 browser_.reset(); |
| 315 profile_.reset(); | 307 profile_.reset(); |
| 316 | 308 |
| 317 // Run the message loop to ensure we delete allTasks and fully shut down. | 309 // Run the message loop to ensure we delete allTasks and fully shut down. |
| 318 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); | 310 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
| 319 base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop); | 311 base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop); |
| 320 base::RunLoop run_loop; | 312 base::RunLoop run_loop; |
| 321 loop->task_runner()->PostTask(FROM_HERE, run_loop.QuitClosure()); | 313 loop->task_runner()->PostTask(FROM_HERE, run_loop.QuitClosure()); |
| 322 run_loop.Run(); | 314 run_loop.Run(); |
| 323 | 315 |
| 324 ViewEventTestBase::TearDown(); | 316 ViewEventTestBase::TearDown(); |
| 325 BookmarkBarView::DisableAnimationsForTesting(false); | 317 BookmarkBarView::DisableAnimationsForTesting(false); |
| 326 constrained_window::SetConstrainedWindowViewsClient(nullptr); | 318 constrained_window::SetConstrainedWindowViewsClient(nullptr); |
| 327 | 319 |
| 328 browser_content_client_.reset(); | 320 browser_content_client_.reset(); |
| 329 content_client_.reset(); | 321 content_client_.reset(); |
| 330 content::SetContentClient(NULL); | 322 content::SetContentClient(NULL); |
| 331 } | 323 } |
| 332 | 324 |
| 333 protected: | 325 protected: |
| 334 views::View* CreateContentsView() override { return bb_view_.get(); } | 326 views::View* CreateContentsView() override { return bb_view_.get(); } |
| 335 | 327 |
| 336 gfx::Size GetPreferredSize() const override { return bb_view_pref_; } | 328 gfx::Size GetPreferredSize() const override { |
| 329 // Calculate the preferred size so that one button doesn't fit, which | |
| 330 // triggers the overflow button to appear. We have to do this incrementally | |
| 331 // as there isn't a good way to determine the point at which the overflow | |
| 332 // button is shown. | |
| 333 // | |
| 334 // This code looks a bit hacky, but it is written so that it shouldn't | |
|
msw
2015/07/13 17:54:03
nit: This code *does* look hacky; it's fine to lea
tapted
2015/07/14 05:36:12
I actually tried this while investigating one of t
| |
| 335 // depend on any of the layout code in BookmarkBarView, or extra buttons | |
| 336 // added to the right of the bookmarks. Instead, brute force search for a | |
| 337 // size that triggers the overflow button. | |
| 338 gfx::Size size = bb_view_->GetPreferredSize(); | |
| 339 size.set_width(1000); | |
| 340 do { | |
| 341 size.set_width(size.width() - 25); | |
| 342 bb_view_->SetBounds(0, 0, size.width(), size.height()); | |
| 343 bb_view_->Layout(); | |
| 344 } while (bb_view_->GetBookmarkButton(6)->visible()); | |
| 345 return size; | |
| 346 } | |
| 337 | 347 |
| 338 views::LabelButton* GetBookmarkButton(int view_index) { | 348 views::LabelButton* GetBookmarkButton(int view_index) { |
| 339 return bb_view_->GetBookmarkButton(view_index); | 349 return bb_view_->GetBookmarkButton(view_index); |
| 340 } | 350 } |
| 341 | 351 |
| 342 // See comment above class description for what this does. | 352 // See comment above class description for what this does. |
| 343 virtual bool CreateBigMenu() { return false; } | 353 virtual bool CreateBigMenu() { return false; } |
| 344 | 354 |
| 345 BookmarkModel* model_; | 355 BookmarkModel* model_; |
| 346 scoped_ptr<BookmarkBarView> bb_view_; | 356 scoped_ptr<BookmarkBarView> bb_view_; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 372 const BookmarkNode* of = model_->AddFolder(model_->other_node(), 1, | 382 const BookmarkNode* of = model_->AddFolder(model_->other_node(), 1, |
| 373 ASCIIToUTF16("OF")); | 383 ASCIIToUTF16("OF")); |
| 374 model_->AddURL(of, 0, ASCIIToUTF16("ofa"), GURL(test_base + "ofa")); | 384 model_->AddURL(of, 0, ASCIIToUTF16("ofa"), GURL(test_base + "ofa")); |
| 375 model_->AddURL(of, 1, ASCIIToUTF16("ofb"), GURL(test_base + "ofb")); | 385 model_->AddURL(of, 1, ASCIIToUTF16("ofb"), GURL(test_base + "ofb")); |
| 376 const BookmarkNode* of2 = model_->AddFolder(model_->other_node(), 2, | 386 const BookmarkNode* of2 = model_->AddFolder(model_->other_node(), 2, |
| 377 ASCIIToUTF16("OF2")); | 387 ASCIIToUTF16("OF2")); |
| 378 model_->AddURL(of2, 0, ASCIIToUTF16("of2a"), GURL(test_base + "of2a")); | 388 model_->AddURL(of2, 0, ASCIIToUTF16("of2a"), GURL(test_base + "of2a")); |
| 379 model_->AddURL(of2, 1, ASCIIToUTF16("of2b"), GURL(test_base + "of2b")); | 389 model_->AddURL(of2, 1, ASCIIToUTF16("of2b"), GURL(test_base + "of2b")); |
| 380 } | 390 } |
| 381 | 391 |
| 382 gfx::Size bb_view_pref_; | |
| 383 scoped_ptr<ChromeContentClient> content_client_; | 392 scoped_ptr<ChromeContentClient> content_client_; |
| 384 scoped_ptr<chrome::ChromeContentBrowserClient> browser_content_client_; | 393 scoped_ptr<chrome::ChromeContentBrowserClient> browser_content_client_; |
| 385 scoped_ptr<TestingProfile> profile_; | 394 scoped_ptr<TestingProfile> profile_; |
| 386 scoped_ptr<Browser> browser_; | 395 scoped_ptr<Browser> browser_; |
| 387 scoped_ptr<ScopedTestingLocalState> local_state_; | 396 scoped_ptr<ScopedTestingLocalState> local_state_; |
| 388 }; | 397 }; |
| 389 | 398 |
| 390 // Clicks on first menu, makes sure button is depressed. Moves mouse to first | 399 // Clicks on first menu, makes sure button is depressed. Moves mouse to first |
| 391 // child, clicks it and makes sure a navigation occurs. | 400 // child, clicks it and makes sure a navigation occurs. |
| 392 class BookmarkBarViewTest1 : public BookmarkBarViewEventTestBase { | 401 class BookmarkBarViewTest1 : public BookmarkBarViewEventTestBase { |
| (...skipping 1662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2055 }; | 2064 }; |
| 2056 | 2065 |
| 2057 #if defined(OS_WIN) | 2066 #if defined(OS_WIN) |
| 2058 // This test times out on Windows. TODO(pkotwicz): Find out why. | 2067 // This test times out on Windows. TODO(pkotwicz): Find out why. |
| 2059 #define MAYBE_CloseSourceBrowserDuringDrag DISABLED_CloseSourceBrowserDuringDrag | 2068 #define MAYBE_CloseSourceBrowserDuringDrag DISABLED_CloseSourceBrowserDuringDrag |
| 2060 #else | 2069 #else |
| 2061 #define MAYBE_CloseSourceBrowserDuringDrag CloseSourceBrowserDuringDrag | 2070 #define MAYBE_CloseSourceBrowserDuringDrag CloseSourceBrowserDuringDrag |
| 2062 #endif | 2071 #endif |
| 2063 | 2072 |
| 2064 VIEW_TEST(BookmarkBarViewTest22, MAYBE_CloseSourceBrowserDuringDrag) | 2073 VIEW_TEST(BookmarkBarViewTest22, MAYBE_CloseSourceBrowserDuringDrag) |
| OLD | NEW |