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

Unified Diff: chrome/browser/ui/app_list/app_list_shower_views_unittest.cc

Issue 225053004: Refactor views app list services to allow more code sharing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase+sim30 Created 6 years, 8 months 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 side-by-side diff with in-line comments
Download patch
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 58%
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 0174963472e8d4a0a994a95f81bfaffc07f2bc8a..fb2f7476abaf9af52ade0454c7b738828045f27c 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 FakeAppListShower : public AppListShower {
public:
- explicit FakeAppList(Profile* profile)
- : profile_(profile) {
+ explicit FakeAppListShower(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() OVERRIDE {
+ 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(FakeAppListShower);
};
-class AppListShowerUnitTest : public testing::Test {
+} // namespace
+
+class AppListShowerUnitTest : public testing::Test,
+ public AppListShowerDelegate {
public:
+ AppListShowerUnitTest()
+ : views_created_(0),
+ views_dismissed_(0) {}
+
virtual void SetUp() OVERRIDE {
- factory_ = new FakeFactory;
- shower_.reset(
- new AppListShower(scoped_ptr<AppListFactory>(factory_),
- NULL /* service */));
+ shower_.reset(new FakeAppListShower(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() OVERRIDE {
+ 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 OnViewDismissed() OVERRIDE { ++views_dismissed_; }
+ virtual void MoveNearCursor(app_list::AppListView* view) OVERRIDE {}
+
+ protected:
+ scoped_ptr<FakeAppListShower> shower_;
scoped_ptr<FakeProfile> profile1_;
scoped_ptr<FakeProfile> profile2_;
+
+ int views_created_;
+ int views_dismissed_;
};
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_dismissed_);
shower_->DismissAppList();
+ EXPECT_EQ(1, views_dismissed_);
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_dismissed_);
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_dismissed_);
}
« no previous file with comments | « chrome/browser/ui/app_list/app_list_shower_views.cc ('k') | chrome/browser/ui/app_list/test/app_list_shower_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698