blob: 1a33fd8648fb3539f7c06f6b8755162bfb20e883 [file] [log] [blame]
Nan Zhou93b443d2022-06-21 17:46:51 +00001#include "http_utility.hpp"
George Liu647b3cd2021-07-05 12:43:56 +08002
Nan Zhoud5c80ad2022-07-11 01:16:31 +00003#include <gtest/gtest.h> // IWYU pragma: keep
4
5// IWYU pragma: no_include <gtest/gtest-message.h>
6// IWYU pragma: no_include <gtest/gtest-test-part.h>
7// IWYU pragma: no_include "gtest/gtest_pred_impl.h"
George Liu647b3cd2021-07-05 12:43:56 +08008
Nan Zhouad3edd42022-06-21 17:46:44 +00009namespace http_helpers
10{
11namespace
12{
13
Nan Zhoua02b5862022-06-21 17:46:56 +000014TEST(RequestPrefersHtml, ContainsHtmlReturnsTrue)
15{
16 EXPECT_TRUE(requestPrefersHtml("text/html, application/json"));
17}
18
19TEST(RequestPrefersHtml, NoHtmlReturnsFalse)
George Liu647b3cd2021-07-05 12:43:56 +080020{
Nan Zhouad3edd42022-06-21 17:46:44 +000021 EXPECT_FALSE(requestPrefersHtml("*/*, application/octet-stream"));
Nan Zhouad3edd42022-06-21 17:46:44 +000022 EXPECT_FALSE(requestPrefersHtml("application/json"));
Nan Zhoua02b5862022-06-21 17:46:56 +000023}
24
25TEST(IsOctetAccepted, ContainsOctetReturnsTrue)
26{
27 EXPECT_TRUE(isOctetAccepted("*/*, application/octet-stream"));
28}
29
Gunnar Millsa3526fe2022-02-02 21:56:44 +000030TEST(IsOctetAccepted, ContainsAnyMimeTypeReturnsTrue)
31{
32 EXPECT_TRUE(http_helpers::isOctetAccepted("text/html, */*"));
33}
34
35TEST(IsOctetAccepted, ContainsQFactorWeightingReturnsTrue)
36{
37 EXPECT_TRUE(http_helpers::isOctetAccepted("text/html, */*;q=0.8"));
38}
39
Nan Zhoua02b5862022-06-21 17:46:56 +000040TEST(IsOctetAccepted, NoOctetReturnsFalse)
41{
42 EXPECT_FALSE(isOctetAccepted("text/html, application/json"));
Nan Zhouad3edd42022-06-21 17:46:44 +000043 EXPECT_FALSE(isOctetAccepted("application/json"));
George Liu647b3cd2021-07-05 12:43:56 +080044}
Nan Zhouad3edd42022-06-21 17:46:44 +000045
46} // namespace
Gunnar Millsa3526fe2022-02-02 21:56:44 +000047} // namespace http_helpers