Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Unified Diff: ui/app_list/views/apps_grid_view_unittest.cc

Issue 339933005: Fix flaky AppsGridViewTest on valgrind bot. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/app_list/views/apps_grid_view_unittest.cc
diff --git a/ui/app_list/views/apps_grid_view_unittest.cc b/ui/app_list/views/apps_grid_view_unittest.cc
index 95e4f855ced0d65a0fbe4e9abaf3f674bc3a0f9f..18347fe161a50b13569ba525b661005f83e1da6b 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,17 @@ 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());
+ // Page should be flipped after sometime to hit page 1 and 2.
+ EXPECT_TRUE(test_api_->HasPendingPageFlip());
+ while (page_flip_waiter.selected_pages() != "1,2") {
stevenjb 2014/06/17 21:20:44 nit: Could we wait on while(test_api_->HasPendingP
xiyuan 2014/06/17 21:32:44 Done.
+ page_flip_waiter.Wait();
+ }
// Stay there longer and no page flip happen since we are at the last page.
stevenjb 2014/06/17 21:20:44 Update comment
xiyuan 2014/06/17 21:32:44 Comment here is removed and added "then stop" to c
- EXPECT_FALSE(page_flip_waiter.Wait(100));
+ EXPECT_FALSE(test_api_->HasPendingPageFlip());
EXPECT_EQ(2, GetPaginationModel()->selected_page());
apps_grid_view_->EndDrag(true);
@@ -537,15 +529,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));
- EXPECT_EQ(0, GetPaginationModel()->selected_page());
+ EXPECT_TRUE(test_api_->HasPendingPageFlip());
+ while (page_flip_waiter.selected_pages() != "1,0") {
stevenjb 2014/06/17 21:20:44 Here too
xiyuan 2014/06/17 21:32:44 Done.
+ page_flip_waiter.Wait();
+ }
- EXPECT_FALSE(page_flip_waiter.Wait(100));
+ EXPECT_FALSE(test_api_->HasPendingPageFlip());
EXPECT_EQ(0, GetPaginationModel()->selected_page());
apps_grid_view_->EndDrag(true);
}
« no previous file with comments | « tools/valgrind/gtest_exclude/app_list_unittests.gtest-memcheck.txt ('k') | ui/app_list/views/test/apps_grid_view_test_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698