Added #ifdefs around PrintHeaderAndFooter for Windows and Mac.
[chromium-blink-merge.git] / athena / content / content_proxy_browsertest.cc
blob47d019823c550e8144bc5a6e7e0278fcdc3bec91
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"
15 #include "url/gurl.h"
17 namespace athena {
19 namespace {
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 {
26 public:
27 ContentProxyBrowserTest() {}
28 ~ContentProxyBrowserTest() override {}
30 // AthenaBrowserTest:
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);
37 private:
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.
48 Activity* activity1 =
49 test_util::CreateTestWebActivity(context,
50 base::UTF8ToUTF16("App1"),
51 gurl);
53 DCHECK_EQ(activity1->GetActivityViewModel()->GetOverviewModeImage()
54 .size().ToString(),
55 gfx::Size().ToString());
57 // Allow the activity time to start the renderer. Locally this was not a
58 // problem in over 150 runs, but the try server shows flakiness.
59 test_util::WaitUntilIdle();
61 // Create another activity. The size of all overview images should be empty
62 // since they have the visible state.
63 Activity* activity2 =
64 test_util::CreateTestWebActivity(context,
65 base::UTF8ToUTF16("App2"),
66 gurl);
67 DCHECK_EQ(activity1->GetActivityViewModel()->GetOverviewModeImage()
68 .size().ToString(),
69 gfx::Size().ToString());
70 DCHECK_EQ(activity2->GetActivityViewModel()->GetOverviewModeImage()
71 .size().ToString(),
72 gfx::Size().ToString());
74 // As above.
75 test_util::WaitUntilIdle();
77 // Turn the activity invisible which should create the ContentProxy.
78 activity1->SetCurrentState(Activity::ACTIVITY_INVISIBLE);
79 test_util::WaitUntilIdle();
80 DCHECK_EQ(activity1->GetCurrentState(), Activity::ACTIVITY_INVISIBLE);
82 // Wait until an image is loaded, but do not give more then 2 seconds.
83 gfx::ImageSkia image;
84 int iteration = 0;
85 while (image.isNull()) {
86 // TODO(skuhne): If we add an observer to track the creation, we should add
87 // its use here.
88 image = activity1->GetActivityViewModel()->GetOverviewModeImage();
89 if (++iteration > kTimeoutMS / kIterationSleepMS) {
90 LOG(ERROR) << "Timout on reading back the content image.";
91 break;
93 test_util::WaitUntilIdle();
94 usleep(1000 * kIterationSleepMS);
97 // Check that the image of the old activity has now a usable size.
98 DCHECK_NE(activity1->GetActivityViewModel()->GetOverviewModeImage()
99 .size().ToString(),
100 gfx::Size().ToString());
101 DCHECK_EQ(activity2->GetActivityViewModel()->GetOverviewModeImage()
102 .size().ToString(),
103 gfx::Size().ToString());
105 // After the Activity gets entirely unloaded, the image should still be there.
106 activity1->SetCurrentState(Activity::ACTIVITY_UNLOADED);
107 test_util::WaitUntilIdle();
108 DCHECK_EQ(activity1->GetCurrentState(), Activity::ACTIVITY_UNLOADED);
110 DCHECK_NE(activity1->GetActivityViewModel()->GetOverviewModeImage()
111 .size().ToString(),
112 gfx::Size().ToString());
114 // When it then becomes visible again, the image will be gone.
115 activity1->SetCurrentState(Activity::ACTIVITY_VISIBLE);
116 test_util::WaitUntilIdle();
117 DCHECK_EQ(activity1->GetCurrentState(), Activity::ACTIVITY_VISIBLE);
119 DCHECK_EQ(activity1->GetActivityViewModel()->GetOverviewModeImage()
120 .size().ToString(),
121 gfx::Size().ToString());
124 } // namespace athena