Chromium Code Reviews| Index: chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_unittest.cc |
| diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_unittest.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_unittest.cc |
| index ea3861f90553a44d80aa1382140e4b393e3a69be..89b8aebabb5556f5d083b17f3a5ae826f6f138a0 100644 |
| --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_unittest.cc |
| +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_unittest.cc |
| @@ -33,8 +33,10 @@ |
| #include "chrome/common/extensions/extension_constants.h" |
| #include "chrome/common/pref_names.h" |
| #include "chrome/test/base/browser_with_test_window_test.h" |
| +#include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| #include "chrome/test/base/testing_pref_service_syncable.h" |
| #include "chrome/test/base/testing_profile.h" |
| +#include "content/public/browser/web_contents.h" |
| #include "content/public/test/test_browser_thread.h" |
| #include "extensions/common/manifest_constants.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -107,6 +109,46 @@ class TestLauncherModelObserver : public ash::LauncherModelObserver { |
| DISALLOW_COPY_AND_ASSIGN(TestLauncherModelObserver); |
| }; |
| +// Test implementation of AppTabHelper. |
| +class TestAppTabHelperImpl : public ChromeLauncherController::AppTabHelper { |
| + public: |
| + TestAppTabHelperImpl() {} |
| + virtual ~TestAppTabHelperImpl() {} |
| + |
| + // Sets the id for the specified tab. The id is removed if Remove() is |
| + // invoked. |
| + void SetAppID(content::WebContents* tab, const std::string& id) { |
| + tab_id_map_[tab] = id; |
| + } |
| + |
| + // Returns true if there is an id registered for |tab|. |
| + bool HasAppID(content::WebContents* tab) const { |
| + return tab_id_map_.find(tab) != tab_id_map_.end(); |
| + } |
| + |
| + // AppTabHelper implementation: |
| + virtual std::string GetAppID(content::WebContents* tab) OVERRIDE { |
| + return tab_id_map_.find(tab) != tab_id_map_.end() ? tab_id_map_[tab] : |
| + std::string(); |
| + } |
| + |
| + virtual bool IsValidID(const std::string& id) OVERRIDE { |
| + for (TabToStringMap::const_iterator i = tab_id_map_.begin(); |
| + i != tab_id_map_.end(); ++i) { |
| + if (i->second == id) |
| + return true; |
| + } |
| + return false; |
| + } |
| + |
| + private: |
| + typedef std::map<content::WebContents*, std::string> TabToStringMap; |
| + |
| + TabToStringMap tab_id_map_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestAppTabHelperImpl); |
| +}; |
| + |
| // Test implementation of AppIconLoader. |
| class TestAppIconLoaderImpl : public extensions::AppIconLoader { |
| public: |
| @@ -1385,3 +1427,154 @@ TEST_F(ChromeLauncherControllerPerAppTest, GmailOfflineMatching) { |
| // The content should not be able to be handled by the app. |
| EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); |
| } |
| + |
|
Mr4D (OOO till 08-26)
2013/08/16 22:43:22
How did this all end up here?
simonhong_
2013/08/19 05:26:11
Most of unit tests in browser_launcher_item_contro
|
| +class LauncherItemControllerPerAppTest |
| + : public ChromeRenderViewHostTestHarness { |
| + public: |
| + LauncherItemControllerPerAppTest() {} |
| + virtual ~LauncherItemControllerPerAppTest() {} |
| + |
| + virtual void SetUp() OVERRIDE { |
| + ChromeRenderViewHostTestHarness::SetUp(); |
| + |
| + launcher_model_.reset(new ash::LauncherModel); |
| + launcher_delegate_.reset( |
| + ChromeLauncherController::CreateInstance(profile(), |
| + launcher_model_.get())); |
| + app_tab_helper_ = new TestAppTabHelperImpl; |
| + app_icon_loader_ = new TestAppIconLoaderImpl; |
| + launcher_delegate_->SetAppTabHelperForTest(app_tab_helper_); |
| + launcher_delegate_->SetAppIconLoaderForTest(app_icon_loader_); |
| + launcher_delegate_->Init(); |
| + } |
| + |
| + virtual void TearDown() OVERRIDE { |
| + launcher_delegate_.reset(); |
| + ChromeRenderViewHostTestHarness::TearDown(); |
| + } |
| + |
| + protected: |
| + const std::string& GetAppID(ash::LauncherID id) const { |
| + return launcher_delegate_->GetAppIdFromLauncherIdForTest(id); |
| + } |
| + |
| + void ResetAppTabHelper() { |
| + launcher_delegate_->SetAppTabHelperForTest(app_tab_helper_); |
| + } |
| + |
| + void ResetAppIconLoader() { |
| + launcher_delegate_->SetAppIconLoaderForTest(app_icon_loader_); |
| + } |
| + |
| + void UnpinAppsWithID(const std::string& app_id) { |
| + launcher_delegate_->UnpinAppsWithID(app_id); |
| + } |
| + |
| + scoped_ptr<ash::LauncherModel> launcher_model_; |
| + scoped_ptr<ChromeLauncherController> launcher_delegate_; |
| + |
| + // Owned by BrowserLauncherItemController. |
| + TestAppTabHelperImpl* app_tab_helper_; |
| + TestAppIconLoaderImpl* app_icon_loader_; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(LauncherItemControllerPerAppTest); |
| +}; |
| + |
| +// Verify that the launcher item positions are persisted and restored. |
| +TEST_F(LauncherItemControllerPerAppTest, PersistLauncherItemPositions) { |
| + EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, |
| + launcher_model_->items()[0].type); |
| + EXPECT_EQ(ash::TYPE_APP_LIST, |
| + launcher_model_->items()[1].type); |
| + scoped_ptr<content::WebContents> tab1(CreateTestWebContents()); |
| + scoped_ptr<content::WebContents> tab2(CreateTestWebContents()); |
| + app_tab_helper_->SetAppID(tab1.get(), "1"); |
| + app_tab_helper_->SetAppID(tab1.get(), "2"); |
| + |
| + EXPECT_FALSE(launcher_delegate_->IsAppPinned("1")); |
| + launcher_delegate_->PinAppWithID("1"); |
| + EXPECT_TRUE(launcher_delegate_->IsAppPinned("1")); |
| + launcher_delegate_->PinAppWithID("2"); |
| + |
| + EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, |
| + launcher_model_->items()[0].type); |
| + EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| + launcher_model_->items()[1].type); |
| + EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| + launcher_model_->items()[2].type); |
| + EXPECT_EQ(ash::TYPE_APP_LIST, |
| + launcher_model_->items()[3].type); |
| + |
| + launcher_model_->Move(0, 2); |
| + EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| + launcher_model_->items()[0].type); |
| + EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| + launcher_model_->items()[1].type); |
| + EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, |
| + launcher_model_->items()[2].type); |
| + EXPECT_EQ(ash::TYPE_APP_LIST, |
| + launcher_model_->items()[3].type); |
| + |
| + launcher_delegate_.reset(); |
| + launcher_model_.reset(new ash::LauncherModel); |
| + launcher_delegate_.reset( |
| + ChromeLauncherController::CreateInstance(profile(), |
| + launcher_model_.get())); |
| + app_tab_helper_ = new TestAppTabHelperImpl; |
| + app_tab_helper_->SetAppID(tab1.get(), "1"); |
| + app_tab_helper_->SetAppID(tab2.get(), "2"); |
| + ResetAppTabHelper(); |
| + |
| + launcher_delegate_->Init(); |
| + |
| + EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| + launcher_model_->items()[0].type); |
| + EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| + launcher_model_->items()[1].type); |
| + EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, |
| + launcher_model_->items()[2].type); |
| + EXPECT_EQ(ash::TYPE_APP_LIST, |
| + launcher_model_->items()[3].type); |
| +} |
| + |
| +// Verifies pinned apps are persisted and restored. |
| +TEST_F(LauncherItemControllerPerAppTest, PersistPinned) { |
| + size_t initial_size = launcher_model_->items().size(); |
| + scoped_ptr<content::WebContents> tab1(CreateTestWebContents()); |
| + |
| + app_tab_helper_->SetAppID(tab1.get(), "1"); |
| + |
| + EXPECT_EQ(0, app_icon_loader_->fetch_count()); |
| + launcher_delegate_->PinAppWithID("1"); |
| + ash::LauncherID id = launcher_delegate_->GetLauncherIDForAppID("1"); |
| + int app_index = launcher_model_->ItemIndexByID(id); |
| + EXPECT_EQ(1, app_icon_loader_->fetch_count()); |
| + EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| + launcher_model_->items()[app_index].type); |
| + EXPECT_TRUE(launcher_delegate_->IsAppPinned("1")); |
| + EXPECT_FALSE(launcher_delegate_->IsAppPinned("0")); |
| + EXPECT_EQ(initial_size + 1, launcher_model_->items().size()); |
| + |
| + launcher_delegate_.reset(); |
| + launcher_model_.reset(new ash::LauncherModel); |
| + launcher_delegate_.reset( |
| + ChromeLauncherController::CreateInstance(profile(), |
| + launcher_model_.get())); |
| + app_tab_helper_ = new TestAppTabHelperImpl; |
| + app_tab_helper_->SetAppID(tab1.get(), "1"); |
| + ResetAppTabHelper(); |
| + app_icon_loader_ = new TestAppIconLoaderImpl; |
| + ResetAppIconLoader(); |
| + launcher_delegate_->Init(); |
| + EXPECT_EQ(1, app_icon_loader_->fetch_count()); |
| + ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| + EXPECT_TRUE(launcher_delegate_->IsAppPinned("1")); |
| + EXPECT_FALSE(launcher_delegate_->IsAppPinned("0")); |
| + EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| + launcher_model_->items()[app_index].type); |
| + |
| + UnpinAppsWithID("1"); |
| + ASSERT_EQ(initial_size, launcher_model_->items().size()); |
| +} |
| + |