Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / athena / content / chrome / web_activity_browsertest.cc
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.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"
15 #include "url/gurl.h"
16
17 namespace athena {
18
19 namespace {
20 // The test URL to navigate to.
21 const char kTestUrl[] = "chrome:about";
22 }
23
24 typedef AthenaChromeBrowserTest WebActivityBrowserTest;
25
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
35   // shutdown.
36 }
37
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();
44
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);
55
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());
63   EXPECT_TRUE(
64       activity1->GetWebContents()->GetRenderViewHost()->IsRenderViewLive());
65   EXPECT_TRUE(
66       activity2->GetWebContents()->GetRenderViewHost()->IsRenderViewLive());
67
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());
73
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());
77   EXPECT_TRUE(
78       activity2->GetWebContents()->GetSiteInstance()->GetSiteURL().is_empty());
79   EXPECT_TRUE(
80       activity1->GetWebContents()->GetRenderViewHost()->IsRenderViewLive());
81   EXPECT_FALSE(
82       activity2->GetWebContents()->GetRenderViewHost()->IsRenderViewLive());
83
84   // Load it again.
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());
90   EXPECT_TRUE(
91       activity1->GetWebContents()->GetRenderViewHost()->IsRenderViewLive());
92   EXPECT_TRUE(
93       activity2->GetWebContents()->GetRenderViewHost()->IsRenderViewLive());
94 }
95
96
97 }  // namespace athena