Views Omnibox: tolerate minor click-to-select-all dragging.
[chromium-blink-merge.git] / ui / app_list / views / app_list_main_view_unittest.cc
blob6ca1820ef44d28d713fedf94f6b32a0fb940defb
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"
18 namespace app_list {
19 namespace test {
21 namespace {
23 const int kInitialItems = 2;
25 class AppListMainViewTest : public views::ViewsTestBase {
26 public:
27 AppListMainViewTest()
28 : widget_(NULL),
29 main_view_(NULL) {}
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);
39 main_view_ =
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 {
53 widget_->Close();
54 views::ViewsTestBase::TearDown();
55 delegate_.reset();
58 const views::ViewModel* ViewModel() {
59 return main_view_->contents_view()->apps_container_view()->apps_grid_view()
60 ->view_model_for_test();
63 protected:
64 views::Widget* widget_; // Owned by native window.
65 AppListMainView* main_view_; // Owned by |widget_|.
66 PaginationModel pagination_model_;
67 scoped_ptr<AppListTestViewDelegate> delegate_;
69 private:
70 DISALLOW_COPY_AND_ASSIGN(AppListMainViewTest);
73 } // namespace
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());
89 } // namespace test
90 } // namespace app_list