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.h" | 5 #include "athena/activity/public/activity.h" |
6 #include "athena/resource_manager/public/resource_manager.h" | 6 #include "athena/resource_manager/public/resource_manager.h" |
7 #include "athena/test/base/activity_lifetime_tracker.h" | 7 #include "athena/test/base/activity_lifetime_tracker.h" |
8 #include "athena/test/chrome/athena_app_browsertest.h" | 8 #include "athena/test/chrome/athena_app_browsertest.h" |
9 #include "athena/test/chrome/test_util.h" | 9 #include "athena/test/chrome/test_util.h" |
10 #include "athena/wm/public/window_list_provider.h" | 10 #include "athena/wm/public/window_list_provider.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 virtual void TearDownOnMainThread() override { | 34 virtual void TearDownOnMainThread() override { |
35 tracker_.reset(); | 35 tracker_.reset(); |
36 AthenaAppBrowserTest::TearDownOnMainThread(); | 36 AthenaAppBrowserTest::TearDownOnMainThread(); |
37 } | 37 } |
38 | 38 |
39 protected: | 39 protected: |
40 // A |proxy_activity| got deleted and this function waits, using the |tracker| | 40 // A |proxy_activity| got deleted and this function waits, using the |tracker| |
41 // until the application got restarted returning the new application activity. | 41 // until the application got restarted returning the new application activity. |
42 Activity* WaitForProxyDestruction(Activity* proxy_activity) { | 42 Activity* WaitForProxyDestruction(Activity* proxy_activity) { |
43 ActivityLifetimeTracker tracker; | 43 ActivityLifetimeTracker tracker; |
44 void* deleted_activity = NULL; | 44 void* deleted_activity = nullptr; |
45 Activity* app_activity = NULL; | 45 Activity* app_activity = nullptr; |
46 while (!app_activity && !deleted_activity) { | 46 while (!app_activity && !deleted_activity) { |
47 deleted_activity = tracker_->GetDeletedActivityAndReset(); | 47 deleted_activity = tracker_->GetDeletedActivityAndReset(); |
48 app_activity = tracker_->GetNewActivityAndReset(); | 48 app_activity = tracker_->GetNewActivityAndReset(); |
49 test_util::WaitUntilIdle(); | 49 test_util::WaitUntilIdle(); |
50 usleep(5000); | 50 usleep(5000); |
51 } | 51 } |
52 EXPECT_EQ(deleted_activity, proxy_activity); | 52 EXPECT_EQ(deleted_activity, proxy_activity); |
53 EXPECT_TRUE(app_activity); | 53 EXPECT_TRUE(app_activity); |
54 return app_activity; | 54 return app_activity; |
55 } | 55 } |
56 | 56 |
57 // Returns true when the window of the |activity| has the focus. | 57 // Returns true when the window of the |activity| has the focus. |
58 bool IsActivityActive(Activity* activity) { | 58 bool IsActivityActive(Activity* activity) { |
59 return wm::IsActiveWindow(activity->GetWindow()); | 59 return wm::IsActiveWindow(activity->GetWindow()); |
60 } | 60 } |
61 | 61 |
62 // Create a setup where the frontmost window is a web activity and then | 62 // Create a setup where the frontmost window is a web activity and then |
63 // an unloaded app activity (proxy). Note that the resource manager will be | 63 // an unloaded app activity (proxy). Note that the resource manager will be |
64 // set to CRITICAL to force the application to unload. | 64 // set to CRITICAL to force the application to unload. |
65 void SetUpWebAndProxyActivity(Activity** web_activity, | 65 void SetUpWebAndProxyActivity(Activity** web_activity, |
66 Activity** proxy_activity) { | 66 Activity** proxy_activity) { |
67 // Create an application activity. | 67 // Create an application activity. |
68 Activity* app_activity = CreateTestAppActivity(GetTestAppID()); | 68 Activity* app_activity = CreateTestAppActivity(GetTestAppID()); |
69 ASSERT_TRUE(app_activity); | 69 ASSERT_TRUE(app_activity); |
70 EXPECT_EQ(app_activity, tracker_->GetNewActivityAndReset()); | 70 EXPECT_EQ(app_activity, tracker_->GetNewActivityAndReset()); |
71 EXPECT_EQ(NULL, tracker_->GetDeletedActivityAndReset()); | 71 EXPECT_EQ(nullptr, tracker_->GetDeletedActivityAndReset()); |
72 | 72 |
73 // Then a web activity (which will then be in front of the app). | 73 // Then a web activity (which will then be in front of the app). |
74 *web_activity = test_util::CreateTestWebActivity( | 74 *web_activity = test_util::CreateTestWebActivity( |
75 test_util::GetBrowserContext(), | 75 test_util::GetBrowserContext(), |
76 base::UTF8ToUTF16("App1"), | 76 base::UTF8ToUTF16("App1"), |
77 GURL(kTestUrl)); | 77 GURL(kTestUrl)); |
78 ASSERT_TRUE(*web_activity); | 78 ASSERT_TRUE(*web_activity); |
79 EXPECT_EQ(*web_activity, tracker_->GetNewActivityAndReset()); | 79 EXPECT_EQ(*web_activity, tracker_->GetNewActivityAndReset()); |
80 EXPECT_EQ(NULL, tracker_->GetDeletedActivityAndReset()); | 80 EXPECT_EQ(nullptr, tracker_->GetDeletedActivityAndReset()); |
81 | 81 |
82 const aura::Window::Windows& windows = | 82 const aura::Window::Windows& windows = |
83 WindowManager::Get()->GetWindowListProvider()->GetWindowList(); | 83 WindowManager::Get()->GetWindowListProvider()->GetWindowList(); |
84 | 84 |
85 // The order of windows should now be: Web activity, app activity. | 85 // The order of windows should now be: Web activity, app activity. |
86 EXPECT_EQ(app_activity->GetWindow(), windows[0]); | 86 EXPECT_EQ(app_activity->GetWindow(), windows[0]); |
87 EXPECT_EQ((*web_activity)->GetWindow(), windows[1]); | 87 EXPECT_EQ((*web_activity)->GetWindow(), windows[1]); |
88 | 88 |
89 // We let the ResourceManager unload now the app. To accomplish this, we | 89 // We let the ResourceManager unload now the app. To accomplish this, we |
90 // first set the app to INIVSIBLE and then let the ResourceManager unload it | 90 // first set the app to INIVSIBLE and then let the ResourceManager unload it |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 EXPECT_TRUE(IsActivityActive(web_activity)); | 131 EXPECT_TRUE(IsActivityActive(web_activity)); |
132 | 132 |
133 Activity* app_activity = CreateTestAppActivity(GetTestAppID()); | 133 Activity* app_activity = CreateTestAppActivity(GetTestAppID()); |
134 EXPECT_TRUE(IsActivityActive(app_activity)); | 134 EXPECT_TRUE(IsActivityActive(app_activity)); |
135 } | 135 } |
136 | 136 |
137 // Test that setting an application state to UNLOADED a proxy gets created and | 137 // Test that setting an application state to UNLOADED a proxy gets created and |
138 // upon changing it to invisible it gets reloaded it its current list location. | 138 // upon changing it to invisible it gets reloaded it its current list location. |
139 IN_PROC_BROWSER_TEST_F(AppActivityBrowserTest, UnloadReloadApplicationInPlace) { | 139 IN_PROC_BROWSER_TEST_F(AppActivityBrowserTest, UnloadReloadApplicationInPlace) { |
140 // Set up the experiment. | 140 // Set up the experiment. |
141 Activity* proxy_activity = NULL; | 141 Activity* proxy_activity = nullptr; |
142 Activity* web_activity = NULL; | 142 Activity* web_activity = nullptr; |
143 SetUpWebAndProxyActivity(&web_activity, &proxy_activity); | 143 SetUpWebAndProxyActivity(&web_activity, &proxy_activity); |
144 // By returning to a low memory pressure the application should start again. | 144 // By returning to a low memory pressure the application should start again. |
145 test_util::SendTestMemoryPressureEvent(ResourceManager::MEMORY_PRESSURE_LOW); | 145 test_util::SendTestMemoryPressureEvent(ResourceManager::MEMORY_PRESSURE_LOW); |
146 Activity* app_activity = WaitForProxyDestruction(proxy_activity); | 146 Activity* app_activity = WaitForProxyDestruction(proxy_activity); |
147 proxy_activity = NULL; // The proxy is gone now. | 147 proxy_activity = nullptr; // The proxy is gone now. |
148 | 148 |
149 // After this, the application should remain at its current location in the | 149 // After this, the application should remain at its current location in the |
150 // stack and the current window should stay active. | 150 // stack and the current window should stay active. |
151 const aura::Window::Windows& windows = | 151 const aura::Window::Windows& windows = |
152 WindowManager::Get()->GetWindowListProvider()->GetWindowList(); | 152 WindowManager::Get()->GetWindowListProvider()->GetWindowList(); |
153 EXPECT_EQ(app_activity->GetWindow(), windows[0]); | 153 EXPECT_EQ(app_activity->GetWindow(), windows[0]); |
154 EXPECT_EQ(web_activity->GetWindow(), windows[1]); | 154 EXPECT_EQ(web_activity->GetWindow(), windows[1]); |
155 EXPECT_TRUE(IsActivityActive(web_activity)); | 155 EXPECT_TRUE(IsActivityActive(web_activity)); |
156 } | 156 } |
157 | 157 |
158 // Check that activating an unloaded application will bring it properly to the | 158 // Check that activating an unloaded application will bring it properly to the |
159 // front of the stack (and activate it). | 159 // front of the stack (and activate it). |
160 IN_PROC_BROWSER_TEST_F(AppActivityBrowserTest, ReloadActivatedApplication) { | 160 IN_PROC_BROWSER_TEST_F(AppActivityBrowserTest, ReloadActivatedApplication) { |
161 // Set up the experiment. | 161 // Set up the experiment. |
162 Activity* proxy_activity = NULL; | 162 Activity* proxy_activity = nullptr; |
163 Activity* web_activity = NULL; | 163 Activity* web_activity = nullptr; |
164 SetUpWebAndProxyActivity(&web_activity, &proxy_activity); | 164 SetUpWebAndProxyActivity(&web_activity, &proxy_activity); |
165 | 165 |
166 // Activating the proxy should push back the web app, lauch the application, | 166 // Activating the proxy should push back the web app, lauch the application, |
167 // kill the proxy and turn it active. | 167 // kill the proxy and turn it active. |
168 proxy_activity->GetWindow()->Show(); | 168 proxy_activity->GetWindow()->Show(); |
169 wm::ActivateWindow(proxy_activity->GetWindow()); | 169 wm::ActivateWindow(proxy_activity->GetWindow()); |
170 const aura::Window::Windows& windows = | 170 const aura::Window::Windows& windows = |
171 WindowManager::Get()->GetWindowListProvider()->GetWindowList(); | 171 WindowManager::Get()->GetWindowListProvider()->GetWindowList(); |
172 EXPECT_EQ(web_activity->GetWindow(), windows[0]); | 172 EXPECT_EQ(web_activity->GetWindow(), windows[0]); |
173 | 173 |
174 Activity* app_activity = WaitForProxyDestruction(proxy_activity); | 174 Activity* app_activity = WaitForProxyDestruction(proxy_activity); |
175 proxy_activity = NULL; // The proxy is gone now. | 175 proxy_activity = nullptr; // The proxy is gone now. |
176 | 176 |
177 // After this, the application should remain at its current location in the | 177 // After this, the application should remain at its current location in the |
178 // stack and the activation focus should remain on the current window as well. | 178 // stack and the activation focus should remain on the current window as well. |
179 EXPECT_EQ(app_activity->GetWindow(), windows[1]); | 179 EXPECT_EQ(app_activity->GetWindow(), windows[1]); |
180 EXPECT_TRUE(IsActivityActive(app_activity)); | 180 EXPECT_TRUE(IsActivityActive(app_activity)); |
181 EXPECT_EQ(web_activity->GetWindow(), windows[0]); | 181 EXPECT_EQ(web_activity->GetWindow(), windows[0]); |
182 } | 182 } |
183 | 183 |
184 // Check that moving a proxy window to the front will properly restart the app | 184 // Check that moving a proxy window to the front will properly restart the app |
185 // and activate it. | 185 // and activate it. |
186 IN_PROC_BROWSER_TEST_F(AppActivityBrowserTest, ReloadMovedApplication) { | 186 IN_PROC_BROWSER_TEST_F(AppActivityBrowserTest, ReloadMovedApplication) { |
187 // Set up the experiment. | 187 // Set up the experiment. |
188 Activity* proxy_activity = NULL; | 188 Activity* proxy_activity = nullptr; |
189 Activity* web_activity = NULL; | 189 Activity* web_activity = nullptr; |
190 SetUpWebAndProxyActivity(&web_activity, &proxy_activity); | 190 SetUpWebAndProxyActivity(&web_activity, &proxy_activity); |
191 // Moving the window to the front will restart the app. | 191 // Moving the window to the front will restart the app. |
192 WindowManager::Get()->GetWindowListProvider()->StackWindowFrontOf( | 192 WindowManager::Get()->GetWindowListProvider()->StackWindowFrontOf( |
193 proxy_activity->GetWindow(), | 193 proxy_activity->GetWindow(), |
194 web_activity->GetWindow()); | 194 web_activity->GetWindow()); |
195 const aura::Window::Windows& windows = | 195 const aura::Window::Windows& windows = |
196 WindowManager::Get()->GetWindowListProvider()->GetWindowList(); | 196 WindowManager::Get()->GetWindowListProvider()->GetWindowList(); |
197 EXPECT_EQ(web_activity->GetWindow(), windows[0]); | 197 EXPECT_EQ(web_activity->GetWindow(), windows[0]); |
198 | 198 |
199 Activity* app_activity = WaitForProxyDestruction(proxy_activity); | 199 Activity* app_activity = WaitForProxyDestruction(proxy_activity); |
200 proxy_activity = NULL; // The proxy is gone now. | 200 proxy_activity = nullptr; // The proxy is gone now. |
201 | 201 |
202 // After this, the application should remain at its current location in the | 202 // After this, the application should remain at its current location in the |
203 // stack and the activation focus should remain on the current window as well. | 203 // stack and the activation focus should remain on the current window as well. |
204 EXPECT_EQ(app_activity->GetWindow(), windows[1]); | 204 EXPECT_EQ(app_activity->GetWindow(), windows[1]); |
205 EXPECT_TRUE(IsActivityActive(app_activity)); | 205 EXPECT_TRUE(IsActivityActive(app_activity)); |
206 EXPECT_EQ(web_activity->GetWindow(), windows[0]); | 206 EXPECT_EQ(web_activity->GetWindow(), windows[0]); |
207 } | 207 } |
208 | 208 |
209 } // namespace athena | 209 } // namespace athena |
OLD | NEW |