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/public/activity.h"
6 #include "athena/resource_manager/public/resource_manager.h"
7 #include "athena/test/base/test_util.h"
8 #include "athena/test/chrome/athena_chrome_browser_test.h"
9 #include "athena/wm/public/window_list_provider.h"
10 #include "athena/wm/public/window_manager.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/site_instance.h"
14 #include "content/public/browser/web_contents.h"
20 // The test URL to navigate to.
21 const char kTestUrl
[] = "chrome:about";
24 typedef AthenaChromeBrowserTest WebActivityBrowserTest
;
26 // A simple test to create web content.
27 IN_PROC_BROWSER_TEST_F(WebActivityBrowserTest
, SimpleCreate
) {
28 const GURL
target_url(kTestUrl
);
29 // Create an activity, wait until it is loaded and check that it was created.
30 Activity
* activity
= test_util::CreateTestWebActivity(
31 GetBrowserContext(), base::UTF8ToUTF16("App"), target_url
);
32 ASSERT_TRUE(activity
);
33 EXPECT_NE(Activity::ACTIVITY_UNLOADED
, activity
->GetCurrentState());
34 // The activity manager should take care of destroying the activity upon
38 // A test to load, unload and reload content, verifying that it is getting
39 // loaded / unloaded properly.
40 IN_PROC_BROWSER_TEST_F(WebActivityBrowserTest
, LoadUnloadReload
) {
41 const GURL
target_url(kTestUrl
);
42 const aura::Window::Windows
& list
=
43 WindowManager::Get()->GetWindowListProvider()->GetWindowList();
45 // Create an activity (and wait until it is loaded).
46 // The size of its overview image should be empty since it is visible.
47 Activity
* activity2
= test_util::CreateTestWebActivity(
48 GetBrowserContext(), base::UTF8ToUTF16("App2"), target_url
);
49 EXPECT_TRUE(activity2
);
50 EXPECT_EQ(list
[0], activity2
->GetWindow());
51 EXPECT_NE(Activity::ACTIVITY_UNLOADED
, activity2
->GetCurrentState());
52 Activity
* activity1
= test_util::CreateTestWebActivity(
53 GetBrowserContext(), base::UTF8ToUTF16("App1"), target_url
);
54 EXPECT_TRUE(activity1
);
56 // |activity2| should now be the second activity. Both activities should have
57 // an active render view and the same, valid SiteURL.
58 EXPECT_EQ(list
[0], activity2
->GetWindow());
59 EXPECT_EQ(list
[1], activity1
->GetWindow());
60 GURL url
= activity1
->GetWebContents()->GetSiteInstance()->GetSiteURL();
61 EXPECT_FALSE(url
.is_empty());
62 EXPECT_EQ(url
, activity2
->GetWebContents()->GetSiteInstance()->GetSiteURL());
64 activity1
->GetWebContents()->GetRenderViewHost()->IsRenderViewLive());
66 activity2
->GetWebContents()->GetRenderViewHost()->IsRenderViewLive());
68 // Unload the second activity. The window should still be there.
69 activity2
->SetCurrentState(Activity::ACTIVITY_UNLOADED
);
70 test_util::WaitUntilIdle();
71 EXPECT_EQ(list
[0], activity2
->GetWindow());
72 EXPECT_EQ(Activity::ACTIVITY_UNLOADED
, activity2
->GetCurrentState());
74 // There should be no change to the first activity, but the second one should
75 // neither have a SiteURL, nor a RenderView.
76 EXPECT_EQ(url
, activity1
->GetWebContents()->GetSiteInstance()->GetSiteURL());
78 activity2
->GetWebContents()->GetSiteInstance()->GetSiteURL().is_empty());
80 activity1
->GetWebContents()->GetRenderViewHost()->IsRenderViewLive());
82 activity2
->GetWebContents()->GetRenderViewHost()->IsRenderViewLive());
85 activity2
->SetCurrentState(Activity::ACTIVITY_INVISIBLE
);
86 EXPECT_EQ(list
[0], activity2
->GetWindow());
87 EXPECT_EQ(Activity::ACTIVITY_INVISIBLE
, activity2
->GetCurrentState());
88 EXPECT_EQ(url
, activity1
->GetWebContents()->GetSiteInstance()->GetSiteURL());
89 EXPECT_EQ(url
, activity2
->GetWebContents()->GetSiteInstance()->GetSiteURL());
91 activity1
->GetWebContents()->GetRenderViewHost()->IsRenderViewLive());
93 activity2
->GetWebContents()->GetRenderViewHost()->IsRenderViewLive());