Disable some more flaky AppWindowInterceptAllKeysTest.* on Windows
[chromium-blink-merge.git] / athena / activity / activity_manager_unittest.cc
blob206136b06d7b74507ace7127fb915cb9c78202c8
1 /// Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "athena/activity/activity_manager_impl.h"
7 #include "athena/activity/public/activity.h"
8 #include "athena/activity/public/activity_factory.h"
9 #include "athena/activity/public/activity_view_model.h"
10 #include "athena/test/base/athena_test_base.h"
11 #include "athena/test/base/test_windows.h"
12 #include "ui/aura/window.h"
13 #include "ui/gfx/image/image_skia.h"
14 #include "ui/views/widget/widget.h"
15 #include "ui/wm/core/window_util.h"
17 namespace athena {
19 typedef test::AthenaTestBase ActivityManagerTest;
21 class WidgetActivity : public Activity,
22 public ActivityViewModel {
23 public:
24 WidgetActivity() : initialized_(false) {
25 widget_.reset(new views::Widget());
26 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
27 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
28 widget_->Init(params);
31 bool initialized() const { return initialized_; }
33 private:
34 ~WidgetActivity() override {}
36 // athena::Activity:
37 athena::ActivityViewModel* GetActivityViewModel() override { return this; }
38 void SetCurrentState(Activity::ActivityState state) override {}
39 ActivityState GetCurrentState() override { return ACTIVITY_VISIBLE; }
40 bool IsVisible() override { return true; }
41 ActivityMediaState GetMediaState() override {
42 return ACTIVITY_MEDIA_STATE_NONE;
44 aura::Window* GetWindow() override { return widget_->GetNativeView(); }
45 content::WebContents* GetWebContents() override { return nullptr; }
47 // athena::ActivityViewModel:
48 void Init() override {
49 initialized_ = true;
52 SkColor GetRepresentativeColor() const override { return SK_ColorBLACK; }
53 base::string16 GetTitle() const override { return base::string16(); }
54 gfx::ImageSkia GetIcon() const override { return gfx::ImageSkia(); }
55 void SetActivityView(ActivityView* activity_view) override {}
56 bool UsesFrame() const override { return false; }
57 views::View* GetContentsView() override { return nullptr; }
58 gfx::ImageSkia GetOverviewModeImage() override { return gfx::ImageSkia(); }
59 void PrepareContentsForOverview() override {}
60 void ResetContentsView() override {}
62 scoped_ptr<views::Widget> widget_;
63 bool initialized_;
65 DISALLOW_COPY_AND_ASSIGN(WidgetActivity);
68 TEST_F(ActivityManagerTest, Basic) {
69 ActivityManagerImpl* activity_manager =
70 static_cast<ActivityManagerImpl*>(ActivityManager::Get());
71 ActivityFactory* factory = ActivityFactory::Get();
73 Activity* activity1 =
74 factory->CreateWebActivity(nullptr, base::string16(), GURL());
75 EXPECT_EQ(1, activity_manager->num_activities());
77 // Activity is not visible when created.
78 EXPECT_FALSE(activity1->GetWindow()->TargetVisibility());
79 Activity::Show(activity1);
80 EXPECT_TRUE(activity1->GetWindow()->TargetVisibility());
82 Activity* activity2 =
83 factory->CreateWebActivity(nullptr, base::string16(), GURL());
84 EXPECT_EQ(2, activity_manager->num_activities());
86 Activity::Delete(activity1);
87 EXPECT_EQ(1, activity_manager->num_activities());
89 // Deleting the activity's window should delete the activity itself.
90 delete activity2->GetWindow();
91 EXPECT_EQ(0, activity_manager->num_activities());
94 TEST_F(ActivityManagerTest, GetActivityForWindow) {
95 ActivityManager* manager = ActivityManager::Get();
96 ActivityFactory* factory = ActivityFactory::Get();
98 Activity* activity1 =
99 factory->CreateWebActivity(nullptr, base::string16(), GURL());
100 Activity* activity2 =
101 factory->CreateWebActivity(nullptr, base::string16(), GURL());
103 EXPECT_EQ(activity1, manager->GetActivityForWindow(activity1->GetWindow()));
104 EXPECT_EQ(activity2, manager->GetActivityForWindow(activity2->GetWindow()));
106 EXPECT_EQ(nullptr, manager->GetActivityForWindow(nullptr));
108 scoped_ptr<aura::Window> window = test::CreateNormalWindow(nullptr, nullptr);
109 EXPECT_EQ(nullptr, manager->GetActivityForWindow(window.get()));
112 TEST_F(ActivityManagerTest, ActivationBringsActivityToTop) {
113 ActivityManager* manager = ActivityManager::Get();
114 ActivityFactory* factory = ActivityFactory::Get();
116 Activity* activity1 =
117 factory->CreateWebActivity(nullptr, base::string16(), GURL());
118 Activity* activity2 =
119 factory->CreateWebActivity(nullptr, base::string16(), GURL());
120 activity1->GetWindow()->Show();
121 activity2->GetWindow()->Show();
123 ASSERT_EQ(2u, manager->GetActivityList().size());
124 EXPECT_EQ(activity2, manager->GetActivityList()[0]);
125 EXPECT_EQ(activity1, manager->GetActivityList()[1]);
127 wm::ActivateWindow(activity1->GetWindow());
128 ASSERT_EQ(2u, manager->GetActivityList().size());
129 EXPECT_EQ(activity1, manager->GetActivityList()[0]);
130 EXPECT_EQ(activity2, manager->GetActivityList()[1]);
133 TEST_F(ActivityManagerTest, WidgetActivityModelIsInitialized) {
134 ActivityManager* manager = ActivityManager::Get();
135 WidgetActivity* activity = new WidgetActivity();
136 manager->AddActivity(activity);
137 EXPECT_TRUE(activity->initialized());
138 Activity::Delete(activity);
141 } // namespace athena