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

Unified Diff: ui/app_list/apps_grid_view_unittest.cc

Issue 10539038: Reland 140878 - cleanup: Remove applist v1 code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix borken AppInstallConfirmation* browser_tests Created 8 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
« no previous file with comments | « ui/app_list/apps_grid_view.cc ('k') | ui/app_list/test/app_list_test_suite.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/app_list/apps_grid_view_unittest.cc
diff --git a/ui/app_list/apps_grid_view_unittest.cc b/ui/app_list/apps_grid_view_unittest.cc
index 70a330adc79a7b26b028612591e7662bfc9a85e3..a1beb6120a15e77fbc36533529cf3e2ecbad4391 100644
--- a/ui/app_list/apps_grid_view_unittest.cc
+++ b/ui/app_list/apps_grid_view_unittest.cc
@@ -4,66 +4,108 @@
#include "ui/app_list/apps_grid_view.h"
+#include <string>
+
+#include "base/memory/scoped_ptr.h"
+#include "base/stringprintf.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/app_list/app_list_item_model.h"
+#include "ui/app_list/app_list_model.h"
#include "ui/app_list/app_list_item_view.h"
+#include "ui/app_list/pagination_model.h"
+
+namespace app_list {
+namespace test {
namespace {
-struct ModelViewCalculateLayoutCase {
- gfx::Size screen_size;
- int num_of_tiles;
- gfx::Size expected_icon_size;
- int expected_rows;
- int expected_cols;
-};
+const int kIconDimension = 48;
+const int kCols = 2;
+const int kRows = 2;
+
+const int kWidth = 320;
+const int kHeight = 240;
} // namespace
-namespace app_list {
+class AppsGridViewTest : public testing::Test {
+ public:
+ AppsGridViewTest() {}
+ virtual ~AppsGridViewTest() {}
+
+ // testing::Test overrides:
+ virtual void SetUp() OVERRIDE {
+ apps_model_.reset(new AppListModel::Apps);
+ pagination_model_.reset(new PaginationModel);
+
+ apps_grid_view_.reset(new AppsGridView(NULL, pagination_model_.get()));
+ apps_grid_view_->SetLayout(kIconDimension, kCols, kRows);
+ apps_grid_view_->SetBoundsRect(gfx::Rect(gfx::Size(kWidth, kHeight)));
+ apps_grid_view_->SetModel(apps_model_.get());
+ }
+ virtual void TearDown() OVERRIDE {
+ apps_grid_view_.reset(); // Release apps grid view before models.
+ }
+
+ protected:
+ void PopulateApps(int n) {
+ for (int i = 0; i < n; ++i) {
+ std::string title = base::StringPrintf("Item %d", i);
+ apps_model_->Add(CreateItem(title));
+ }
+ }
-TEST(AppsGridViewTest, ModelViewCalculateLayout) {
- // kMinTitleWidth is the average width of 15 chars of default size 12 font in
- // chromeos. Override here to avoid flakiness from different default font on
- // bots.
- const int kMinTitleWidth = 90;
- AppListItemView::SetMinTitleWidth(kMinTitleWidth);
-
- const int kLauncherHeight = 50;
- const ModelViewCalculateLayoutCase kCases[] = {
- { gfx::Size(1024, 768), 4, gfx::Size(128, 128), 2, 3 },
- { gfx::Size(1024, 768), 29, gfx::Size(64, 64), 5, 6 },
- { gfx::Size(1024, 768), 40, gfx::Size(48, 48), 5, 8 },
- { gfx::Size(1024, 768), 48, gfx::Size(48, 48), 6, 8 },
-
- { gfx::Size(1280, 1024), 4, gfx::Size(128, 128), 2, 3 },
- { gfx::Size(1280, 1024), 29, gfx::Size(64, 64), 5, 7 },
- { gfx::Size(1280, 1024), 50, gfx::Size(64, 64), 7, 8 },
- { gfx::Size(1280, 1024), 70, gfx::Size(48, 48), 7, 10 },
- { gfx::Size(1280, 1024), 99, gfx::Size(48, 48), 9, 11 },
-
- { gfx::Size(1600, 900), 4, gfx::Size(128, 128), 2, 3 },
- { gfx::Size(1600, 900), 29, gfx::Size(64, 64), 4, 8 },
-
- // Not able to fit into screen case.
- { gfx::Size(1024, 768), 50, gfx::Size(32, 32), 6, 9 },
- { gfx::Size(1280, 1024), 100, gfx::Size(32, 32), 10, 11 },
- };
-
- for (size_t i = 0; i < arraysize(kCases); ++i) {
- gfx::Size icon_size;
- int rows = 0;
- int cols = 0;
- gfx::Size content_size(kCases[i].screen_size.width(),
- kCases[i].screen_size.height() - kLauncherHeight);
- AppsGridView::CalculateLayout(content_size,
- kCases[i].num_of_tiles,
- &icon_size,
- &rows,
- &cols);
- EXPECT_EQ(kCases[i].expected_icon_size, icon_size) << "i=" << i;
- EXPECT_EQ(kCases[i].expected_rows, rows) << "i=" << i;
- EXPECT_EQ(kCases[i].expected_cols, cols) << "i=" << i;
+ AppListItemModel* CreateItem(const std::string& title) {
+ AppListItemModel* item = new AppListItemModel;
+ item->SetTitle(title);
+ return item;
}
+
+ void HighlightItemAt(int index) {
+ AppListItemModel* item = apps_model_->GetItemAt(index);
+ item->SetHighlighted(true);
+ }
+
+ scoped_ptr<AppListModel::Apps> apps_model_;
+ scoped_ptr<PaginationModel> pagination_model_;
+ scoped_ptr<AppsGridView> apps_grid_view_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AppsGridViewTest);
+};
+
+TEST_F(AppsGridViewTest, CreatePage) {
+ // Fully populates a page.
+ const int kPages = 1;
+ PopulateApps(kPages * apps_grid_view_->tiles_per_page());
+ EXPECT_EQ(kPages, pagination_model_->total_pages());
+
+ // Adds one more and gets a new page created.
+ apps_model_->Add(CreateItem(std::string("Extra")));
+ EXPECT_EQ(kPages + 1, pagination_model_->total_pages());
+}
+
+TEST_F(AppsGridViewTest, EnsureHighlightedVisible) {
+ const int kPages = 3;
+ PopulateApps(kPages * apps_grid_view_->tiles_per_page());
+ EXPECT_EQ(kPages, pagination_model_->total_pages());
+ EXPECT_EQ(0, pagination_model_->selected_page());
+
+ // Highlight first one and last one one first page and first page should be
+ // selected.
+ HighlightItemAt(0);
+ EXPECT_EQ(0, pagination_model_->selected_page());
+ HighlightItemAt(apps_grid_view_->tiles_per_page() - 1);
+ EXPECT_EQ(0, pagination_model_->selected_page());
+
+ // Highlight first one on 2nd page and 2nd page should be selected.
+ HighlightItemAt(apps_grid_view_->tiles_per_page() + 1);
+ EXPECT_EQ(1, pagination_model_->selected_page());
+
+ // Highlight last one in the model and last page should be selected.
+ HighlightItemAt(apps_model_->item_count() - 1);
+ EXPECT_EQ(kPages - 1, pagination_model_->selected_page());
}
+} // namespace test
} // namespace app_list
« no previous file with comments | « ui/app_list/apps_grid_view.cc ('k') | ui/app_list/test/app_list_test_suite.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698