OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "athena/activity/public/activity_manager.h" | |
6 | |
7 #include "athena/activity/public/activity_factory.h" | |
8 #include "athena/content/app_activity.h" | |
9 #include "athena/content/app_activity_registry.h" | |
10 #include "athena/content/public/app_content_delegate.h" | |
11 #include "athena/content/public/app_registry.h" | |
12 #include "athena/test/athena_test_base.h" | |
13 #include "extensions/shell/browser/shell_app_window.h" | |
14 #include "ui/views/view.h" | |
15 | |
16 | |
17 namespace content { | |
18 class BrowserContext; | |
19 } | |
20 | |
21 namespace athena { | |
22 namespace test { | |
23 | |
24 namespace { | |
25 | |
26 // An identifier for the running apps. | |
27 const char kDummyApp1[] = "aaaaaaa"; | |
28 const char kDummyApp2[] = "bbbbbbb"; | |
29 | |
30 // A dummy test app activity which works without content / ShellAppWindow. | |
31 class TestAppActivity : public AppActivity { | |
32 public: | |
33 explicit TestAppActivity(const std::string& app_id) : | |
34 AppActivity(NULL), | |
35 app_id_(app_id), | |
36 view_(new views::View()) { | |
37 app_activity_registry_ = | |
38 AppRegistry::Get()->GetAppActivityRegistry(app_id, NULL); | |
39 app_activity_registry_->RegisterAppActivity(this); | |
40 } | |
41 virtual ~TestAppActivity() { | |
42 app_activity_registry_->UnregisterAppActivity(this); | |
43 // We need to remove ourselves here since the activity will not be destroyed | |
44 // with the window closure. | |
45 ActivityManager::Get()->RemoveActivity(this); | |
46 } | |
47 | |
48 AppActivityRegistry* app_activity_registry() { | |
49 return app_activity_registry_; | |
50 } | |
51 | |
52 // Activity: | |
53 virtual ActivityViewModel* GetActivityViewModel() OVERRIDE { | |
54 return this; | |
55 } | |
56 virtual bool IsVisible() OVERRIDE { | |
57 return true; | |
58 } | |
59 virtual ActivityMediaState GetMediaState() OVERRIDE { | |
60 return Activity::ACTIVITY_MEDIA_STATE_NONE; | |
61 } | |
62 virtual aura::Window* GetWindow() OVERRIDE { return NULL; } | |
63 | |
64 // ActivityViewModel: | |
65 virtual void Init() OVERRIDE {} | |
66 virtual SkColor GetRepresentativeColor() const OVERRIDE { return 0; } | |
67 virtual base::string16 GetTitle() const OVERRIDE { return title_; } | |
68 virtual bool UsesFrame() const OVERRIDE { return true; } | |
69 virtual views::View* GetContentsView() OVERRIDE { return view_; } | |
70 virtual void CreateOverviewModeImage() OVERRIDE {} | |
71 | |
72 private: | |
73 // If known the registry which holds all activities for the associated app. | |
74 AppActivityRegistry* app_activity_registry_; | |
75 | |
76 // The application ID. | |
77 const std::string& app_id_; | |
78 | |
79 // The title of the activity. | |
80 base::string16 title_; | |
81 | |
82 // Our view. | |
83 views::View* view_; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(TestAppActivity); | |
86 }; | |
87 | |
88 // An AppContentDelegateClass which we can query for call stats. | |
89 class TestAppContentDelegate : public AppContentDelegate { | |
90 public: | |
91 TestAppContentDelegate() : unload_called_(0), | |
92 restart_called_(0) {} | |
93 virtual ~TestAppContentDelegate() {} | |
94 | |
95 int unload_called() { return unload_called_; } | |
96 int restart_called() { return restart_called_; } | |
97 void SetExtensionID(const std::string& extension_id) { | |
98 extension_id_to_return_ = extension_id; | |
99 } | |
100 | |
101 // Unload an application. Returns true when unloaded. | |
102 virtual bool UnloadApplication( | |
103 const std::string& app_id, | |
104 content::BrowserContext* browser_context) OVERRIDE { | |
105 unload_called_++; | |
106 return true; | |
107 } | |
108 // Restarts an application. Returns true when the restart was initiated. | |
109 virtual bool RestartApplication( | |
110 const std::string& app_id, | |
111 content::BrowserContext* browser_context) OVERRIDE { | |
112 restart_called_++; | |
113 return true; | |
114 } | |
115 // Returns the application ID (or an empty string) for a given web content. | |
116 virtual std::string GetExtensionID( | |
117 content::WebContents* web_contents) OVERRIDE { | |
118 return extension_id_to_return_; | |
119 } | |
120 | |
121 private: | |
122 int unload_called_; | |
123 int restart_called_; | |
124 std::string extension_id_to_return_; | |
125 | |
126 DISALLOW_COPY_AND_ASSIGN(TestAppContentDelegate); | |
127 }; | |
128 | |
129 } // namespace | |
130 | |
131 // Our testing base. | |
132 class AppActivityTest : public AthenaTestBase { | |
133 public: | |
134 AppActivityTest() : test_app_content_delegate_(NULL) {} | |
135 virtual ~AppActivityTest() {} | |
136 | |
137 // AthenaTestBase: | |
138 virtual void SetUp() OVERRIDE { | |
139 AthenaTestBase::SetUp(); | |
140 // Create and install our TestAppContentDelegate with instrumentation. | |
141 test_app_content_delegate_ = new TestAppContentDelegate(); | |
142 AppRegistry::Get()->SetDelegate(test_app_content_delegate_); | |
143 } | |
144 | |
145 // A function to create an Activity. | |
146 TestAppActivity* CreateAppActivity(const std::string& app_id) { | |
147 TestAppActivity* activity = new TestAppActivity(app_id); | |
148 ActivityManager::Get()->AddActivity(activity); | |
149 return activity; | |
150 } | |
151 | |
152 protected: | |
153 TestAppContentDelegate* test_app_content_delegate() { | |
154 return test_app_content_delegate_; | |
155 } | |
156 | |
157 private: | |
158 TestAppContentDelegate* test_app_content_delegate_; | |
159 | |
160 DISALLOW_COPY_AND_ASSIGN(AppActivityTest); | |
161 }; | |
162 | |
163 // Only creates one activity and destroys it. | |
164 TEST_F(AppActivityTest, OneAppActivity) { | |
165 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); | |
166 { | |
167 scoped_ptr<TestAppActivity> app_activity(CreateAppActivity(kDummyApp1)); | |
168 EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications()); | |
169 EXPECT_EQ(1, app_activity->app_activity_registry()->NumberOfActivities()); | |
170 } | |
171 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); | |
172 EXPECT_EQ(0, test_app_content_delegate()->unload_called()); | |
173 EXPECT_EQ(0, test_app_content_delegate()->restart_called()); | |
174 } | |
175 | |
176 // Test running of two applications. | |
177 TEST_F(AppActivityTest, TwoAppsWithOneActivityEach) { | |
178 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); | |
179 { | |
180 scoped_ptr<TestAppActivity> app_activity1(CreateAppActivity(kDummyApp1)); | |
181 EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications()); | |
182 EXPECT_EQ(1, app_activity1->app_activity_registry()->NumberOfActivities()); | |
183 scoped_ptr<TestAppActivity> app_activity2(CreateAppActivity(kDummyApp2)); | |
184 EXPECT_EQ(2, AppRegistry::Get()->NumberOfApplications()); | |
185 EXPECT_EQ(1, app_activity2->app_activity_registry()->NumberOfActivities()); | |
186 EXPECT_EQ(1, app_activity1->app_activity_registry()->NumberOfActivities()); | |
187 } | |
188 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); | |
189 EXPECT_EQ(0, test_app_content_delegate()->unload_called()); | |
190 EXPECT_EQ(0, test_app_content_delegate()->restart_called()); | |
191 } | |
192 | |
193 // Create and destroy two activities for the same application. | |
194 TEST_F(AppActivityTest, TwoAppActivities) { | |
195 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); | |
196 { | |
197 TestAppActivity* app_activity1 = CreateAppActivity(kDummyApp1); | |
198 TestAppActivity* app_activity2 = CreateAppActivity(kDummyApp1); | |
199 EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications()); | |
200 EXPECT_EQ(2, app_activity1->app_activity_registry()->NumberOfActivities()); | |
201 EXPECT_EQ(app_activity1->app_activity_registry(), | |
202 app_activity2->app_activity_registry()); | |
203 delete app_activity1; | |
oshima
2014/08/18 17:51:43
scoped_ptr
Mr4D (OOO till 08-26)
2014/08/18 22:36:31
This is outdated and got already changed.
| |
204 EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications()); | |
205 EXPECT_EQ(1, app_activity2->app_activity_registry()->NumberOfActivities()); | |
206 delete app_activity2; | |
207 } | |
208 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); | |
209 { | |
210 TestAppActivity* app_activity1 = CreateAppActivity(kDummyApp1); | |
211 TestAppActivity* app_activity2 = CreateAppActivity(kDummyApp1); | |
212 EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications()); | |
213 EXPECT_EQ(2, app_activity1->app_activity_registry()->NumberOfActivities()); | |
214 EXPECT_EQ(app_activity1->app_activity_registry(), | |
215 app_activity2->app_activity_registry()); | |
216 delete app_activity2; | |
217 EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications()); | |
218 EXPECT_EQ(1, app_activity1->app_activity_registry()->NumberOfActivities()); | |
219 delete app_activity1; | |
220 } | |
221 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); | |
222 EXPECT_EQ(0, test_app_content_delegate()->unload_called()); | |
223 EXPECT_EQ(0, test_app_content_delegate()->restart_called()); | |
224 } | |
225 | |
226 // Test unload and the creation of the proxy. | |
227 TEST_F(AppActivityTest, TestUnloadWithoutDestruction) { | |
228 // TODO. | |
229 } | |
230 | |
231 // Test that when unloading an app while multiple apps / activities are present, | |
232 // the proxy gets created in the correct location. | |
233 TEST_F(AppActivityTest, TestUnloadProxyLocation) { | |
234 // TODO. | |
235 } | |
236 | |
237 // Test that an unload with multiple activities of the same app will only unload | |
238 // when all activities were marked for unloading. | |
239 TEST_F(AppActivityTest, TestMultipleActivityUnloadLock) { | |
240 // TODO. | |
241 } | |
242 | |
243 // Test that activating the proxy will reload the application. | |
244 TEST_F(AppActivityTest, TestUnloadWithReload) { | |
245 // TODO. | |
246 } | |
247 | |
248 } // namespace test | |
249 } // namespace athena | |
OLD | NEW |