| 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 "ash/app_list/app_list_item_view.h" | 5 #include "ui/app_list/app_list_model_view.h" |
| 6 #include "ash/app_list/app_list_model_view.h" | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/app_list/app_list_item_view.h" |
| 8 | 9 |
| 9 namespace { | 10 namespace { |
| 10 | 11 |
| 11 struct ModelViewCalculateLayoutCase { | 12 struct ModelViewCalculateLayoutCase { |
| 12 gfx::Size screen_size; | 13 gfx::Size screen_size; |
| 13 int num_of_tiles; | 14 int num_of_tiles; |
| 14 gfx::Size expected_icon_size; | 15 gfx::Size expected_icon_size; |
| 15 int expected_rows; | 16 int expected_rows; |
| 16 int expected_cols; | 17 int expected_cols; |
| 17 }; | 18 }; |
| 18 | 19 |
| 19 } // namespace | 20 } // namespace |
| 20 | 21 |
| 21 TEST(AppListTest, ModelViewCalculateLayout) { | 22 namespace app_list { |
| 23 |
| 24 TEST(AppListModelViewTest, ModelViewCalculateLayout) { |
| 22 // kMinTitleWidth is the average width of 15 chars of default size 12 font in | 25 // kMinTitleWidth is the average width of 15 chars of default size 12 font in |
| 23 // chromeos. Override here to avoid flakiness from different default font on | 26 // chromeos. Override here to avoid flakiness from different default font on |
| 24 // bots. | 27 // bots. |
| 25 const int kMinTitleWidth = 90; | 28 const int kMinTitleWidth = 90; |
| 26 ash::AppListItemView::SetMinTitleWidth(kMinTitleWidth); | 29 AppListItemView::SetMinTitleWidth(kMinTitleWidth); |
| 27 | 30 |
| 28 const int kLauncherHeight = 50; | 31 const int kLauncherHeight = 50; |
| 29 const ModelViewCalculateLayoutCase kCases[] = { | 32 const ModelViewCalculateLayoutCase kCases[] = { |
| 30 { gfx::Size(1024, 768), 4, gfx::Size(128, 128), 2, 3 }, | 33 { gfx::Size(1024, 768), 4, gfx::Size(128, 128), 2, 3 }, |
| 31 { gfx::Size(1024, 768), 29, gfx::Size(64, 64), 5, 6 }, | 34 { gfx::Size(1024, 768), 29, gfx::Size(64, 64), 5, 6 }, |
| 32 { gfx::Size(1024, 768), 40, gfx::Size(48, 48), 5, 8 }, | 35 { gfx::Size(1024, 768), 40, gfx::Size(48, 48), 5, 8 }, |
| 33 { gfx::Size(1024, 768), 48, gfx::Size(48, 48), 6, 8 }, | 36 { gfx::Size(1024, 768), 48, gfx::Size(48, 48), 6, 8 }, |
| 34 | 37 |
| 35 { gfx::Size(1280, 1024), 4, gfx::Size(128, 128), 2, 3 }, | 38 { gfx::Size(1280, 1024), 4, gfx::Size(128, 128), 2, 3 }, |
| 36 { gfx::Size(1280, 1024), 29, gfx::Size(64, 64), 5, 7 }, | 39 { gfx::Size(1280, 1024), 29, gfx::Size(64, 64), 5, 7 }, |
| 37 { gfx::Size(1280, 1024), 50, gfx::Size(64, 64), 7, 8 }, | 40 { gfx::Size(1280, 1024), 50, gfx::Size(64, 64), 7, 8 }, |
| 38 { gfx::Size(1280, 1024), 70, gfx::Size(48, 48), 7, 10 }, | 41 { gfx::Size(1280, 1024), 70, gfx::Size(48, 48), 7, 10 }, |
| 39 { gfx::Size(1280, 1024), 99, gfx::Size(48, 48), 9, 11 }, | 42 { gfx::Size(1280, 1024), 99, gfx::Size(48, 48), 9, 11 }, |
| 40 | 43 |
| 41 { gfx::Size(1600, 900), 4, gfx::Size(128, 128), 2, 3 }, | 44 { gfx::Size(1600, 900), 4, gfx::Size(128, 128), 2, 3 }, |
| 42 { gfx::Size(1600, 900), 29, gfx::Size(64, 64), 4, 8 }, | 45 { gfx::Size(1600, 900), 29, gfx::Size(64, 64), 4, 8 }, |
| 43 | 46 |
| 44 // Not able to fit into screen case. | 47 // Not able to fit into screen case. |
| 45 { gfx::Size(1024, 768), 50, gfx::Size(32, 32), 6, 9 }, | 48 { gfx::Size(1024, 768), 50, gfx::Size(32, 32), 6, 9 }, |
| 46 { gfx::Size(1280, 1024), 100, gfx::Size(32, 32), 10, 11 }, | 49 { gfx::Size(1280, 1024), 100, gfx::Size(32, 32), 10, 11 }, |
| 47 }; | 50 }; |
| 48 | 51 |
| 49 for (size_t i = 0; i < arraysize(kCases); ++i) { | 52 for (size_t i = 0; i < arraysize(kCases); ++i) { |
| 50 gfx::Size icon_size; | 53 gfx::Size icon_size; |
| 51 int rows = 0; | 54 int rows = 0; |
| 52 int cols = 0; | 55 int cols = 0; |
| 53 gfx::Size content_size(kCases[i].screen_size.width(), | 56 gfx::Size content_size(kCases[i].screen_size.width(), |
| 54 kCases[i].screen_size.height() - kLauncherHeight); | 57 kCases[i].screen_size.height() - kLauncherHeight); |
| 55 ash::AppListModelView::CalculateLayout(content_size, | 58 AppListModelView::CalculateLayout(content_size, |
| 56 kCases[i].num_of_tiles, | 59 kCases[i].num_of_tiles, |
| 57 &icon_size, | 60 &icon_size, |
| 58 &rows, | 61 &rows, |
| 59 &cols); | 62 &cols); |
| 60 EXPECT_EQ(kCases[i].expected_icon_size, icon_size) << "i=" << i; | 63 EXPECT_EQ(kCases[i].expected_icon_size, icon_size) << "i=" << i; |
| 61 EXPECT_EQ(kCases[i].expected_rows, rows) << "i=" << i; | 64 EXPECT_EQ(kCases[i].expected_rows, rows) << "i=" << i; |
| 62 EXPECT_EQ(kCases[i].expected_cols, cols) << "i=" << i; | 65 EXPECT_EQ(kCases[i].expected_cols, cols) << "i=" << i; |
| 63 } | 66 } |
| 64 } | 67 } |
| 68 |
| 69 } // namespace app_list |
| OLD | NEW |