diff options
author | Sadrul Habib Chowdhury <sadrul@chromium.org> | 2014-11-05 16:50:13 -0500 |
---|---|---|
committer | Sadrul Habib Chowdhury <sadrul@chromium.org> | 2014-11-05 21:51:15 +0000 |
commit | 1e173686bb53fd0202767b2e3d3074f1e8f0e75f (patch) | |
tree | 6826418b946c3e43cb5793ba94bddaf1144ed27c /athena | |
parent | 5a645aa13b8230ff1725ab5d90f0ecd65e8d5d90 (diff) | |
download | chromium_src-1e173686bb53fd0202767b2e3d3074f1e8f0e75f.zip chromium_src-1e173686bb53fd0202767b2e3d3074f1e8f0e75f.tar.gz chromium_src-1e173686bb53fd0202767b2e3d3074f1e8f0e75f.tar.bz2 |
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}
Diffstat (limited to 'athena')
-rw-r--r-- | athena/activity/activity_manager_impl.cc | 3 | ||||
-rw-r--r-- | athena/activity/activity_manager_unittest.cc | 58 |
2 files changed, 60 insertions, 1 deletions
diff --git a/athena/activity/activity_manager_impl.cc b/athena/activity/activity_manager_impl.cc index f47b236..a998155 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 561578e..206136b 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<views::Widget> widget_; + bool initialized_; + + DISALLOW_COPY_AND_ASSIGN(WidgetActivity); +}; + TEST_F(ActivityManagerTest, Basic) { ActivityManagerImpl* activity_manager = static_cast<ActivityManagerImpl*>(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 |