| OLD | NEW |
| 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 "chrome/browser/ui/views/ash/launcher/launcher_updater.h" | 5 #include "chrome/browser/ui/views/ash/launcher/launcher_updater.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "ash/launcher/launcher_model.h" | 10 #include "ash/launcher/launcher_model.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 13 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.h" | 13 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.h" |
| 14 #include "chrome/browser/tabs/tab_strip_model.h" | 14 #include "chrome/browser/tabs/tab_strip_model.h" |
| 15 #include "chrome/browser/tabs/test_tab_strip_model_delegate.h" | 15 #include "chrome/browser/tabs/test_tab_strip_model_delegate.h" |
| 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 18 #include "content/browser/tab_contents/test_tab_contents.h" | 18 #include "content/browser/tab_contents/test_tab_contents.h" |
| 19 #include "content/test/test_browser_thread.h" | 19 #include "content/test/test_browser_thread.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
| 22 #include "ui/aura/client/activation_delegate.h" |
| 23 #include "ui/aura/test/test_activation_client.h" |
| 24 #include "ui/aura/test/test_window_delegate.h" |
| 25 #include "ui/aura/root_window.h" |
| 22 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
| 27 #include "ui/aura/window_delegate.h" |
| 23 | 28 |
| 24 namespace { | 29 namespace { |
| 25 | 30 |
| 26 // Test implementation of AppIconLoader. | 31 // Test implementation of AppIconLoader. |
| 27 class AppIconLoaderImpl : public ChromeLauncherDelegate::AppIconLoader { | 32 class AppIconLoaderImpl : public ChromeLauncherDelegate::AppIconLoader { |
| 28 public: | 33 public: |
| 29 AppIconLoaderImpl() : fetch_count_(0) {} | 34 AppIconLoaderImpl() : fetch_count_(0) {} |
| 30 virtual ~AppIconLoaderImpl() {} | 35 virtual ~AppIconLoaderImpl() {} |
| 31 | 36 |
| 32 // Sets the id for the specified tab. The id is removed if Remove() is | 37 // Sets the id for the specified tab. The id is removed if Remove() is |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 private: | 75 private: |
| 71 typedef std::map<TabContentsWrapper*, std::string> TabToStringMap; | 76 typedef std::map<TabContentsWrapper*, std::string> TabToStringMap; |
| 72 | 77 |
| 73 TabToStringMap tab_id_map_; | 78 TabToStringMap tab_id_map_; |
| 74 | 79 |
| 75 int fetch_count_; | 80 int fetch_count_; |
| 76 | 81 |
| 77 DISALLOW_COPY_AND_ASSIGN(AppIconLoaderImpl); | 82 DISALLOW_COPY_AND_ASSIGN(AppIconLoaderImpl); |
| 78 }; | 83 }; |
| 79 | 84 |
| 80 // Contains all the objects needed to create a LauncherUpdater. | |
| 81 struct State { | |
| 82 State(Profile* profile, | |
| 83 ChromeLauncherDelegate* launcher_delegate, | |
| 84 const std::string& app_id, | |
| 85 LauncherUpdater::Type launcher_type) | |
| 86 : window(NULL), | |
| 87 tab_strip(&tab_strip_delegate, profile), | |
| 88 updater(&window, &tab_strip, launcher_delegate, launcher_type, | |
| 89 app_id) { | |
| 90 updater.Init(); | |
| 91 } | |
| 92 | |
| 93 aura::Window window; | |
| 94 TestTabStripModelDelegate tab_strip_delegate; | |
| 95 TabStripModel tab_strip; | |
| 96 LauncherUpdater updater; | |
| 97 | |
| 98 private: | |
| 99 DISALLOW_COPY_AND_ASSIGN(State); | |
| 100 }; | |
| 101 | |
| 102 } // namespace | 85 } // namespace |
| 103 | 86 |
| 104 class LauncherUpdaterTest : public ChromeRenderViewHostTestHarness { | 87 class LauncherUpdaterTest : public ChromeRenderViewHostTestHarness { |
| 105 public: | 88 public: |
| 106 LauncherUpdaterTest() | 89 LauncherUpdaterTest() |
| 107 : browser_thread_(content::BrowserThread::UI, &message_loop_) { | 90 : browser_thread_(content::BrowserThread::UI, &message_loop_) { |
| 108 } | 91 } |
| 109 | 92 |
| 110 virtual void SetUp() OVERRIDE { | 93 virtual void SetUp() OVERRIDE { |
| 111 ChromeRenderViewHostTestHarness::SetUp(); | 94 ChromeRenderViewHostTestHarness::SetUp(); |
| 95 |
| 96 activation_client_.reset( |
| 97 new aura::test::TestActivationClient(root_window())); |
| 112 launcher_model_.reset(new ash::LauncherModel); | 98 launcher_model_.reset(new ash::LauncherModel); |
| 113 launcher_delegate_.reset( | 99 launcher_delegate_.reset( |
| 114 new ChromeLauncherDelegate(profile(), launcher_model_.get())); | 100 new ChromeLauncherDelegate(profile(), launcher_model_.get())); |
| 115 app_icon_loader_ = new AppIconLoaderImpl; | 101 app_icon_loader_ = new AppIconLoaderImpl; |
| 116 launcher_delegate_->SetAppIconLoaderForTest(app_icon_loader_); | 102 launcher_delegate_->SetAppIconLoaderForTest(app_icon_loader_); |
| 117 launcher_delegate_->Init(); | 103 launcher_delegate_->Init(); |
| 118 } | 104 } |
| 119 | 105 |
| 120 protected: | 106 protected: |
| 107 // Contains all the objects needed to create a LauncherUpdater. |
| 108 struct State : public aura::client::ActivationDelegate { |
| 109 public: |
| 110 State(LauncherUpdaterTest* test, |
| 111 const std::string& app_id, |
| 112 LauncherUpdater::Type launcher_type) |
| 113 : launcher_test(test), |
| 114 window(NULL), |
| 115 tab_strip(&tab_strip_delegate, test->profile()), |
| 116 updater(&window, |
| 117 &tab_strip, |
| 118 test->launcher_delegate_.get(), |
| 119 launcher_type, |
| 120 app_id) { |
| 121 window.Init(ui::Layer::LAYER_NOT_DRAWN); |
| 122 launcher_test->root_window()->AddChild(&window); |
| 123 launcher_test->activation_client_->ActivateWindow(&window); |
| 124 updater.Init(); |
| 125 aura::client::SetActivationDelegate(&window, this); |
| 126 } |
| 127 |
| 128 ash::LauncherItem GetUpdaterItem() { |
| 129 ash::LauncherID launcher_id = |
| 130 LauncherUpdater::TestApi(&updater).item_id(); |
| 131 int index = launcher_test->launcher_model_->ItemIndexByID(launcher_id); |
| 132 return launcher_test->launcher_model_->items()[index]; |
| 133 } |
| 134 |
| 135 // aura::client::ActivationDelegate overrides. |
| 136 virtual bool ShouldActivate(aura::Event* event) { return true; } |
| 137 virtual void OnActivated() { |
| 138 updater.BrowserActivationStateChanged(); |
| 139 } |
| 140 virtual void OnLostActive() { |
| 141 updater.BrowserActivationStateChanged(); |
| 142 } |
| 143 |
| 144 LauncherUpdaterTest* launcher_test; |
| 145 aura::Window window; |
| 146 TestTabStripModelDelegate tab_strip_delegate; |
| 147 TabStripModel tab_strip; |
| 148 LauncherUpdater updater; |
| 149 |
| 150 private: |
| 151 DISALLOW_COPY_AND_ASSIGN(State); |
| 152 }; |
| 153 |
| 121 LauncherUpdater* GetUpdaterByID(ash::LauncherID id) const { | 154 LauncherUpdater* GetUpdaterByID(ash::LauncherID id) const { |
| 122 return launcher_delegate_->id_to_item_map_[id].updater; | 155 return launcher_delegate_->id_to_item_map_[id].updater; |
| 123 } | 156 } |
| 124 | 157 |
| 125 const std::string& GetAppID(ash::LauncherID id) const { | 158 const std::string& GetAppID(ash::LauncherID id) const { |
| 126 return launcher_delegate_->id_to_item_map_[id].app_id; | 159 return launcher_delegate_->id_to_item_map_[id].app_id; |
| 127 } | 160 } |
| 128 | 161 |
| 129 void ResetAppIconLoader() { | 162 void ResetAppIconLoader() { |
| 130 launcher_delegate_->SetAppIconLoaderForTest(app_icon_loader_); | 163 launcher_delegate_->SetAppIconLoaderForTest(app_icon_loader_); |
| 131 } | 164 } |
| 132 | 165 |
| 133 void UnpinAppsWithID(const std::string& app_id) { | 166 void UnpinAppsWithID(const std::string& app_id) { |
| 134 launcher_delegate_->UnpinAppsWithID(app_id); | 167 launcher_delegate_->UnpinAppsWithID(app_id); |
| 135 } | 168 } |
| 136 | 169 |
| 170 ash::LauncherItem GetItem(LauncherUpdater& updater, |
| 171 TabContentsWrapper* tab) { |
| 172 LauncherUpdater::TestApi test_api(&updater); |
| 173 ash::LauncherID launcher_id = test_api.GetLauncherID(tab); |
| 174 int index = launcher_model_->ItemIndexByID(launcher_id); |
| 175 return launcher_model_->items()[index]; |
| 176 } |
| 177 |
| 137 scoped_ptr<ash::LauncherModel> launcher_model_; | 178 scoped_ptr<ash::LauncherModel> launcher_model_; |
| 138 scoped_ptr<ChromeLauncherDelegate> launcher_delegate_; | 179 scoped_ptr<ChromeLauncherDelegate> launcher_delegate_; |
| 139 | 180 |
| 140 // Owned by LauncherUpdater. | 181 // Owned by LauncherUpdater. |
| 141 AppIconLoaderImpl* app_icon_loader_; | 182 AppIconLoaderImpl* app_icon_loader_; |
| 142 | 183 |
| 184 scoped_ptr<aura::test::TestActivationClient> activation_client_; |
| 185 |
| 143 private: | 186 private: |
| 144 content::TestBrowserThread browser_thread_; | 187 content::TestBrowserThread browser_thread_; |
| 188 std::vector<State*> states; |
| 145 | 189 |
| 146 DISALLOW_COPY_AND_ASSIGN(LauncherUpdaterTest); | 190 DISALLOW_COPY_AND_ASSIGN(LauncherUpdaterTest); |
| 147 }; | 191 }; |
| 148 | 192 |
| 149 // Verifies a new launcher item is added for TYPE_TABBED. | 193 // Verifies a new launcher item is added for TYPE_TABBED. |
| 150 TEST_F(LauncherUpdaterTest, TabbedSetup) { | 194 TEST_F(LauncherUpdaterTest, TabbedSetup) { |
| 151 size_t initial_size = launcher_model_->items().size(); | 195 size_t initial_size = launcher_model_->items().size(); |
| 152 { | 196 { |
| 153 TabContentsWrapper wrapper(CreateTestTabContents()); | 197 TabContentsWrapper wrapper(CreateTestTabContents()); |
| 154 State state(profile(), launcher_delegate_.get(), std::string(), | 198 State state(this, std::string(), LauncherUpdater::TYPE_TABBED); |
| 155 LauncherUpdater::TYPE_TABBED); | 199 |
| 156 // Since the type is tabbed and there is nothing in the tabstrip an item | 200 // Since the type is tabbed and there is nothing in the tabstrip an item |
| 157 // should not have been added. | 201 // should not have been added. |
| 158 EXPECT_EQ(initial_size, launcher_model_->items().size()); | 202 EXPECT_EQ(initial_size, launcher_model_->items().size()); |
| 159 | 203 |
| 160 // Add a tab. | 204 // Add a tab. |
| 161 state.tab_strip.InsertTabContentsAt(0, &wrapper, TabStripModel::ADD_NONE); | 205 state.tab_strip.InsertTabContentsAt(0, &wrapper, TabStripModel::ADD_ACTIVE); |
| 162 | 206 |
| 163 // There should be one more item. | 207 // There should be one more item. |
| 164 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 208 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 165 // New item should be added at the end. | 209 // New item should be added at the end. |
| 166 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); | 210 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); |
| 167 } | 211 } |
| 168 // Deleting the LauncherUpdater should have removed the item. | 212 // Deleting the LauncherUpdater should have removed the item. |
| 169 ASSERT_EQ(initial_size, launcher_model_->items().size()); | 213 ASSERT_EQ(initial_size, launcher_model_->items().size()); |
| 170 | 214 |
| 171 // Do the same, but this time add the tab first. | 215 // Do the same, but this time add the tab first. |
| 172 { | 216 { |
| 173 TabContentsWrapper wrapper(CreateTestTabContents()); | 217 TabContentsWrapper wrapper(CreateTestTabContents()); |
| 174 | 218 |
| 175 TestTabStripModelDelegate tab_strip_delegate; | 219 TestTabStripModelDelegate tab_strip_delegate; |
| 176 TabStripModel tab_strip(&tab_strip_delegate, profile()); | 220 TabStripModel tab_strip(&tab_strip_delegate, profile()); |
| 177 tab_strip.InsertTabContentsAt(0, &wrapper, TabStripModel::ADD_NONE); | 221 tab_strip.InsertTabContentsAt(0, &wrapper, TabStripModel::ADD_ACTIVE); |
| 178 LauncherUpdater updater(NULL, &tab_strip, launcher_delegate_.get(), | 222 aura::Window window(NULL); |
| 223 window.Init(ui::Layer::LAYER_NOT_DRAWN); |
| 224 root_window()->AddChild(&window); |
| 225 LauncherUpdater updater(&window, &tab_strip, launcher_delegate_.get(), |
| 179 LauncherUpdater::TYPE_TABBED, std::string()); | 226 LauncherUpdater::TYPE_TABBED, std::string()); |
| 180 updater.Init(); | 227 updater.Init(); |
| 181 | 228 |
| 182 // There should be one more item. | 229 // There should be one more item. |
| 183 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 230 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 184 // New item should be added at the end. | 231 // New item should be added at the end. |
| 185 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); | 232 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); |
| 186 } | 233 } |
| 187 } | 234 } |
| 188 | 235 |
| 189 // Verifies a new launcher item is added for TYPE_APP. | 236 // Verifies a new launcher item is added for TYPE_APP. |
| 190 TEST_F(LauncherUpdaterTest, AppSetup) { | 237 TEST_F(LauncherUpdaterTest, AppSetup) { |
| 191 size_t initial_size = launcher_model_->items().size(); | 238 size_t initial_size = launcher_model_->items().size(); |
| 192 { | 239 { |
| 193 State state(profile(), launcher_delegate_.get(), std::string(), | 240 State state(this, std::string(), LauncherUpdater::TYPE_APP); |
| 194 LauncherUpdater::TYPE_APP); | |
| 195 // There should be one more item. | 241 // There should be one more item. |
| 196 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 242 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 197 // New item should be added at the end. | 243 // New item should be added at the end. |
| 198 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); | 244 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); |
| 199 } | 245 } |
| 200 // Deleting the LauncherUpdater should have removed the item. | 246 // Deleting the LauncherUpdater should have removed the item. |
| 201 ASSERT_EQ(initial_size, launcher_model_->items().size()); | 247 ASSERT_EQ(initial_size, launcher_model_->items().size()); |
| 202 } | 248 } |
| 203 | 249 |
| 204 // Various assertions when adding/removing a tab that has an app associated with | 250 // Various assertions when adding/removing a tab that has an app associated with |
| 205 // it. | 251 // it. |
| 206 TEST_F(LauncherUpdaterTest, TabbedWithApp) { | 252 TEST_F(LauncherUpdaterTest, TabbedWithApp) { |
| 207 size_t initial_size = launcher_model_->items().size(); | 253 size_t initial_size = launcher_model_->items().size(); |
| 208 { | 254 { |
| 209 TabContentsWrapper initial_tab(CreateTestTabContents()); | 255 TabContentsWrapper initial_tab(CreateTestTabContents()); |
| 210 State state(profile(), launcher_delegate_.get(), std::string(), | 256 State state(this, std::string(), LauncherUpdater::TYPE_TABBED); |
| 211 LauncherUpdater::TYPE_TABBED); | |
| 212 // Add a tab. | 257 // Add a tab. |
| 213 state.tab_strip.InsertTabContentsAt(0, &initial_tab, | 258 state.tab_strip.InsertTabContentsAt(0, &initial_tab, |
| 214 TabStripModel::ADD_NONE); | 259 TabStripModel::ADD_ACTIVE); |
| 215 | 260 |
| 216 // There should be one more item. | 261 // There should be one more item. |
| 217 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 262 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 218 // New item should be added at the end. | 263 // New item should be added at the end. |
| 219 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); | 264 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); |
| 220 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id; | 265 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id; |
| 221 | 266 |
| 222 // Add another tab, configure it so that the launcher thinks it's an app. | 267 // Add another tab, configure it so that the launcher thinks it's an app. |
| 223 TabContentsWrapper app_tab(CreateTestTabContents()); | 268 TabContentsWrapper app_tab(CreateTestTabContents()); |
| 224 app_icon_loader_->SetAppID(&app_tab, "1"); | 269 app_icon_loader_->SetAppID(&app_tab, "1"); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 243 launcher_model_->items()[initial_size].type); | 288 launcher_model_->items()[initial_size].type); |
| 244 | 289 |
| 245 } | 290 } |
| 246 // Deleting the LauncherUpdater should have removed the item. | 291 // Deleting the LauncherUpdater should have removed the item. |
| 247 ASSERT_EQ(initial_size, launcher_model_->items().size()); | 292 ASSERT_EQ(initial_size, launcher_model_->items().size()); |
| 248 } | 293 } |
| 249 | 294 |
| 250 TEST_F(LauncherUpdaterTest, TabbedWithAppOnCreate) { | 295 TEST_F(LauncherUpdaterTest, TabbedWithAppOnCreate) { |
| 251 size_t initial_size = launcher_model_->items().size(); | 296 size_t initial_size = launcher_model_->items().size(); |
| 252 aura::Window window(NULL); | 297 aura::Window window(NULL); |
| 298 window.Init(ui::Layer::LAYER_NOT_DRAWN); |
| 299 root_window()->AddChild(&window); |
| 253 TestTabStripModelDelegate tab_strip_delegate; | 300 TestTabStripModelDelegate tab_strip_delegate; |
| 254 TabStripModel tab_strip(&tab_strip_delegate, profile()); | 301 TabStripModel tab_strip(&tab_strip_delegate, profile()); |
| 255 TabContentsWrapper app_tab(CreateTestTabContents()); | 302 TabContentsWrapper app_tab(CreateTestTabContents()); |
| 256 app_icon_loader_->SetAppID(&app_tab, "1"); | 303 app_icon_loader_->SetAppID(&app_tab, "1"); |
| 257 tab_strip.InsertTabContentsAt(0, &app_tab, TabStripModel::ADD_NONE); | 304 tab_strip.InsertTabContentsAt(0, &app_tab, TabStripModel::ADD_ACTIVE); |
| 258 LauncherUpdater updater(&window, &tab_strip, launcher_delegate_.get(), | 305 LauncherUpdater updater(&window, &tab_strip, launcher_delegate_.get(), |
| 259 LauncherUpdater::TYPE_TABBED, std::string()); | 306 LauncherUpdater::TYPE_TABBED, std::string()); |
| 260 updater.Init(); | 307 updater.Init(); |
| 261 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 308 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 262 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); | 309 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); |
| 263 } | 310 } |
| 264 | 311 |
| 265 // Verifies transitioning from a normal tab to app tab and back works. | 312 // Verifies transitioning from a normal tab to app tab and back works. |
| 266 TEST_F(LauncherUpdaterTest, ChangeToApp) { | 313 TEST_F(LauncherUpdaterTest, ChangeToApp) { |
| 267 size_t initial_size = launcher_model_->items().size(); | 314 size_t initial_size = launcher_model_->items().size(); |
| 268 { | 315 { |
| 269 TabContentsWrapper initial_tab(CreateTestTabContents()); | 316 TabContentsWrapper initial_tab(CreateTestTabContents()); |
| 270 State state(profile(), launcher_delegate_.get(), std::string(), | 317 State state(this, std::string(), LauncherUpdater::TYPE_TABBED); |
| 271 LauncherUpdater::TYPE_TABBED); | |
| 272 // Add a tab. | 318 // Add a tab. |
| 273 state.tab_strip.InsertTabContentsAt(0, &initial_tab, | 319 state.tab_strip.InsertTabContentsAt(0, &initial_tab, |
| 274 TabStripModel::ADD_NONE); | 320 TabStripModel::ADD_ACTIVE); |
| 275 | 321 |
| 276 // There should be one more item. | 322 // There should be one more item. |
| 277 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 323 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 278 // New item should be added at the end. | 324 // New item should be added at the end. |
| 279 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); | 325 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); |
| 280 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id; | 326 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id; |
| 281 | 327 |
| 282 app_icon_loader_->SetAppID(&initial_tab, "1"); | 328 app_icon_loader_->SetAppID(&initial_tab, "1"); |
| 283 // Triggers LauncherUpdater seeing the tab changed to an app. | 329 // Triggers LauncherUpdater seeing the tab changed to an app. |
| 284 state.updater.TabChangedAt(&initial_tab, 0, TabStripModelObserver::ALL); | 330 state.updater.TabChangedAt(&initial_tab, 0, TabStripModelObserver::ALL); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 295 } | 341 } |
| 296 // Deleting the LauncherUpdater should have removed the item. | 342 // Deleting the LauncherUpdater should have removed the item. |
| 297 ASSERT_EQ(initial_size, launcher_model_->items().size()); | 343 ASSERT_EQ(initial_size, launcher_model_->items().size()); |
| 298 } | 344 } |
| 299 | 345 |
| 300 // Verifies AppIconLoader is queried appropriately. | 346 // Verifies AppIconLoader is queried appropriately. |
| 301 TEST_F(LauncherUpdaterTest, QueryAppIconLoader) { | 347 TEST_F(LauncherUpdaterTest, QueryAppIconLoader) { |
| 302 size_t initial_size = launcher_model_->items().size(); | 348 size_t initial_size = launcher_model_->items().size(); |
| 303 { | 349 { |
| 304 TabContentsWrapper initial_tab(CreateTestTabContents()); | 350 TabContentsWrapper initial_tab(CreateTestTabContents()); |
| 305 State state(profile(), launcher_delegate_.get(), std::string(), | 351 State state(this, std::string(), LauncherUpdater::TYPE_TABBED); |
| 306 LauncherUpdater::TYPE_TABBED); | |
| 307 // Configure the tab as an app. | 352 // Configure the tab as an app. |
| 308 app_icon_loader_->SetAppID(&initial_tab, "1"); | 353 app_icon_loader_->SetAppID(&initial_tab, "1"); |
| 309 // Add a tab. | 354 // Add a tab. |
| 310 state.tab_strip.InsertTabContentsAt(0, &initial_tab, | 355 state.tab_strip.InsertTabContentsAt(0, &initial_tab, |
| 311 TabStripModel::ADD_NONE); | 356 TabStripModel::ADD_ACTIVE); |
| 312 // AppIconLoader should have been queried. | 357 // AppIconLoader should have been queried. |
| 313 EXPECT_GT(app_icon_loader_->GetAndClearFetchCount(), 0); | 358 EXPECT_GT(app_icon_loader_->GetAndClearFetchCount(), 0); |
| 314 // Remove the tab. | 359 // Remove the tab. |
| 315 state.tab_strip.DetachTabContentsAt(0); | 360 state.tab_strip.DetachTabContentsAt(0); |
| 316 } | 361 } |
| 317 // Deleting the LauncherUpdater should have removed the item. | 362 // Deleting the LauncherUpdater should have removed the item. |
| 318 ASSERT_EQ(initial_size, launcher_model_->items().size()); | 363 ASSERT_EQ(initial_size, launcher_model_->items().size()); |
| 319 } | 364 } |
| 320 | 365 |
| 321 // Verifies SetAppImage works. | 366 // Verifies SetAppImage works. |
| 322 TEST_F(LauncherUpdaterTest, SetAppImage) { | 367 TEST_F(LauncherUpdaterTest, SetAppImage) { |
| 323 size_t initial_size = launcher_model_->items().size(); | 368 size_t initial_size = launcher_model_->items().size(); |
| 324 TabContentsWrapper initial_tab(CreateTestTabContents()); | 369 TabContentsWrapper initial_tab(CreateTestTabContents()); |
| 325 State state(profile(), launcher_delegate_.get(), std::string(), | 370 State state(this, std::string(), LauncherUpdater::TYPE_TABBED); |
| 326 LauncherUpdater::TYPE_TABBED); | |
| 327 // Configure the tab as an app. | 371 // Configure the tab as an app. |
| 328 app_icon_loader_->SetAppID(&initial_tab, "1"); | 372 app_icon_loader_->SetAppID(&initial_tab, "1"); |
| 329 // Add a tab. | 373 // Add a tab. |
| 330 state.tab_strip.InsertTabContentsAt(0, &initial_tab, | 374 state.tab_strip.InsertTabContentsAt(0, &initial_tab, |
| 331 TabStripModel::ADD_NONE); | 375 TabStripModel::ADD_ACTIVE); |
| 332 SkBitmap image; | 376 SkBitmap image; |
| 333 image.setConfig(SkBitmap::kARGB_8888_Config, 2, 3); | 377 image.setConfig(SkBitmap::kARGB_8888_Config, 2, 3); |
| 334 image.allocPixels(); | 378 image.allocPixels(); |
| 335 launcher_delegate_->SetAppImage("1", &image); | 379 launcher_delegate_->SetAppImage("1", &image); |
| 336 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 380 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 337 EXPECT_EQ(2, launcher_model_->items()[initial_size].image.width()); | 381 EXPECT_EQ(2, launcher_model_->items()[initial_size].image.width()); |
| 338 EXPECT_EQ(3, launcher_model_->items()[initial_size].image.height()); | 382 EXPECT_EQ(3, launcher_model_->items()[initial_size].image.height()); |
| 339 } | 383 } |
| 340 | 384 |
| 341 // Verifies app tabs are added right after the existing tabbed item. | 385 // Verifies app tabs are added right after the existing tabbed item. |
| 342 TEST_F(LauncherUpdaterTest, AddAppAfterTabbed) { | 386 TEST_F(LauncherUpdaterTest, AddAppAfterTabbed) { |
| 343 size_t initial_size = launcher_model_->items().size(); | 387 size_t initial_size = launcher_model_->items().size(); |
| 344 TabContentsWrapper tab1(CreateTestTabContents()); | 388 TabContentsWrapper tab1(CreateTestTabContents()); |
| 345 State state1(profile(), launcher_delegate_.get(), std::string(), | 389 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); |
| 346 LauncherUpdater::TYPE_TABBED); | |
| 347 // Add a tab. | 390 // Add a tab. |
| 348 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE); | 391 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); |
| 349 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 392 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 350 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id; | 393 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id; |
| 351 | 394 |
| 352 // Create another LauncherUpdater. | 395 // Create another LauncherUpdater. |
| 353 State state2(profile(), launcher_delegate_.get(), std::string(), | 396 State state2(this, std::string(), LauncherUpdater::TYPE_APP); |
| 354 LauncherUpdater::TYPE_APP); | |
| 355 | 397 |
| 356 // Should be two extra items. | 398 // Should be two extra items. |
| 357 EXPECT_EQ(initial_size + 2, launcher_model_->items().size()); | 399 EXPECT_EQ(initial_size + 2, launcher_model_->items().size()); |
| 358 | 400 |
| 359 // Add an app tab to state1, it should go after the item for state1 but | 401 // Add an app tab to state1, it should go after the item for state1 but |
| 360 // before the item for state2. | 402 // before the item for state2. |
| 361 int next_id = launcher_model_->next_id(); | 403 int next_id = launcher_model_->next_id(); |
| 362 TabContentsWrapper app_tab(CreateTestTabContents()); | 404 TabContentsWrapper app_tab(CreateTestTabContents()); |
| 363 app_icon_loader_->SetAppID(&app_tab, "1"); | 405 app_icon_loader_->SetAppID(&app_tab, "1"); |
| 364 state1.tab_strip.InsertTabContentsAt(1, &app_tab, TabStripModel::ADD_NONE); | 406 state1.tab_strip.InsertTabContentsAt(1, &app_tab, TabStripModel::ADD_ACTIVE); |
| 365 | 407 |
| 366 ASSERT_EQ(initial_size + 3, launcher_model_->items().size()); | 408 ASSERT_EQ(initial_size + 3, launcher_model_->items().size()); |
| 367 EXPECT_EQ(next_id, launcher_model_->items()[initial_size + 1].id); | 409 EXPECT_EQ(next_id, launcher_model_->items()[initial_size + 1].id); |
| 368 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size + 1].type); | 410 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size + 1].type); |
| 369 | 411 |
| 370 // Remove the non-app tab. | 412 // Remove the non-app tab. |
| 371 state1.tab_strip.DetachTabContentsAt(0); | 413 state1.tab_strip.DetachTabContentsAt(0); |
| 372 // Should have removed one item. | 414 // Should have removed one item. |
| 373 EXPECT_EQ(initial_size + 2, launcher_model_->items().size()); | 415 EXPECT_EQ(initial_size + 2, launcher_model_->items().size()); |
| 374 EXPECT_EQ(-1, launcher_model_->ItemIndexByID(tabbed_id)); | 416 EXPECT_EQ(-1, launcher_model_->ItemIndexByID(tabbed_id)); |
| 375 next_id = launcher_model_->next_id(); | 417 next_id = launcher_model_->next_id(); |
| 376 // Add the non-app tab back. It should go to the original position (but get a | 418 // Add the non-app tab back. It should go to the original position (but get a |
| 377 // new id). | 419 // new id). |
| 378 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE); | 420 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE); |
| 379 ASSERT_EQ(initial_size + 3, launcher_model_->items().size()); | 421 ASSERT_EQ(initial_size + 3, launcher_model_->items().size()); |
| 380 EXPECT_EQ(next_id, launcher_model_->items()[initial_size].id); | 422 EXPECT_EQ(next_id, launcher_model_->items()[initial_size].id); |
| 381 } | 423 } |
| 382 | 424 |
| 383 // Verifies GetWindowAndTabByID works. | 425 // Verifies GetWindowAndTabByID works. |
| 384 TEST_F(LauncherUpdaterTest, GetUpdaterByID) { | 426 TEST_F(LauncherUpdaterTest, GetUpdaterByID) { |
| 385 size_t initial_size = launcher_model_->items().size(); | 427 size_t initial_size = launcher_model_->items().size(); |
| 386 TabContentsWrapper tab1(CreateTestTabContents()); | 428 TabContentsWrapper tab1(CreateTestTabContents()); |
| 387 TabContentsWrapper tab2(CreateTestTabContents()); | 429 TabContentsWrapper tab2(CreateTestTabContents()); |
| 388 TabContentsWrapper tab3(CreateTestTabContents()); | 430 TabContentsWrapper tab3(CreateTestTabContents()); |
| 389 | 431 |
| 390 // Create 3 states: | 432 // Create 3 states: |
| 391 // . tabbed with an app tab and normal tab. | 433 // . tabbed with an app tab and normal tab. |
| 392 // . tabbed with a normal tab. | 434 // . tabbed with a normal tab. |
| 393 // . app. | 435 // . app. |
| 394 State state1(profile(), launcher_delegate_.get(), std::string(), | 436 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); |
| 395 LauncherUpdater::TYPE_TABBED); | 437 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); |
| 396 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE); | |
| 397 app_icon_loader_->SetAppID(&tab2, "1"); | 438 app_icon_loader_->SetAppID(&tab2, "1"); |
| 398 state1.tab_strip.InsertTabContentsAt(0, &tab2, TabStripModel::ADD_NONE); | 439 state1.tab_strip.InsertTabContentsAt(0, &tab2, TabStripModel::ADD_NONE); |
| 399 State state2(profile(), launcher_delegate_.get(), std::string(), | 440 State state2(this, std::string(), LauncherUpdater::TYPE_TABBED); |
| 400 LauncherUpdater::TYPE_TABBED); | |
| 401 state2.tab_strip.InsertTabContentsAt(0, &tab3, TabStripModel::ADD_NONE); | 441 state2.tab_strip.InsertTabContentsAt(0, &tab3, TabStripModel::ADD_NONE); |
| 402 State state3(profile(), launcher_delegate_.get(), std::string(), | 442 State state3(this, std::string(), LauncherUpdater::TYPE_APP); |
| 403 LauncherUpdater::TYPE_APP); | |
| 404 ASSERT_EQ(initial_size + 4, launcher_model_->items().size()); | 443 ASSERT_EQ(initial_size + 4, launcher_model_->items().size()); |
| 405 | 444 |
| 406 // Tabbed item from first state. | 445 // Tabbed item from first state. |
| 407 ash::LauncherID id = launcher_model_->items()[initial_size].id; | 446 ash::LauncherID id = launcher_model_->items()[initial_size].id; |
| 408 LauncherUpdater* updater = GetUpdaterByID(id); | 447 LauncherUpdater* updater = GetUpdaterByID(id); |
| 409 EXPECT_EQ(&(state1.updater), updater); | 448 EXPECT_EQ(&(state1.updater), updater); |
| 410 ASSERT_TRUE(updater); | 449 ASSERT_TRUE(updater); |
| 411 EXPECT_TRUE(updater->GetTab(id) == NULL); | 450 EXPECT_TRUE(updater->GetTab(id) == NULL); |
| 412 | 451 |
| 413 // App item from first state. | 452 // App item from first state. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 435 // Various assertions around pinning. In particular verifies destroying a | 474 // Various assertions around pinning. In particular verifies destroying a |
| 436 // LauncherUpdater doesn't remove the entry for a pinned app. | 475 // LauncherUpdater doesn't remove the entry for a pinned app. |
| 437 TEST_F(LauncherUpdaterTest, Pin) { | 476 TEST_F(LauncherUpdaterTest, Pin) { |
| 438 size_t initial_size = launcher_model_->items().size(); | 477 size_t initial_size = launcher_model_->items().size(); |
| 439 TabContentsWrapper tab1(CreateTestTabContents()); | 478 TabContentsWrapper tab1(CreateTestTabContents()); |
| 440 TabContentsWrapper tab2(CreateTestTabContents()); | 479 TabContentsWrapper tab2(CreateTestTabContents()); |
| 441 TabContentsWrapper tab3(CreateTestTabContents()); | 480 TabContentsWrapper tab3(CreateTestTabContents()); |
| 442 | 481 |
| 443 ash::LauncherID id; | 482 ash::LauncherID id; |
| 444 { | 483 { |
| 445 State state1(profile(), launcher_delegate_.get(), std::string(), | 484 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); |
| 446 LauncherUpdater::TYPE_TABBED); | |
| 447 app_icon_loader_->SetAppID(&tab1, "1"); | 485 app_icon_loader_->SetAppID(&tab1, "1"); |
| 448 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE); | 486 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); |
| 449 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 487 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 450 id = launcher_model_->items()[initial_size].id; | 488 id = launcher_model_->items()[initial_size].id; |
| 451 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); | 489 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); |
| 452 // Shouldn't be pinned. | 490 // Shouldn't be pinned. |
| 453 EXPECT_FALSE(launcher_delegate_->IsPinned(id)); | 491 EXPECT_FALSE(launcher_delegate_->IsPinned(id)); |
| 454 launcher_delegate_->Pin(id); | 492 launcher_delegate_->Pin(id); |
| 455 EXPECT_TRUE(launcher_delegate_->IsPinned(id)); | 493 EXPECT_TRUE(launcher_delegate_->IsPinned(id)); |
| 456 EXPECT_EQ(ash::STATUS_RUNNING, | 494 EXPECT_EQ(ash::STATUS_ACTIVE, |
| 457 launcher_model_->items()[initial_size].status); | 495 launcher_model_->items()[initial_size].status); |
| 458 } | 496 } |
| 459 | 497 |
| 460 // Should still have the item. | 498 // Should still have the item. |
| 461 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 499 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 462 EXPECT_TRUE(launcher_delegate_->IsPinned(id)); | 500 EXPECT_TRUE(launcher_delegate_->IsPinned(id)); |
| 463 EXPECT_TRUE(GetUpdaterByID(id) == NULL); | 501 EXPECT_TRUE(GetUpdaterByID(id) == NULL); |
| 464 EXPECT_EQ(ash::STATUS_CLOSED, launcher_model_->items()[initial_size].status); | 502 EXPECT_EQ(ash::STATUS_CLOSED, launcher_model_->items()[initial_size].status); |
| 465 | 503 |
| 466 // Create another app tab, it shouldn't get the same id. | 504 // Create another app tab, it shouldn't get the same id. |
| 467 { | 505 { |
| 468 State state1(profile(), launcher_delegate_.get(), std::string(), | 506 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); |
| 469 LauncherUpdater::TYPE_TABBED); | |
| 470 app_icon_loader_->SetAppID(&tab2, "2"); | 507 app_icon_loader_->SetAppID(&tab2, "2"); |
| 471 state1.tab_strip.InsertTabContentsAt(0, &tab2, TabStripModel::ADD_NONE); | 508 state1.tab_strip.InsertTabContentsAt(0, &tab2, TabStripModel::ADD_ACTIVE); |
| 472 ASSERT_EQ(initial_size + 2, launcher_model_->items().size()); | 509 ASSERT_EQ(initial_size + 2, launcher_model_->items().size()); |
| 473 ash::LauncherID new_id = launcher_model_->items()[initial_size + 1].id; | 510 ash::LauncherID new_id = launcher_model_->items()[initial_size + 1].id; |
| 474 EXPECT_NE(id, new_id); | 511 EXPECT_NE(id, new_id); |
| 475 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size + 1].type); | 512 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size + 1].type); |
| 476 // Shouldn't be pinned. | 513 // Shouldn't be pinned. |
| 477 EXPECT_FALSE(launcher_delegate_->IsPinned(new_id)); | 514 EXPECT_FALSE(launcher_delegate_->IsPinned(new_id)); |
| 478 // But existing one should still be pinned. | 515 // But existing one should still be pinned. |
| 479 EXPECT_TRUE(launcher_delegate_->IsPinned(id)); | 516 EXPECT_TRUE(launcher_delegate_->IsPinned(id)); |
| 480 } | 517 } |
| 481 | 518 |
| 482 // Add it back and make sure we don't get another entry. | 519 // Add it back and make sure we don't get another entry. |
| 483 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 520 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 484 { | 521 { |
| 485 State state1(profile(), launcher_delegate_.get(), std::string(), | 522 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); |
| 486 LauncherUpdater::TYPE_TABBED); | |
| 487 app_icon_loader_->SetAppID(&tab1, "1"); | 523 app_icon_loader_->SetAppID(&tab1, "1"); |
| 488 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE); | 524 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); |
| 489 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 525 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 490 ash::LauncherID new_id = launcher_model_->items()[initial_size].id; | 526 ash::LauncherID new_id = launcher_model_->items()[initial_size].id; |
| 491 EXPECT_EQ(id, new_id); | 527 EXPECT_EQ(id, new_id); |
| 492 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); | 528 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); |
| 493 EXPECT_TRUE(launcher_delegate_->IsPinned(id)); | 529 EXPECT_TRUE(launcher_delegate_->IsPinned(id)); |
| 494 EXPECT_EQ(&(state1.updater), GetUpdaterByID(id)); | 530 EXPECT_EQ(&(state1.updater), GetUpdaterByID(id)); |
| 495 | 531 |
| 496 // Add another tab. | 532 // Add another tab. |
| 497 state1.tab_strip.InsertTabContentsAt(0, &tab3, TabStripModel::ADD_NONE); | 533 state1.tab_strip.InsertTabContentsAt(0, &tab3, TabStripModel::ADD_NONE); |
| 498 ASSERT_EQ(initial_size + 2, launcher_model_->items().size()); | 534 ASSERT_EQ(initial_size + 2, launcher_model_->items().size()); |
| 499 new_id = launcher_model_->items()[initial_size].id; | 535 new_id = launcher_model_->items()[initial_size].id; |
| 500 EXPECT_NE(id, new_id); | 536 EXPECT_NE(id, new_id); |
| 501 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); | 537 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); |
| 502 EXPECT_EQ(&(state1.updater), GetUpdaterByID(new_id)); | 538 EXPECT_EQ(&(state1.updater), GetUpdaterByID(new_id)); |
| 503 } | 539 } |
| 504 | 540 |
| 505 // Add it back and make sure we don't get another entry. | 541 // Add it back and make sure we don't get another entry. |
| 506 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 542 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 507 { | 543 { |
| 508 State state1(profile(), launcher_delegate_.get(), std::string(), | 544 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); |
| 509 LauncherUpdater::TYPE_TABBED); | 545 state1.tab_strip.InsertTabContentsAt(0, &tab3, TabStripModel::ADD_ACTIVE); |
| 510 state1.tab_strip.InsertTabContentsAt(0, &tab3, TabStripModel::ADD_NONE); | |
| 511 ASSERT_EQ(initial_size + 2, launcher_model_->items().size()); | 546 ASSERT_EQ(initial_size + 2, launcher_model_->items().size()); |
| 512 ash::LauncherID new_id = launcher_model_->items()[initial_size + 1].id; | 547 ash::LauncherID new_id = launcher_model_->items()[initial_size + 1].id; |
| 513 EXPECT_NE(id, new_id); | 548 EXPECT_NE(id, new_id); |
| 514 EXPECT_EQ(ash::TYPE_TABBED, | 549 EXPECT_EQ(ash::TYPE_TABBED, |
| 515 launcher_model_->items()[initial_size + 1].type); | 550 launcher_model_->items()[initial_size + 1].type); |
| 516 EXPECT_TRUE(GetUpdaterByID(id) == NULL); | 551 EXPECT_TRUE(GetUpdaterByID(id) == NULL); |
| 517 EXPECT_EQ(&(state1.updater), GetUpdaterByID(new_id)); | 552 EXPECT_EQ(&(state1.updater), GetUpdaterByID(new_id)); |
| 518 | 553 |
| 519 // Add the app tab. | 554 // Add the app tab. |
| 520 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE); | 555 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE); |
| 521 ASSERT_EQ(initial_size + 2, launcher_model_->items().size()); | 556 ASSERT_EQ(initial_size + 2, launcher_model_->items().size()); |
| 522 new_id = launcher_model_->items()[initial_size].id; | 557 new_id = launcher_model_->items()[initial_size].id; |
| 523 EXPECT_EQ(id, new_id); | 558 EXPECT_EQ(id, new_id); |
| 524 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); | 559 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); |
| 525 EXPECT_EQ(&(state1.updater), GetUpdaterByID(new_id)); | 560 EXPECT_EQ(&(state1.updater), GetUpdaterByID(new_id)); |
| 526 } | 561 } |
| 527 } | 562 } |
| 528 | 563 |
| 529 // Verifies pinned apps are persisted and restored. | 564 // Verifies pinned apps are persisted and restored. |
| 530 TEST_F(LauncherUpdaterTest, PersistPinned) { | 565 TEST_F(LauncherUpdaterTest, PersistPinned) { |
| 531 size_t initial_size = launcher_model_->items().size(); | 566 size_t initial_size = launcher_model_->items().size(); |
| 532 TabContentsWrapper tab1(CreateTestTabContents()); | 567 TabContentsWrapper tab1(CreateTestTabContents()); |
| 533 | 568 |
| 534 app_icon_loader_->SetAppID(&tab1, "1"); | 569 app_icon_loader_->SetAppID(&tab1, "1"); |
| 535 app_icon_loader_->SetAppID(NULL, "2"); | 570 app_icon_loader_->SetAppID(NULL, "2"); |
| 536 { | 571 { |
| 537 State state1(profile(), launcher_delegate_.get(), std::string(), | 572 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); |
| 538 LauncherUpdater::TYPE_TABBED); | 573 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); |
| 539 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE); | |
| 540 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 574 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 541 ash::LauncherID id = launcher_model_->items()[initial_size].id; | 575 ash::LauncherID id = launcher_model_->items()[initial_size].id; |
| 542 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); | 576 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); |
| 543 // Shouldn't be pinned. | 577 // Shouldn't be pinned. |
| 544 EXPECT_FALSE(launcher_delegate_->IsPinned(id)); | 578 EXPECT_FALSE(launcher_delegate_->IsPinned(id)); |
| 545 launcher_delegate_->Pin(id); | 579 launcher_delegate_->Pin(id); |
| 546 EXPECT_TRUE(launcher_delegate_->IsPinned(id)); | 580 EXPECT_TRUE(launcher_delegate_->IsPinned(id)); |
| 547 | 581 |
| 548 // Create an app window. | 582 // Create an app window. |
| 549 State state2(profile(), launcher_delegate_.get(), "2", | 583 State state2(this, "2", LauncherUpdater::TYPE_APP); |
| 550 LauncherUpdater::TYPE_APP); | |
| 551 ASSERT_EQ(initial_size + 2, launcher_model_->items().size()); | 584 ASSERT_EQ(initial_size + 2, launcher_model_->items().size()); |
| 552 ash::LauncherID id2 = launcher_model_->items()[initial_size + 1].id; | 585 ash::LauncherID id2 = launcher_model_->items()[initial_size + 1].id; |
| 553 EXPECT_NE(id, id2); | 586 EXPECT_NE(id, id2); |
| 554 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size + 1].type); | 587 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size + 1].type); |
| 555 launcher_delegate_->Pin(id2); | 588 launcher_delegate_->Pin(id2); |
| 556 EXPECT_TRUE(launcher_delegate_->IsPinned(id2)); | 589 EXPECT_TRUE(launcher_delegate_->IsPinned(id2)); |
| 557 } | 590 } |
| 558 | 591 |
| 559 launcher_delegate_.reset(NULL); | 592 launcher_delegate_.reset(NULL); |
| 560 ASSERT_EQ(initial_size, launcher_model_->items().size()); | 593 ASSERT_EQ(initial_size, launcher_model_->items().size()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 578 EXPECT_EQ("2", GetAppID(id2)); | 611 EXPECT_EQ("2", GetAppID(id2)); |
| 579 EXPECT_EQ(ChromeLauncherDelegate::APP_TYPE_WINDOW, | 612 EXPECT_EQ(ChromeLauncherDelegate::APP_TYPE_WINDOW, |
| 580 launcher_delegate_->GetAppType(id2)); | 613 launcher_delegate_->GetAppType(id2)); |
| 581 EXPECT_TRUE(launcher_delegate_->IsPinned(id2)); | 614 EXPECT_TRUE(launcher_delegate_->IsPinned(id2)); |
| 582 | 615 |
| 583 UnpinAppsWithID("1"); | 616 UnpinAppsWithID("1"); |
| 584 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 617 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 585 ash::LauncherID id3 = launcher_model_->items()[initial_size].id; | 618 ash::LauncherID id3 = launcher_model_->items()[initial_size].id; |
| 586 EXPECT_EQ(id2, id3); | 619 EXPECT_EQ(id2, id3); |
| 587 } | 620 } |
| 621 |
| 622 // Confirm that tabbed browsers with apps handle activation correctly. |
| 623 TEST_F(LauncherUpdaterTest, ActivateAppsInBrowser) { |
| 624 State state(this, std::string(), LauncherUpdater::TYPE_TABBED); |
| 625 TabContentsWrapper app_tab1(CreateTestTabContents()); |
| 626 app_icon_loader_->SetAppID(&app_tab1, "1"); |
| 627 TabContentsWrapper app_tab2(CreateTestTabContents()); |
| 628 app_icon_loader_->SetAppID(&app_tab2, "2"); |
| 629 TabContentsWrapper app_tab3(CreateTestTabContents()); |
| 630 app_icon_loader_->SetAppID(&app_tab3, "3"); |
| 631 |
| 632 // Insert an app tab. |
| 633 state.tab_strip.InsertTabContentsAt(0, &app_tab1, TabStripModel::ADD_ACTIVE); |
| 634 ASSERT_EQ(0, state.tab_strip.active_index()); |
| 635 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab1).status); |
| 636 |
| 637 // Add a second, inactive tab. |
| 638 state.tab_strip.InsertTabContentsAt(1, &app_tab2, TabStripModel::ADD_NONE); |
| 639 ASSERT_EQ(0, state.tab_strip.active_index()); |
| 640 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab1).status); |
| 641 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status); |
| 642 |
| 643 // Add a third, and make it active. |
| 644 state.tab_strip.InsertTabContentsAt(2, &app_tab3, TabStripModel::ADD_ACTIVE); |
| 645 ASSERT_EQ(2, state.tab_strip.active_index()); |
| 646 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab1).status); |
| 647 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status); |
| 648 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab3).status); |
| 649 |
| 650 // Make the first active |
| 651 state.tab_strip.ActivateTabAt(0, false); |
| 652 ASSERT_EQ(0, state.tab_strip.active_index()); |
| 653 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab1).status); |
| 654 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status); |
| 655 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab3).status); |
| 656 |
| 657 { |
| 658 // Add a 4th tab. |
| 659 TabContentsWrapper app_tab4(CreateTestTabContents()); |
| 660 app_icon_loader_->SetAppID(&app_tab3, "4"); |
| 661 state.tab_strip.InsertTabContentsAt( |
| 662 4, &app_tab4, TabStripModel::ADD_ACTIVE); |
| 663 ASSERT_EQ(3, state.tab_strip.active_index()); |
| 664 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab1).status); |
| 665 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status); |
| 666 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab3).status); |
| 667 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab4).status); |
| 668 } |
| 669 |
| 670 // After the 4th is closed the third becomes active. |
| 671 ASSERT_EQ(2, state.tab_strip.active_index()); |
| 672 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab1).status); |
| 673 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status); |
| 674 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab3).status); |
| 675 } |
| 676 |
| 677 // Confirm that tabbed browsers handle activation correctly. |
| 678 TEST_F(LauncherUpdaterTest, ActivateBrowsers) { |
| 679 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); |
| 680 TabContentsWrapper tab1(CreateTestTabContents()); |
| 681 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); |
| 682 |
| 683 // First browser is active. |
| 684 EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status); |
| 685 |
| 686 { |
| 687 // Second browser is active and first is inactive. |
| 688 State state2(this, std::string(), LauncherUpdater::TYPE_TABBED); |
| 689 TabContentsWrapper tab2(CreateTestTabContents()); |
| 690 state2.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); |
| 691 EXPECT_EQ(ash::STATUS_ACTIVE, state2.GetUpdaterItem().status); |
| 692 EXPECT_EQ(ash::STATUS_RUNNING, state1.GetUpdaterItem().status); |
| 693 |
| 694 // Make first browser active again. |
| 695 activation_client_->ActivateWindow(&state1.window); |
| 696 EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status); |
| 697 EXPECT_EQ(ash::STATUS_RUNNING, state2.GetUpdaterItem().status); |
| 698 |
| 699 // And back to second. |
| 700 activation_client_->ActivateWindow(&state2.window); |
| 701 EXPECT_EQ(ash::STATUS_ACTIVE, state2.GetUpdaterItem().status); |
| 702 EXPECT_EQ(ash::STATUS_RUNNING, state1.GetUpdaterItem().status); |
| 703 } |
| 704 |
| 705 // First browser should be active again after second is closed. |
| 706 EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status); |
| 707 } |
| 708 |
| 709 // Confirm that applications handle activation correctly. |
| 710 TEST_F(LauncherUpdaterTest, ActivateApps) { |
| 711 State state1(this, "1", LauncherUpdater::TYPE_APP); |
| 712 |
| 713 // First app is active. |
| 714 EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status); |
| 715 |
| 716 { |
| 717 // Second app is active and first is inactive. |
| 718 State state2(this, "2", LauncherUpdater::TYPE_APP); |
| 719 EXPECT_EQ(ash::STATUS_ACTIVE, state2.GetUpdaterItem().status); |
| 720 EXPECT_EQ(ash::STATUS_RUNNING, state1.GetUpdaterItem().status); |
| 721 |
| 722 // Make first app active again. |
| 723 activation_client_->ActivateWindow(&state1.window); |
| 724 EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status); |
| 725 EXPECT_EQ(ash::STATUS_RUNNING, state2.GetUpdaterItem().status); |
| 726 |
| 727 // And back to second. |
| 728 activation_client_->ActivateWindow(&state2.window); |
| 729 EXPECT_EQ(ash::STATUS_ACTIVE, state2.GetUpdaterItem().status); |
| 730 EXPECT_EQ(ash::STATUS_RUNNING, state1.GetUpdaterItem().status); |
| 731 } |
| 732 |
| 733 // First app should be active again after second is closed. |
| 734 EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status); |
| 735 } |
| 736 |
| OLD | NEW |