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 "ui/app_list/views/apps_grid_view.h" | 5 #include "ui/app_list/views/apps_grid_view.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/strings/string_number_conversions.h" | |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "base/timer/timer.h" | |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "ui/app_list/app_list_constants.h" | 17 #include "ui/app_list/app_list_constants.h" |
18 #include "ui/app_list/app_list_folder_item.h" | 18 #include "ui/app_list/app_list_folder_item.h" |
19 #include "ui/app_list/app_list_item.h" | 19 #include "ui/app_list/app_list_item.h" |
20 #include "ui/app_list/app_list_model.h" | 20 #include "ui/app_list/app_list_model.h" |
21 #include "ui/app_list/app_list_switches.h" | 21 #include "ui/app_list/app_list_switches.h" |
22 #include "ui/app_list/pagination_model.h" | 22 #include "ui/app_list/pagination_model.h" |
23 #include "ui/app_list/test/app_list_test_model.h" | 23 #include "ui/app_list/test/app_list_test_model.h" |
24 #include "ui/app_list/views/app_list_item_view.h" | 24 #include "ui/app_list/views/app_list_item_view.h" |
25 #include "ui/app_list/views/apps_grid_view_folder_delegate.h" | 25 #include "ui/app_list/views/apps_grid_view_folder_delegate.h" |
26 #include "ui/app_list/views/test/apps_grid_view_test_api.h" | 26 #include "ui/app_list/views/test/apps_grid_view_test_api.h" |
27 #include "ui/views/test/views_test_base.h" | 27 #include "ui/views/test/views_test_base.h" |
28 | 28 |
29 namespace app_list { | 29 namespace app_list { |
30 namespace test { | 30 namespace test { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 const int kIconDimension = 48; | 34 const int kIconDimension = 48; |
35 const int kCols = 2; | 35 const int kCols = 2; |
36 const int kRows = 2; | 36 const int kRows = 2; |
37 const int kTilesPerPage = kCols * kRows; | 37 const int kTilesPerPage = kCols * kRows; |
38 | 38 |
39 const int kWidth = 320; | 39 const int kWidth = 320; |
40 const int kHeight = 240; | 40 const int kHeight = 240; |
41 | 41 |
42 class PageFlipWaiter : public PaginationModelObserver { | 42 class PageFlipWaiter : public PaginationModelObserver { |
43 public: | 43 public: |
44 PageFlipWaiter(base::MessageLoopForUI* ui_loop, PaginationModel* model) | 44 PageFlipWaiter(base::MessageLoopForUI* ui_loop, PaginationModel* model) |
45 : ui_loop_(ui_loop), model_(model), wait_(false), page_changed_(false) { | 45 : ui_loop_(ui_loop), model_(model), wait_(false) { |
46 model_->AddObserver(this); | 46 model_->AddObserver(this); |
47 } | 47 } |
48 | 48 |
49 virtual ~PageFlipWaiter() { | 49 virtual ~PageFlipWaiter() { |
50 model_->RemoveObserver(this); | 50 model_->RemoveObserver(this); |
51 } | 51 } |
52 | 52 |
53 bool Wait(int time_out_ms) { | 53 void Wait() { |
54 DCHECK(!wait_); | 54 DCHECK(!wait_); |
55 wait_ = true; | 55 wait_ = true; |
56 page_changed_ = false; | |
57 | |
58 if (time_out_ms) { | |
59 wait_timer_.Stop(); | |
60 wait_timer_.Start(FROM_HERE, | |
61 base::TimeDelta::FromMilliseconds(time_out_ms), | |
62 this, &PageFlipWaiter::OnWaitTimeOut); | |
63 } | |
64 | 56 |
65 ui_loop_->Run(); | 57 ui_loop_->Run(); |
66 wait_ = false; | 58 wait_ = false; |
67 return page_changed_; | |
68 } | 59 } |
69 | 60 |
61 void Reset() { selected_pages_.clear(); } | |
62 | |
63 const std::string& selected_pages() const { return selected_pages_; } | |
64 | |
70 private: | 65 private: |
71 void OnWaitTimeOut() { | |
72 ui_loop_->Quit(); | |
73 } | |
74 | |
75 // PaginationModelObserver overrides: | 66 // PaginationModelObserver overrides: |
76 virtual void TotalPagesChanged() OVERRIDE { | 67 virtual void TotalPagesChanged() OVERRIDE { |
77 } | 68 } |
78 virtual void SelectedPageChanged(int old_selected, | 69 virtual void SelectedPageChanged(int old_selected, |
79 int new_selected) OVERRIDE { | 70 int new_selected) OVERRIDE { |
80 page_changed_ = true; | 71 if (!selected_pages_.empty()) |
72 selected_pages_ += ','; | |
73 selected_pages_ += base::IntToString(new_selected); | |
74 | |
81 if (wait_) | 75 if (wait_) |
82 ui_loop_->Quit(); | 76 ui_loop_->Quit(); |
83 } | 77 } |
84 virtual void TransitionStarted() OVERRIDE { | 78 virtual void TransitionStarted() OVERRIDE { |
85 } | 79 } |
86 virtual void TransitionChanged() OVERRIDE { | 80 virtual void TransitionChanged() OVERRIDE { |
87 } | 81 } |
88 | 82 |
89 base::MessageLoopForUI* ui_loop_; | 83 base::MessageLoopForUI* ui_loop_; |
90 PaginationModel* model_; | 84 PaginationModel* model_; |
91 bool wait_; | 85 bool wait_; |
92 bool page_changed_; | 86 std::string selected_pages_; |
93 base::OneShotTimer<PageFlipWaiter> wait_timer_; | |
94 | 87 |
95 DISALLOW_COPY_AND_ASSIGN(PageFlipWaiter); | 88 DISALLOW_COPY_AND_ASSIGN(PageFlipWaiter); |
96 }; | 89 }; |
97 | 90 |
98 } // namespace | 91 } // namespace |
99 | 92 |
100 class AppsGridViewTest : public views::ViewsTestBase { | 93 class AppsGridViewTest : public views::ViewsTestBase { |
101 public: | 94 public: |
102 AppsGridViewTest() {} | 95 AppsGridViewTest() {} |
103 virtual ~AppsGridViewTest() {} | 96 virtual ~AppsGridViewTest() {} |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
511 const int kPages = 3; | 504 const int kPages = 3; |
512 model_->PopulateApps(kPages * kTilesPerPage); | 505 model_->PopulateApps(kPages * kTilesPerPage); |
513 EXPECT_EQ(kPages, GetPaginationModel()->total_pages()); | 506 EXPECT_EQ(kPages, GetPaginationModel()->total_pages()); |
514 EXPECT_EQ(0, GetPaginationModel()->selected_page()); | 507 EXPECT_EQ(0, GetPaginationModel()->selected_page()); |
515 | 508 |
516 gfx::Point from = GetItemTileRectAt(0, 0).CenterPoint(); | 509 gfx::Point from = GetItemTileRectAt(0, 0).CenterPoint(); |
517 gfx::Point to = gfx::Point(apps_grid_view_->width(), | 510 gfx::Point to = gfx::Point(apps_grid_view_->width(), |
518 apps_grid_view_->height() / 2); | 511 apps_grid_view_->height() / 2); |
519 | 512 |
520 // Drag to right edge. | 513 // Drag to right edge. |
514 page_flip_waiter.Reset(); | |
521 SimulateDrag(AppsGridView::MOUSE, from, to); | 515 SimulateDrag(AppsGridView::MOUSE, from, to); |
522 | 516 |
523 // Page should be flipped after sometime. | 517 // Page should be flipped after sometime to hit page 1 and 2. |
524 EXPECT_TRUE(page_flip_waiter.Wait(0)); | 518 EXPECT_TRUE(test_api_->HasPendingPageFlip()); |
525 EXPECT_EQ(1, GetPaginationModel()->selected_page()); | 519 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.
| |
526 | 520 page_flip_waiter.Wait(); |
527 // Stay there and page should be flipped again. | 521 } |
528 EXPECT_TRUE(page_flip_waiter.Wait(0)); | |
529 EXPECT_EQ(2, GetPaginationModel()->selected_page()); | |
530 | 522 |
531 // Stay there longer and no page flip happen since we are at the last page. | 523 // 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
| |
532 EXPECT_FALSE(page_flip_waiter.Wait(100)); | 524 EXPECT_FALSE(test_api_->HasPendingPageFlip()); |
533 EXPECT_EQ(2, GetPaginationModel()->selected_page()); | 525 EXPECT_EQ(2, GetPaginationModel()->selected_page()); |
534 | 526 |
535 apps_grid_view_->EndDrag(true); | 527 apps_grid_view_->EndDrag(true); |
536 | 528 |
537 // Now drag to the left edge and test the other direction. | 529 // Now drag to the left edge and test the other direction. |
538 to.set_x(0); | 530 to.set_x(0); |
539 | 531 |
532 page_flip_waiter.Reset(); | |
540 SimulateDrag(AppsGridView::MOUSE, from, to); | 533 SimulateDrag(AppsGridView::MOUSE, from, to); |
541 | 534 |
542 EXPECT_TRUE(page_flip_waiter.Wait(0)); | 535 EXPECT_TRUE(test_api_->HasPendingPageFlip()); |
543 EXPECT_EQ(1, GetPaginationModel()->selected_page()); | 536 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.
| |
537 page_flip_waiter.Wait(); | |
538 } | |
544 | 539 |
545 EXPECT_TRUE(page_flip_waiter.Wait(0)); | 540 EXPECT_FALSE(test_api_->HasPendingPageFlip()); |
546 EXPECT_EQ(0, GetPaginationModel()->selected_page()); | |
547 | |
548 EXPECT_FALSE(page_flip_waiter.Wait(100)); | |
549 EXPECT_EQ(0, GetPaginationModel()->selected_page()); | 541 EXPECT_EQ(0, GetPaginationModel()->selected_page()); |
550 apps_grid_view_->EndDrag(true); | 542 apps_grid_view_->EndDrag(true); |
551 } | 543 } |
552 | 544 |
553 TEST_F(AppsGridViewTest, SimultaneousDragWithFolderDisabled) { | 545 TEST_F(AppsGridViewTest, SimultaneousDragWithFolderDisabled) { |
554 model_->SetFoldersEnabled(false); | 546 model_->SetFoldersEnabled(false); |
555 const int kTotalItems = 4; | 547 const int kTotalItems = 4; |
556 model_->PopulateApps(kTotalItems); | 548 model_->PopulateApps(kTotalItems); |
557 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), | 549 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), |
558 model_->GetModelContent()); | 550 model_->GetModelContent()); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 AppListItemView* item_view = GetItemViewAt(0); | 705 AppListItemView* item_view = GetItemViewAt(0); |
714 ASSERT_TRUE(item_view); | 706 ASSERT_TRUE(item_view); |
715 const views::Label* title_label = item_view->title(); | 707 const views::Label* title_label = item_view->title(); |
716 EXPECT_FALSE(title_label->GetTooltipText( | 708 EXPECT_FALSE(title_label->GetTooltipText( |
717 title_label->bounds().CenterPoint(), &actual_tooltip)); | 709 title_label->bounds().CenterPoint(), &actual_tooltip)); |
718 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); | 710 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); |
719 } | 711 } |
720 | 712 |
721 } // namespace test | 713 } // namespace test |
722 } // namespace app_list | 714 } // namespace app_list |
OLD | NEW |