summaryrefslogtreecommitdiffstats
path: root/ash/launcher
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-14 19:48:36 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-14 19:48:36 +0000
commit64936bfc5e259b97286498932cd4abe1ad4d3c57 (patch)
tree977b1c6e7c9b2af1b63dbe46312ba9b6603b0894 /ash/launcher
parent04afd69e36366fa5cdc3b8c03720119d755c5580 (diff)
downloadchromium_src-64936bfc5e259b97286498932cd4abe1ad4d3c57.zip
chromium_src-64936bfc5e259b97286498932cd4abe1ad4d3c57.tar.gz
chromium_src-64936bfc5e259b97286498932cd4abe1ad4d3c57.tar.bz2
ash: Rename LauncherModel to ShelfModel.
* Move launcher_model.* from launcher/ to shelf/ * Rename to shelf_model.* BUG=248353 TEST=None, no functional changes R=jamescook@chromium.org,harrym@chromium.org Review URL: https://codereview.chromium.org/71653003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235217 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/launcher')
-rw-r--r--ash/launcher/launcher.cc12
-rw-r--r--ash/launcher/launcher.h4
-rw-r--r--ash/launcher/launcher_item_delegate_manager.cc6
-rw-r--r--ash/launcher/launcher_item_delegate_manager.h6
-rw-r--r--ash/launcher/launcher_model.cc184
-rw-r--r--ash/launcher/launcher_model.h91
-rw-r--r--ash/launcher/launcher_model_unittest.cc405
-rw-r--r--ash/launcher/launcher_unittest.cc29
8 files changed, 28 insertions, 709 deletions
diff --git a/ash/launcher/launcher.cc b/ash/launcher/launcher.cc
index e981709..e0dc133 100644
--- a/ash/launcher/launcher.cc
+++ b/ash/launcher/launcher.cc
@@ -11,10 +11,10 @@
#include "ash/launcher/launcher_delegate.h"
#include "ash/launcher/launcher_item_delegate.h"
#include "ash/launcher/launcher_item_delegate_manager.h"
-#include "ash/launcher/launcher_model.h"
#include "ash/root_window_controller.h"
#include "ash/screen_ash.h"
#include "ash/shelf/shelf_layout_manager.h"
+#include "ash/shelf/shelf_model.h"
#include "ash/shelf/shelf_navigator.h"
#include "ash/shelf/shelf_view.h"
#include "ash/shelf/shelf_widget.h"
@@ -41,7 +41,7 @@ namespace ash {
const char Launcher::kNativeViewName[] = "ShelfView";
-Launcher::Launcher(LauncherModel* launcher_model,
+Launcher::Launcher(ShelfModel* shelf_model,
LauncherDelegate* launcher_delegate,
ShelfWidget* shelf_widget)
: shelf_view_(NULL),
@@ -49,7 +49,7 @@ Launcher::Launcher(LauncherModel* launcher_model,
delegate_(launcher_delegate),
shelf_widget_(shelf_widget) {
shelf_view_ = new internal::ShelfView(
- launcher_model, delegate_, shelf_widget_->shelf_layout_manager());
+ shelf_model, delegate_, shelf_widget_->shelf_layout_manager());
shelf_view_->Init();
shelf_widget_->GetContentsView()->AddChildView(shelf_view_);
shelf_widget_->GetNativeView()->SetName(kNativeViewName);
@@ -154,9 +154,9 @@ views::View* Launcher::GetAppListButtonView() const {
}
void Launcher::LaunchAppIndexAt(int item_index) {
- LauncherModel* launcher_model = shelf_view_->model();
- const LauncherItems& items = launcher_model->items();
- int item_count = launcher_model->item_count();
+ ShelfModel* shelf_model = shelf_view_->model();
+ const LauncherItems& items = shelf_model->items();
+ int item_count = shelf_model->item_count();
int indexes_left = item_index >= 0 ? item_index : item_count;
int found_index = -1;
diff --git a/ash/launcher/launcher.h b/ash/launcher/launcher.h
index 5c663b4..5f1da0b 100644
--- a/ash/launcher/launcher.h
+++ b/ash/launcher/launcher.h
@@ -42,15 +42,15 @@ class LauncherTestAPI;
}
class LauncherDelegate;
-class LauncherModel;
class ShelfIconObserver;
+class ShelfModel;
class ShelfWidget;
class ASH_EXPORT Launcher {
public:
static const char kNativeViewName[];
- Launcher(LauncherModel* launcher_model,
+ Launcher(ShelfModel* shelf_model,
LauncherDelegate* launcher_delegate,
ShelfWidget* shelf_widget);
virtual ~Launcher();
diff --git a/ash/launcher/launcher_item_delegate_manager.cc b/ash/launcher/launcher_item_delegate_manager.cc
index ecc821c..efd8857 100644
--- a/ash/launcher/launcher_item_delegate_manager.cc
+++ b/ash/launcher/launcher_item_delegate_manager.cc
@@ -5,15 +5,15 @@
#include "ash/launcher/launcher_item_delegate_manager.h"
#include "ash/launcher/launcher_item_delegate.h"
-#include "ash/launcher/launcher_model.h"
+#include "ash/shelf/shelf_model.h"
#include "ash/shell.h"
#include "base/logging.h"
#include "base/stl_util.h"
namespace ash {
-LauncherItemDelegateManager::LauncherItemDelegateManager(
- ash::LauncherModel* model) : model_(model) {
+LauncherItemDelegateManager::LauncherItemDelegateManager(ShelfModel* model)
+ : model_(model) {
DCHECK(model_);
model_->AddObserver(this);
}
diff --git a/ash/launcher/launcher_item_delegate_manager.h b/ash/launcher/launcher_item_delegate_manager.h
index a04e1e0..7ae9abb 100644
--- a/ash/launcher/launcher_item_delegate_manager.h
+++ b/ash/launcher/launcher_item_delegate_manager.h
@@ -15,7 +15,7 @@
namespace ash {
class LauncherItemDelegate;
-class LauncherModel;
+class ShelfModel;
namespace test {
class LauncherItemDelegateManagerTestAPI;
@@ -28,7 +28,7 @@ class LauncherItemDelegateManagerTestAPI;
// LauncherItemDelegates when the corresponding item from the model is removed.
class ASH_EXPORT LauncherItemDelegateManager : public ShelfModelObserver {
public:
- explicit LauncherItemDelegateManager(ash::LauncherModel* model);
+ explicit LauncherItemDelegateManager(ShelfModel* model);
virtual ~LauncherItemDelegateManager();
// Set |item_delegate| for |id| and take an ownership.
@@ -58,7 +58,7 @@ class ASH_EXPORT LauncherItemDelegateManager : public ShelfModelObserver {
// Clear all exsiting LauncherItemDelegate for test.
// Not owned by LauncherItemDelegate.
- ash::LauncherModel* model_;
+ ShelfModel* model_;
LauncherIDToItemDelegateMap id_to_item_delegate_map_;
diff --git a/ash/launcher/launcher_model.cc b/ash/launcher/launcher_model.cc
deleted file mode 100644
index a8c206393..0000000
--- a/ash/launcher/launcher_model.cc
+++ /dev/null
@@ -1,184 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ash/launcher/launcher_model.h"
-
-#include <algorithm>
-
-#include "ash/ash_switches.h"
-#include "ash/shelf/shelf_model_observer.h"
-
-namespace ash {
-
-namespace {
-
-int LauncherItemTypeToWeight(LauncherItemType type) {
- if (ash::switches::UseAlternateShelfLayout()) {
- switch (type) {
- case TYPE_APP_LIST:
- // TODO(skuhne): If the app list item becomes movable again, this need
- // to be a fallthrough.
- return 0;
- case TYPE_BROWSER_SHORTCUT:
- case TYPE_APP_SHORTCUT:
- case TYPE_WINDOWED_APP:
- return 1;
- case TYPE_PLATFORM_APP:
- return 2;
- case TYPE_APP_PANEL:
- return 3;
- case TYPE_UNDEFINED:
- NOTREACHED() << "LauncherItemType must be set";
- return -1;
- }
- } else {
- switch (type) {
- case TYPE_BROWSER_SHORTCUT:
- case TYPE_APP_SHORTCUT:
- case TYPE_WINDOWED_APP:
- return 0;
- case TYPE_PLATFORM_APP:
- return 1;
- case TYPE_APP_LIST:
- return 2;
- case TYPE_APP_PANEL:
- return 3;
- case TYPE_UNDEFINED:
- NOTREACHED() << "LauncherItemType must be set";
- return -1;
- }
- }
-
- NOTREACHED() << "Invalid type " << type;
- return 1;
-}
-
-bool CompareByWeight(const LauncherItem& a, const LauncherItem& b) {
- return LauncherItemTypeToWeight(a.type) < LauncherItemTypeToWeight(b.type);
-}
-
-} // namespace
-
-LauncherModel::LauncherModel() : next_id_(1), status_(STATUS_NORMAL) {
-}
-
-LauncherModel::~LauncherModel() {
-}
-
-int LauncherModel::Add(const LauncherItem& item) {
- return AddAt(items_.size(), item);
-}
-
-int LauncherModel::AddAt(int index, const LauncherItem& item) {
- index = ValidateInsertionIndex(item.type, index);
- items_.insert(items_.begin() + index, item);
- items_[index].id = next_id_++;
- FOR_EACH_OBSERVER(ShelfModelObserver, observers_, ShelfItemAdded(index));
- return index;
-}
-
-void LauncherModel::RemoveItemAt(int index) {
- DCHECK(index >= 0 && index < item_count());
- // The app list and browser shortcut can't be removed.
- DCHECK(items_[index].type != TYPE_APP_LIST &&
- items_[index].type != TYPE_BROWSER_SHORTCUT);
- LauncherID id = items_[index].id;
- items_.erase(items_.begin() + index);
- FOR_EACH_OBSERVER(ShelfModelObserver, observers_,
- ShelfItemRemoved(index, id));
-}
-
-void LauncherModel::Move(int index, int target_index) {
- if (index == target_index)
- return;
- // TODO: this needs to enforce valid ranges.
- LauncherItem item(items_[index]);
- items_.erase(items_.begin() + index);
- items_.insert(items_.begin() + target_index, item);
- FOR_EACH_OBSERVER(ShelfModelObserver, observers_,
- ShelfItemMoved(index, target_index));
-}
-
-void LauncherModel::Set(int index, const LauncherItem& item) {
- DCHECK(index >= 0 && index < item_count());
- int new_index = item.type == items_[index].type ?
- index : ValidateInsertionIndex(item.type, index);
-
- LauncherItem old_item(items_[index]);
- items_[index] = item;
- items_[index].id = old_item.id;
- FOR_EACH_OBSERVER(ShelfModelObserver, observers_,
- ShelfItemChanged(index, old_item));
-
- // If the type changes confirm that the item is still in the right order.
- if (new_index != index) {
- // The move function works by removing one item and then inserting it at the
- // new location. However - by removing the item first the order will change
- // so that our target index needs to be corrected.
- // TODO(skuhne): Moving this into the Move function breaks lots of unit
- // tests. So several functions were already using this incorrectly.
- // That needs to be cleaned up.
- if (index < new_index)
- new_index--;
-
- Move(index, new_index);
- }
-}
-
-int LauncherModel::ItemIndexByID(LauncherID id) const {
- LauncherItems::const_iterator i = ItemByID(id);
- return i == items_.end() ? -1 : static_cast<int>(i - items_.begin());
-}
-
-LauncherItems::const_iterator LauncherModel::ItemByID(int id) const {
- for (LauncherItems::const_iterator i = items_.begin();
- i != items_.end(); ++i) {
- if (i->id == id)
- return i;
- }
- return items_.end();
-}
-
-int LauncherModel::FirstPanelIndex() const {
- LauncherItem weight_dummy;
- weight_dummy.type = TYPE_APP_PANEL;
- return std::lower_bound(items_.begin(), items_.end(), weight_dummy,
- CompareByWeight) - items_.begin();
-}
-
-void LauncherModel::SetStatus(Status status) {
- if (status_ == status)
- return;
-
- status_ = status;
- FOR_EACH_OBSERVER(ShelfModelObserver, observers_, ShelfStatusChanged());
-}
-
-void LauncherModel::AddObserver(ShelfModelObserver* observer) {
- observers_.AddObserver(observer);
-}
-
-void LauncherModel::RemoveObserver(ShelfModelObserver* observer) {
- observers_.RemoveObserver(observer);
-}
-
-int LauncherModel::ValidateInsertionIndex(LauncherItemType type,
- int index) const {
- DCHECK(index >= 0 && index <= item_count() +
- (ash::switches::UseAlternateShelfLayout() ? 1 : 0));
-
- // Clamp |index| to the allowed range for the type as determined by |weight|.
- LauncherItem weight_dummy;
- weight_dummy.type = type;
- index = std::max(std::lower_bound(items_.begin(), items_.end(), weight_dummy,
- CompareByWeight) - items_.begin(),
- static_cast<LauncherItems::difference_type>(index));
- index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy,
- CompareByWeight) - items_.begin(),
- static_cast<LauncherItems::difference_type>(index));
-
- return index;
-}
-
-} // namespace ash
diff --git a/ash/launcher/launcher_model.h b/ash/launcher/launcher_model.h
deleted file mode 100644
index 2845fb0..0000000
--- a/ash/launcher/launcher_model.h
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef ASH_LAUNCHER_LAUNCHER_MODEL_H_
-#define ASH_LAUNCHER_LAUNCHER_MODEL_H_
-
-#include "ash/ash_export.h"
-#include "ash/launcher/launcher_types.h"
-#include "base/basictypes.h"
-#include "base/observer_list.h"
-
-namespace ash {
-
-class ShelfModelObserver;
-
-// Model used by ShelfView.
-class ASH_EXPORT LauncherModel {
- public:
- enum Status {
- STATUS_NORMAL,
- // A status that indicates apps are syncing/loading.
- STATUS_LOADING,
- };
-
- LauncherModel();
- ~LauncherModel();
-
- // Adds a new item to the model. Returns the resulting index.
- int Add(const LauncherItem& item);
-
- // Adds the item. |index| is the requested insertion index, which may be
- // modified to meet type-based ordering. Returns the actual insertion index.
- int AddAt(int index, const LauncherItem& item);
-
- // Removes the item at |index|.
- void RemoveItemAt(int index);
-
- // Moves the item at |index| to |target_index|. |target_index| is in terms
- // of the model *after* the item at |index| is removed.
- void Move(int index, int target_index);
-
- // Resets the item at the specified index. The item maintains its existing
- // id and type.
- void Set(int index, const LauncherItem& item);
-
- // Returns the index of the item by id.
- int ItemIndexByID(LauncherID id) const;
-
- // Returns the index of the first panel or the index where the first panel
- // would go if there are no panels.
- int FirstPanelIndex() const;
-
- // Returns the id assigned to the next item added.
- LauncherID next_id() const { return next_id_; }
-
- // Returns a reserved id which will not be used by the |LauncherModel|.
- LauncherID reserve_external_id() { return next_id_++; }
-
- // Returns an iterator into items() for the item with the specified id, or
- // items().end() if there is no item with the specified id.
- LauncherItems::const_iterator ItemByID(LauncherID id) const;
-
- const LauncherItems& items() const { return items_; }
- int item_count() const { return static_cast<int>(items_.size()); }
-
- void SetStatus(Status status);
- Status status() const { return status_; }
-
- void AddObserver(ShelfModelObserver* observer);
- void RemoveObserver(ShelfModelObserver* observer);
-
- private:
- // Makes sure |index| is in line with the type-based order of items. If that
- // is not the case, adjusts index by shifting it to the valid range and
- // returns the new value.
- int ValidateInsertionIndex(LauncherItemType type, int index) const;
-
- // ID assigned to the next item.
- LauncherID next_id_;
-
- LauncherItems items_;
- Status status_;
- ObserverList<ShelfModelObserver> observers_;
-
- DISALLOW_COPY_AND_ASSIGN(LauncherModel);
-};
-
-} // namespace ash
-
-#endif // ASH_LAUNCHER_LAUNCHER_MODEL_H_
diff --git a/ash/launcher/launcher_model_unittest.cc b/ash/launcher/launcher_model_unittest.cc
deleted file mode 100644
index b22dee9..0000000
--- a/ash/launcher/launcher_model_unittest.cc
+++ /dev/null
@@ -1,405 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ash/launcher/launcher_model.h"
-
-#include <set>
-#include <string>
-
-#include "ash/ash_switches.h"
-#include "ash/shelf/shelf_model_observer.h"
-#include "base/command_line.h"
-#include "base/strings/stringprintf.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace ash {
-
-namespace {
-
-// ShelfModelObserver implementation that tracks what message are invoked.
-class TestShelfModelObserver : public ShelfModelObserver {
- public:
- TestShelfModelObserver()
- : added_count_(0),
- removed_count_(0),
- changed_count_(0),
- moved_count_(0) {
- }
-
- // Returns a string description of the changes that have occurred since this
- // was last invoked. Resets state to initial state.
- std::string StateStringAndClear() {
- std::string result;
- AddToResult("added=%d", added_count_, &result);
- AddToResult("removed=%d", removed_count_, &result);
- AddToResult("changed=%d", changed_count_, &result);
- AddToResult("moved=%d", moved_count_, &result);
- added_count_ = removed_count_ = changed_count_ = moved_count_ = 0;
- return result;
- }
-
- // ShelfModelObserver overrides:
- virtual void ShelfItemAdded(int index) OVERRIDE {
- added_count_++;
- }
- virtual void ShelfItemRemoved(int index, LauncherID id) OVERRIDE {
- removed_count_++;
- }
- virtual void ShelfItemChanged(int index,
- const LauncherItem& old_item) OVERRIDE {
- changed_count_++;
- }
- virtual void ShelfItemMoved(int start_index, int target_index) OVERRIDE {
- moved_count_++;
- }
- virtual void ShelfStatusChanged() OVERRIDE {
- }
-
- private:
- void AddToResult(const std::string& format, int count, std::string* result) {
- if (!count)
- return;
- if (!result->empty())
- *result += " ";
- *result += base::StringPrintf(format.c_str(), count);
- }
-
- int added_count_;
- int removed_count_;
- int changed_count_;
- int moved_count_;
-
- DISALLOW_COPY_AND_ASSIGN(TestShelfModelObserver);
-};
-
-} // namespace
-
-class LauncherModelTest : public testing::Test {
- public:
- LauncherModelTest() {}
- virtual ~LauncherModelTest() {}
-
- virtual void SetUp() {
- model_.reset(new LauncherModel);
- observer_.reset(new TestShelfModelObserver);
- EXPECT_EQ(0, model_->item_count());
-
- LauncherItem item;
- item.type = TYPE_APP_LIST;
- model_->Add(item);
- EXPECT_EQ(1, model_->item_count());
-
- model_->AddObserver(observer_.get());
- }
-
- virtual void TearDown() {
- observer_.reset();
- model_.reset();
- }
-
- scoped_ptr<LauncherModel> model_;
- scoped_ptr<TestShelfModelObserver> observer_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(LauncherModelTest);
-};
-
-TEST_F(LauncherModelTest, BasicAssertions) {
- // Add an item.
- LauncherItem item;
- item.type = TYPE_APP_SHORTCUT;
- int index = model_->Add(item);
- EXPECT_EQ(2, model_->item_count());
- EXPECT_EQ("added=1", observer_->StateStringAndClear());
-
- // Change to a platform app item.
- LauncherID original_id = model_->items()[index].id;
- item.type = TYPE_PLATFORM_APP;
- model_->Set(index, item);
- EXPECT_EQ(original_id, model_->items()[index].id);
- EXPECT_EQ("changed=1", observer_->StateStringAndClear());
- EXPECT_EQ(TYPE_PLATFORM_APP, model_->items()[index].type);
-
- // Remove the item.
- model_->RemoveItemAt(index);
- EXPECT_EQ(1, model_->item_count());
- EXPECT_EQ("removed=1", observer_->StateStringAndClear());
-
- // Add an app item.
- item.type = TYPE_APP_SHORTCUT;
- index = model_->Add(item);
- observer_->StateStringAndClear();
-
- // Change everything.
- model_->Set(index, item);
- EXPECT_EQ("changed=1", observer_->StateStringAndClear());
- EXPECT_EQ(TYPE_APP_SHORTCUT, model_->items()[index].type);
-
- // Add another item.
- item.type = TYPE_APP_SHORTCUT;
- model_->Add(item);
- observer_->StateStringAndClear();
-
- // Move the second to the first.
- model_->Move(1, 0);
- EXPECT_EQ("moved=1", observer_->StateStringAndClear());
-
- // And back.
- model_->Move(0, 1);
- EXPECT_EQ("moved=1", observer_->StateStringAndClear());
-
- // Verifies all the items get unique ids.
- std::set<LauncherID> ids;
- for (int i = 0; i < model_->item_count(); ++i)
- ids.insert(model_->items()[i].id);
- EXPECT_EQ(model_->item_count(), static_cast<int>(ids.size()));
-}
-
-// Assertions around where items are added.
-TEST_F(LauncherModelTest, AddIndices) {
- // Insert browser short cut at index 1.
- LauncherItem browser_shortcut;
- browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
- int browser_shortcut_index = model_->Add(browser_shortcut);
- EXPECT_EQ(1, browser_shortcut_index);
-
- // platform app items should be after browser shortcut.
- LauncherItem item;
- item.type = TYPE_PLATFORM_APP;
- int platform_app_index1 = model_->Add(item);
- EXPECT_EQ(2, platform_app_index1);
-
- // Add another platform app item, it should follow first.
- int platform_app_index2 = model_->Add(item);
- EXPECT_EQ(3, platform_app_index2);
-
- // APP_SHORTCUT priority is higher than PLATFORM_APP but same as
- // BROWSER_SHORTCUT. So APP_SHORTCUT is located after BROWSER_SHORCUT.
- item.type = TYPE_APP_SHORTCUT;
- int app_shortcut_index1 = model_->Add(item);
- EXPECT_EQ(2, app_shortcut_index1);
-
- item.type = TYPE_APP_SHORTCUT;
- int app_shortcut_index2 = model_->Add(item);
- EXPECT_EQ(3, app_shortcut_index2);
-
- // Check that AddAt() figures out the correct indexes for app shortcuts.
- // APP_SHORTCUT and BROWSER_SHORTCUT has the same weight.
- // So APP_SHORTCUT is located at index 0. And, BROWSER_SHORTCUT is located at
- // index 1.
- item.type = TYPE_APP_SHORTCUT;
- int app_shortcut_index3 = model_->AddAt(1, item);
- EXPECT_EQ(1, app_shortcut_index3);
-
- item.type = TYPE_APP_SHORTCUT;
- int app_shortcut_index4 = model_->AddAt(6, item);
- EXPECT_EQ(5, app_shortcut_index4);
-
- item.type = TYPE_APP_SHORTCUT;
- int app_shortcut_index5 = model_->AddAt(3, item);
- EXPECT_EQ(3, app_shortcut_index5);
-
- // Before there are any panels, no icons should be right aligned.
- EXPECT_EQ(model_->item_count(), model_->FirstPanelIndex());
-
- // Check that AddAt() figures out the correct indexes for platform apps and
- // panels.
- item.type = TYPE_PLATFORM_APP;
- int platform_app_index3 = model_->AddAt(3, item);
- EXPECT_EQ(7, platform_app_index3);
-
- item.type = TYPE_APP_PANEL;
- int app_panel_index1 = model_->AddAt(2, item);
- EXPECT_EQ(10, app_panel_index1);
-
- item.type = TYPE_PLATFORM_APP;
- int platform_app_index4 = model_->AddAt(11, item);
- EXPECT_EQ(10, platform_app_index4);
-
- item.type = TYPE_APP_PANEL;
- int app_panel_index2 = model_->AddAt(12, item);
- EXPECT_EQ(12, app_panel_index2);
-
- item.type = TYPE_PLATFORM_APP;
- int platform_app_index5 = model_->AddAt(7, item);
- EXPECT_EQ(7, platform_app_index5);
-
- item.type = TYPE_APP_PANEL;
- int app_panel_index3 = model_->AddAt(13, item);
- EXPECT_EQ(13, app_panel_index3);
-
- // Right aligned index should be the first app panel index.
- EXPECT_EQ(12, model_->FirstPanelIndex());
-
- EXPECT_EQ(TYPE_BROWSER_SHORTCUT, model_->items()[2].type);
- EXPECT_EQ(TYPE_APP_LIST, model_->items()[0].type);
-}
-
-// Assertions around where items are added.
-TEST_F(LauncherModelTest, AddIndicesForLegacyShelfLayout) {
- CommandLine::ForCurrentProcess()->AppendSwitch(
- ash::switches::kAshDisableAlternateShelfLayout);
-
- // Insert browser short cut at index 0.
- LauncherItem browser_shortcut;
- browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
- int browser_shortcut_index = model_->Add(browser_shortcut);
- EXPECT_EQ(0, browser_shortcut_index);
-
- // platform app items should be after browser shortcut.
- LauncherItem item;
- item.type = TYPE_PLATFORM_APP;
- int platform_app_index1 = model_->Add(item);
- EXPECT_EQ(1, platform_app_index1);
-
- // Add another platform app item, it should follow first.
- int platform_app_index2 = model_->Add(item);
- EXPECT_EQ(2, platform_app_index2);
-
- // APP_SHORTCUT priority is higher than PLATFORM_APP but same as
- // BROWSER_SHORTCUT. So APP_SHORTCUT is located after BROWSER_SHORCUT.
- item.type = TYPE_APP_SHORTCUT;
- int app_shortcut_index1 = model_->Add(item);
- EXPECT_EQ(1, app_shortcut_index1);
-
- item.type = TYPE_APP_SHORTCUT;
- int app_shortcut_index2 = model_->Add(item);
- EXPECT_EQ(2, app_shortcut_index2);
-
- // Check that AddAt() figures out the correct indexes for app shortcuts.
- // APP_SHORTCUT and BROWSER_SHORTCUT has the same weight.
- // So APP_SHORTCUT is located at index 0. And, BROWSER_SHORTCUT is located at
- // index 1.
- item.type = TYPE_APP_SHORTCUT;
- int app_shortcut_index3 = model_->AddAt(0, item);
- EXPECT_EQ(0, app_shortcut_index3);
-
- item.type = TYPE_APP_SHORTCUT;
- int app_shortcut_index4 = model_->AddAt(5, item);
- EXPECT_EQ(4, app_shortcut_index4);
-
- item.type = TYPE_APP_SHORTCUT;
- int app_shortcut_index5 = model_->AddAt(2, item);
- EXPECT_EQ(2, app_shortcut_index5);
-
- // Before there are any panels, no icons should be right aligned.
- EXPECT_EQ(model_->item_count(), model_->FirstPanelIndex());
-
- // Check that AddAt() figures out the correct indexes for platform apps and
- // panels.
- item.type = TYPE_PLATFORM_APP;
- int platform_app_index3 = model_->AddAt(2, item);
- EXPECT_EQ(6, platform_app_index3);
-
- item.type = TYPE_APP_PANEL;
- int app_panel_index1 = model_->AddAt(2, item);
- EXPECT_EQ(10, app_panel_index1);
-
- item.type = TYPE_PLATFORM_APP;
- int platform_app_index4 = model_->AddAt(11, item);
- EXPECT_EQ(9, platform_app_index4);
-
- item.type = TYPE_APP_PANEL;
- int app_panel_index2 = model_->AddAt(12, item);
- EXPECT_EQ(12, app_panel_index2);
-
- item.type = TYPE_PLATFORM_APP;
- int platform_app_index5 = model_->AddAt(7, item);
- EXPECT_EQ(7, platform_app_index5);
-
- item.type = TYPE_APP_PANEL;
- int app_panel_index3 = model_->AddAt(13, item);
- EXPECT_EQ(13, app_panel_index3);
-
- // Right aligned index should be the first app panel index.
- EXPECT_EQ(12, model_->FirstPanelIndex());
-
- EXPECT_EQ(TYPE_BROWSER_SHORTCUT, model_->items()[1].type);
- EXPECT_EQ(TYPE_APP_LIST, model_->items()[model_->FirstPanelIndex() - 1].type);
-}
-
-// Assertions around id generation and usage.
-TEST_F(LauncherModelTest, LauncherIDTests) {
- // Get the next to use ID counter.
- LauncherID id = model_->next_id();
-
- // Calling this function multiple times does not change the returned ID.
- EXPECT_EQ(model_->next_id(), id);
-
- // Check that when we reserve a value it will be the previously retrieved ID,
- // but it will not change the item count and retrieving the next ID should
- // produce something new.
- EXPECT_EQ(model_->reserve_external_id(), id);
- EXPECT_EQ(1, model_->item_count());
- LauncherID id2 = model_->next_id();
- EXPECT_NE(id2, id);
-
- // Adding another item to the list should also produce a new ID.
- LauncherItem item;
- item.type = TYPE_PLATFORM_APP;
- model_->Add(item);
- EXPECT_NE(model_->next_id(), id2);
-}
-
-// This verifies that converting an existing item into a lower weight category
-// (e.g. shortcut to running but not pinned app) will move it to the proper
-// location. See crbug.com/248769.
-TEST_F(LauncherModelTest, CorrectMoveItemsWhenStateChange) {
- // The first item is the app list and last item is the browser.
- LauncherItem browser_shortcut;
- browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
- int browser_shortcut_index = model_->Add(browser_shortcut);
- EXPECT_EQ(TYPE_APP_LIST, model_->items()[0].type);
- EXPECT_EQ(1, browser_shortcut_index);
-
- // Add three shortcuts. They should all be moved between the two.
- LauncherItem item;
- item.type = TYPE_APP_SHORTCUT;
- int app1_index = model_->Add(item);
- EXPECT_EQ(2, app1_index);
- int app2_index = model_->Add(item);
- EXPECT_EQ(3, app2_index);
- int app3_index = model_->Add(item);
- EXPECT_EQ(4, app3_index);
-
- // Now change the type of the second item and make sure that it is moving
- // behind the shortcuts.
- item.type = TYPE_PLATFORM_APP;
- model_->Set(app2_index, item);
-
- // The item should have moved in front of the app launcher.
- EXPECT_EQ(TYPE_PLATFORM_APP, model_->items()[4].type);
-}
-
-TEST_F(LauncherModelTest, CorrectMoveItemsWhenStateChangeForLegacyShelfLayout) {
- CommandLine::ForCurrentProcess()->AppendSwitch(
- ash::switches::kAshDisableAlternateShelfLayout);
-
- // The first item is the browser and the second item is app list.
- LauncherItem browser_shortcut;
- browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
- int browser_shortcut_index = model_->Add(browser_shortcut);
- EXPECT_EQ(0, browser_shortcut_index);
- EXPECT_EQ(TYPE_APP_LIST, model_->items()[1].type);
-
- // Add three shortcuts. They should all be moved between the two.
- LauncherItem item;
- item.type = TYPE_APP_SHORTCUT;
- int app1_index = model_->Add(item);
- EXPECT_EQ(1, app1_index);
- int app2_index = model_->Add(item);
- EXPECT_EQ(2, app2_index);
- int app3_index = model_->Add(item);
- EXPECT_EQ(3, app3_index);
-
- // Now change the type of the second item and make sure that it is moving
- // behind the shortcuts.
- item.type = TYPE_PLATFORM_APP;
- model_->Set(app2_index, item);
-
- // The item should have moved in front of the app launcher.
- EXPECT_EQ(TYPE_PLATFORM_APP, model_->items()[3].type);
-}
-
-} // namespace ash
diff --git a/ash/launcher/launcher_unittest.cc b/ash/launcher/launcher_unittest.cc
index 3e72f6d..32dafb6 100644
--- a/ash/launcher/launcher_unittest.cc
+++ b/ash/launcher/launcher_unittest.cc
@@ -5,7 +5,7 @@
#include "ash/launcher/launcher.h"
#include "ash/launcher/launcher_button.h"
#include "ash/launcher/launcher_item_delegate_manager.h"
-#include "ash/launcher/launcher_model.h"
+#include "ash/shelf/shelf_model.h"
#include "ash/shelf/shelf_view.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
@@ -35,7 +35,7 @@ class LauncherTest : public ash::test::AshTestBase {
public:
LauncherTest() : launcher_(NULL),
shelf_view_(NULL),
- launcher_model_(NULL),
+ shelf_model_(NULL),
item_delegate_manager_(NULL) {
}
@@ -49,7 +49,7 @@ class LauncherTest : public ash::test::AshTestBase {
ash::test::LauncherTestAPI test(launcher_);
shelf_view_ = test.shelf_view();
- launcher_model_ = shelf_view_->model();
+ shelf_model_ = shelf_view_->model();
item_delegate_manager_ =
Shell::GetInstance()->launcher_item_delegate_manager();
@@ -68,8 +68,8 @@ class LauncherTest : public ash::test::AshTestBase {
return shelf_view_;
}
- LauncherModel* launcher_model() {
- return launcher_model_;
+ ShelfModel* shelf_model() {
+ return shelf_model_;
}
LauncherItemDelegateManager* item_manager() {
@@ -83,7 +83,7 @@ class LauncherTest : public ash::test::AshTestBase {
private:
Launcher* launcher_;
ShelfView* shelf_view_;
- LauncherModel* launcher_model_;
+ ShelfModel* shelf_model_;
LauncherItemDelegateManager* item_delegate_manager_;
scoped_ptr<ash::test::ShelfViewTestAPI> test_;
@@ -99,13 +99,13 @@ TEST_F(LauncherTest, StatusReflection) {
LauncherItem item;
item.type = TYPE_PLATFORM_APP;
item.status = STATUS_RUNNING;
- int index = launcher_model()->Add(item);
+ int index = shelf_model()->Add(item);
ASSERT_EQ(++button_count, test_api()->GetButtonCount());
LauncherButton* button = test_api()->GetButton(index);
EXPECT_EQ(LauncherButton::STATE_RUNNING, button->state());
// Remove it.
- launcher_model()->RemoveItemAt(index);
+ shelf_model()->RemoveItemAt(index);
ASSERT_EQ(--button_count, test_api()->GetButtonCount());
}
@@ -119,11 +119,11 @@ TEST_F(LauncherTest, checkHoverAfterMenu) {
LauncherItem item;
item.type = TYPE_PLATFORM_APP;
item.status = STATUS_RUNNING;
- int index = launcher_model()->Add(item);
+ int index = shelf_model()->Add(item);
scoped_ptr<LauncherItemDelegate> delegate(
new ash::test::TestLauncherItemDelegate(NULL));
- item_manager()->SetLauncherItemDelegate(launcher_model()->items()[index].id,
+ item_manager()->SetLauncherItemDelegate(shelf_model()->items()[index].id,
delegate.Pass());
ASSERT_EQ(++button_count, test_api()->GetButtonCount());
@@ -133,11 +133,11 @@ TEST_F(LauncherTest, checkHoverAfterMenu) {
EXPECT_FALSE(button->state() & LauncherButton::STATE_HOVERED);
// Remove it.
- launcher_model()->RemoveItemAt(index);
+ shelf_model()->RemoveItemAt(index);
}
TEST_F(LauncherTest, ShowOverflowBubble) {
- LauncherID first_item_id = launcher_model()->next_id();
+ LauncherID first_item_id = shelf_model()->next_id();
// Add platform app button until overflow.
int items_added = 0;
@@ -145,7 +145,7 @@ TEST_F(LauncherTest, ShowOverflowBubble) {
LauncherItem item;
item.type = TYPE_PLATFORM_APP;
item.status = STATUS_RUNNING;
- launcher_model()->Add(item);
+ shelf_model()->Add(item);
++items_added;
ASSERT_LT(items_added, 10000);
@@ -156,8 +156,7 @@ TEST_F(LauncherTest, ShowOverflowBubble) {
EXPECT_TRUE(launcher()->IsShowingOverflowBubble());
// Removes the first item in main shelf view.
- launcher_model()->RemoveItemAt(
- launcher_model()->ItemIndexByID(first_item_id));
+ shelf_model()->RemoveItemAt(shelf_model()->ItemIndexByID(first_item_id));
// Waits for all transitions to finish and there should be no crash.
test_api()->RunMessageLoopUntilAnimationsDone();