OLD | NEW |
1 /// Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "athena/activity/public/activity_factory.h" | 5 #include "athena/activity/public/activity_factory.h" |
6 #include "athena/activity/public/activity_manager.h" | 6 #include "athena/activity/public/activity_manager.h" |
7 #include "athena/content/app_activity.h" | 7 #include "athena/content/app_activity.h" |
8 #include "athena/content/app_activity_registry.h" | 8 #include "athena/content/app_activity_registry.h" |
9 #include "athena/content/public/app_registry.h" | 9 #include "athena/content/public/app_registry.h" |
10 #include "athena/extensions/public/extensions_delegate.h" | 10 #include "athena/extensions/public/extensions_delegate.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 // An identifier for the running apps. | 28 // An identifier for the running apps. |
29 const char kDummyApp1[] = "aaaaaaa"; | 29 const char kDummyApp1[] = "aaaaaaa"; |
30 const char kDummyApp2[] = "bbbbbbb"; | 30 const char kDummyApp2[] = "bbbbbbb"; |
31 | 31 |
32 // A dummy test app activity which works without content / ShellAppWindow. | 32 // A dummy test app activity which works without content / ShellAppWindow. |
33 class TestAppActivity : public AppActivity { | 33 class TestAppActivity : public AppActivity { |
34 public: | 34 public: |
35 explicit TestAppActivity(const std::string& app_id) | 35 explicit TestAppActivity(const std::string& app_id) |
36 : AppActivity(app_id), | 36 : AppActivity(app_id), |
37 view_(new views::View()), | 37 view_(new views::View()) { |
38 current_state_(ACTIVITY_VISIBLE) { | |
39 app_activity_registry_ = | |
40 AppRegistry::Get()->GetAppActivityRegistry(app_id, nullptr); | |
41 app_activity_registry_->RegisterAppActivity(this); | |
42 } | 38 } |
43 ~TestAppActivity() override { | 39 ~TestAppActivity() override { |
44 app_activity_registry_->UnregisterAppActivity(this); | |
45 } | 40 } |
46 | 41 |
47 AppActivityRegistry* app_activity_registry() { | 42 AppActivityRegistry* app_activity_registry() { |
48 return app_activity_registry_; | 43 return AppActivity::app_activity_registry(); |
49 } | |
50 | |
51 // Activity: | |
52 ActivityViewModel* GetActivityViewModel() override { return this; } | |
53 void SetCurrentState(Activity::ActivityState state) override { | |
54 current_state_ = state; | |
55 if (state == ACTIVITY_UNLOADED) | |
56 app_activity_registry_->Unload(); | |
57 } | |
58 ActivityState GetCurrentState() override { return current_state_; } | |
59 bool IsVisible() override { return true; } | |
60 ActivityMediaState GetMediaState() override { | |
61 return Activity::ACTIVITY_MEDIA_STATE_NONE; | |
62 } | |
63 aura::Window* GetWindow() override { | |
64 return view_->GetWidget() ? view_->GetWidget()->GetNativeWindow() : nullptr; | |
65 } | 44 } |
66 | 45 |
67 // ActivityViewModel: | 46 // ActivityViewModel: |
68 void Init() override {} | |
69 SkColor GetRepresentativeColor() const override { return 0; } | |
70 base::string16 GetTitle() const override { return title_; } | |
71 bool UsesFrame() const override { return true; } | |
72 views::View* GetContentsView() override { return view_; } | 47 views::View* GetContentsView() override { return view_; } |
73 gfx::ImageSkia GetOverviewModeImage() override { return gfx::ImageSkia(); } | |
74 | 48 |
75 private: | 49 private: |
76 // If known the registry which holds all activities for the associated app. | |
77 AppActivityRegistry* app_activity_registry_; | |
78 | |
79 // The title of the activity. | |
80 base::string16 title_; | |
81 | |
82 // Our view. | 50 // Our view. |
83 views::View* view_; | 51 views::View* view_; |
84 | 52 |
85 // The current state for this activity. | |
86 ActivityState current_state_; | |
87 | |
88 DISALLOW_COPY_AND_ASSIGN(TestAppActivity); | 53 DISALLOW_COPY_AND_ASSIGN(TestAppActivity); |
89 }; | 54 }; |
90 | 55 |
91 // An AppContentDelegateClass which we can query for call stats. | 56 // An AppContentDelegateClass which we can query for call stats. |
92 class TestExtensionsDelegate : public ExtensionsDelegate { | 57 class TestExtensionsDelegate : public ExtensionsDelegate { |
93 public: | 58 public: |
94 TestExtensionsDelegate() : unload_called_(0), restart_called_(0) {} | 59 TestExtensionsDelegate() : unload_called_(0), restart_called_(0) {} |
95 ~TestExtensionsDelegate() override {} | 60 ~TestExtensionsDelegate() override {} |
96 | 61 |
97 int unload_called() const { return unload_called_; } | 62 int unload_called() const { return unload_called_; } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 AthenaTestBase::SetUp(); | 107 AthenaTestBase::SetUp(); |
143 // Create and install our TestAppContentDelegate with instrumentation. | 108 // Create and install our TestAppContentDelegate with instrumentation. |
144 ExtensionsDelegate::Shutdown(); | 109 ExtensionsDelegate::Shutdown(); |
145 // The instance will be deleted by ExtensionsDelegate::Shutdown(). | 110 // The instance will be deleted by ExtensionsDelegate::Shutdown(). |
146 test_extensions_delegate_ = new TestExtensionsDelegate(); | 111 test_extensions_delegate_ = new TestExtensionsDelegate(); |
147 } | 112 } |
148 | 113 |
149 // A function to create an Activity. | 114 // A function to create an Activity. |
150 TestAppActivity* CreateAppActivity(const std::string& app_id) { | 115 TestAppActivity* CreateAppActivity(const std::string& app_id) { |
151 TestAppActivity* activity = new TestAppActivity(app_id); | 116 TestAppActivity* activity = new TestAppActivity(app_id); |
| 117 activity->SetCurrentState(Activity::ACTIVITY_VISIBLE); |
152 ActivityManager::Get()->AddActivity(activity); | 118 ActivityManager::Get()->AddActivity(activity); |
153 return activity; | 119 return activity; |
154 } | 120 } |
155 | 121 |
156 void DeleteActivity(Activity* activity) { | 122 void DeleteActivity(Activity* activity) { |
157 Activity::Delete(activity); | 123 Activity::Delete(activity); |
158 RunAllPendingInMessageLoop(); | 124 RunAllPendingInMessageLoop(); |
159 } | 125 } |
160 | 126 |
161 // Get the position of the activity in the navigation history. | 127 // Get the position of the activity in the navigation history (the position |
| 128 // of the oldest activity is 0). |
162 int GetActivityPosition(Activity* activity) { | 129 int GetActivityPosition(Activity* activity) { |
163 aura::Window* window = activity->GetActivityViewModel()->GetContentsView() | 130 const ActivityList& activity_list = |
164 ->GetWidget()->GetNativeWindow(); | 131 ActivityManager::Get()->GetActivityList(); |
165 aura::Window::Windows windows = activity->GetWindow()->parent()->children(); | 132 ActivityList::const_iterator iter = |
166 for (size_t i = 0; i < windows.size(); i++) { | 133 std::find(activity_list.begin(), activity_list.end(), activity); |
167 if (windows[i] == window) | 134 return (iter == activity_list.end()) ? -1 |
168 return i; | 135 : (activity_list.end() - iter - 1); |
169 } | |
170 return -1; | |
171 } | 136 } |
172 | 137 |
173 // To avoid interference of the ResourceManager in these AppActivity | 138 // To avoid interference of the ResourceManager in these AppActivity |
174 // framework tests, we disable the ResourceManager for some tests. | 139 // framework tests, we disable the ResourceManager for some tests. |
175 // Every use/interference of this function gets explained. | 140 // Every use/interference of this function gets explained. |
176 void DisableResourceManager() { | 141 void DisableResourceManager() { |
177 ResourceManager::Get()->Pause(true); | 142 ResourceManager::Get()->Pause(true); |
178 } | 143 } |
179 | 144 |
180 protected: | 145 protected: |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 // However - the restart in this test framework does not really restart and | 387 // However - the restart in this test framework does not really restart and |
423 // all objects should be still there.. | 388 // all objects should be still there.. |
424 EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications()); | 389 EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications()); |
425 EXPECT_TRUE(app_activity_registry->unloaded_activity_proxy()); | 390 EXPECT_TRUE(app_activity_registry->unloaded_activity_proxy()); |
426 Activity::Delete(app_activity_registry->unloaded_activity_proxy()); | 391 Activity::Delete(app_activity_registry->unloaded_activity_proxy()); |
427 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); | 392 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); |
428 } | 393 } |
429 | 394 |
430 } // namespace test | 395 } // namespace test |
431 } // namespace athena | 396 } // namespace athena |
OLD | NEW |