| OLD | NEW |
| 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 "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/ash_switches.h" | 11 #include "ash/ash_switches.h" |
| 12 #include "ash/launcher/launcher_item_delegate_manager.h" | 12 #include "ash/launcher/launcher_item_delegate_manager.h" |
| 13 #include "ash/launcher/launcher_model.h" | 13 #include "ash/launcher/launcher_model.h" |
| 14 #include "ash/launcher/launcher_model_observer.h" | 14 #include "ash/shelf/shelf_model_observer.h" |
| 15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "ash/test/launcher_item_delegate_manager_test_api.h" | 16 #include "ash/test/launcher_item_delegate_manager_test_api.h" |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
| 19 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
| 20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/values.h" | 23 #include "base/values.h" |
| 24 #include "chrome/browser/extensions/extension_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 78 |
| 79 // As defined in /chromeos/dbus/cryptohome_client.cc. | 79 // As defined in /chromeos/dbus/cryptohome_client.cc. |
| 80 const char kUserIdHashSuffix[] = "-hash"; | 80 const char kUserIdHashSuffix[] = "-hash"; |
| 81 | 81 |
| 82 // An extension prefix. | 82 // An extension prefix. |
| 83 const char kCrxAppPrefix[] = "_crx_"; | 83 const char kCrxAppPrefix[] = "_crx_"; |
| 84 } | 84 } |
| 85 | 85 |
| 86 namespace { | 86 namespace { |
| 87 | 87 |
| 88 // LauncherModelObserver implementation that tracks what messages are invoked. | 88 // ShelfModelObserver implementation that tracks what messages are invoked. |
| 89 class TestLauncherModelObserver : public ash::LauncherModelObserver { | 89 class TestShelfModelObserver : public ash::ShelfModelObserver { |
| 90 public: | 90 public: |
| 91 TestLauncherModelObserver() | 91 TestShelfModelObserver() |
| 92 : added_(0), | 92 : added_(0), |
| 93 removed_(0), | 93 removed_(0), |
| 94 changed_(0) { | 94 changed_(0) { |
| 95 } | 95 } |
| 96 | 96 |
| 97 virtual ~TestLauncherModelObserver() { | 97 virtual ~TestShelfModelObserver() { |
| 98 } | 98 } |
| 99 | 99 |
| 100 // LauncherModelObserver | 100 // Overridden from ash::ShelfModelObserver: |
| 101 virtual void LauncherItemAdded(int index) OVERRIDE { | 101 virtual void ShelfItemAdded(int index) OVERRIDE { |
| 102 ++added_; | 102 ++added_; |
| 103 last_index_ = index; | 103 last_index_ = index; |
| 104 } | 104 } |
| 105 | 105 |
| 106 virtual void LauncherItemRemoved(int index, ash::LauncherID id) OVERRIDE { | 106 virtual void ShelfItemRemoved(int index, ash::LauncherID id) OVERRIDE { |
| 107 ++removed_; | 107 ++removed_; |
| 108 last_index_ = index; | 108 last_index_ = index; |
| 109 } | 109 } |
| 110 | 110 |
| 111 virtual void LauncherItemChanged(int index, | 111 virtual void ShelfItemChanged(int index, |
| 112 const ash::LauncherItem& old_item) OVERRIDE { | 112 const ash::LauncherItem& old_item) OVERRIDE { |
| 113 ++changed_; | 113 ++changed_; |
| 114 last_index_ = index; | 114 last_index_ = index; |
| 115 } | 115 } |
| 116 | 116 |
| 117 virtual void LauncherItemMoved(int start_index, int target_index) OVERRIDE { | 117 virtual void ShelfItemMoved(int start_index, int target_index) OVERRIDE { |
| 118 last_index_ = target_index; | 118 last_index_ = target_index; |
| 119 } | 119 } |
| 120 | 120 |
| 121 virtual void LauncherStatusChanged() OVERRIDE { | 121 virtual void ShelfStatusChanged() OVERRIDE { |
| 122 } | 122 } |
| 123 | 123 |
| 124 void clear_counts() { | 124 void clear_counts() { |
| 125 added_ = 0; | 125 added_ = 0; |
| 126 removed_ = 0; | 126 removed_ = 0; |
| 127 changed_ = 0; | 127 changed_ = 0; |
| 128 last_index_ = 0; | 128 last_index_ = 0; |
| 129 } | 129 } |
| 130 | 130 |
| 131 int added() const { return added_; } | 131 int added() const { return added_; } |
| 132 int removed() const { return removed_; } | 132 int removed() const { return removed_; } |
| 133 int changed() const { return changed_; } | 133 int changed() const { return changed_; } |
| 134 int last_index() const { return last_index_; } | 134 int last_index() const { return last_index_; } |
| 135 | 135 |
| 136 private: | 136 private: |
| 137 int added_; | 137 int added_; |
| 138 int removed_; | 138 int removed_; |
| 139 int changed_; | 139 int changed_; |
| 140 int last_index_; | 140 int last_index_; |
| 141 | 141 |
| 142 DISALLOW_COPY_AND_ASSIGN(TestLauncherModelObserver); | 142 DISALLOW_COPY_AND_ASSIGN(TestShelfModelObserver); |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 // Test implementation of AppIconLoader. | 145 // Test implementation of AppIconLoader. |
| 146 class TestAppIconLoaderImpl : public extensions::AppIconLoader { | 146 class TestAppIconLoaderImpl : public extensions::AppIconLoader { |
| 147 public: | 147 public: |
| 148 TestAppIconLoaderImpl() : fetch_count_(0) { | 148 TestAppIconLoaderImpl() : fetch_count_(0) { |
| 149 } | 149 } |
| 150 | 150 |
| 151 virtual ~TestAppIconLoaderImpl() { | 151 virtual ~TestAppIconLoaderImpl() { |
| 152 } | 152 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 SetHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH); | 265 SetHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH); |
| 266 } | 266 } |
| 267 | 267 |
| 268 virtual ~ChromeLauncherControllerTest() { | 268 virtual ~ChromeLauncherControllerTest() { |
| 269 } | 269 } |
| 270 | 270 |
| 271 virtual void SetUp() OVERRIDE { | 271 virtual void SetUp() OVERRIDE { |
| 272 BrowserWithTestWindowTest::SetUp(); | 272 BrowserWithTestWindowTest::SetUp(); |
| 273 | 273 |
| 274 model_.reset(new ash::LauncherModel); | 274 model_.reset(new ash::LauncherModel); |
| 275 model_observer_.reset(new TestLauncherModelObserver); | 275 model_observer_.reset(new TestShelfModelObserver); |
| 276 model_->AddObserver(model_observer_.get()); | 276 model_->AddObserver(model_observer_.get()); |
| 277 | 277 |
| 278 if (ash::Shell::HasInstance()) { | 278 if (ash::Shell::HasInstance()) { |
| 279 item_delegate_manager_ = | 279 item_delegate_manager_ = |
| 280 ash::Shell::GetInstance()->launcher_item_delegate_manager(); | 280 ash::Shell::GetInstance()->launcher_item_delegate_manager(); |
| 281 } else { | 281 } else { |
| 282 item_delegate_manager_ = | 282 item_delegate_manager_ = |
| 283 new ash::LauncherItemDelegateManager(model_.get()); | 283 new ash::LauncherItemDelegateManager(model_.get()); |
| 284 } | 284 } |
| 285 | 285 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 // Needed for extension service & friends to work. | 583 // Needed for extension service & friends to work. |
| 584 scoped_refptr<Extension> extension1_; | 584 scoped_refptr<Extension> extension1_; |
| 585 scoped_refptr<Extension> extension2_; | 585 scoped_refptr<Extension> extension2_; |
| 586 scoped_refptr<Extension> extension3_; | 586 scoped_refptr<Extension> extension3_; |
| 587 scoped_refptr<Extension> extension4_; | 587 scoped_refptr<Extension> extension4_; |
| 588 scoped_refptr<Extension> extension5_; | 588 scoped_refptr<Extension> extension5_; |
| 589 scoped_refptr<Extension> extension6_; | 589 scoped_refptr<Extension> extension6_; |
| 590 scoped_refptr<Extension> extension7_; | 590 scoped_refptr<Extension> extension7_; |
| 591 scoped_refptr<Extension> extension8_; | 591 scoped_refptr<Extension> extension8_; |
| 592 scoped_ptr<ChromeLauncherController> launcher_controller_; | 592 scoped_ptr<ChromeLauncherController> launcher_controller_; |
| 593 scoped_ptr<TestLauncherModelObserver> model_observer_; | 593 scoped_ptr<TestShelfModelObserver> model_observer_; |
| 594 scoped_ptr<ash::LauncherModel> model_; | 594 scoped_ptr<ash::LauncherModel> model_; |
| 595 | 595 |
| 596 // |item_delegate_manager_| owns |test_controller_|. | 596 // |item_delegate_manager_| owns |test_controller_|. |
| 597 LauncherItemController* test_controller_; | 597 LauncherItemController* test_controller_; |
| 598 | 598 |
| 599 ExtensionService* extension_service_; | 599 ExtensionService* extension_service_; |
| 600 | 600 |
| 601 ash::LauncherItemDelegateManager* item_delegate_manager_; | 601 ash::LauncherItemDelegateManager* item_delegate_manager_; |
| 602 | 602 |
| 603 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); | 603 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); |
| (...skipping 1985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2589 | 2589 |
| 2590 EXPECT_EQ(1, app_icon_loader->fetch_count()); | 2590 EXPECT_EQ(1, app_icon_loader->fetch_count()); |
| 2591 ASSERT_EQ(initial_size + 1, model_->items().size()); | 2591 ASSERT_EQ(initial_size + 1, model_->items().size()); |
| 2592 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); | 2592 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); |
| 2593 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); | 2593 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); |
| 2594 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); | 2594 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); |
| 2595 | 2595 |
| 2596 launcher_controller_->UnpinAppWithID("1"); | 2596 launcher_controller_->UnpinAppWithID("1"); |
| 2597 ASSERT_EQ(initial_size, model_->items().size()); | 2597 ASSERT_EQ(initial_size, model_->items().size()); |
| 2598 } | 2598 } |
| OLD | NEW |