1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "athena/activity/activity_manager_impl.h"
#include "athena/activity/public/activity.h"
#include "athena/activity/public/activity_factory.h"
#include "athena/test/base/athena_test_base.h"
#include "athena/test/base/test_windows.h"
#include "ui/aura/window.h"
#include "ui/wm/core/window_util.h"
namespace athena {
typedef test::AthenaTestBase ActivityManagerTest;
TEST_F(ActivityManagerTest, Basic) {
ActivityManagerImpl* activity_manager =
static_cast<ActivityManagerImpl*>(ActivityManager::Get());
ActivityFactory* factory = ActivityFactory::Get();
Activity* activity1 =
factory->CreateWebActivity(nullptr, base::string16(), GURL());
EXPECT_EQ(1, activity_manager->num_activities());
// Activity is not visible when created.
EXPECT_FALSE(activity1->GetWindow()->TargetVisibility());
Activity::Show(activity1);
EXPECT_TRUE(activity1->GetWindow()->TargetVisibility());
Activity* activity2 =
factory->CreateWebActivity(nullptr, base::string16(), GURL());
EXPECT_EQ(2, activity_manager->num_activities());
Activity::Delete(activity1);
EXPECT_EQ(1, activity_manager->num_activities());
// Deleting the activity's window should delete the activity itself.
delete activity2->GetWindow();
EXPECT_EQ(0, activity_manager->num_activities());
}
TEST_F(ActivityManagerTest, GetActivityForWindow) {
ActivityManager* manager = ActivityManager::Get();
ActivityFactory* factory = ActivityFactory::Get();
Activity* activity1 =
factory->CreateWebActivity(nullptr, base::string16(), GURL());
Activity* activity2 =
factory->CreateWebActivity(nullptr, base::string16(), GURL());
EXPECT_EQ(activity1, manager->GetActivityForWindow(activity1->GetWindow()));
EXPECT_EQ(activity2, manager->GetActivityForWindow(activity2->GetWindow()));
EXPECT_EQ(nullptr, manager->GetActivityForWindow(nullptr));
scoped_ptr<aura::Window> window = test::CreateNormalWindow(nullptr, nullptr);
EXPECT_EQ(nullptr, manager->GetActivityForWindow(window.get()));
}
TEST_F(ActivityManagerTest, ActivationBringsActivityToTop) {
ActivityManager* manager = ActivityManager::Get();
ActivityFactory* factory = ActivityFactory::Get();
Activity* activity1 =
factory->CreateWebActivity(nullptr, base::string16(), GURL());
Activity* activity2 =
factory->CreateWebActivity(nullptr, base::string16(), GURL());
activity1->GetWindow()->Show();
activity2->GetWindow()->Show();
ASSERT_EQ(2u, manager->GetActivityList().size());
EXPECT_EQ(activity2, manager->GetActivityList()[0]);
EXPECT_EQ(activity1, manager->GetActivityList()[1]);
wm::ActivateWindow(activity1->GetWindow());
ASSERT_EQ(2u, manager->GetActivityList().size());
EXPECT_EQ(activity1, manager->GetActivityList()[0]);
EXPECT_EQ(activity2, manager->GetActivityList()[1]);
}
} // namespace athena
|