From 1e173686bb53fd0202767b2e3d3074f1e8f0e75f Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Wed, 5 Nov 2014 16:50:13 -0500 Subject: [PATCH] athena: Make sure the ActivityViewModel is always initialized correctly. The ActivityViewModel should always be initialized, whether the Activity creates its own views::Widget or not. BUG=430030 R=oshima@chromium.org Review URL: https://codereview.chromium.org/704623003 Cr-Commit-Position: refs/heads/master@{#302877} --- athena/activity/activity_manager_impl.cc | 3 +- athena/activity/activity_manager_unittest.cc | 58 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/athena/activity/activity_manager_impl.cc b/athena/activity/activity_manager_impl.cc index f47b236220b6..a9981556d7f6 100644 --- a/athena/activity/activity_manager_impl.cc +++ b/athena/activity/activity_manager_impl.cc @@ -34,7 +34,6 @@ views::Widget* CreateWidget(Activity* activity) { params.delegate = new ActivityWidgetDelegate(activity->GetActivityViewModel()); widget->Init(params); - activity->GetActivityViewModel()->Init(); return widget; } @@ -72,6 +71,8 @@ void ActivityManagerImpl::AddActivity(Activity* activity) { activities_.insert(activities_.begin(), activity); views::Widget* widget = CreateWidget(activity); widget->GetNativeView()->AddObserver(this); + activity->GetActivityViewModel()->Init(); + FOR_EACH_OBSERVER(ActivityManagerObserver, observers_, OnActivityStarted(activity)); diff --git a/athena/activity/activity_manager_unittest.cc b/athena/activity/activity_manager_unittest.cc index 561578e241cb..206136b06d7b 100644 --- a/athena/activity/activity_manager_unittest.cc +++ b/athena/activity/activity_manager_unittest.cc @@ -6,15 +6,65 @@ #include "athena/activity/public/activity.h" #include "athena/activity/public/activity_factory.h" +#include "athena/activity/public/activity_view_model.h" #include "athena/test/base/athena_test_base.h" #include "athena/test/base/test_windows.h" #include "ui/aura/window.h" +#include "ui/gfx/image/image_skia.h" +#include "ui/views/widget/widget.h" #include "ui/wm/core/window_util.h" namespace athena { typedef test::AthenaTestBase ActivityManagerTest; +class WidgetActivity : public Activity, + public ActivityViewModel { + public: + WidgetActivity() : initialized_(false) { + widget_.reset(new views::Widget()); + views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; + widget_->Init(params); + } + + bool initialized() const { return initialized_; } + + private: + ~WidgetActivity() override {} + + // athena::Activity: + athena::ActivityViewModel* GetActivityViewModel() override { return this; } + void SetCurrentState(Activity::ActivityState state) override {} + ActivityState GetCurrentState() override { return ACTIVITY_VISIBLE; } + bool IsVisible() override { return true; } + ActivityMediaState GetMediaState() override { + return ACTIVITY_MEDIA_STATE_NONE; + } + aura::Window* GetWindow() override { return widget_->GetNativeView(); } + content::WebContents* GetWebContents() override { return nullptr; } + + // athena::ActivityViewModel: + void Init() override { + initialized_ = true; + } + + SkColor GetRepresentativeColor() const override { return SK_ColorBLACK; } + base::string16 GetTitle() const override { return base::string16(); } + gfx::ImageSkia GetIcon() const override { return gfx::ImageSkia(); } + void SetActivityView(ActivityView* activity_view) override {} + bool UsesFrame() const override { return false; } + views::View* GetContentsView() override { return nullptr; } + gfx::ImageSkia GetOverviewModeImage() override { return gfx::ImageSkia(); } + void PrepareContentsForOverview() override {} + void ResetContentsView() override {} + + scoped_ptr widget_; + bool initialized_; + + DISALLOW_COPY_AND_ASSIGN(WidgetActivity); +}; + TEST_F(ActivityManagerTest, Basic) { ActivityManagerImpl* activity_manager = static_cast(ActivityManager::Get()); @@ -80,4 +130,12 @@ TEST_F(ActivityManagerTest, ActivationBringsActivityToTop) { EXPECT_EQ(activity2, manager->GetActivityList()[1]); } +TEST_F(ActivityManagerTest, WidgetActivityModelIsInitialized) { + ActivityManager* manager = ActivityManager::Get(); + WidgetActivity* activity = new WidgetActivity(); + manager->AddActivity(activity); + EXPECT_TRUE(activity->initialized()); + Activity::Delete(activity); +} + } // namespace athena -- 2.11.4.GIT