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/activity/public/activity_view_model.h"
7 #include "athena/resource_manager/public/resource_manager.h"
8 #include "athena/test/base/test_util.h"
9 #include "athena/test/chrome/athena_chrome_browser_test.h"
10 #include "base/command_line.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "ui/compositor/compositor_switches.h"
13 #include "ui/gfx/image/image_skia.h"
14 #include "ui/gfx/size.h"
20 // The test URL to navigate to.
21 const char kTestUrl
[] = "chrome:about";
24 // Need to override the test class to make the test always draw its content.
25 class ContentProxyBrowserTest
: public AthenaChromeBrowserTest
{
27 ContentProxyBrowserTest() {}
28 ~ContentProxyBrowserTest() override
{}
31 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
32 // Make sure that we draw the output - it's required for this test.
33 command_line
->AppendSwitch(switches::kEnablePixelOutputInTests
);
34 AthenaChromeBrowserTest::SetUpCommandLine(command_line
);
38 DISALLOW_COPY_AND_ASSIGN(ContentProxyBrowserTest
);
41 IN_PROC_BROWSER_TEST_F(ContentProxyBrowserTest
, CreateContent
) {
42 const int kTimeoutMS
= 12000; // The timeout: 2 seconds.
43 const int kIterationSleepMS
= 5; // The wait time in ms per iteration.
44 const GURL
gurl(kTestUrl
);
45 content::BrowserContext
* context
= GetBrowserContext();
46 // Create an activity (and wait until it is loaded).
47 // The size of its overview image should be empty since it is visible.
49 test_util::CreateTestWebActivity(context
,
50 base::UTF8ToUTF16("App1"),
53 DCHECK_EQ(activity1
->GetActivityViewModel()->GetOverviewModeImage()
55 gfx::Size().ToString());
57 // Create another activity. The size of all overview images should be empty
58 // since they have the visible state.
60 test_util::CreateTestWebActivity(context
,
61 base::UTF8ToUTF16("App2"),
63 DCHECK_EQ(activity1
->GetActivityViewModel()->GetOverviewModeImage()
65 gfx::Size().ToString());
66 DCHECK_EQ(activity2
->GetActivityViewModel()->GetOverviewModeImage()
68 gfx::Size().ToString());
70 // Turn the activity invisible which should create the ContentProxy.
71 activity1
->SetCurrentState(Activity::ACTIVITY_INVISIBLE
);
72 test_util::WaitUntilIdle();
73 DCHECK_EQ(activity1
->GetCurrentState(), Activity::ACTIVITY_INVISIBLE
);
75 // Wait until an image is loaded, but do not give more then 2 seconds.
78 while (image
.isNull()) {
79 // TODO(skuhne): If we add an observer to track the creation, we should add
81 image
= activity1
->GetActivityViewModel()->GetOverviewModeImage();
82 if (++iteration
> kTimeoutMS
/ kIterationSleepMS
) {
83 LOG(ERROR
) << "Timout on reading back the content image.";
86 test_util::WaitUntilIdle();
87 usleep(1000 * kIterationSleepMS
);
90 // Check that the image of the old activity has now a usable size.
91 DCHECK_NE(activity1
->GetActivityViewModel()->GetOverviewModeImage()
93 gfx::Size().ToString());
94 DCHECK_EQ(activity2
->GetActivityViewModel()->GetOverviewModeImage()
96 gfx::Size().ToString());
98 // After the Activity gets entirely unloaded, the image should still be there.
99 activity1
->SetCurrentState(Activity::ACTIVITY_UNLOADED
);
100 test_util::WaitUntilIdle();
101 DCHECK_EQ(activity1
->GetCurrentState(), Activity::ACTIVITY_UNLOADED
);
103 DCHECK_NE(activity1
->GetActivityViewModel()->GetOverviewModeImage()
105 gfx::Size().ToString());
107 // When it then becomes visible again, the image will be gone.
108 activity1
->SetCurrentState(Activity::ACTIVITY_VISIBLE
);
109 test_util::WaitUntilIdle();
110 DCHECK_EQ(activity1
->GetCurrentState(), Activity::ACTIVITY_VISIBLE
);
112 DCHECK_EQ(activity1
->GetActivityViewModel()->GetOverviewModeImage()
114 gfx::Size().ToString());
117 } // namespace athena