forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgoogle_url_loader_throttle_unittest.cc
83 lines (67 loc) · 2.67 KB
/
google_url_loader_throttle_unittest.cc
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
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/common/google_url_loader_throttle.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/renderer_configuration.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_ANDROID)
#include "ui/base/device_form_factor.h"
#endif
class GoogleURLLoaderThrottleTest : public testing::Test {
public:
GoogleURLLoaderThrottleTest() {
scoped_feature_list_.InitWithFeatureList(
std::make_unique<base::FeatureList>());
}
~GoogleURLLoaderThrottleTest() override = default;
base::test::ScopedFeatureList& scoped_feature_list() {
return scoped_feature_list_;
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
#if defined(OS_ANDROID)
TEST_F(GoogleURLLoaderThrottleTest, RequestDesktopHeaderForLargeScreen) {
scoped_feature_list().Reset();
scoped_feature_list().InitAndEnableFeature(
features::kRequestDesktopSiteForTablets);
GoogleURLLoaderThrottle throttle(/* client_header= */ "",
/* is_tab_large_enough= */ true,
chrome::mojom::DynamicParams());
network::ResourceRequest request;
request.url = GURL("https://www.google.com");
bool defer = false;
throttle.WillStartRequest(&request, &defer);
// Only set header for tablets, not for phone.
if (ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET) {
std::string isTablet;
EXPECT_TRUE(request.headers.GetHeader("X-Eligible-Tablet", &isTablet));
EXPECT_EQ(isTablet, "1");
} else {
EXPECT_FALSE(request.headers.HasHeader("X-Eligible-Tablet"));
}
}
TEST_F(GoogleURLLoaderThrottleTest, RequestDesktopHeaderForSmallScreen) {
scoped_feature_list().Reset();
scoped_feature_list().InitAndEnableFeature(
features::kRequestDesktopSiteForTablets);
GoogleURLLoaderThrottle throttle(/* client_header= */ "",
/* is_tab_large_enough= */ false,
chrome::mojom::DynamicParams());
network::ResourceRequest request;
request.url = GURL("https://www.google.com");
bool defer = false;
throttle.WillStartRequest(&request, &defer);
// Only set header for tablets, not for phone.
if (ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET) {
std::string isTablet;
EXPECT_TRUE(request.headers.GetHeader("X-Eligible-Tablet", &isTablet));
EXPECT_EQ(isTablet, "0");
} else {
EXPECT_FALSE(request.headers.HasHeader("X-Eligible-Tablet"));
}
}
#endif