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

Side by Side Diff: ash/launcher/launcher_model_unittest.cc

Issue 68243002: ash: Rename LauncherModelObserver to ShelfModelObserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | « ash/launcher/launcher_model_observer.h ('k') | ash/shelf/shelf_model_observer.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 (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/launcher/launcher_model.h" 5 #include "ash/launcher/launcher_model.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
11 #include "ash/launcher/launcher_model_observer.h" 11 #include "ash/shelf/shelf_model_observer.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace ash { 16 namespace ash {
17 17
18 namespace { 18 namespace {
19 19
20 // LauncherModelObserver implementation that tracks what message are invoked. 20 // ShelfModelObserver implementation that tracks what message are invoked.
21 class TestLauncherModelObserver : public LauncherModelObserver { 21 class TestShelfModelObserver : public ShelfModelObserver {
22 public: 22 public:
23 TestLauncherModelObserver() 23 TestShelfModelObserver()
24 : added_count_(0), 24 : added_count_(0),
25 removed_count_(0), 25 removed_count_(0),
26 changed_count_(0), 26 changed_count_(0),
27 moved_count_(0) { 27 moved_count_(0) {
28 } 28 }
29 29
30 // Returns a string description of the changes that have occurred since this 30 // Returns a string description of the changes that have occurred since this
31 // was last invoked. Resets state to initial state. 31 // was last invoked. Resets state to initial state.
32 std::string StateStringAndClear() { 32 std::string StateStringAndClear() {
33 std::string result; 33 std::string result;
34 AddToResult("added=%d", added_count_, &result); 34 AddToResult("added=%d", added_count_, &result);
35 AddToResult("removed=%d", removed_count_, &result); 35 AddToResult("removed=%d", removed_count_, &result);
36 AddToResult("changed=%d", changed_count_, &result); 36 AddToResult("changed=%d", changed_count_, &result);
37 AddToResult("moved=%d", moved_count_, &result); 37 AddToResult("moved=%d", moved_count_, &result);
38 added_count_ = removed_count_ = changed_count_ = moved_count_ = 0; 38 added_count_ = removed_count_ = changed_count_ = moved_count_ = 0;
39 return result; 39 return result;
40 } 40 }
41 41
42 // LauncherModelObserver overrides: 42 // ShelfModelObserver overrides:
43 virtual void LauncherItemAdded(int index) OVERRIDE { 43 virtual void ShelfItemAdded(int index) OVERRIDE {
44 added_count_++; 44 added_count_++;
45 } 45 }
46 virtual void LauncherItemRemoved(int index, LauncherID id) OVERRIDE { 46 virtual void ShelfItemRemoved(int index, LauncherID id) OVERRIDE {
47 removed_count_++; 47 removed_count_++;
48 } 48 }
49 virtual void LauncherItemChanged(int index, 49 virtual void ShelfItemChanged(int index,
50 const LauncherItem& old_item) OVERRIDE { 50 const LauncherItem& old_item) OVERRIDE {
51 changed_count_++; 51 changed_count_++;
52 } 52 }
53 virtual void LauncherItemMoved(int start_index, int target_index) OVERRIDE { 53 virtual void ShelfItemMoved(int start_index, int target_index) OVERRIDE {
54 moved_count_++; 54 moved_count_++;
55 } 55 }
56 virtual void LauncherStatusChanged() OVERRIDE { 56 virtual void ShelfStatusChanged() OVERRIDE {
57 } 57 }
58 58
59 private: 59 private:
60 void AddToResult(const std::string& format, int count, std::string* result) { 60 void AddToResult(const std::string& format, int count, std::string* result) {
61 if (!count) 61 if (!count)
62 return; 62 return;
63 if (!result->empty()) 63 if (!result->empty())
64 *result += " "; 64 *result += " ";
65 *result += base::StringPrintf(format.c_str(), count); 65 *result += base::StringPrintf(format.c_str(), count);
66 } 66 }
67 67
68 int added_count_; 68 int added_count_;
69 int removed_count_; 69 int removed_count_;
70 int changed_count_; 70 int changed_count_;
71 int moved_count_; 71 int moved_count_;
72 72
73 DISALLOW_COPY_AND_ASSIGN(TestLauncherModelObserver); 73 DISALLOW_COPY_AND_ASSIGN(TestShelfModelObserver);
74 }; 74 };
75 75
76 } // namespace 76 } // namespace
77 77
78 class LauncherModelTest : public testing::Test { 78 class LauncherModelTest : public testing::Test {
79 public: 79 public:
80 LauncherModelTest() {} 80 LauncherModelTest() {}
81 virtual ~LauncherModelTest() {} 81 virtual ~LauncherModelTest() {}
82 82
83 virtual void SetUp() { 83 virtual void SetUp() {
84 model_.reset(new LauncherModel); 84 model_.reset(new LauncherModel);
85 observer_.reset(new TestLauncherModelObserver); 85 observer_.reset(new TestShelfModelObserver);
86 EXPECT_EQ(0, model_->item_count()); 86 EXPECT_EQ(0, model_->item_count());
87 87
88 LauncherItem item; 88 LauncherItem item;
89 item.type = TYPE_APP_LIST; 89 item.type = TYPE_APP_LIST;
90 model_->Add(item); 90 model_->Add(item);
91 EXPECT_EQ(1, model_->item_count()); 91 EXPECT_EQ(1, model_->item_count());
92 92
93 model_->AddObserver(observer_.get()); 93 model_->AddObserver(observer_.get());
94 } 94 }
95 95
96 virtual void TearDown() { 96 virtual void TearDown() {
97 observer_.reset(); 97 observer_.reset();
98 model_.reset(); 98 model_.reset();
99 } 99 }
100 100
101 scoped_ptr<LauncherModel> model_; 101 scoped_ptr<LauncherModel> model_;
102 scoped_ptr<TestLauncherModelObserver> observer_; 102 scoped_ptr<TestShelfModelObserver> observer_;
103 103
104 private: 104 private:
105 DISALLOW_COPY_AND_ASSIGN(LauncherModelTest); 105 DISALLOW_COPY_AND_ASSIGN(LauncherModelTest);
106 }; 106 };
107 107
108 TEST_F(LauncherModelTest, BasicAssertions) { 108 TEST_F(LauncherModelTest, BasicAssertions) {
109 // Add an item. 109 // Add an item.
110 LauncherItem item; 110 LauncherItem item;
111 item.type = TYPE_APP_SHORTCUT; 111 item.type = TYPE_APP_SHORTCUT;
112 int index = model_->Add(item); 112 int index = model_->Add(item);
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // Now change the type of the second item and make sure that it is moving 396 // Now change the type of the second item and make sure that it is moving
397 // behind the shortcuts. 397 // behind the shortcuts.
398 item.type = TYPE_PLATFORM_APP; 398 item.type = TYPE_PLATFORM_APP;
399 model_->Set(app2_index, item); 399 model_->Set(app2_index, item);
400 400
401 // The item should have moved in front of the app launcher. 401 // The item should have moved in front of the app launcher.
402 EXPECT_EQ(TYPE_PLATFORM_APP, model_->items()[3].type); 402 EXPECT_EQ(TYPE_PLATFORM_APP, model_->items()[3].type);
403 } 403 }
404 404
405 } // namespace ash 405 } // namespace ash
OLDNEW
« no previous file with comments | « ash/launcher/launcher_model_observer.h ('k') | ash/shelf/shelf_model_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698