Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_unittest.cc

Issue 71653003: ash: Rename LauncherModel to ShelfModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: chrome changes Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/shelf/shelf_model.h"
14 #include "ash/shelf/shelf_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"
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 extension_service_(NULL) { 265 extension_service_(NULL) {
266 SetHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH); 266 SetHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH);
267 } 267 }
268 268
269 virtual ~ChromeLauncherControllerTest() { 269 virtual ~ChromeLauncherControllerTest() {
270 } 270 }
271 271
272 virtual void SetUp() OVERRIDE { 272 virtual void SetUp() OVERRIDE {
273 BrowserWithTestWindowTest::SetUp(); 273 BrowserWithTestWindowTest::SetUp();
274 274
275 model_.reset(new ash::LauncherModel); 275 model_.reset(new ash::ShelfModel);
276 model_observer_.reset(new TestShelfModelObserver); 276 model_observer_.reset(new TestShelfModelObserver);
277 model_->AddObserver(model_observer_.get()); 277 model_->AddObserver(model_observer_.get());
278 278
279 if (ash::Shell::HasInstance()) { 279 if (ash::Shell::HasInstance()) {
280 item_delegate_manager_ = 280 item_delegate_manager_ =
281 ash::Shell::GetInstance()->launcher_item_delegate_manager(); 281 ash::Shell::GetInstance()->launcher_item_delegate_manager();
282 } else { 282 } else {
283 item_delegate_manager_ = 283 item_delegate_manager_ =
284 new ash::LauncherItemDelegateManager(model_.get()); 284 new ash::LauncherItemDelegateManager(model_.get());
285 } 285 }
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 scoped_refptr<Extension> extension1_; 585 scoped_refptr<Extension> extension1_;
586 scoped_refptr<Extension> extension2_; 586 scoped_refptr<Extension> extension2_;
587 scoped_refptr<Extension> extension3_; 587 scoped_refptr<Extension> extension3_;
588 scoped_refptr<Extension> extension4_; 588 scoped_refptr<Extension> extension4_;
589 scoped_refptr<Extension> extension5_; 589 scoped_refptr<Extension> extension5_;
590 scoped_refptr<Extension> extension6_; 590 scoped_refptr<Extension> extension6_;
591 scoped_refptr<Extension> extension7_; 591 scoped_refptr<Extension> extension7_;
592 scoped_refptr<Extension> extension8_; 592 scoped_refptr<Extension> extension8_;
593 scoped_ptr<ChromeLauncherController> launcher_controller_; 593 scoped_ptr<ChromeLauncherController> launcher_controller_;
594 scoped_ptr<TestShelfModelObserver> model_observer_; 594 scoped_ptr<TestShelfModelObserver> model_observer_;
595 scoped_ptr<ash::LauncherModel> model_; 595 scoped_ptr<ash::ShelfModel> model_;
596 596
597 // |item_delegate_manager_| owns |test_controller_|. 597 // |item_delegate_manager_| owns |test_controller_|.
598 LauncherItemController* test_controller_; 598 LauncherItemController* test_controller_;
599 599
600 ExtensionService* extension_service_; 600 ExtensionService* extension_service_;
601 601
602 ash::LauncherItemDelegateManager* item_delegate_manager_; 602 ash::LauncherItemDelegateManager* item_delegate_manager_;
603 603
604 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); 604 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest);
605 }; 605 };
(...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after
1591 base::ListValue policy_value1; 1591 base::ListValue policy_value1;
1592 InsertPrefValue(&policy_value1, 0, extension3_->id()); 1592 InsertPrefValue(&policy_value1, 0, extension3_->id());
1593 InsertPrefValue(&policy_value1, 1, extension2_->id()); 1593 InsertPrefValue(&policy_value1, 1, extension2_->id());
1594 InsertPrefValue(&policy_value1, 2, extension1_->id()); 1594 InsertPrefValue(&policy_value1, 2, extension1_->id());
1595 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1595 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1596 policy_value1.DeepCopy()); 1596 policy_value1.DeepCopy());
1597 EXPECT_EQ("AppList, Chrome, App3, App2, App1, ", GetPinnedAppStatus()); 1597 EXPECT_EQ("AppList, Chrome, App3, App2, App1, ", GetPinnedAppStatus());
1598 1598
1599 // Going back to a status where there is no requirement for app 2 to be pinned 1599 // Going back to a status where there is no requirement for app 2 to be pinned
1600 // should convert it back to locked but not pinned and state. The position 1600 // should convert it back to locked but not pinned and state. The position
1601 // is determined by the |LauncherModel|'s weight system. Since at the moment 1601 // is determined by the |ShelfModel|'s weight system. Since at the moment
1602 // the weight of a running app has the same as a shortcut, it will remain 1602 // the weight of a running app has the same as a shortcut, it will remain
1603 // where it is. Surely note ideal, but since the sync process can shift around 1603 // where it is. Surely note ideal, but since the sync process can shift around
1604 // locations - as well as many other edge cases - this gets nearly impossible 1604 // locations - as well as many other edge cases - this gets nearly impossible
1605 // to get right. 1605 // to get right.
1606 // TODO(skuhne): Filed crbug.com/293761 to track of this. 1606 // TODO(skuhne): Filed crbug.com/293761 to track of this.
1607 base::ListValue policy_value2; 1607 base::ListValue policy_value2;
1608 InsertPrefValue(&policy_value2, 0, extension3_->id()); 1608 InsertPrefValue(&policy_value2, 0, extension3_->id());
1609 InsertPrefValue(&policy_value2, 1, extension1_->id()); 1609 InsertPrefValue(&policy_value2, 1, extension1_->id());
1610 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1610 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1611 policy_value2.DeepCopy()); 1611 policy_value2.DeepCopy());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 base::ListValue policy_value1; 1648 base::ListValue policy_value1;
1649 InsertPrefValue(&policy_value1, 0, extension3_->id()); 1649 InsertPrefValue(&policy_value1, 0, extension3_->id());
1650 InsertPrefValue(&policy_value1, 1, extension2_->id()); 1650 InsertPrefValue(&policy_value1, 1, extension2_->id());
1651 InsertPrefValue(&policy_value1, 2, extension1_->id()); 1651 InsertPrefValue(&policy_value1, 2, extension1_->id());
1652 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1652 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1653 policy_value1.DeepCopy()); 1653 policy_value1.DeepCopy());
1654 EXPECT_EQ("AppList, Chrome, App3, App2, App1, ", GetPinnedAppStatus()); 1654 EXPECT_EQ("AppList, Chrome, App3, App2, App1, ", GetPinnedAppStatus());
1655 1655
1656 // Going back to a status where there is no requirement for app 2 to be pinned 1656 // Going back to a status where there is no requirement for app 2 to be pinned
1657 // should convert it back to running V2 app. Since the position is determined 1657 // should convert it back to running V2 app. Since the position is determined
1658 // by the |LauncherModel|'s weight system, it will be after last pinned item. 1658 // by the |ShelfModel|'s weight system, it will be after last pinned item.
1659 base::ListValue policy_value2; 1659 base::ListValue policy_value2;
1660 InsertPrefValue(&policy_value2, 0, extension3_->id()); 1660 InsertPrefValue(&policy_value2, 0, extension3_->id());
1661 InsertPrefValue(&policy_value2, 1, extension1_->id()); 1661 InsertPrefValue(&policy_value2, 1, extension1_->id());
1662 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1662 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1663 policy_value2.DeepCopy()); 1663 policy_value2.DeepCopy());
1664 EXPECT_EQ("AppList, Chrome, App3, App1, *app2, ", GetPinnedAppStatus()); 1664 EXPECT_EQ("AppList, Chrome, App3, App1, *app2, ", GetPinnedAppStatus());
1665 1665
1666 // Removing an item should simply close it and everything should shift. 1666 // Removing an item should simply close it and everything should shift.
1667 base::ListValue policy_value3; 1667 base::ListValue policy_value3;
1668 InsertPrefValue(&policy_value3, 0, extension3_->id()); 1668 InsertPrefValue(&policy_value3, 0, extension3_->id());
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
2510 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); 2510 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type);
2511 2511
2512 launcher_controller_.reset(); 2512 launcher_controller_.reset();
2513 if (!ash::Shell::HasInstance()) { 2513 if (!ash::Shell::HasInstance()) {
2514 delete item_delegate_manager_; 2514 delete item_delegate_manager_;
2515 } else { 2515 } else {
2516 // Clear already registered LauncherItemDelegate. 2516 // Clear already registered LauncherItemDelegate.
2517 ash::test::LauncherItemDelegateManagerTestAPI test(item_delegate_manager_); 2517 ash::test::LauncherItemDelegateManagerTestAPI test(item_delegate_manager_);
2518 test.RemoveAllLauncherItemDelegateForTest(); 2518 test.RemoveAllLauncherItemDelegateForTest();
2519 } 2519 }
2520 model_.reset(new ash::LauncherModel); 2520 model_.reset(new ash::ShelfModel);
2521 2521
2522 AddAppListLauncherItem(); 2522 AddAppListLauncherItem();
2523 launcher_controller_.reset( 2523 launcher_controller_.reset(
2524 ChromeLauncherController::CreateInstance(profile(), model_.get())); 2524 ChromeLauncherController::CreateInstance(profile(), model_.get()));
2525 app_tab_helper = new TestAppTabHelperImpl; 2525 app_tab_helper = new TestAppTabHelperImpl;
2526 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 2526 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
2527 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); 2527 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2");
2528 SetAppTabHelper(app_tab_helper); 2528 SetAppTabHelper(app_tab_helper);
2529 if (!ash::Shell::HasInstance()) { 2529 if (!ash::Shell::HasInstance()) {
2530 item_delegate_manager_ = 2530 item_delegate_manager_ =
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2566 EXPECT_EQ(initial_size + 1, model_->items().size()); 2566 EXPECT_EQ(initial_size + 1, model_->items().size());
2567 2567
2568 launcher_controller_.reset(); 2568 launcher_controller_.reset();
2569 if (!ash::Shell::HasInstance()) { 2569 if (!ash::Shell::HasInstance()) {
2570 delete item_delegate_manager_; 2570 delete item_delegate_manager_;
2571 } else { 2571 } else {
2572 // Clear already registered LauncherItemDelegate. 2572 // Clear already registered LauncherItemDelegate.
2573 ash::test::LauncherItemDelegateManagerTestAPI test(item_delegate_manager_); 2573 ash::test::LauncherItemDelegateManagerTestAPI test(item_delegate_manager_);
2574 test.RemoveAllLauncherItemDelegateForTest(); 2574 test.RemoveAllLauncherItemDelegateForTest();
2575 } 2575 }
2576 model_.reset(new ash::LauncherModel); 2576 model_.reset(new ash::ShelfModel);
2577 2577
2578 AddAppListLauncherItem(); 2578 AddAppListLauncherItem();
2579 launcher_controller_.reset( 2579 launcher_controller_.reset(
2580 ChromeLauncherController::CreateInstance(profile(), model_.get())); 2580 ChromeLauncherController::CreateInstance(profile(), model_.get()));
2581 app_tab_helper = new TestAppTabHelperImpl; 2581 app_tab_helper = new TestAppTabHelperImpl;
2582 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 2582 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
2583 SetAppTabHelper(app_tab_helper); 2583 SetAppTabHelper(app_tab_helper);
2584 app_icon_loader = new TestAppIconLoaderImpl; 2584 app_icon_loader = new TestAppIconLoaderImpl;
2585 SetAppIconLoader(app_icon_loader); 2585 SetAppIconLoader(app_icon_loader);
2586 if (!ash::Shell::HasInstance()) { 2586 if (!ash::Shell::HasInstance()) {
2587 item_delegate_manager_ = 2587 item_delegate_manager_ =
2588 new ash::LauncherItemDelegateManager(model_.get()); 2588 new ash::LauncherItemDelegateManager(model_.get());
2589 SetLauncherItemDelegateManager(item_delegate_manager_); 2589 SetLauncherItemDelegateManager(item_delegate_manager_);
2590 } 2590 }
2591 launcher_controller_->Init(); 2591 launcher_controller_->Init();
2592 2592
2593 EXPECT_EQ(1, app_icon_loader->fetch_count()); 2593 EXPECT_EQ(1, app_icon_loader->fetch_count());
2594 ASSERT_EQ(initial_size + 1, model_->items().size()); 2594 ASSERT_EQ(initial_size + 1, model_->items().size());
2595 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 2595 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
2596 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); 2596 EXPECT_FALSE(launcher_controller_->IsAppPinned("0"));
2597 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); 2597 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type);
2598 2598
2599 launcher_controller_->UnpinAppWithID("1"); 2599 launcher_controller_->UnpinAppWithID("1");
2600 ASSERT_EQ(initial_size, model_->items().size()); 2600 ASSERT_EQ(initial_size, model_->items().size());
2601 } 2601 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698