dbus: Remove MockShillDeviceClient and MockShillIPConfigClient
[chromium-blink-merge.git] / ash / test / test_launcher_delegate.cc
blob98f1db0f10a8dd26316af5fdbbc7261bd8c4ccd9
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
3 // found in the LICENSE file.
5 #include "ash/test/test_launcher_delegate.h"
7 #include "ash/launcher/launcher_item_delegate_manager.h"
8 #include "ash/launcher/launcher_model.h"
9 #include "ash/shelf/shelf_util.h"
10 #include "ash/shell.h"
11 #include "ash/test/test_launcher_item_delegate.h"
12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "grit/ash_resources.h"
15 #include "ui/aura/window.h"
17 namespace ash {
18 namespace test {
20 TestLauncherDelegate* TestLauncherDelegate::instance_ = NULL;
22 TestLauncherDelegate::TestLauncherDelegate(LauncherModel* model)
23 : model_(model) {
24 CHECK(!instance_);
25 instance_ = this;
28 TestLauncherDelegate::~TestLauncherDelegate() {
29 instance_ = NULL;
32 void TestLauncherDelegate::AddLauncherItem(aura::Window* window) {
33 AddLauncherItem(window, STATUS_CLOSED);
36 void TestLauncherDelegate::AddLauncherItem(
37 aura::Window* window,
38 LauncherItemStatus status) {
39 ash::LauncherItem item;
40 if (window->type() == aura::client::WINDOW_TYPE_PANEL)
41 item.type = ash::TYPE_APP_PANEL;
42 else
43 item.type = ash::TYPE_PLATFORM_APP;
44 DCHECK(window_to_id_.find(window) == window_to_id_.end());
45 window_to_id_[window] = model_->next_id();
46 item.status = status;
47 model_->Add(item);
48 window->AddObserver(this);
50 ash::LauncherItemDelegateManager* manager =
51 ash::Shell::GetInstance()->launcher_item_delegate_manager();
52 // |manager| owns TestLauncherItemDelegate.
53 scoped_ptr<LauncherItemDelegate> delegate(
54 new TestLauncherItemDelegate(window));
55 manager->SetLauncherItemDelegate(window_to_id_[window], delegate.Pass());
58 void TestLauncherDelegate::RemoveLauncherItemForWindow(aura::Window* window) {
59 ash::LauncherID id = GetIDByWindow(window);
60 if (id == 0)
61 return;
62 int index = model_->ItemIndexByID(id);
63 DCHECK_NE(-1, index);
64 model_->RemoveItemAt(index);
65 window_to_id_.erase(window);
66 window->RemoveObserver(this);
69 void TestLauncherDelegate::OnWindowDestroying(aura::Window* window) {
70 RemoveLauncherItemForWindow(window);
73 void TestLauncherDelegate::OnWindowHierarchyChanging(
74 const HierarchyChangeParams& params) {
75 // The window may be legitimately reparented while staying open if it moves
76 // to another display or container. If the window does not have a new parent
77 // then remove the launcher item.
78 if (!params.new_parent)
79 RemoveLauncherItemForWindow(params.target);
82 ash::LauncherID TestLauncherDelegate::GetIDByWindow(aura::Window* window) {
83 WindowToID::const_iterator found = window_to_id_.find(window);
84 if (found == window_to_id_.end())
85 return 0;
86 return found->second;
89 void TestLauncherDelegate::OnLauncherCreated(Launcher* launcher) {
92 void TestLauncherDelegate::OnLauncherDestroyed(Launcher* launcher) {
95 LauncherID TestLauncherDelegate::GetLauncherIDForAppID(
96 const std::string& app_id) {
97 return 0;
100 const std::string& TestLauncherDelegate::GetAppIDForLauncherID(LauncherID id) {
101 return EmptyString();
104 void TestLauncherDelegate::PinAppWithID(const std::string& app_id) {
107 bool TestLauncherDelegate::CanPin() const {
108 return true;
111 bool TestLauncherDelegate::IsAppPinned(const std::string& app_id) {
112 return false;
115 void TestLauncherDelegate::UnpinAppWithID(const std::string& app_id) {
118 } // namespace test
119 } // namespace ash