Commit 49855258 authored by calamity@chromium.org's avatar calamity@chromium.org

Add a unit test for the experimental app list.

This CL adds a unit test for the experimental app list that instantiates
the app list in experimental mode and performs a series of very basic
checks.

BUG=349727

Review URL: https://codereview.chromium.org/291653003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272871 0039d316-1c4b-4281-b951-d872f2087c98
parent 1c85eb42
......@@ -18,6 +18,7 @@
#include "ui/app_list/views/apps_grid_view.h"
#include "ui/app_list/views/contents_view.h"
#include "ui/app_list/views/search_box_view.h"
#include "ui/app_list/views/start_page_view.h"
#include "ui/app_list/views/test/apps_grid_view_test_api.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/window.h"
......@@ -30,6 +31,18 @@ namespace test {
namespace {
enum TestType {
TEST_TYPE_START = 0,
NORMAL = TEST_TYPE_START,
LANDSCAPE,
EXPERIMENTAL,
TEST_TYPE_END,
};
bool IsViewAtOrigin(views::View* view) {
return view->bounds().origin().IsOrigin();
}
// Choose a set that is 3 regular app list pages and 2 landscape app list pages.
const int kInitialItems = 34;
......@@ -37,7 +50,7 @@ const int kInitialItems = 34;
// root window or a desktop window tree host.
class AppListViewTestContext {
public:
AppListViewTestContext(bool is_landscape, aura::Window* parent);
AppListViewTestContext(int test_type, aura::Window* parent);
~AppListViewTestContext();
// Test displaying the app list and performs a standard set of checks on its
......@@ -48,6 +61,9 @@ class AppListViewTestContext {
// view to be shown.
void RunReshowWithOpenFolderTest();
// Tests displaying of the experimental app list and shows the start page.
void RunStartPageTest();
// A standard set of checks on a view, e.g., ensuring it is drawn and visible.
static void CheckView(views::View* subview);
......@@ -60,7 +76,9 @@ class AppListViewTestContext {
}
// Whether the experimental "landscape" app launcher UI is being tested.
bool is_landscape() const { return is_landscape_; }
bool is_landscape() const {
return test_type_ == LANDSCAPE || test_type_ == EXPERIMENTAL;
}
private:
// Shows the app list and waits until a paint occurs.
......@@ -69,7 +87,7 @@ class AppListViewTestContext {
// Closes the app list. This sets |view_| to NULL.
void Close();
const bool is_landscape_;
const TestType test_type_;
scoped_ptr<base::RunLoop> run_loop_;
PaginationModel pagination_model_;
app_list::AppListView* view_; // Owned by native widget.
......@@ -99,12 +117,23 @@ class UnitTestViewDelegate : public app_list::test::AppListTestViewDelegate {
DISALLOW_COPY_AND_ASSIGN(UnitTestViewDelegate);
};
AppListViewTestContext::AppListViewTestContext(bool is_landscape,
AppListViewTestContext::AppListViewTestContext(int test_type,
aura::Window* parent)
: is_landscape_(is_landscape) {
if (is_landscape_) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableCenteredAppList);
: test_type_(static_cast<TestType>(test_type)) {
switch (test_type_) {
case NORMAL:
break;
case LANDSCAPE:
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableCenteredAppList);
break;
case EXPERIMENTAL:
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExperimentalAppList);
break;
default:
NOTREACHED();
break;
}
delegate_ = new UnitTestViewDelegate(this);
......@@ -157,7 +186,7 @@ void AppListViewTestContext::RunDisplayTest() {
delegate_->GetTestModel()->PopulateApps(kInitialItems);
Show();
if (is_landscape_)
if (is_landscape())
EXPECT_EQ(2, pagination_model_.total_pages());
else
EXPECT_EQ(3, pagination_model_.total_pages());
......@@ -216,8 +245,44 @@ void AppListViewTestContext::RunReshowWithOpenFolderTest() {
Close();
}
void AppListViewTestContext::RunStartPageTest() {
EXPECT_FALSE(view_->GetWidget()->IsVisible());
EXPECT_EQ(-1, pagination_model_.total_pages());
delegate_->GetTestModel()->PopulateApps(kInitialItems);
Show();
AppListMainView* main_view = view_->app_list_main_view();
StartPageView* start_page_view =
main_view->contents_view()->start_page_view();
// Checks on the main view.
EXPECT_NO_FATAL_FAILURE(CheckView(main_view));
EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view()));
if (test_type_ == EXPERIMENTAL) {
EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view));
main_view->contents_view()->SetShowState(ContentsView::SHOW_START_PAGE);
main_view->contents_view()->Layout();
EXPECT_FALSE(main_view->search_box_view()->visible());
EXPECT_TRUE(IsViewAtOrigin(start_page_view));
EXPECT_FALSE(
IsViewAtOrigin(main_view->contents_view()->apps_container_view()));
main_view->contents_view()->SetShowState(ContentsView::SHOW_APPS);
main_view->contents_view()->Layout();
EXPECT_TRUE(main_view->search_box_view()->visible());
EXPECT_FALSE(IsViewAtOrigin(start_page_view));
EXPECT_TRUE(
IsViewAtOrigin(main_view->contents_view()->apps_container_view()));
} else {
EXPECT_EQ(NULL, start_page_view);
}
Close();
}
class AppListViewTestAura : public views::ViewsTestBase,
public ::testing::WithParamInterface<bool> {
public ::testing::WithParamInterface<int> {
public:
AppListViewTestAura() {}
virtual ~AppListViewTestAura() {}
......@@ -241,7 +306,7 @@ class AppListViewTestAura : public views::ViewsTestBase,
};
class AppListViewTestDesktop : public views::ViewsTestBase,
public ::testing::WithParamInterface<bool> {
public ::testing::WithParamInterface<int> {
public:
AppListViewTestDesktop() {}
virtual ~AppListViewTestDesktop() {}
......@@ -320,13 +385,22 @@ TEST_P(AppListViewTestDesktop, ReshowWithOpenFolder) {
EXPECT_NO_FATAL_FAILURE(test_context_->RunReshowWithOpenFolderTest());
}
// Tests that the start page view operates correctly.
TEST_P(AppListViewTestAura, StartPageTest) {
EXPECT_NO_FATAL_FAILURE(test_context_->RunStartPageTest());
}
TEST_P(AppListViewTestDesktop, StartPageTest) {
EXPECT_NO_FATAL_FAILURE(test_context_->RunStartPageTest());
}
INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance,
AppListViewTestAura,
::testing::Bool());
::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END));
INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance,
AppListViewTestDesktop,
::testing::Bool());
::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END));
} // namespace test
} // namespace app_list
......@@ -58,6 +58,7 @@ ContentsView::ContentsView(AppListMainView* app_list_main_view,
AppListViewDelegate* view_delegate)
: show_state_(SHOW_APPS),
pagination_model_(pagination_model),
start_page_view_(NULL),
app_list_main_view_(app_list_main_view),
view_model_(new views::ViewModel),
bounds_animator_(new views::BoundsAnimator(this)) {
......@@ -79,10 +80,10 @@ ContentsView::ContentsView(AppListMainView* app_list_main_view,
if (app_list::switches::IsExperimentalAppListEnabled()) {
content::WebContents* start_page_contents =
view_delegate->GetStartPageContents();
StartPageView* start_page_view =
start_page_view_ =
new StartPageView(app_list_main_view, start_page_contents);
AddChildView(start_page_view);
view_model_->Add(start_page_view, kIndexStartPage);
AddChildView(start_page_view_);
view_model_->Add(start_page_view_, kIndexStartPage);
}
GetSearchResultListView(view_model_.get())->SetResults(model->results());
......
......@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "ui/app_list/app_list_export.h"
#include "ui/views/view.h"
namespace content {
......@@ -35,7 +36,7 @@ class StartPageView;
// switcher and search results). The two sets of sub views are mutually
// exclusive. ContentsView manages a show state to choose one set to show
// and animates the transition between show states.
class ContentsView : public views::View {
class APP_LIST_EXPORT ContentsView : public views::View {
public:
enum ShowState {
SHOW_APPS,
......@@ -66,6 +67,7 @@ class ContentsView : public views::View {
void Prerender();
AppsContainerView* apps_container_view() { return apps_container_view_; }
StartPageView* start_page_view() { return start_page_view_; }
ShowState show_state() const { return show_state_; }
......@@ -90,6 +92,8 @@ class ContentsView : public views::View {
PaginationModel* pagination_model_; // Owned by AppListController.
AppsContainerView* apps_container_view_; // Owned by the views hierarchy.
StartPageView* start_page_view_; // Owned by the views hierarchy.
AppListMainView* app_list_main_view_; // Parent view, owns this.
scoped_ptr<views::ViewModel> view_model_;
......
......@@ -72,8 +72,9 @@ StartPageView::StartPageView(AppListMainView* app_list_main_view,
instant_container_->SetLayoutManager(new views::BoxLayout(
views::BoxLayout::kVertical, 0, kTopMargin, kInstantContainerSpacing));
views::WebView* web_view =
new views::WebView(start_page_web_contents->GetBrowserContext());
views::WebView* web_view = new views::WebView(
start_page_web_contents ? start_page_web_contents->GetBrowserContext()
: NULL);
web_view->SetPreferredSize(gfx::Size(kWebViewWidth, kWebViewHeight));
web_view->SetWebContents(start_page_web_contents);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment