1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/app_list/views/app_list_main_view.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/app_list/pagination_model.h"
9 #include "ui/app_list/test/app_list_test_model.h"
10 #include "ui/app_list/test/app_list_test_view_delegate.h"
11 #include "ui/app_list/views/apps_container_view.h"
12 #include "ui/app_list/views/apps_grid_view.h"
13 #include "ui/app_list/views/contents_view.h"
14 #include "ui/views/test/views_test_base.h"
15 #include "ui/views/view_model.h"
16 #include "ui/views/widget/widget.h"
23 const int kInitialItems
= 2;
25 class AppListMainViewTest
: public views::ViewsTestBase
{
31 virtual ~AppListMainViewTest() {}
33 // testing::Test overrides:
34 virtual void SetUp() OVERRIDE
{
35 views::ViewsTestBase::SetUp();
36 delegate_
.reset(new AppListTestViewDelegate
);
37 delegate_
->GetTestModel()->PopulateApps(kInitialItems
);
40 new AppListMainView(delegate_
.get(), &pagination_model_
, GetContext());
41 main_view_
->SetPaintToLayer(true);
43 widget_
= new views::Widget
;
44 views::Widget::InitParams params
=
45 CreateParams(views::Widget::InitParams::TYPE_POPUP
);
46 params
.bounds
.set_size(main_view_
->GetPreferredSize());
47 widget_
->Init(params
);
49 widget_
->SetContentsView(main_view_
);
52 virtual void TearDown() OVERRIDE
{
54 views::ViewsTestBase::TearDown();
58 const views::ViewModel
* ViewModel() {
59 return main_view_
->contents_view()->apps_container_view()->apps_grid_view()
60 ->view_model_for_test();
64 views::Widget
* widget_
; // Owned by native window.
65 AppListMainView
* main_view_
; // Owned by |widget_|.
66 PaginationModel pagination_model_
;
67 scoped_ptr
<AppListTestViewDelegate
> delegate_
;
70 DISALLOW_COPY_AND_ASSIGN(AppListMainViewTest
);
75 // Tests changing the AppListModel when switching profiles.
76 TEST_F(AppListMainViewTest
, ModelChanged
) {
77 EXPECT_EQ(kInitialItems
, ViewModel()->view_size());
79 // The model is owned by a profile keyed service, which is never destroyed
80 // until after profile switching.
81 scoped_ptr
<AppListModel
> old_model(delegate_
->ReleaseTestModel());
83 const int kReplacementItems
= 5;
84 delegate_
->ReplaceTestModel(kReplacementItems
);
85 main_view_
->ModelChanged();
86 EXPECT_EQ(kReplacementItems
, ViewModel()->view_size());
90 } // namespace app_list