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

Side by Side Diff: ui/app_list/app_list_model_unittest.cc

Issue 63283003: Move AppListModel::Users to AppListViewDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mac fixes Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/app_list/app_list_model_observer.h ('k') | ui/app_list/app_list_view_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "ui/app_list/app_list_model.h" 5 #include "ui/app_list/app_list_model.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/app_list/app_list_folder_item.h" 11 #include "ui/app_list/app_list_folder_item.h"
12 #include "ui/app_list/app_list_item_model.h" 12 #include "ui/app_list/app_list_item_model.h"
13 #include "ui/app_list/app_list_model_observer.h" 13 #include "ui/app_list/app_list_model_observer.h"
14 #include "ui/app_list/test/app_list_test_model.h" 14 #include "ui/app_list/test/app_list_test_model.h"
15 #include "ui/base/models/list_model_observer.h" 15 #include "ui/base/models/list_model_observer.h"
16 16
17 namespace app_list { 17 namespace app_list {
18 18
19 namespace { 19 namespace {
20 20
21 class TestObserver : public AppListModelObserver, 21 class TestObserver : public AppListModelObserver,
22 public AppListItemListObserver { 22 public AppListItemListObserver {
23 public: 23 public:
24 TestObserver() 24 TestObserver()
25 : status_changed_count_(0), 25 : status_changed_count_(0),
26 users_changed_count_(0),
27 signin_changed_count_(0), 26 signin_changed_count_(0),
28 items_added_(0), 27 items_added_(0),
29 items_removed_(0), 28 items_removed_(0),
30 items_moved_(0) { 29 items_moved_(0) {
31 } 30 }
32 virtual ~TestObserver() { 31 virtual ~TestObserver() {
33 } 32 }
34 33
35 // AppListModelObserver 34 // AppListModelObserver
36 virtual void OnAppListModelStatusChanged() OVERRIDE { 35 virtual void OnAppListModelStatusChanged() OVERRIDE {
37 ++status_changed_count_; 36 ++status_changed_count_;
38 } 37 }
39 38
40 virtual void OnAppListModelUsersChanged() OVERRIDE {
41 ++users_changed_count_;
42 }
43
44 virtual void OnAppListModelSigninStatusChanged() OVERRIDE { 39 virtual void OnAppListModelSigninStatusChanged() OVERRIDE {
45 ++signin_changed_count_; 40 ++signin_changed_count_;
46 } 41 }
47 42
48 // AppListItemListObserver 43 // AppListItemListObserver
49 virtual void OnListItemAdded(size_t index, AppListItemModel* item) OVERRIDE { 44 virtual void OnListItemAdded(size_t index, AppListItemModel* item) OVERRIDE {
50 items_added_++; 45 items_added_++;
51 } 46 }
52 47
53 virtual void OnListItemRemoved(size_t index, 48 virtual void OnListItemRemoved(size_t index,
54 AppListItemModel* item) OVERRIDE { 49 AppListItemModel* item) OVERRIDE {
55 items_removed_++; 50 items_removed_++;
56 } 51 }
57 52
58 virtual void OnListItemMoved(size_t from_index, 53 virtual void OnListItemMoved(size_t from_index,
59 size_t to_index, 54 size_t to_index,
60 AppListItemModel* item) OVERRIDE { 55 AppListItemModel* item) OVERRIDE {
61 items_moved_++; 56 items_moved_++;
62 } 57 }
63 58
64 int status_changed_count() const { return status_changed_count_; } 59 int status_changed_count() const { return status_changed_count_; }
65 int users_changed_count() const { return users_changed_count_; }
66 int signin_changed_count() const { return signin_changed_count_; } 60 int signin_changed_count() const { return signin_changed_count_; }
67 size_t items_added() { return items_added_; } 61 size_t items_added() { return items_added_; }
68 size_t items_removed() { return items_removed_; } 62 size_t items_removed() { return items_removed_; }
69 size_t items_moved() { return items_moved_; } 63 size_t items_moved() { return items_moved_; }
70 64
71 void ResetCounts() { 65 void ResetCounts() {
72 status_changed_count_ = 0; 66 status_changed_count_ = 0;
73 users_changed_count_ = 0;
74 signin_changed_count_ = 0; 67 signin_changed_count_ = 0;
75 items_added_ = 0; 68 items_added_ = 0;
76 items_removed_ = 0; 69 items_removed_ = 0;
77 items_moved_ = 0; 70 items_moved_ = 0;
78 } 71 }
79 72
80 private: 73 private:
81 int status_changed_count_; 74 int status_changed_count_;
82 int users_changed_count_;
83 int signin_changed_count_; 75 int signin_changed_count_;
84 size_t items_added_; 76 size_t items_added_;
85 size_t items_removed_; 77 size_t items_removed_;
86 size_t items_moved_; 78 size_t items_moved_;
87 79
88 DISALLOW_COPY_AND_ASSIGN(TestObserver); 80 DISALLOW_COPY_AND_ASSIGN(TestObserver);
89 }; 81 };
90 82
91 } // namespace 83 } // namespace
92 84
(...skipping 30 matching lines...) Expand all
123 model_.SetStatus(AppListModel::STATUS_SYNCING); 115 model_.SetStatus(AppListModel::STATUS_SYNCING);
124 EXPECT_EQ(1, observer_.status_changed_count()); 116 EXPECT_EQ(1, observer_.status_changed_count());
125 EXPECT_EQ(AppListModel::STATUS_SYNCING, model_.status()); 117 EXPECT_EQ(AppListModel::STATUS_SYNCING, model_.status());
126 model_.SetStatus(AppListModel::STATUS_NORMAL); 118 model_.SetStatus(AppListModel::STATUS_NORMAL);
127 EXPECT_EQ(2, observer_.status_changed_count()); 119 EXPECT_EQ(2, observer_.status_changed_count());
128 // Set the same status, no change is expected. 120 // Set the same status, no change is expected.
129 model_.SetStatus(AppListModel::STATUS_NORMAL); 121 model_.SetStatus(AppListModel::STATUS_NORMAL);
130 EXPECT_EQ(2, observer_.status_changed_count()); 122 EXPECT_EQ(2, observer_.status_changed_count());
131 } 123 }
132 124
133 TEST_F(AppListModelTest, SetUsers) {
134 EXPECT_EQ(0u, model_.users().size());
135 AppListModel::Users users;
136 users.push_back(AppListModel::User());
137 users[0].name = UTF8ToUTF16("test");
138 model_.SetUsers(users);
139 EXPECT_EQ(1, observer_.users_changed_count());
140 ASSERT_EQ(1u, model_.users().size());
141 EXPECT_EQ(UTF8ToUTF16("test"), model_.users()[0].name);
142 }
143
144 TEST_F(AppListModelTest, SetSignedIn) { 125 TEST_F(AppListModelTest, SetSignedIn) {
145 EXPECT_TRUE(model_.signed_in()); 126 EXPECT_TRUE(model_.signed_in());
146 model_.SetSignedIn(false); 127 model_.SetSignedIn(false);
147 EXPECT_EQ(1, observer_.signin_changed_count()); 128 EXPECT_EQ(1, observer_.signin_changed_count());
148 EXPECT_FALSE(model_.signed_in()); 129 EXPECT_FALSE(model_.signed_in());
149 model_.SetSignedIn(true); 130 model_.SetSignedIn(true);
150 EXPECT_EQ(2, observer_.signin_changed_count()); 131 EXPECT_EQ(2, observer_.signin_changed_count());
151 EXPECT_TRUE(model_.signed_in()); 132 EXPECT_TRUE(model_.signed_in());
152 // Set the same signin state, no change is expected. 133 // Set the same signin state, no change is expected.
153 model_.SetSignedIn(true); 134 model_.SetSignedIn(true);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 EXPECT_TRUE(ItemObservedByFolder( 285 EXPECT_TRUE(ItemObservedByFolder(
305 folder.get(), folder->item_list()->item_at(0))); 286 folder.get(), folder->item_list()->item_at(0)));
306 EXPECT_TRUE(ItemObservedByFolder( 287 EXPECT_TRUE(ItemObservedByFolder(
307 folder.get(), folder->item_list()->item_at(num_observed_apps - 1))); 288 folder.get(), folder->item_list()->item_at(num_observed_apps - 1)));
308 // Check that item 4 is not observed. 289 // Check that item 4 is not observed.
309 EXPECT_FALSE(ItemObservedByFolder( 290 EXPECT_FALSE(ItemObservedByFolder(
310 folder.get(), folder->item_list()->item_at(num_observed_apps))); 291 folder.get(), folder->item_list()->item_at(num_observed_apps)));
311 } 292 }
312 293
313 } // namespace app_list 294 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/app_list_model_observer.h ('k') | ui/app_list/app_list_view_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698