diff options
author | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-18 13:07:39 +0000 |
---|---|---|
committer | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-18 13:07:39 +0000 |
commit | ef827520780f4ae561834a46e454103c7ffd9d16 (patch) | |
tree | a1f6a7860239b9d392e2b34c6c6b424311bf6a8e /ui | |
parent | 1f355b54ab218870800e3a59636fffbfb41e2057 (diff) | |
download | chromium_src-ef827520780f4ae561834a46e454103c7ffd9d16.zip chromium_src-ef827520780f4ae561834a46e454103c7ffd9d16.tar.gz chromium_src-ef827520780f4ae561834a46e454103c7ffd9d16.tar.bz2 |
Fix flaky AppsGridViewTest on valgrind bot.
- Remove local test timeouts;
- Add page flip history to PageFlipWaiter and use that for test expectations
to solve the problem that a single Wait returns with multiple page flipping
happened on valgrind;
BUG=385167
Review URL: https://codereview.chromium.org/339933005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278049 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/app_list/views/apps_grid_view_unittest.cc | 58 | ||||
-rw-r--r-- | ui/app_list/views/test/apps_grid_view_test_api.cc | 4 | ||||
-rw-r--r-- | ui/app_list/views/test/apps_grid_view_test_api.h | 2 |
3 files changed, 29 insertions, 35 deletions
diff --git a/ui/app_list/views/apps_grid_view_unittest.cc b/ui/app_list/views/apps_grid_view_unittest.cc index 95e4f85..643621d 100644 --- a/ui/app_list/views/apps_grid_view_unittest.cc +++ b/ui/app_list/views/apps_grid_view_unittest.cc @@ -11,8 +11,8 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" +#include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" -#include "base/timer/timer.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/app_list/app_list_constants.h" #include "ui/app_list/app_list_folder_item.h" @@ -42,7 +42,7 @@ const int kHeight = 240; class PageFlipWaiter : public PaginationModelObserver { public: PageFlipWaiter(base::MessageLoopForUI* ui_loop, PaginationModel* model) - : ui_loop_(ui_loop), model_(model), wait_(false), page_changed_(false) { + : ui_loop_(ui_loop), model_(model), wait_(false) { model_->AddObserver(this); } @@ -50,34 +50,28 @@ class PageFlipWaiter : public PaginationModelObserver { model_->RemoveObserver(this); } - bool Wait(int time_out_ms) { + void Wait() { DCHECK(!wait_); wait_ = true; - page_changed_ = false; - - if (time_out_ms) { - wait_timer_.Stop(); - wait_timer_.Start(FROM_HERE, - base::TimeDelta::FromMilliseconds(time_out_ms), - this, &PageFlipWaiter::OnWaitTimeOut); - } ui_loop_->Run(); wait_ = false; - return page_changed_; } - private: - void OnWaitTimeOut() { - ui_loop_->Quit(); - } + void Reset() { selected_pages_.clear(); } + const std::string& selected_pages() const { return selected_pages_; } + + private: // PaginationModelObserver overrides: virtual void TotalPagesChanged() OVERRIDE { } virtual void SelectedPageChanged(int old_selected, int new_selected) OVERRIDE { - page_changed_ = true; + if (!selected_pages_.empty()) + selected_pages_ += ','; + selected_pages_ += base::IntToString(new_selected); + if (wait_) ui_loop_->Quit(); } @@ -89,8 +83,7 @@ class PageFlipWaiter : public PaginationModelObserver { base::MessageLoopForUI* ui_loop_; PaginationModel* model_; bool wait_; - bool page_changed_; - base::OneShotTimer<PageFlipWaiter> wait_timer_; + std::string selected_pages_; DISALLOW_COPY_AND_ASSIGN(PageFlipWaiter); }; @@ -518,18 +511,14 @@ TEST_F(AppsGridViewTest, MouseDragFlipPage) { apps_grid_view_->height() / 2); // Drag to right edge. + page_flip_waiter.Reset(); SimulateDrag(AppsGridView::MOUSE, from, to); - // Page should be flipped after sometime. - EXPECT_TRUE(page_flip_waiter.Wait(0)); - EXPECT_EQ(1, GetPaginationModel()->selected_page()); - - // Stay there and page should be flipped again. - EXPECT_TRUE(page_flip_waiter.Wait(0)); - EXPECT_EQ(2, GetPaginationModel()->selected_page()); - - // Stay there longer and no page flip happen since we are at the last page. - EXPECT_FALSE(page_flip_waiter.Wait(100)); + // Page should be flipped after sometime to hit page 1 and 2 then stop. + while (test_api_->HasPendingPageFlip()) { + page_flip_waiter.Wait(); + } + EXPECT_EQ("1,2", page_flip_waiter.selected_pages()); EXPECT_EQ(2, GetPaginationModel()->selected_page()); apps_grid_view_->EndDrag(true); @@ -537,16 +526,15 @@ TEST_F(AppsGridViewTest, MouseDragFlipPage) { // Now drag to the left edge and test the other direction. to.set_x(0); + page_flip_waiter.Reset(); SimulateDrag(AppsGridView::MOUSE, from, to); - EXPECT_TRUE(page_flip_waiter.Wait(0)); - EXPECT_EQ(1, GetPaginationModel()->selected_page()); - - EXPECT_TRUE(page_flip_waiter.Wait(0)); + while (test_api_->HasPendingPageFlip()) { + page_flip_waiter.Wait(); + } + EXPECT_EQ("1,0", page_flip_waiter.selected_pages()); EXPECT_EQ(0, GetPaginationModel()->selected_page()); - EXPECT_FALSE(page_flip_waiter.Wait(100)); - EXPECT_EQ(0, GetPaginationModel()->selected_page()); apps_grid_view_->EndDrag(true); } diff --git a/ui/app_list/views/test/apps_grid_view_test_api.cc b/ui/app_list/views/test/apps_grid_view_test_api.cc index 6b95b17..b2a49be 100644 --- a/ui/app_list/views/test/apps_grid_view_test_api.cc +++ b/ui/app_list/views/test/apps_grid_view_test_api.cc @@ -45,5 +45,9 @@ void AppsGridViewTestApi::DisableSynchronousDrag() { #endif } +bool AppsGridViewTestApi::HasPendingPageFlip() const { + return view_->page_flip_timer_.IsRunning(); +} + } // namespace test } // namespace app_list diff --git a/ui/app_list/views/test/apps_grid_view_test_api.h b/ui/app_list/views/test/apps_grid_view_test_api.h index 234fc9a..900fcff 100644 --- a/ui/app_list/views/test/apps_grid_view_test_api.h +++ b/ui/app_list/views/test/apps_grid_view_test_api.h @@ -32,6 +32,8 @@ class AppsGridViewTestApi { void DisableSynchronousDrag(); + bool HasPendingPageFlip() const; + private: AppsGridView* view_; |