Chromium Code Reviews| Index: chrome/browser/ui/app_list/app_list_shower_views_unittest.cc |
| diff --git a/chrome/browser/ui/app_list/test/app_list_shower_unittest.cc b/chrome/browser/ui/app_list/app_list_shower_views_unittest.cc |
| similarity index 59% |
| rename from chrome/browser/ui/app_list/test/app_list_shower_unittest.cc |
| rename to chrome/browser/ui/app_list/app_list_shower_views_unittest.cc |
| index 66224a9206dc3f14d0331d1b4a9fe09a368b133f..6a85d00d9e7d8fb535ca554890873299d08b4373 100644 |
| --- a/chrome/browser/ui/app_list/test/app_list_shower_unittest.cc |
| +++ b/chrome/browser/ui/app_list/app_list_shower_views_unittest.cc |
| @@ -2,26 +2,38 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "chrome/browser/ui/app_list/app_list_shower_views.h" |
| + |
| #include "base/files/file_path.h" |
| #include "chrome/browser/profiles/profile.h" |
| -#include "chrome/browser/ui/app_list/app_list.h" |
| -#include "chrome/browser/ui/app_list/app_list_factory.h" |
| -#include "chrome/browser/ui/app_list/app_list_shower.h" |
| +#include "chrome/browser/ui/app_list/app_list_shower_delegate.h" |
| #include "chrome/browser/ui/app_list/scoped_keep_alive.h" |
| #include "chrome/browser/ui/app_list/test/fake_profile.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| -class FakeAppList : public AppList { |
| +namespace { |
| + |
| +class TestAppListShower : public AppListShower { |
|
Matt Giuca
2014/04/30 00:41:23
Is FakeAppListShower a better name? (This is not a
tapted
2014/04/30 03:26:03
Done.
|
| public: |
| - explicit FakeAppList(Profile* profile) |
| - : profile_(profile) { |
| + explicit TestAppListShower(AppListShowerDelegate* delegate) |
| + : AppListShower(delegate), has_view_(false), visible_(false) {} |
| + |
| + // AppListShower: |
| + virtual void HandleViewBeingDestroyed() OVERRIDE { |
| + AppListShower::HandleViewBeingDestroyed(); |
| + has_view_ = false; |
| + visible_ = false; |
| } |
| - std::string profile_name() { |
| - return profile_->GetProfileName(); |
| + virtual bool IsAppListVisible() const OVERRIDE { return visible_; } |
| + |
| + virtual app_list::AppListView* MakeViewForCurrentProfile() { |
| + has_view_ = true; |
| + return NULL; |
| } |
| - // AppList overrides. |
| + virtual void UpdateViewForNewProfile() OVERRIDE {} |
| + |
| virtual void Show() OVERRIDE { |
| visible_ = true; |
| } |
| @@ -30,54 +42,28 @@ class FakeAppList : public AppList { |
| visible_ = false; |
| } |
| - virtual void MoveNearCursor() OVERRIDE { |
| + virtual bool HasView() const OVERRIDE { |
| + return has_view_; |
| } |
| - virtual bool IsVisible() OVERRIDE { |
| - return visible_; |
| - } |
| - |
| - virtual void Prerender() OVERRIDE { |
| - prerendered_ = true; |
| - } |
| - |
| - virtual gfx::NativeWindow GetWindow() OVERRIDE { |
| - return NULL; |
| - } |
| - |
| - virtual void SetProfile(Profile* profile) OVERRIDE { |
| - profile_ = profile; |
| - } |
| - |
| - Profile* profile_; |
| + private: |
| + bool has_view_; |
| bool visible_; |
| - bool prerendered_; |
| -}; |
| - |
| -class FakeFactory : public AppListFactory { |
| - public: |
| - FakeFactory() |
| - : views_created_(0) { |
| - } |
| - |
| - virtual AppList* CreateAppList( |
| - Profile* profile, |
| - AppListService* service, |
| - const base::Closure& on_should_dismiss) OVERRIDE { |
| - views_created_++; |
| - return new FakeAppList(profile); |
| - } |
| - int views_created_; |
| + DISALLOW_COPY_AND_ASSIGN(TestAppListShower); |
| }; |
| -class AppListShowerUnitTest : public testing::Test { |
| +} // namespace |
| + |
| +class AppListShowerUnitTest : public testing::Test, |
| + public AppListShowerDelegate { |
| public: |
| + AppListShowerUnitTest() |
| + : views_created_(0), |
| + views_hidden_(0) {} |
| + |
| virtual void SetUp() OVERRIDE { |
| - factory_ = new FakeFactory; |
| - shower_.reset( |
| - new AppListShower(scoped_ptr<AppListFactory>(factory_), |
| - NULL /* service */)); |
| + shower_.reset(new TestAppListShower(this)); |
| profile1_ = CreateProfile("p1").Pass(); |
| profile2_ = CreateProfile("p2").Pass(); |
| } |
| @@ -89,19 +75,26 @@ class AppListShowerUnitTest : public testing::Test { |
| return make_scoped_ptr(new FakeProfile(name)); |
| } |
| - FakeAppList* GetCurrentAppList() { |
| - return static_cast<FakeAppList*>(shower_->app_list()); |
| + // AppListCreatorDelegate: |
| + virtual AppListControllerDelegate* GetControllerDelegateForCreate() { |
| + return NULL; |
| } |
| bool HasKeepAlive() const { |
| return shower_->keep_alive_.get() != NULL; |
| } |
| - // Owned by |shower_|. |
| - FakeFactory* factory_; |
| - scoped_ptr<AppListShower> shower_; |
| + virtual void OnViewCreated() OVERRIDE { ++views_created_; } |
| + virtual void OnViewHidden() OVERRIDE { ++views_hidden_; } |
| + virtual void MoveNearCursor(app_list::AppListView* view) OVERRIDE {} |
| + |
| + protected: |
| + scoped_ptr<TestAppListShower> shower_; |
| scoped_ptr<FakeProfile> profile1_; |
| scoped_ptr<FakeProfile> profile2_; |
| + |
| + int views_created_; |
| + int views_hidden_; |
| }; |
| TEST_F(AppListShowerUnitTest, Preconditions) { |
| @@ -126,17 +119,23 @@ TEST_F(AppListShowerUnitTest, HidingViewRemovesKeepalive) { |
| } |
| TEST_F(AppListShowerUnitTest, HideAndShowReusesView) { |
| + EXPECT_EQ(0, views_created_); |
| shower_->ShowForProfile(profile1_.get()); |
| + EXPECT_EQ(1, views_created_); |
| + EXPECT_EQ(0, views_hidden_); |
| shower_->DismissAppList(); |
| + EXPECT_EQ(1, views_hidden_); |
| shower_->ShowForProfile(profile1_.get()); |
| - EXPECT_EQ(1, factory_->views_created_); |
| + EXPECT_EQ(1, views_created_); |
| } |
| TEST_F(AppListShowerUnitTest, CloseAndShowRecreatesView) { |
| shower_->ShowForProfile(profile1_.get()); |
| shower_->HandleViewBeingDestroyed(); |
| + // Destroying implies hiding. A separate notification shouldn't go out. |
| + EXPECT_EQ(0, views_hidden_); |
| shower_->ShowForProfile(profile1_.get()); |
| - EXPECT_EQ(2, factory_->views_created_); |
| + EXPECT_EQ(2, views_created_); |
| } |
| TEST_F(AppListShowerUnitTest, CloseRemovesView) { |
| @@ -157,10 +156,11 @@ TEST_F(AppListShowerUnitTest, CloseAppListClearsProfile) { |
| TEST_F(AppListShowerUnitTest, SwitchingProfiles) { |
| shower_->ShowForProfile(profile1_.get()); |
| - EXPECT_EQ("p1", GetCurrentAppList()->profile_name()); |
| + EXPECT_EQ("p1", shower_->profile()->GetProfileName()); |
| shower_->ShowForProfile(profile2_.get()); |
| - EXPECT_EQ("p2", GetCurrentAppList()->profile_name()); |
| + EXPECT_EQ("p2", shower_->profile()->GetProfileName()); |
| // Shouldn't create new view for second profile - it should switch in place. |
| - EXPECT_EQ(1, factory_->views_created_); |
| + EXPECT_EQ(1, views_created_); |
| + EXPECT_EQ(0, views_hidden_); |
| } |