| 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/ash/launcher/browser_launcher_item_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 | 233 |
| 234 // Owned by BrowserLauncherItemController. | 234 // Owned by BrowserLauncherItemController. |
| 235 AppTabHelperImpl* app_tab_helper_; | 235 AppTabHelperImpl* app_tab_helper_; |
| 236 AppIconLoaderImpl* app_icon_loader_; | 236 AppIconLoaderImpl* app_icon_loader_; |
| 237 | 237 |
| 238 scoped_ptr<aura::test::TestActivationClient> activation_client_; | 238 scoped_ptr<aura::test::TestActivationClient> activation_client_; |
| 239 }; | 239 }; |
| 240 | 240 |
| 241 // Verify that the launcher item positions are persisted and restored. | 241 // Verify that the launcher item positions are persisted and restored. |
| 242 TEST_F(LauncherItemControllerPerAppTest, PersistLauncherItemPositions) { | 242 TEST_F(LauncherItemControllerPerAppTest, PersistLauncherItemPositions) { |
| 243 EXPECT_EQ(ash::TYPE_APP_LIST, |
| 244 launcher_model_->items()[0].type); |
| 243 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, | 245 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, |
| 244 launcher_model_->items()[0].type); | |
| 245 EXPECT_EQ(ash::TYPE_APP_LIST, | |
| 246 launcher_model_->items()[1].type); | 246 launcher_model_->items()[1].type); |
| 247 scoped_ptr<content::WebContents> tab1(CreateTestWebContents()); | 247 scoped_ptr<content::WebContents> tab1(CreateTestWebContents()); |
| 248 scoped_ptr<content::WebContents> tab2(CreateTestWebContents()); | 248 scoped_ptr<content::WebContents> tab2(CreateTestWebContents()); |
| 249 app_tab_helper_->SetAppID(tab1.get(), "1"); | 249 app_tab_helper_->SetAppID(tab1.get(), "1"); |
| 250 app_tab_helper_->SetAppID(tab1.get(), "2"); | 250 app_tab_helper_->SetAppID(tab1.get(), "2"); |
| 251 | 251 |
| 252 EXPECT_FALSE(launcher_delegate_->IsAppPinned("1")); | 252 EXPECT_FALSE(launcher_delegate_->IsAppPinned("1")); |
| 253 launcher_delegate_->PinAppWithID("1"); | 253 launcher_delegate_->PinAppWithID("1"); |
| 254 EXPECT_TRUE(launcher_delegate_->IsAppPinned("1")); | 254 EXPECT_TRUE(launcher_delegate_->IsAppPinned("1")); |
| 255 launcher_delegate_->PinAppWithID("2"); | 255 launcher_delegate_->PinAppWithID("2"); |
| 256 | 256 |
| 257 EXPECT_EQ(ash::TYPE_APP_LIST, |
| 258 launcher_model_->items()[0].type); |
| 257 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, | 259 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, |
| 260 launcher_model_->items()[1].type); |
| 261 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| 262 launcher_model_->items()[2].type); |
| 263 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| 264 launcher_model_->items()[3].type); |
| 265 |
| 266 launcher_model_->Move(1, 3); |
| 267 EXPECT_EQ(ash::TYPE_APP_LIST, |
| 258 launcher_model_->items()[0].type); | 268 launcher_model_->items()[0].type); |
| 259 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | 269 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| 260 launcher_model_->items()[1].type); | 270 launcher_model_->items()[1].type); |
| 261 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | 271 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| 262 launcher_model_->items()[2].type); | 272 launcher_model_->items()[2].type); |
| 263 EXPECT_EQ(ash::TYPE_APP_LIST, | |
| 264 launcher_model_->items()[3].type); | |
| 265 | |
| 266 launcher_model_->Move(0, 2); | |
| 267 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | |
| 268 launcher_model_->items()[0].type); | |
| 269 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | |
| 270 launcher_model_->items()[1].type); | |
| 271 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, | 273 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, |
| 272 launcher_model_->items()[2].type); | |
| 273 EXPECT_EQ(ash::TYPE_APP_LIST, | |
| 274 launcher_model_->items()[3].type); | 274 launcher_model_->items()[3].type); |
| 275 | 275 |
| 276 launcher_delegate_.reset(); | 276 launcher_delegate_.reset(); |
| 277 launcher_model_.reset(new ash::LauncherModel); | 277 launcher_model_.reset(new ash::LauncherModel); |
| 278 launcher_delegate_.reset( | 278 launcher_delegate_.reset( |
| 279 ChromeLauncherController::CreateInstance(profile(), | 279 ChromeLauncherController::CreateInstance(profile(), |
| 280 launcher_model_.get())); | 280 launcher_model_.get())); |
| 281 app_tab_helper_ = new AppTabHelperImpl; | 281 app_tab_helper_ = new AppTabHelperImpl; |
| 282 app_tab_helper_->SetAppID(tab1.get(), "1"); | 282 app_tab_helper_->SetAppID(tab1.get(), "1"); |
| 283 app_tab_helper_->SetAppID(tab2.get(), "2"); | 283 app_tab_helper_->SetAppID(tab2.get(), "2"); |
| 284 ResetAppTabHelper(); | 284 ResetAppTabHelper(); |
| 285 | 285 |
| 286 launcher_delegate_->Init(); | 286 launcher_delegate_->Init(); |
| 287 | 287 |
| 288 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | 288 EXPECT_EQ(ash::TYPE_APP_LIST, |
| 289 launcher_model_->items()[0].type); | 289 launcher_model_->items()[0].type); |
| 290 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | 290 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| 291 launcher_model_->items()[1].type); | 291 launcher_model_->items()[1].type); |
| 292 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| 293 launcher_model_->items()[2].type); |
| 292 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, | 294 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, |
| 293 launcher_model_->items()[2].type); | |
| 294 EXPECT_EQ(ash::TYPE_APP_LIST, | |
| 295 launcher_model_->items()[3].type); | 295 launcher_model_->items()[3].type); |
| 296 } | 296 } |
| 297 | 297 |
| 298 class BrowserLauncherItemControllerTest | 298 class BrowserLauncherItemControllerTest |
| 299 : public LauncherItemControllerPerAppTest { | 299 : public LauncherItemControllerPerAppTest { |
| 300 public: | 300 public: |
| 301 BrowserLauncherItemControllerTest() {} | 301 BrowserLauncherItemControllerTest() {} |
| 302 | 302 |
| 303 virtual void SetUp() OVERRIDE { | 303 virtual void SetUp() OVERRIDE { |
| 304 CommandLine::ForCurrentProcess()->AppendSwitch( | 304 CommandLine::ForCurrentProcess()->AppendSwitch( |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | 390 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| 391 launcher_model_->items()[app_index].type); | 391 launcher_model_->items()[app_index].type); |
| 392 | 392 |
| 393 UnpinAppsWithID("1"); | 393 UnpinAppsWithID("1"); |
| 394 ASSERT_EQ(initial_size, launcher_model_->items().size()); | 394 ASSERT_EQ(initial_size, launcher_model_->items().size()); |
| 395 } | 395 } |
| 396 | 396 |
| 397 // Verify that launcher item positions are persisted and restored. | 397 // Verify that launcher item positions are persisted and restored. |
| 398 TEST_F(BrowserLauncherItemControllerTest, | 398 TEST_F(BrowserLauncherItemControllerTest, |
| 399 PersistLauncherItemPositionsPerBrowser) { | 399 PersistLauncherItemPositionsPerBrowser) { |
| 400 int browser_shortcut_index = 0; | 400 int app_list_index = 0; |
| 401 int app_list_index = 1; | 401 int browser_shortcut_index = 1; |
| 402 | 402 |
| 403 EXPECT_EQ(ash::TYPE_APP_LIST, |
| 404 launcher_model_->items()[app_list_index].type); |
| 403 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, | 405 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, |
| 404 launcher_model_->items()[browser_shortcut_index].type); | 406 launcher_model_->items()[browser_shortcut_index].type); |
| 405 EXPECT_EQ(ash::TYPE_APP_LIST, | |
| 406 launcher_model_->items()[app_list_index].type); | |
| 407 | 407 |
| 408 scoped_ptr<content::WebContents> tab1(CreateTestWebContents()); | 408 scoped_ptr<content::WebContents> tab1(CreateTestWebContents()); |
| 409 scoped_ptr<content::WebContents> tab2(CreateTestWebContents()); | 409 scoped_ptr<content::WebContents> tab2(CreateTestWebContents()); |
| 410 | 410 |
| 411 app_tab_helper_->SetAppID(tab1.get(), "1"); | 411 app_tab_helper_->SetAppID(tab1.get(), "1"); |
| 412 app_tab_helper_->SetAppID(tab2.get(), "2"); | 412 app_tab_helper_->SetAppID(tab2.get(), "2"); |
| 413 | 413 |
| 414 app_icon_loader_->GetAndClearFetchCount(); | 414 app_icon_loader_->GetAndClearFetchCount(); |
| 415 launcher_delegate_->PinAppWithID("1"); | 415 launcher_delegate_->PinAppWithID("1"); |
| 416 ash::LauncherID id = launcher_delegate_->GetLauncherIDForAppID("1"); | 416 ash::LauncherID id = launcher_delegate_->GetLauncherIDForAppID("1"); |
| 417 int app1_index = launcher_model_->ItemIndexByID(id); | 417 int app1_index = launcher_model_->ItemIndexByID(id); |
| 418 | 418 |
| 419 launcher_delegate_->PinAppWithID("2"); | 419 launcher_delegate_->PinAppWithID("2"); |
| 420 id = launcher_delegate_->GetLauncherIDForAppID("2"); | 420 id = launcher_delegate_->GetLauncherIDForAppID("2"); |
| 421 int app2_index = launcher_model_->ItemIndexByID(id); | 421 int app2_index = launcher_model_->ItemIndexByID(id); |
| 422 | 422 |
| 423 launcher_model_->Move(browser_shortcut_index, app1_index); | 423 launcher_model_->Move(browser_shortcut_index, app1_index); |
| 424 | 424 |
| 425 browser_shortcut_index = 1; | 425 std::swap(browser_shortcut_index, app1_index); |
| 426 app1_index = 0; | |
| 427 | 426 |
| 428 EXPECT_GT(app_icon_loader_->GetAndClearFetchCount(), 0); | 427 EXPECT_GT(app_icon_loader_->GetAndClearFetchCount(), 0); |
| 429 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | 428 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| 430 launcher_model_->items()[app1_index].type); | 429 launcher_model_->items()[app1_index].type); |
| 431 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, | 430 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, |
| 432 launcher_model_->items()[browser_shortcut_index].type); | 431 launcher_model_->items()[browser_shortcut_index].type); |
| 433 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | 432 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| 434 launcher_model_->items()[app2_index].type); | 433 launcher_model_->items()[app2_index].type); |
| 435 | 434 |
| 436 launcher_delegate_.reset(); | 435 launcher_delegate_.reset(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 EXPECT_EQ(ash::STATUS_RUNNING, app_state.GetUpdaterItem().status); | 533 EXPECT_EQ(ash::STATUS_RUNNING, app_state.GetUpdaterItem().status); |
| 535 | 534 |
| 536 // App window should go to attention state. | 535 // App window should go to attention state. |
| 537 app_state.window.SetProperty(aura::client::kDrawAttentionKey, true); | 536 app_state.window.SetProperty(aura::client::kDrawAttentionKey, true); |
| 538 EXPECT_EQ(ash::STATUS_ATTENTION, app_state.GetUpdaterItem().status); | 537 EXPECT_EQ(ash::STATUS_ATTENTION, app_state.GetUpdaterItem().status); |
| 539 | 538 |
| 540 // Activating app window should clear attention state. | 539 // Activating app window should clear attention state. |
| 541 activation_client_->ActivateWindow(&app_state.window); | 540 activation_client_->ActivateWindow(&app_state.window); |
| 542 EXPECT_EQ(ash::STATUS_ACTIVE, app_state.GetUpdaterItem().status); | 541 EXPECT_EQ(ash::STATUS_ACTIVE, app_state.GetUpdaterItem().status); |
| 543 } | 542 } |
| OLD | NEW |