1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
fuchsia_web / webengine / browser / headless_browsertest.cc [blame]
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/auto_reset.h"
#include "base/test/scoped_command_line.h"
#include "content/public/test/browser_test.h"
#include "fuchsia_web/common/test/frame_for_test.h"
#include "fuchsia_web/common/test/frame_test_util.h"
#include "fuchsia_web/common/test/test_navigation_listener.h"
#include "fuchsia_web/webengine/switches.h"
#include "fuchsia_web/webengine/test/test_data.h"
#include "fuchsia_web/webengine/test/web_engine_browser_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/switches.h"
#include "ui/ozone/public/ozone_switches.h"
namespace {
// Defines a suite of tests that exercise browser-level configuration and
// functionality.
class HeadlessTest : public WebEngineBrowserTest {
public:
HeadlessTest() { set_test_server_root(base::FilePath(kTestServerRoot)); }
~HeadlessTest() override = default;
HeadlessTest(const HeadlessTest&) = delete;
HeadlessTest& operator=(const HeadlessTest&) = delete;
protected:
void SetUp() override {
command_line_.GetProcessCommandLine()->AppendSwitchNative(
switches::kOzonePlatform, switches::kHeadless);
command_line_.GetProcessCommandLine()->AppendSwitch(switches::kHeadless);
WebEngineBrowserTest::SetUp();
}
base::test::ScopedCommandLine command_line_;
};
IN_PROC_BROWSER_TEST_F(HeadlessTest, AnimationRunsWhenFrameAlreadyActive) {
ASSERT_TRUE(embedded_test_server()->Start());
const GURL kAnimationUrl(
embedded_test_server()->GetURL("/css_animation.html"));
auto frame =
FrameForTest::Create(context(), fuchsia::web::CreateFrameParams());
frame->EnableHeadlessRendering();
LoadUrlAndExpectResponse(frame.GetNavigationController(),
fuchsia::web::LoadUrlParams(), kAnimationUrl.spec());
frame.navigation_listener().RunUntilUrlAndTitleEquals(kAnimationUrl,
"animation finished");
}
IN_PROC_BROWSER_TEST_F(HeadlessTest, AnimationNeverRunsWhenInactive) {
ASSERT_TRUE(embedded_test_server()->Start());
const GURL kAnimationUrl(
embedded_test_server()->GetURL("/css_animation.html"));
auto frame =
FrameForTest::Create(context(), fuchsia::web::CreateFrameParams());
LoadUrlAndExpectResponse(frame.GetNavigationController(),
fuchsia::web::LoadUrlParams(), kAnimationUrl.spec());
frame.navigation_listener().RunUntilUrlAndTitleEquals(
kAnimationUrl, "animation never started");
}
IN_PROC_BROWSER_TEST_F(HeadlessTest, ActivateFrameAfterDocumentLoad) {
ASSERT_TRUE(embedded_test_server()->Start());
const GURL kAnimationUrl(
embedded_test_server()->GetURL("/css_animation.html"));
auto frame =
FrameForTest::Create(context(), fuchsia::web::CreateFrameParams());
LoadUrlAndExpectResponse(frame.GetNavigationController(),
fuchsia::web::LoadUrlParams(), kAnimationUrl.spec());
frame.navigation_listener().RunUntilUrlAndTitleEquals(
kAnimationUrl, "animation never started");
frame->EnableHeadlessRendering();
frame.navigation_listener().RunUntilUrlAndTitleEquals(kAnimationUrl,
"animation finished");
}
IN_PROC_BROWSER_TEST_F(HeadlessTest, DeactivationPreventsFutureAnimations) {
ASSERT_TRUE(embedded_test_server()->Start());
const GURL kAnimationUrl(
embedded_test_server()->GetURL("/css_animation.html"));
// Activate the frame and load the page. The animation should run.
auto frame =
FrameForTest::Create(context(), fuchsia::web::CreateFrameParams());
frame->EnableHeadlessRendering();
LoadUrlAndExpectResponse(frame.GetNavigationController(),
fuchsia::web::LoadUrlParams(), kAnimationUrl.spec());
frame.navigation_listener().RunUntilUrlAndTitleEquals(kAnimationUrl,
"animation finished");
// Deactivate the page and reload it. The animation should no longer run.
frame->DisableHeadlessRendering();
frame.GetNavigationController()->Reload(fuchsia::web::ReloadType::NO_CACHE);
frame.navigation_listener().RunUntilUrlAndTitleEquals(
kAnimationUrl, "animation never started");
}
} // namespace