Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 1 | // Copyright 2017 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. |
| 4 | |
Tarun Bansal | 62efba1 | 2018-05-04 22:58:35 | [diff] [blame] | 5 | #include <cctype> |
| 6 | |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 7 | #include "base/base_switches.h" |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 8 | #include "base/bind.h" |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 9 | #include "base/command_line.h" |
Tarun Bansal | bef6d65 | 2018-10-02 18:41:01 | [diff] [blame] | 10 | #include "base/metrics/field_trial_param_associator.h" |
Gabriel Charette | b71eec89 | 2017-09-14 22:52:56 | [diff] [blame] | 11 | #include "base/run_loop.h" |
Tarun Bansal | 6bf5430 | 2017-10-02 07:39:14 | [diff] [blame] | 12 | #include "base/stl_util.h" |
Mike West | e555be86 | 2019-02-20 16:17:30 | [diff] [blame] | 13 | #include "base/strings/string_util.h" |
Callum May | 7d88ff3e | 2019-11-12 18:21:46 | [diff] [blame] | 14 | #include "base/synchronization/lock.h" |
Devlin Cronin | 626d80c | 2018-06-01 01:08:36 | [diff] [blame] | 15 | #include "base/test/metrics/histogram_tester.h" |
Tarun Bansal | 5c28afb | 2018-03-17 02:55:20 | [diff] [blame] | 16 | #include "build/build_config.h" |
Mike West | e555be86 | 2019-02-20 16:17:30 | [diff] [blame] | 17 | #include "chrome/browser/chrome_content_browser_client.h" |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 18 | #include "chrome/browser/content_settings/cookie_settings_factory.h" |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 19 | #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 20 | #include "chrome/browser/metrics/subprocess_metrics_provider.h" |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 21 | #include "chrome/browser/profiles/profile.h" |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 22 | #include "chrome/browser/ui/browser.h" |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 23 | #include "chrome/browser/ui/browser_commands.h" |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 24 | #include "chrome/test/base/in_process_browser_test.h" |
| 25 | #include "chrome/test/base/ui_test_utils.h" |
Clark DuVall | 84a33d61 | 2020-04-17 16:01:00 | [diff] [blame] | 26 | #include "components/content_settings/browser/tab_specific_content_settings.h" |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 27 | #include "components/content_settings/core/browser/cookie_settings.h" |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 28 | #include "components/content_settings/core/browser/host_content_settings_map.h" |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 29 | #include "components/content_settings/core/common/pref_names.h" |
| 30 | #include "components/prefs/pref_service.h" |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 31 | #include "content/public/browser/browser_thread.h" |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 32 | #include "content/public/browser/navigation_entry.h" |
Changwan Ryu | 434c3a3 | 2019-07-30 23:42:58 | [diff] [blame] | 33 | #include "content/public/browser/render_view_host.h" |
Tarun Bansal | bef6d65 | 2018-10-02 18:41:01 | [diff] [blame] | 34 | #include "content/public/common/content_features.h" |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 35 | #include "content/public/common/content_switches.h" |
Changwan Ryu | 434c3a3 | 2019-07-30 23:42:58 | [diff] [blame] | 36 | #include "content/public/common/web_preferences.h" |
Peter Kasting | 919ce65 | 2020-05-07 10:22:36 | [diff] [blame^] | 37 | #include "content/public/test/browser_test.h" |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 38 | #include "content/public/test/browser_test_utils.h" |
| 39 | #include "content/public/test/test_utils.h" |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 40 | #include "content/public/test/url_loader_interceptor.h" |
| 41 | #include "net/dns/mock_host_resolver.h" |
| 42 | #include "net/http/http_request_headers.h" |
Tarun Bansal | 7f3fe8c | 2018-04-06 22:37:47 | [diff] [blame] | 43 | #include "net/nqe/effective_connection_type.h" |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 44 | #include "net/test/embedded_test_server/embedded_test_server.h" |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 45 | #include "net/test/embedded_test_server/http_request.h" |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 46 | #include "net/test/embedded_test_server/http_response.h" |
Tarun Bansal | 74e189d | 2018-05-07 19:07:35 | [diff] [blame] | 47 | #include "services/network/public/cpp/cors/cors.h" |
Tarun Bansal | ceab959 | 2018-05-01 18:57:35 | [diff] [blame] | 48 | #include "services/network/public/cpp/features.h" |
Tarun Bansal | 7f3fe8c | 2018-04-06 22:37:47 | [diff] [blame] | 49 | #include "services/network/public/cpp/network_switches.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 50 | #include "third_party/blink/public/common/client_hints/client_hints.h" |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 51 | |
| 52 | namespace { |
| 53 | |
Yoav Weiss | fd1d19f | 2020-05-05 09:23:03 | [diff] [blame] | 54 | const unsigned expected_client_hints_number = 12u; |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 55 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 56 | // An interceptor that records count of fetches and client hint headers for |
| 57 | // requests to https://foo.com/non-existing-image.jpg. |
Jay Civelli | 1ff872d | 2018-03-09 21:52:16 | [diff] [blame] | 58 | class ThirdPartyURLLoaderInterceptor { |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 59 | public: |
Jay Civelli | 1ff872d | 2018-03-09 21:52:16 | [diff] [blame] | 60 | explicit ThirdPartyURLLoaderInterceptor(const GURL intercepted_url) |
| 61 | : intercepted_url_(intercepted_url), |
| 62 | interceptor_(base::BindRepeating( |
| 63 | &ThirdPartyURLLoaderInterceptor::InterceptURLRequest, |
| 64 | base::Unretained(this))) {} |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 65 | |
Jay Civelli | 1ff872d | 2018-03-09 21:52:16 | [diff] [blame] | 66 | ~ThirdPartyURLLoaderInterceptor() = default; |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 67 | |
| 68 | size_t request_count_seen() const { return request_count_seen_; } |
| 69 | |
| 70 | size_t client_hints_count_seen() const { return client_hints_count_seen_; } |
| 71 | |
| 72 | private: |
Jay Civelli | 1ff872d | 2018-03-09 21:52:16 | [diff] [blame] | 73 | bool InterceptURLRequest( |
| 74 | content::URLLoaderInterceptor::RequestParams* params) { |
| 75 | if (params->url_request.url != intercepted_url_) |
| 76 | return false; |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 77 | |
Jay Civelli | 1ff872d | 2018-03-09 21:52:16 | [diff] [blame] | 78 | request_count_seen_++; |
Mike West | 14c1110 | 2019-02-04 16:16:47 | [diff] [blame] | 79 | for (size_t i = 0; i < blink::kClientHintsMappingsCount; ++i) { |
Tarun Bansal | f9cf989 | 2018-04-06 04:38:01 | [diff] [blame] | 80 | if (params->url_request.headers.HasHeader( |
| 81 | blink::kClientHintsHeaderMapping[i])) { |
| 82 | client_hints_count_seen_++; |
| 83 | } |
Tarun Bansal | 5c28afb | 2018-03-17 02:55:20 | [diff] [blame] | 84 | } |
Jay Civelli | 1ff872d | 2018-03-09 21:52:16 | [diff] [blame] | 85 | return false; |
| 86 | } |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 87 | |
Jay Civelli | 1ff872d | 2018-03-09 21:52:16 | [diff] [blame] | 88 | GURL intercepted_url_; |
| 89 | |
| 90 | size_t request_count_seen_ = 0u; |
| 91 | |
| 92 | size_t client_hints_count_seen_ = 0u; |
| 93 | |
| 94 | content::URLLoaderInterceptor interceptor_; |
| 95 | |
| 96 | DISALLOW_COPY_AND_ASSIGN(ThirdPartyURLLoaderInterceptor); |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 97 | }; |
| 98 | |
Tarun Bansal | 62efba1 | 2018-05-04 22:58:35 | [diff] [blame] | 99 | // Returns true only if |header_value| satisfies ABNF: 1*DIGIT [ "." 1*DIGIT ] |
| 100 | bool IsSimilarToDoubleABNF(const std::string& header_value) { |
| 101 | if (header_value.empty()) |
| 102 | return false; |
| 103 | char first_char = header_value.at(0); |
| 104 | if (!isdigit(first_char)) |
| 105 | return false; |
| 106 | |
| 107 | bool period_found = false; |
| 108 | bool digit_found_after_period = false; |
| 109 | for (char ch : header_value) { |
| 110 | if (isdigit(ch)) { |
| 111 | if (period_found) { |
| 112 | digit_found_after_period = true; |
| 113 | } |
| 114 | continue; |
| 115 | } |
| 116 | if (ch == '.') { |
| 117 | if (period_found) |
| 118 | return false; |
| 119 | period_found = true; |
| 120 | continue; |
| 121 | } |
| 122 | return false; |
| 123 | } |
| 124 | if (period_found) |
| 125 | return digit_found_after_period; |
| 126 | return true; |
| 127 | } |
| 128 | |
| 129 | // Returns true only if |header_value| satisfies ABNF: 1*DIGIT |
| 130 | bool IsSimilarToIntABNF(const std::string& header_value) { |
| 131 | if (header_value.empty()) |
| 132 | return false; |
| 133 | |
| 134 | for (char ch : header_value) { |
| 135 | if (!isdigit(ch)) |
| 136 | return false; |
| 137 | } |
| 138 | return true; |
| 139 | } |
| 140 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 141 | } // namespace |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 142 | |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 143 | class ClientHintsBrowserTest : public InProcessBrowserTest, |
| 144 | public testing::WithParamInterface<bool> { |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 145 | public: |
| 146 | ClientHintsBrowserTest() |
Mikel Astiz | 2de748d | 2019-11-16 10:39:36 | [diff] [blame] | 147 | : http_server_(net::EmbeddedTestServer::TYPE_HTTP), |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 148 | https_server_(net::EmbeddedTestServer::TYPE_HTTPS), |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 149 | https_cross_origin_server_(net::EmbeddedTestServer::TYPE_HTTPS), |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 150 | expect_client_hints_on_main_frame_(false), |
| 151 | expect_client_hints_on_subresources_(false), |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 152 | count_user_agent_hint_headers_seen_(0), |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 153 | count_ua_mobile_client_hints_headers_seen_(0), |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 154 | count_client_hints_headers_seen_(0), |
| 155 | request_interceptor_(nullptr) { |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 156 | http_server_.ServeFilesFromSourceDirectory("chrome/test/data/client_hints"); |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 157 | https_server_.ServeFilesFromSourceDirectory( |
| 158 | "chrome/test/data/client_hints"); |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 159 | https_cross_origin_server_.ServeFilesFromSourceDirectory( |
| 160 | "chrome/test/data/client_hints"); |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 161 | |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 162 | http_server_.RegisterRequestMonitor( |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 163 | base::BindRepeating(&ClientHintsBrowserTest::MonitorResourceRequest, |
| 164 | base::Unretained(this))); |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 165 | https_server_.RegisterRequestMonitor( |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 166 | base::BindRepeating(&ClientHintsBrowserTest::MonitorResourceRequest, |
| 167 | base::Unretained(this))); |
| 168 | https_cross_origin_server_.RegisterRequestMonitor( |
| 169 | base::BindRepeating(&ClientHintsBrowserTest::MonitorResourceRequest, |
| 170 | base::Unretained(this))); |
Tarun Bansal | 293a7b6c | 2018-12-05 17:41:12 | [diff] [blame] | 171 | https_cross_origin_server_.RegisterRequestHandler( |
| 172 | base::BindRepeating(&ClientHintsBrowserTest::RequestHandlerToRedirect, |
| 173 | base::Unretained(this))); |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 174 | https_server_.RegisterRequestHandler(base::BindRepeating( |
| 175 | &ClientHintsBrowserTest::RequestHandlerToFetchCrossOriginIframe, |
| 176 | base::Unretained(this))); |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 177 | |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 178 | EXPECT_TRUE(http_server_.Start()); |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 179 | EXPECT_TRUE(https_server_.Start()); |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 180 | EXPECT_TRUE(https_cross_origin_server_.Start()); |
| 181 | |
| 182 | EXPECT_NE(https_server_.base_url(), https_cross_origin_server_.base_url()); |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 183 | |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 184 | accept_ch_with_lifetime_http_local_url_ = |
| 185 | http_server_.GetURL("/accept_ch_with_lifetime.html"); |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 186 | http_equiv_accept_ch_with_lifetime_http_local_url_ = |
| 187 | http_server_.GetURL("/http_equiv_accept_ch_with_lifetime.html"); |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 188 | EXPECT_TRUE(accept_ch_with_lifetime_http_local_url_.SchemeIsHTTPOrHTTPS()); |
| 189 | EXPECT_FALSE( |
| 190 | accept_ch_with_lifetime_http_local_url_.SchemeIsCryptographic()); |
| 191 | |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 192 | accept_ch_with_lifetime_url_ = |
| 193 | https_server_.GetURL("/accept_ch_with_lifetime.html"); |
Tarun Bansal | 73502f9 | 2019-04-16 21:21:19 | [diff] [blame] | 194 | accept_ch_with_short_lifetime_url_ = |
| 195 | https_server_.GetURL("/accept_ch_with_short_lifetime.html"); |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 196 | |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 197 | accept_ch_without_lifetime_url_ = |
| 198 | https_server_.GetURL("/accept_ch_without_lifetime.html"); |
| 199 | EXPECT_TRUE(accept_ch_with_lifetime_url_.SchemeIsHTTPOrHTTPS()); |
| 200 | EXPECT_TRUE(accept_ch_with_lifetime_url_.SchemeIsCryptographic()); |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 201 | http_equiv_accept_ch_without_lifetime_url_ = |
| 202 | https_server_.GetURL("/http_equiv_accept_ch_without_lifetime.html"); |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 203 | |
| 204 | without_accept_ch_without_lifetime_url_ = |
| 205 | https_server_.GetURL("/without_accept_ch_without_lifetime.html"); |
| 206 | EXPECT_TRUE(without_accept_ch_without_lifetime_url_.SchemeIsHTTPOrHTTPS()); |
| 207 | EXPECT_TRUE( |
| 208 | without_accept_ch_without_lifetime_url_.SchemeIsCryptographic()); |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 209 | |
| 210 | without_accept_ch_without_lifetime_local_url_ = |
| 211 | http_server_.GetURL("/without_accept_ch_without_lifetime.html"); |
| 212 | EXPECT_TRUE( |
| 213 | without_accept_ch_without_lifetime_local_url_.SchemeIsHTTPOrHTTPS()); |
| 214 | EXPECT_FALSE( |
| 215 | without_accept_ch_without_lifetime_local_url_.SchemeIsCryptographic()); |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 216 | |
| 217 | without_accept_ch_without_lifetime_img_localhost_ = https_server_.GetURL( |
| 218 | "/without_accept_ch_without_lifetime_img_localhost.html"); |
| 219 | without_accept_ch_without_lifetime_img_foo_com_ = https_server_.GetURL( |
| 220 | "/without_accept_ch_without_lifetime_img_foo_com.html"); |
| 221 | accept_ch_without_lifetime_with_iframe_url_ = |
| 222 | https_server_.GetURL("/accept_ch_without_lifetime_with_iframe.html"); |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 223 | http_equiv_accept_ch_without_lifetime_with_iframe_url_ = |
| 224 | https_server_.GetURL( |
| 225 | "/http_equiv_accept_ch_without_lifetime_with_iframe.html"); |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 226 | accept_ch_without_lifetime_with_subresource_url_ = https_server_.GetURL( |
| 227 | "/accept_ch_without_lifetime_with_subresource.html"); |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 228 | http_equiv_accept_ch_without_lifetime_with_subresource_url_ = |
| 229 | https_server_.GetURL( |
| 230 | "/http_equiv_accept_ch_without_lifetime_with_subresource.html"); |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 231 | accept_ch_without_lifetime_with_subresource_iframe_url_ = |
| 232 | https_server_.GetURL( |
| 233 | "/accept_ch_without_lifetime_with_subresource_iframe.html"); |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 234 | http_equiv_accept_ch_without_lifetime_with_subresource_iframe_url_ = |
| 235 | https_server_.GetURL( |
| 236 | "/http_equiv_accept_ch_without_lifetime_with_subresource_iframe." |
| 237 | "html"); |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 238 | accept_ch_without_lifetime_img_localhost_ = |
| 239 | https_server_.GetURL("/accept_ch_without_lifetime_img_localhost.html"); |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 240 | http_equiv_accept_ch_without_lifetime_img_localhost_ = https_server_.GetURL( |
| 241 | "/http_equiv_accept_ch_without_lifetime_img_localhost.html"); |
| 242 | http_equiv_accept_ch_with_lifetime_ = |
| 243 | https_server_.GetURL("/http_equiv_accept_ch_with_lifetime.html"); |
Tarun Bansal | 293a7b6c | 2018-12-05 17:41:12 | [diff] [blame] | 244 | |
| 245 | redirect_url_ = https_cross_origin_server_.GetURL("/redirect.html"); |
Maks Orlovich | 7a588d8 | 2020-05-06 15:17:24 | [diff] [blame] | 246 | |
| 247 | accept_ch_empty_ = https_server_.GetURL("/accept_ch_empty.html"); |
| 248 | http_equiv_accept_ch_merge_ = |
| 249 | https_server_.GetURL("/http_equiv_accept_ch_merge.html"); |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | ~ClientHintsBrowserTest() override {} |
| 253 | |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 254 | virtual std::unique_ptr<base::FeatureList> EnabledFeatures() { |
| 255 | std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 256 | feature_list->InitializeFromCommandLine("UserAgentClientHint", ""); |
| 257 | return feature_list; |
| 258 | } |
| 259 | |
| 260 | void SetUp() override { |
| 261 | scoped_feature_list_.InitWithFeatureList(EnabledFeatures()); |
| 262 | InProcessBrowserTest::SetUp(); |
| 263 | } |
| 264 | |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 265 | void SetUpOnMainThread() override { |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 266 | host_resolver()->AddRule("*", "127.0.0.1"); |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 267 | |
Jay Civelli | 1ff872d | 2018-03-09 21:52:16 | [diff] [blame] | 268 | request_interceptor_ = std::make_unique<ThirdPartyURLLoaderInterceptor>( |
| 269 | GURL("https://foo.com/non-existing-image.jpg")); |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 270 | base::RunLoop().RunUntilIdle(); |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 271 | } |
| 272 | |
Jay Civelli | 1ff872d | 2018-03-09 21:52:16 | [diff] [blame] | 273 | void TearDownOnMainThread() override { request_interceptor_.reset(); } |
| 274 | |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 275 | void SetUpCommandLine(base::CommandLine* cmd) override { |
Tarun Bansal | 7f3fe8c | 2018-04-06 22:37:47 | [diff] [blame] | 276 | cmd->AppendSwitchASCII(network::switches::kForceEffectiveConnectionType, |
| 277 | net::kEffectiveConnectionType2G); |
Mike West | 14c1110 | 2019-02-04 16:16:47 | [diff] [blame] | 278 | cmd->AppendSwitchASCII(switches::kEnableBlinkFeatures, |
| 279 | "LangClientHintHeader"); |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 280 | } |
| 281 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 282 | void SetClientHintExpectationsOnMainFrame(bool expect_client_hints) { |
| 283 | expect_client_hints_on_main_frame_ = expect_client_hints; |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 284 | } |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 285 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 286 | void SetClientHintExpectationsOnSubresources(bool expect_client_hints) { |
Callum May | 1d93974 | 2020-03-02 17:51:30 | [diff] [blame] | 287 | base::AutoLock lock(expect_client_hints_on_subresources_lock_); |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 288 | expect_client_hints_on_subresources_ = expect_client_hints; |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 289 | } |
| 290 | |
Callum May | 1d93974 | 2020-03-02 17:51:30 | [diff] [blame] | 291 | bool expect_client_hints_on_subresources() { |
| 292 | base::AutoLock lock(expect_client_hints_on_subresources_lock_); |
| 293 | return expect_client_hints_on_subresources_; |
| 294 | } |
| 295 | |
Tarun Bansal | c211d8b | 2018-03-19 19:21:58 | [diff] [blame] | 296 | // Verify that the user is not notified that cookies or JavaScript were |
| 297 | // blocked on the webpage due to the checks done by client hints. |
| 298 | void VerifyContentSettingsNotNotified() const { |
| 299 | content::WebContents* web_contents = |
| 300 | browser()->tab_strip_model()->GetActiveWebContents(); |
Clark DuVall | 84a33d61 | 2020-04-17 16:01:00 | [diff] [blame] | 301 | EXPECT_FALSE(content_settings::TabSpecificContentSettings::FromWebContents( |
| 302 | web_contents) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 303 | ->IsContentBlocked(ContentSettingsType::COOKIES)); |
Tarun Bansal | c211d8b | 2018-03-19 19:21:58 | [diff] [blame] | 304 | |
Clark DuVall | 84a33d61 | 2020-04-17 16:01:00 | [diff] [blame] | 305 | EXPECT_FALSE(content_settings::TabSpecificContentSettings::FromWebContents( |
| 306 | web_contents) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 307 | ->IsContentBlocked(ContentSettingsType::JAVASCRIPT)); |
Tarun Bansal | c211d8b | 2018-03-19 19:21:58 | [diff] [blame] | 308 | } |
| 309 | |
Tarun Bansal | bef6d65 | 2018-10-02 18:41:01 | [diff] [blame] | 310 | void SetExpectedEffectiveConnectionType( |
| 311 | net::EffectiveConnectionType effective_connection_type) { |
| 312 | expected_ect = effective_connection_type; |
| 313 | } |
| 314 | |
Changwan Ryu | 434c3a3 | 2019-07-30 23:42:58 | [diff] [blame] | 315 | void SetJsEnabledForActiveView(bool enabled) { |
| 316 | content::RenderViewHost* view = browser() |
| 317 | ->tab_strip_model() |
| 318 | ->GetActiveWebContents() |
| 319 | ->GetRenderViewHost(); |
| 320 | content::WebPreferences prefs = view->GetWebkitPreferences(); |
| 321 | prefs.javascript_enabled = enabled; |
| 322 | view->UpdateWebkitPreferences(prefs); |
| 323 | } |
| 324 | |
Maks Orlovich | 7227ce0d | 2020-02-28 17:13:16 | [diff] [blame] | 325 | void TestProfilesIndependent(Browser* browser_a, Browser* browser_b); |
| 326 | |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 327 | const GURL& accept_ch_with_lifetime_http_local_url() const { |
| 328 | return accept_ch_with_lifetime_http_local_url_; |
| 329 | } |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 330 | const GURL& http_equiv_accept_ch_with_lifetime_http_local_url() const { |
| 331 | return http_equiv_accept_ch_with_lifetime_http_local_url_; |
| 332 | } |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 333 | |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 334 | // A URL whose response headers include Accept-CH and Accept-CH-Lifetime |
| 335 | // headers. |
| 336 | const GURL& accept_ch_with_lifetime_url() const { |
| 337 | return accept_ch_with_lifetime_url_; |
| 338 | } |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 339 | const GURL& http_equiv_accept_ch_with_lifetime() { |
| 340 | return http_equiv_accept_ch_with_lifetime_; |
| 341 | } |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 342 | |
Tarun Bansal | 73502f9 | 2019-04-16 21:21:19 | [diff] [blame] | 343 | // A URL whose response headers include Accept-CH and Accept-CH-Lifetime |
| 344 | // headers. The Accept-CH-Lifetime duration is set very short to 1 second. |
| 345 | const GURL& accept_ch_with_short_lifetime() const { |
| 346 | return accept_ch_with_short_lifetime_url_; |
| 347 | } |
| 348 | |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 349 | // A URL whose response headers include only Accept-CH header. |
| 350 | const GURL& accept_ch_without_lifetime_url() const { |
| 351 | return accept_ch_without_lifetime_url_; |
| 352 | } |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 353 | const GURL& http_equiv_accept_ch_without_lifetime_url() const { |
| 354 | return http_equiv_accept_ch_without_lifetime_url_; |
| 355 | } |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 356 | |
| 357 | // A URL whose response headers do not include either Accept-CH or |
| 358 | // Accept-CH-Lifetime headers. Navigating to this URL also fetches an image. |
| 359 | const GURL& without_accept_ch_without_lifetime_url() const { |
| 360 | return without_accept_ch_without_lifetime_url_; |
| 361 | } |
| 362 | |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 363 | // A URL whose response headers do not include either Accept-CH or |
| 364 | // Accept-CH-Lifetime headers. Navigating to this URL also fetches an image. |
| 365 | const GURL& without_accept_ch_without_lifetime_local_url() const { |
| 366 | return without_accept_ch_without_lifetime_local_url_; |
| 367 | } |
| 368 | |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 369 | // A URL whose response headers do not include either Accept-CH or |
| 370 | // Accept-CH-Lifetime headers. Navigating to this URL also fetches an image |
| 371 | // from localhost. |
| 372 | const GURL& without_accept_ch_without_lifetime_img_localhost() const { |
| 373 | return without_accept_ch_without_lifetime_img_localhost_; |
| 374 | } |
| 375 | |
| 376 | // A URL whose response headers do not include either Accept-CH or |
| 377 | // Accept-CH-Lifetime headers. Navigating to this URL also fetches an image |
| 378 | // from foo.com. |
| 379 | const GURL& without_accept_ch_without_lifetime_img_foo_com() const { |
| 380 | return without_accept_ch_without_lifetime_img_foo_com_; |
| 381 | } |
| 382 | |
| 383 | // A URL whose response does not include Accept-CH or Accept-CH-Lifetime |
| 384 | // headers. The response loads accept_ch_with_lifetime_url() in an iframe. |
| 385 | const GURL& accept_ch_without_lifetime_with_iframe_url() const { |
| 386 | return accept_ch_without_lifetime_with_iframe_url_; |
| 387 | } |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 388 | const GURL& http_equiv_accept_ch_without_lifetime_with_iframe_url() const { |
| 389 | return http_equiv_accept_ch_without_lifetime_with_iframe_url_; |
| 390 | } |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 391 | |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 392 | // A URL whose response does not include Accept-CH or Accept-CH-Lifetime |
| 393 | // headers. The response loads accept_ch_with_lifetime_url() as a subresource |
| 394 | // in the main frame. |
| 395 | const GURL& accept_ch_without_lifetime_with_subresource_url() const { |
| 396 | return accept_ch_without_lifetime_with_subresource_url_; |
| 397 | } |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 398 | const GURL& http_equiv_accept_ch_without_lifetime_with_subresource_url() |
| 399 | const { |
| 400 | return http_equiv_accept_ch_without_lifetime_with_subresource_url_; |
| 401 | } |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 402 | |
| 403 | // A URL whose response does not include Accept-CH or Accept-CH-Lifetime |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 404 | // headers. The response loads accept_ch_with_lifetime_url() or |
| 405 | // http_equiv_accept_ch_with_lifetime_url() as a subresource in the iframe. |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 406 | const GURL& accept_ch_without_lifetime_with_subresource_iframe_url() const { |
| 407 | return accept_ch_without_lifetime_with_subresource_iframe_url_; |
| 408 | } |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 409 | const GURL& |
| 410 | http_equiv_accept_ch_without_lifetime_with_subresource_iframe_url() const { |
| 411 | return http_equiv_accept_ch_without_lifetime_with_subresource_iframe_url_; |
| 412 | } |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 413 | |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 414 | // A URL whose response includes only Accept-CH header. Navigating to |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 415 | // this URL also fetches two images: One from the localhost, and one from |
| 416 | // foo.com. |
| 417 | const GURL& accept_ch_without_lifetime_img_localhost() const { |
| 418 | return accept_ch_without_lifetime_img_localhost_; |
| 419 | } |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 420 | const GURL& http_equiv_accept_ch_without_lifetime_img_localhost() const { |
| 421 | return http_equiv_accept_ch_without_lifetime_img_localhost_; |
| 422 | } |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 423 | |
Tarun Bansal | 293a7b6c | 2018-12-05 17:41:12 | [diff] [blame] | 424 | const GURL& redirect_url() const { return redirect_url_; } |
| 425 | |
Maks Orlovich | 7a588d8 | 2020-05-06 15:17:24 | [diff] [blame] | 426 | // A URL to a page with a response containing an empty accept_ch header. |
| 427 | const GURL& accept_ch_empty() const { return accept_ch_empty_; } |
| 428 | |
| 429 | // A page where some hints are in accept-ch header, some in http-equiv. |
| 430 | const GURL& http_equiv_accept_ch_merge() const { |
| 431 | return http_equiv_accept_ch_merge_; |
| 432 | } |
| 433 | |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 434 | size_t count_user_agent_hint_headers_seen() const { |
Callum May | 7d88ff3e | 2019-11-12 18:21:46 | [diff] [blame] | 435 | base::AutoLock lock(count_headers_lock_); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 436 | return count_user_agent_hint_headers_seen_; |
| 437 | } |
| 438 | |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 439 | size_t count_ua_mobile_client_hints_headers_seen() const { |
| 440 | base::AutoLock lock(count_headers_lock_); |
| 441 | return count_ua_mobile_client_hints_headers_seen_; |
| 442 | } |
| 443 | |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 444 | size_t count_client_hints_headers_seen() const { |
Callum May | 7d88ff3e | 2019-11-12 18:21:46 | [diff] [blame] | 445 | base::AutoLock lock(count_headers_lock_); |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 446 | return count_client_hints_headers_seen_; |
| 447 | } |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 448 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 449 | size_t third_party_request_count_seen() const { |
| 450 | return request_interceptor_->request_count_seen(); |
| 451 | } |
| 452 | |
| 453 | size_t third_party_client_hints_count_seen() const { |
| 454 | return request_interceptor_->client_hints_count_seen(); |
| 455 | } |
| 456 | |
Mike West | e555be86 | 2019-02-20 16:17:30 | [diff] [blame] | 457 | const std::string& main_frame_ua_observed() const { |
| 458 | return main_frame_ua_observed_; |
| 459 | } |
| 460 | |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 461 | const std::string& main_frame_ua_full_version_observed() const { |
| 462 | return main_frame_ua_full_version_observed_; |
| 463 | } |
| 464 | |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 465 | const std::string& main_frame_ua_mobile_observed() const { |
| 466 | return main_frame_ua_mobile_observed_; |
| 467 | } |
| 468 | |
| 469 | const std::string& main_frame_ua_platform_observed() const { |
| 470 | return main_frame_ua_platform_observed_; |
| 471 | } |
| 472 | |
Tarun Bansal | ea0d826 | 2018-05-21 16:11:50 | [diff] [blame] | 473 | base::test::ScopedFeatureList scoped_feature_list_; |
| 474 | |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 475 | std::string intercept_iframe_resource_; |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 476 | bool intercept_to_http_equiv_iframe_ = false; |
Callum May | 7d88ff3e | 2019-11-12 18:21:46 | [diff] [blame] | 477 | mutable base::Lock count_headers_lock_; |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 478 | |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 479 | private: |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 480 | // Intercepts only the main frame requests that contain |
Tarun Bansal | 293a7b6c | 2018-12-05 17:41:12 | [diff] [blame] | 481 | // "redirect" in the resource path. The intercepted requests |
| 482 | // are served an HTML file that fetches an iframe from a cross-origin HTTPS |
| 483 | // server. |
| 484 | std::unique_ptr<net::test_server::HttpResponse> RequestHandlerToRedirect( |
| 485 | const net::test_server::HttpRequest& request) { |
| 486 | // Check if it's a main frame request. |
| 487 | if (request.relative_url.find(".html") == std::string::npos) |
| 488 | return nullptr; |
| 489 | |
| 490 | if (request.GetURL().spec().find("redirect") == std::string::npos) |
| 491 | return nullptr; |
| 492 | |
| 493 | std::unique_ptr<net::test_server::BasicHttpResponse> response; |
| 494 | response.reset(new net::test_server::BasicHttpResponse); |
| 495 | response->set_code(net::HTTP_FOUND); |
| 496 | response->AddCustomHeader("Location", |
| 497 | without_accept_ch_without_lifetime_url().spec()); |
| 498 | return std::move(response); |
| 499 | } |
| 500 | |
| 501 | // Intercepts only the main frame requests that contain |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 502 | // |intercept_iframe_resource_| in the resource path. The intercepted requests |
| 503 | // are served an HTML file that fetches an iframe from a cross-origin HTTPS |
| 504 | // server. |
| 505 | std::unique_ptr<net::test_server::HttpResponse> |
| 506 | RequestHandlerToFetchCrossOriginIframe( |
| 507 | const net::test_server::HttpRequest& request) { |
| 508 | if (intercept_iframe_resource_.empty()) |
| 509 | return nullptr; |
| 510 | |
| 511 | // Check if it's a main frame request. |
| 512 | if (request.relative_url.find(".html") == std::string::npos) |
| 513 | return nullptr; |
| 514 | |
| 515 | if (request.relative_url.find(intercept_iframe_resource_) == |
| 516 | std::string::npos) { |
| 517 | return nullptr; |
| 518 | } |
| 519 | |
| 520 | const std::string iframe_url = |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 521 | intercept_to_http_equiv_iframe_ |
| 522 | ? https_cross_origin_server_ |
| 523 | .GetURL("/http_equiv_accept_ch_with_lifetime.html") |
| 524 | .spec() |
| 525 | : https_cross_origin_server_.GetURL("/accept_ch_with_lifetime.html") |
| 526 | .spec(); |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 527 | |
| 528 | std::unique_ptr<net::test_server::BasicHttpResponse> http_response( |
| 529 | new net::test_server::BasicHttpResponse()); |
| 530 | http_response->set_code(net::HTTP_OK); |
| 531 | http_response->set_content_type("text/html"); |
| 532 | http_response->set_content( |
| 533 | "<html>" |
| 534 | "<link rel='icon' href='data:;base64,='><head></head>" |
| 535 | "Empty file which uses link-rel to disable favicon fetches. " |
| 536 | "<iframe src='" + |
| 537 | iframe_url + "'></iframe></html>"); |
| 538 | |
| 539 | return std::move(http_response); |
| 540 | } |
| 541 | |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 542 | static std::string UpdateHeaderObservation( |
| 543 | const net::test_server::HttpRequest& request, |
| 544 | const std::string& header) { |
| 545 | if (request.headers.find(header) != request.headers.end()) |
| 546 | return request.headers.find(header)->second; |
| 547 | else |
| 548 | return ""; |
| 549 | } |
| 550 | |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 551 | // Called by |https_server_|. |
| 552 | void MonitorResourceRequest(const net::test_server::HttpRequest& request) { |
Tarun Bansal | 6bf5430 | 2017-10-02 07:39:14 | [diff] [blame] | 553 | bool is_main_frame_navigation = |
| 554 | request.GetURL().spec().find(".html") != std::string::npos; |
| 555 | |
Tarun Bansal | 293a7b6c | 2018-12-05 17:41:12 | [diff] [blame] | 556 | if (is_main_frame_navigation && |
| 557 | request.GetURL().spec().find("redirect") != std::string::npos) { |
| 558 | return; |
| 559 | } |
| 560 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 561 | if (is_main_frame_navigation) { |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 562 | main_frame_ua_observed_ = UpdateHeaderObservation(request, "sec-ch-ua"); |
| 563 | main_frame_ua_full_version_observed_ = |
| 564 | UpdateHeaderObservation(request, "sec-ch-ua-full-version"); |
| 565 | main_frame_ua_mobile_observed_ = |
| 566 | UpdateHeaderObservation(request, "sec-ch-ua-mobile"); |
| 567 | main_frame_ua_platform_observed_ = |
| 568 | UpdateHeaderObservation(request, "sec-ch-ua-platform"); |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 569 | |
Tarun Bansal | f9cf989 | 2018-04-06 04:38:01 | [diff] [blame] | 570 | VerifyClientHintsReceived(expect_client_hints_on_main_frame_, request); |
Tarun Bansal | 5c28afb | 2018-03-17 02:55:20 | [diff] [blame] | 571 | if (expect_client_hints_on_main_frame_) { |
| 572 | double value = 0.0; |
| 573 | EXPECT_TRUE(base::StringToDouble( |
| 574 | request.headers.find("device-memory")->second, &value)); |
| 575 | EXPECT_LT(0.0, value); |
Tarun Bansal | 62efba1 | 2018-05-04 22:58:35 | [diff] [blame] | 576 | EXPECT_TRUE(IsSimilarToDoubleABNF( |
| 577 | request.headers.find("device-memory")->second)); |
Tarun Bansal | 44ad9688 | 2018-03-28 17:47:42 | [diff] [blame] | 578 | main_frame_device_memory_observed_ = value; |
Tarun Bansal | 5c28afb | 2018-03-17 02:55:20 | [diff] [blame] | 579 | |
| 580 | EXPECT_TRUE( |
| 581 | base::StringToDouble(request.headers.find("dpr")->second, &value)); |
| 582 | EXPECT_LT(0.0, value); |
Tarun Bansal | 62efba1 | 2018-05-04 22:58:35 | [diff] [blame] | 583 | EXPECT_TRUE(IsSimilarToDoubleABNF(request.headers.find("dpr")->second)); |
Tarun Bansal | 44ad9688 | 2018-03-28 17:47:42 | [diff] [blame] | 584 | main_frame_dpr_observed_ = value; |
| 585 | |
Tarun Bansal | 5c28afb | 2018-03-17 02:55:20 | [diff] [blame] | 586 | EXPECT_TRUE(base::StringToDouble( |
| 587 | request.headers.find("viewport-width")->second, &value)); |
Tarun Bansal | 62efba1 | 2018-05-04 22:58:35 | [diff] [blame] | 588 | EXPECT_TRUE( |
| 589 | IsSimilarToIntABNF(request.headers.find("viewport-width")->second)); |
Tarun Bansal | 79df868e | 2018-03-20 23:01:36 | [diff] [blame] | 590 | #if !defined(OS_ANDROID) |
Tarun Bansal | 5c28afb | 2018-03-17 02:55:20 | [diff] [blame] | 591 | EXPECT_LT(0.0, value); |
Tarun Bansal | 79df868e | 2018-03-20 23:01:36 | [diff] [blame] | 592 | #else |
| 593 | EXPECT_EQ(980, value); |
Tarun Bansal | 5c28afb | 2018-03-17 02:55:20 | [diff] [blame] | 594 | #endif |
Tarun Bansal | 44ad9688 | 2018-03-28 17:47:42 | [diff] [blame] | 595 | main_frame_viewport_width_observed_ = value; |
Mike West | e555be86 | 2019-02-20 16:17:30 | [diff] [blame] | 596 | |
Tarun Bansal | 7f3fe8c | 2018-04-06 22:37:47 | [diff] [blame] | 597 | VerifyNetworkQualityClientHints(request); |
Tarun Bansal | 5c28afb | 2018-03-17 02:55:20 | [diff] [blame] | 598 | } |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 599 | } |
Tarun Bansal | 6bf5430 | 2017-10-02 07:39:14 | [diff] [blame] | 600 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 601 | if (!is_main_frame_navigation) { |
Callum May | 1d93974 | 2020-03-02 17:51:30 | [diff] [blame] | 602 | VerifyClientHintsReceived(expect_client_hints_on_subresources(), request); |
Tarun Bansal | 5c28afb | 2018-03-17 02:55:20 | [diff] [blame] | 603 | |
Callum May | 1d93974 | 2020-03-02 17:51:30 | [diff] [blame] | 604 | if (expect_client_hints_on_subresources()) { |
Tarun Bansal | 5c28afb | 2018-03-17 02:55:20 | [diff] [blame] | 605 | double value = 0.0; |
| 606 | EXPECT_TRUE(base::StringToDouble( |
| 607 | request.headers.find("device-memory")->second, &value)); |
| 608 | EXPECT_LT(0.0, value); |
Tarun Bansal | 62efba1 | 2018-05-04 22:58:35 | [diff] [blame] | 609 | EXPECT_TRUE(IsSimilarToDoubleABNF( |
| 610 | request.headers.find("device-memory")->second)); |
Tarun Bansal | 44ad9688 | 2018-03-28 17:47:42 | [diff] [blame] | 611 | if (main_frame_device_memory_observed_ > 0) { |
| 612 | EXPECT_EQ(main_frame_device_memory_observed_, value); |
| 613 | } |
Tarun Bansal | 5c28afb | 2018-03-17 02:55:20 | [diff] [blame] | 614 | |
| 615 | EXPECT_TRUE( |
| 616 | base::StringToDouble(request.headers.find("dpr")->second, &value)); |
| 617 | EXPECT_LT(0.0, value); |
Tarun Bansal | 62efba1 | 2018-05-04 22:58:35 | [diff] [blame] | 618 | EXPECT_TRUE(IsSimilarToDoubleABNF(request.headers.find("dpr")->second)); |
Tarun Bansal | 44ad9688 | 2018-03-28 17:47:42 | [diff] [blame] | 619 | if (main_frame_dpr_observed_ > 0) { |
| 620 | EXPECT_EQ(main_frame_dpr_observed_, value); |
| 621 | } |
Tarun Bansal | 5c28afb | 2018-03-17 02:55:20 | [diff] [blame] | 622 | |
| 623 | EXPECT_TRUE(base::StringToDouble( |
| 624 | request.headers.find("viewport-width")->second, &value)); |
Tarun Bansal | 62efba1 | 2018-05-04 22:58:35 | [diff] [blame] | 625 | EXPECT_TRUE( |
| 626 | IsSimilarToIntABNF(request.headers.find("viewport-width")->second)); |
Tarun Bansal | 79df868e | 2018-03-20 23:01:36 | [diff] [blame] | 627 | #if !defined(OS_ANDROID) |
Tarun Bansal | 5c28afb | 2018-03-17 02:55:20 | [diff] [blame] | 628 | EXPECT_LT(0.0, value); |
Tarun Bansal | 79df868e | 2018-03-20 23:01:36 | [diff] [blame] | 629 | #else |
| 630 | EXPECT_EQ(980, value); |
| 631 | #endif |
Tarun Bansal | 44ad9688 | 2018-03-28 17:47:42 | [diff] [blame] | 632 | #if defined(OS_ANDROID) |
| 633 | // TODO(tbansal): https://crbug.com/825892: Viewport width on main |
| 634 | // frame requests may be incorrect when the Chrome window is not |
| 635 | // maximized. |
| 636 | if (main_frame_viewport_width_observed_ > 0) { |
| 637 | EXPECT_EQ(main_frame_viewport_width_observed_, value); |
| 638 | } |
| 639 | #endif |
Tarun Bansal | 7f3fe8c | 2018-04-06 22:37:47 | [diff] [blame] | 640 | VerifyNetworkQualityClientHints(request); |
Tarun Bansal | 5c28afb | 2018-03-17 02:55:20 | [diff] [blame] | 641 | } |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 642 | } |
Tarun Bansal | 6bf5430 | 2017-10-02 07:39:14 | [diff] [blame] | 643 | |
Mike West | 14c1110 | 2019-02-04 16:16:47 | [diff] [blame] | 644 | for (size_t i = 0; i < blink::kClientHintsMappingsCount; ++i) { |
Jan Wilken Dörrie | a8cb5630 | 2019-06-06 18:59:36 | [diff] [blame] | 645 | if (base::Contains(request.headers, |
| 646 | blink::kClientHintsHeaderMapping[i])) { |
Callum May | 7d88ff3e | 2019-11-12 18:21:46 | [diff] [blame] | 647 | base::AutoLock lock(count_headers_lock_); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 648 | // The user agent hint is special: |
| 649 | if (std::string(blink::kClientHintsHeaderMapping[i]) == "sec-ch-ua") { |
| 650 | count_user_agent_hint_headers_seen_++; |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 651 | } else if (std::string(blink::kClientHintsHeaderMapping[i]) == |
| 652 | "sec-ch-ua-mobile") { |
| 653 | count_ua_mobile_client_hints_headers_seen_++; |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 654 | } else { |
| 655 | count_client_hints_headers_seen_++; |
| 656 | } |
Tarun Bansal | f9cf989 | 2018-04-06 04:38:01 | [diff] [blame] | 657 | } |
| 658 | } |
| 659 | } |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 660 | |
Tarun Bansal | f9cf989 | 2018-04-06 04:38:01 | [diff] [blame] | 661 | void VerifyClientHintsReceived(bool expect_client_hints, |
| 662 | const net::test_server::HttpRequest& request) { |
Mike West | 14c1110 | 2019-02-04 16:16:47 | [diff] [blame] | 663 | for (size_t i = 0; i < blink::kClientHintsMappingsCount; ++i) { |
| 664 | SCOPED_TRACE(testing::Message() |
| 665 | << std::string(blink::kClientHintsHeaderMapping[i])); |
Tarun Bansal | f9cf989 | 2018-04-06 04:38:01 | [diff] [blame] | 666 | // Resource width client hint is only attached on image subresources. |
| 667 | if (std::string(blink::kClientHintsHeaderMapping[i]) == "width") { |
| 668 | continue; |
| 669 | } |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 670 | |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 671 | // `Sec-CH-UA` and `Sec-CH-UA-Mobile` is attached on all requests. |
| 672 | if (std::string(blink::kClientHintsHeaderMapping[i]) == "sec-ch-ua" || |
| 673 | std::string(blink::kClientHintsHeaderMapping[i]) == |
| 674 | "sec-ch-ua-mobile") { |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 675 | continue; |
| 676 | } |
| 677 | |
Jan Wilken Dörrie | a8cb5630 | 2019-06-06 18:59:36 | [diff] [blame] | 678 | EXPECT_EQ( |
| 679 | expect_client_hints, |
| 680 | base::Contains(request.headers, blink::kClientHintsHeaderMapping[i])); |
Tarun Bansal | f9cf989 | 2018-04-06 04:38:01 | [diff] [blame] | 681 | } |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 682 | } |
| 683 | |
Tarun Bansal | 7f3fe8c | 2018-04-06 22:37:47 | [diff] [blame] | 684 | void VerifyNetworkQualityClientHints( |
| 685 | const net::test_server::HttpRequest& request) const { |
| 686 | // Effective connection type is forced to 2G using command line in these |
| 687 | // tests. |
Tarun Bansal | 509a8dd | 2018-04-10 17:19:16 | [diff] [blame] | 688 | int rtt_value = 0.0; |
Tarun Bansal | 7f3fe8c | 2018-04-06 22:37:47 | [diff] [blame] | 689 | EXPECT_TRUE( |
Tarun Bansal | 509a8dd | 2018-04-10 17:19:16 | [diff] [blame] | 690 | base::StringToInt(request.headers.find("rtt")->second, &rtt_value)); |
| 691 | EXPECT_LE(0, rtt_value); |
Tarun Bansal | 62efba1 | 2018-05-04 22:58:35 | [diff] [blame] | 692 | EXPECT_TRUE(IsSimilarToIntABNF(request.headers.find("rtt")->second)); |
Tarun Bansal | 509a8dd | 2018-04-10 17:19:16 | [diff] [blame] | 693 | // Verify that RTT value is a multiple of 50 milliseconds. |
| 694 | EXPECT_EQ(0, rtt_value % 50); |
Tarun Bansal | bef6d65 | 2018-10-02 18:41:01 | [diff] [blame] | 695 | EXPECT_GE(expected_ect == net::EFFECTIVE_CONNECTION_TYPE_2G ? 3000 : 500, |
| 696 | rtt_value); |
Tarun Bansal | 7f3fe8c | 2018-04-06 22:37:47 | [diff] [blame] | 697 | |
Tarun Bansal | 509a8dd | 2018-04-10 17:19:16 | [diff] [blame] | 698 | double mbps_value = 0.0; |
| 699 | EXPECT_TRUE(base::StringToDouble(request.headers.find("downlink")->second, |
| 700 | &mbps_value)); |
| 701 | EXPECT_LE(0, mbps_value); |
Tarun Bansal | 62efba1 | 2018-05-04 22:58:35 | [diff] [blame] | 702 | EXPECT_TRUE( |
| 703 | IsSimilarToDoubleABNF(request.headers.find("downlink")->second)); |
Tarun Bansal | 509a8dd | 2018-04-10 17:19:16 | [diff] [blame] | 704 | // Verify that the mbps value is a multiple of 0.050 mbps. |
| 705 | // Allow for small amount of noise due to double to integer conversions. |
| 706 | EXPECT_NEAR(0, (static_cast<int>(mbps_value * 1000)) % 50, 1); |
| 707 | EXPECT_GE(10.0, mbps_value); |
Tarun Bansal | 7f3fe8c | 2018-04-06 22:37:47 | [diff] [blame] | 708 | |
| 709 | EXPECT_FALSE(request.headers.find("ect")->second.empty()); |
Tarun Bansal | ceab959 | 2018-05-01 18:57:35 | [diff] [blame] | 710 | |
| 711 | // TODO(tbansal): https://crbug.com/819244: When network servicification is |
Tarun Bansal | 5ac53354 | 2018-08-10 19:45:52 | [diff] [blame] | 712 | // enabled, the renderer processes do not receive notifications on |
| 713 | // change in the network quality. Hence, the network quality client hints |
| 714 | // are not set to the correct value on subresources. |
| 715 | bool is_main_frame_navigation = |
| 716 | request.GetURL().spec().find(".html") != std::string::npos; |
John Abd-El-Malek | 67facbe8 | 2019-06-06 22:37:08 | [diff] [blame] | 717 | if (is_main_frame_navigation) { |
Tarun Bansal | ceab959 | 2018-05-01 18:57:35 | [diff] [blame] | 718 | // Effective connection type is forced to 2G using command line in these |
| 719 | // tests. RTT is expected to be 1800 msec but leave some gap to account |
| 720 | // for added noise and randomization. |
Tarun Bansal | bef6d65 | 2018-10-02 18:41:01 | [diff] [blame] | 721 | if (expected_ect == net::EFFECTIVE_CONNECTION_TYPE_2G) { |
| 722 | EXPECT_NEAR(1800, rtt_value, 360); |
| 723 | } else if (expected_ect == net::EFFECTIVE_CONNECTION_TYPE_3G) { |
| 724 | EXPECT_NEAR(450, rtt_value, 90); |
| 725 | } else { |
| 726 | NOTREACHED(); |
| 727 | } |
Tarun Bansal | ceab959 | 2018-05-01 18:57:35 | [diff] [blame] | 728 | |
| 729 | // Effective connection type is forced to 2G using command line in these |
| 730 | // tests. downlink is expected to be 0.075 Mbps but leave some gap to |
| 731 | // account for added noise and randomization. |
Tarun Bansal | bef6d65 | 2018-10-02 18:41:01 | [diff] [blame] | 732 | if (expected_ect == net::EFFECTIVE_CONNECTION_TYPE_2G) { |
| 733 | EXPECT_NEAR(0.075, mbps_value, 0.05); |
| 734 | } else if (expected_ect == net::EFFECTIVE_CONNECTION_TYPE_3G) { |
| 735 | EXPECT_NEAR(0.4, mbps_value, 0.1); |
| 736 | } else { |
| 737 | NOTREACHED(); |
| 738 | } |
Tarun Bansal | ceab959 | 2018-05-01 18:57:35 | [diff] [blame] | 739 | |
Tarun Bansal | bef6d65 | 2018-10-02 18:41:01 | [diff] [blame] | 740 | EXPECT_EQ(expected_ect == net::EFFECTIVE_CONNECTION_TYPE_2G ? "2g" : "3g", |
| 741 | request.headers.find("ect")->second); |
Tarun Bansal | ceab959 | 2018-05-01 18:57:35 | [diff] [blame] | 742 | } |
Tarun Bansal | 7f3fe8c | 2018-04-06 22:37:47 | [diff] [blame] | 743 | } |
| 744 | |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 745 | net::EmbeddedTestServer http_server_; |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 746 | net::EmbeddedTestServer https_server_; |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 747 | net::EmbeddedTestServer https_cross_origin_server_; |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 748 | GURL accept_ch_with_lifetime_http_local_url_; |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 749 | GURL http_equiv_accept_ch_with_lifetime_http_local_url_; |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 750 | GURL accept_ch_with_lifetime_url_; |
Tarun Bansal | 73502f9 | 2019-04-16 21:21:19 | [diff] [blame] | 751 | GURL accept_ch_with_short_lifetime_url_; |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 752 | GURL accept_ch_without_lifetime_url_; |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 753 | GURL http_equiv_accept_ch_without_lifetime_url_; |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 754 | GURL without_accept_ch_without_lifetime_url_; |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 755 | GURL without_accept_ch_without_lifetime_local_url_; |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 756 | GURL accept_ch_without_lifetime_with_iframe_url_; |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 757 | GURL http_equiv_accept_ch_without_lifetime_with_iframe_url_; |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 758 | GURL accept_ch_without_lifetime_with_subresource_url_; |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 759 | GURL http_equiv_accept_ch_without_lifetime_with_subresource_url_; |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 760 | GURL accept_ch_without_lifetime_with_subresource_iframe_url_; |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 761 | GURL http_equiv_accept_ch_without_lifetime_with_subresource_iframe_url_; |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 762 | GURL without_accept_ch_without_lifetime_img_foo_com_; |
| 763 | GURL without_accept_ch_without_lifetime_img_localhost_; |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 764 | GURL accept_ch_without_lifetime_img_localhost_; |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 765 | GURL http_equiv_accept_ch_without_lifetime_img_localhost_; |
| 766 | GURL http_equiv_accept_ch_with_lifetime_; |
Tarun Bansal | 293a7b6c | 2018-12-05 17:41:12 | [diff] [blame] | 767 | GURL redirect_url_; |
Maks Orlovich | 7a588d8 | 2020-05-06 15:17:24 | [diff] [blame] | 768 | GURL accept_ch_empty_; |
| 769 | GURL http_equiv_accept_ch_merge_; |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 770 | |
Mike West | e555be86 | 2019-02-20 16:17:30 | [diff] [blame] | 771 | std::string main_frame_ua_observed_; |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 772 | std::string main_frame_ua_full_version_observed_; |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 773 | std::string main_frame_ua_mobile_observed_; |
| 774 | std::string main_frame_ua_platform_observed_; |
Mike West | e555be86 | 2019-02-20 16:17:30 | [diff] [blame] | 775 | |
Tarun Bansal | 44ad9688 | 2018-03-28 17:47:42 | [diff] [blame] | 776 | double main_frame_dpr_observed_ = -1; |
| 777 | double main_frame_viewport_width_observed_ = -1; |
| 778 | double main_frame_device_memory_observed_ = -1; |
| 779 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 780 | // Expect client hints on all the main frame request. |
| 781 | bool expect_client_hints_on_main_frame_; |
| 782 | // Expect client hints on all the subresource requests. |
Callum May | 1d93974 | 2020-03-02 17:51:30 | [diff] [blame] | 783 | bool expect_client_hints_on_subresources_ |
| 784 | GUARDED_BY(expect_client_hints_on_subresources_lock_); |
| 785 | |
| 786 | base::Lock expect_client_hints_on_subresources_lock_; |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 787 | |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 788 | size_t count_user_agent_hint_headers_seen_; |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 789 | size_t count_ua_mobile_client_hints_headers_seen_; |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 790 | size_t count_client_hints_headers_seen_; |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 791 | |
Jay Civelli | 1ff872d | 2018-03-09 21:52:16 | [diff] [blame] | 792 | std::unique_ptr<ThirdPartyURLLoaderInterceptor> request_interceptor_; |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 793 | |
Tarun Bansal | bef6d65 | 2018-10-02 18:41:01 | [diff] [blame] | 794 | // Set to 2G in SetUpCommandLine(). |
| 795 | net::EffectiveConnectionType expected_ect = net::EFFECTIVE_CONNECTION_TYPE_2G; |
| 796 | |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 797 | DISALLOW_COPY_AND_ASSIGN(ClientHintsBrowserTest); |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 798 | }; |
| 799 | |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 800 | // True if testing for http-equiv correctness. When set to true, the tests |
| 801 | // use webpages that may contain http-equiv Accept-CH and Accept-CH-Lifetime |
| 802 | // headers. When set to false, the tests use webpages that set the headers in |
| 803 | // the HTTP response headers. |
Ilia Samsonov | 282c3841 | 2019-12-09 08:15:10 | [diff] [blame] | 804 | INSTANTIATE_TEST_SUITE_P(All, |
Victor Costan | e5e9151 | 2019-02-13 08:24:02 | [diff] [blame] | 805 | ClientHintsBrowserTest, |
| 806 | testing::Bool()); |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 807 | |
Tarun Bansal | ea0d826 | 2018-05-21 16:11:50 | [diff] [blame] | 808 | class ClientHintsAllowThirdPartyBrowserTest : public ClientHintsBrowserTest { |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 809 | std::unique_ptr<base::FeatureList> EnabledFeatures() override { |
| 810 | std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 811 | feature_list->InitializeFromCommandLine( |
| 812 | "AllowClientHintsToThirdParty,UserAgentClientHint", ""); |
| 813 | return feature_list; |
Tarun Bansal | ea0d826 | 2018-05-21 16:11:50 | [diff] [blame] | 814 | } |
| 815 | }; |
| 816 | |
Ilia Samsonov | 282c3841 | 2019-12-09 08:15:10 | [diff] [blame] | 817 | INSTANTIATE_TEST_SUITE_P(All, |
Aaron Tagliaboschi | a09ec44 | 2019-09-18 15:29:03 | [diff] [blame] | 818 | ClientHintsAllowThirdPartyBrowserTest, |
| 819 | testing::Bool()); |
| 820 | |
Tarun Bansal | 74e189d | 2018-05-07 19:07:35 | [diff] [blame] | 821 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, CorsChecks) { |
Mike West | 14c1110 | 2019-02-04 16:16:47 | [diff] [blame] | 822 | for (size_t i = 0; i < blink::kClientHintsMappingsCount; ++i) { |
Tarun Bansal | 74e189d | 2018-05-07 19:07:35 | [diff] [blame] | 823 | // Do not test for headers that have not been enabled on the blink "stable" |
| 824 | // yet. |
| 825 | if (std::string(blink::kClientHintsHeaderMapping[i]) == "rtt" || |
| 826 | std::string(blink::kClientHintsHeaderMapping[i]) == "downlink" || |
| 827 | std::string(blink::kClientHintsHeaderMapping[i]) == "ect") { |
| 828 | continue; |
| 829 | } |
Takashi Toyoshima | 2e01e69 | 2018-11-16 03:23:27 | [diff] [blame] | 830 | EXPECT_TRUE(network::cors::IsCorsSafelistedHeader( |
Tarun Bansal | 74e189d | 2018-05-07 19:07:35 | [diff] [blame] | 831 | blink::kClientHintsHeaderMapping[i], "42" /* value */)); |
| 832 | } |
Takashi Toyoshima | 2e01e69 | 2018-11-16 03:23:27 | [diff] [blame] | 833 | EXPECT_FALSE(network::cors::IsCorsSafelistedHeader("not-a-client-hint-header", |
Tarun Bansal | 74e189d | 2018-05-07 19:07:35 | [diff] [blame] | 834 | "" /* value */)); |
| 835 | EXPECT_TRUE( |
Takashi Toyoshima | 2e01e69 | 2018-11-16 03:23:27 | [diff] [blame] | 836 | network::cors::IsCorsSafelistedHeader("save-data", "on" /* value */)); |
Tarun Bansal | 74e189d | 2018-05-07 19:07:35 | [diff] [blame] | 837 | } |
| 838 | |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 839 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, HttpEquivWorks) { |
| 840 | const GURL gurl = http_equiv_accept_ch_without_lifetime_img_localhost(); |
| 841 | base::HistogramTester histogram_tester; |
| 842 | |
| 843 | SetClientHintExpectationsOnMainFrame(false); |
| 844 | SetClientHintExpectationsOnSubresources(true); |
| 845 | |
| 846 | ui_test_utils::NavigateToURL(browser(), gurl); |
| 847 | histogram_tester.ExpectTotalCount("ClientHints.UpdateEventCount", 0); |
| 848 | } |
| 849 | |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 850 | // Loads a webpage that requests persisting of client hints. Verifies that |
| 851 | // the browser receives the mojo notification from the renderer and persists the |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 852 | // client hints to the disk --- unless it's using http-equiv which shouldn't |
| 853 | // persist. |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 854 | IN_PROC_BROWSER_TEST_P(ClientHintsBrowserTest, ClientHintsHttps) { |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 855 | base::HistogramTester histogram_tester; |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 856 | const GURL gurl = GetParam() ? http_equiv_accept_ch_with_lifetime() |
| 857 | : accept_ch_with_lifetime_url(); |
| 858 | ui_test_utils::NavigateToURL(browser(), gurl); |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 859 | |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 860 | if (GetParam()) |
| 861 | histogram_tester.ExpectTotalCount("ClientHints.UpdateEventCount", 0); |
| 862 | else |
| 863 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateEventCount", 1, 1); |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 864 | |
| 865 | content::FetchHistogramsFromChildProcesses(); |
| 866 | SubprocessMetricsProvider::MergeHistogramDeltasForTesting(); |
| 867 | |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 868 | if (GetParam()) { |
| 869 | histogram_tester.ExpectTotalCount("ClientHints.UpdateSize", 0); |
| 870 | histogram_tester.ExpectTotalCount("ClientHints.PersistDuration", 0); |
| 871 | } else { |
| 872 | // client_hints_url() sets the expected number of client hints. |
| 873 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateSize", |
| 874 | expected_client_hints_number, 1); |
| 875 | // accept_ch_with_lifetime_url() sets client hints persist duration to 3600 |
| 876 | // seconds. |
| 877 | histogram_tester.ExpectUniqueSample("ClientHints.PersistDuration", |
| 878 | 3600 * 1000, 1); |
| 879 | } |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 880 | } |
| 881 | |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 882 | // Test that client hints are attached to subresources only if they belong |
| 883 | // to the same host as document host. |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 884 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 885 | ClientHintsHttpsSubresourceDifferentOrigin) { |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 886 | const GURL gurl = accept_ch_with_lifetime_url(); |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 887 | |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 888 | base::HistogramTester histogram_tester; |
| 889 | |
| 890 | // Add client hints for the embedded test server. |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 891 | ui_test_utils::NavigateToURL(browser(), gurl); |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 892 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateEventCount", 1, 1); |
| 893 | |
| 894 | // Verify that the client hints settings for localhost have been saved. |
| 895 | ContentSettingsForOneType client_hints_settings; |
| 896 | HostContentSettingsMap* host_content_settings_map = |
| 897 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()); |
| 898 | host_content_settings_map->GetSettingsForOneType( |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 899 | ContentSettingsType::CLIENT_HINTS, std::string(), &client_hints_settings); |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 900 | ASSERT_EQ(1U, client_hints_settings.size()); |
| 901 | |
| 902 | // Copy the client hints setting for localhost to foo.com. |
| 903 | host_content_settings_map->SetWebsiteSettingDefaultScope( |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 904 | GURL("https://foo.com/"), GURL(), ContentSettingsType::CLIENT_HINTS, |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 905 | std::string(), |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 906 | std::make_unique<base::Value>( |
Oksana Zhuravlova | b14dc88 | 2018-04-12 17:34:57 | [diff] [blame] | 907 | client_hints_settings.at(0).setting_value.Clone())); |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 908 | |
| 909 | // Verify that client hints for the two hosts has been saved. |
| 910 | host_content_settings_map = |
| 911 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()); |
| 912 | host_content_settings_map->GetSettingsForOneType( |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 913 | ContentSettingsType::CLIENT_HINTS, std::string(), &client_hints_settings); |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 914 | ASSERT_EQ(2U, client_hints_settings.size()); |
| 915 | |
| 916 | // Navigating to without_accept_ch_without_lifetime_img_localhost() should |
| 917 | // attach client hints to the image subresouce contained in that page since |
| 918 | // the image is located on the same server as the document origin. |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 919 | SetClientHintExpectationsOnMainFrame(true); |
| 920 | SetClientHintExpectationsOnSubresources(true); |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 921 | ui_test_utils::NavigateToURL( |
| 922 | browser(), without_accept_ch_without_lifetime_img_localhost()); |
| 923 | base::RunLoop().RunUntilIdle(); |
| 924 | content::FetchHistogramsFromChildProcesses(); |
| 925 | SubprocessMetricsProvider::MergeHistogramDeltasForTesting(); |
| 926 | |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 927 | // The user agent hint is attached to all three requests, as is UA-mobile: |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 928 | EXPECT_EQ(3u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 929 | EXPECT_EQ(3u, count_ua_mobile_client_hints_headers_seen()); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 930 | |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 931 | // Expected number of hints attached to the image request, and the same number |
| 932 | // to the main frame request. |
| 933 | EXPECT_EQ(expected_client_hints_number * 2, |
| 934 | count_client_hints_headers_seen()); |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 935 | |
| 936 | // Navigating to without_accept_ch_without_lifetime_img_foo_com() should not |
| 937 | // attach client hints to the image subresouce contained in that page since |
| 938 | // the image is located on a different server as the document origin. |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 939 | ui_test_utils::NavigateToURL( |
| 940 | browser(), without_accept_ch_without_lifetime_img_foo_com()); |
| 941 | base::RunLoop().RunUntilIdle(); |
| 942 | content::FetchHistogramsFromChildProcesses(); |
| 943 | SubprocessMetricsProvider::MergeHistogramDeltasForTesting(); |
| 944 | |
Tarun Bansal | b30b753 | 2018-03-14 21:50:38 | [diff] [blame] | 945 | // The device-memory and dprheader is attached to the main frame request. |
Tarun Bansal | 5c28afb | 2018-03-17 02:55:20 | [diff] [blame] | 946 | #if defined(OS_ANDROID) |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 947 | EXPECT_EQ(expected_client_hints_number, count_client_hints_headers_seen()); |
Tarun Bansal | 5c28afb | 2018-03-17 02:55:20 | [diff] [blame] | 948 | #else |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 949 | EXPECT_EQ(expected_client_hints_number * 3, |
| 950 | count_client_hints_headers_seen()); |
Tarun Bansal | 5c28afb | 2018-03-17 02:55:20 | [diff] [blame] | 951 | #endif |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 952 | |
| 953 | // Requests to third party servers should have only one client hint attached |
| 954 | // (`Sec-CH-UA`). |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 955 | EXPECT_EQ(1u, third_party_request_count_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 956 | EXPECT_EQ(2u, third_party_client_hints_count_seen()); |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 957 | } |
| 958 | |
Maks Orlovich | 7227ce0d | 2020-02-28 17:13:16 | [diff] [blame] | 959 | // Test that client hints are attached to subresources checks the right setting |
| 960 | // for OTR profile. |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 961 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, |
Maks Orlovich | 7227ce0d | 2020-02-28 17:13:16 | [diff] [blame] | 962 | ClientHintsHttpsSubresourceOffTheRecord) { |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 963 | const GURL gurl = accept_ch_with_lifetime_url(); |
Maks Orlovich | 7227ce0d | 2020-02-28 17:13:16 | [diff] [blame] | 964 | |
| 965 | base::HistogramTester histogram_tester; |
| 966 | |
| 967 | // Add client hints for the embedded test server. |
| 968 | ui_test_utils::NavigateToURL(browser(), gurl); |
| 969 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateEventCount", 1, 1); |
| 970 | |
| 971 | // Main profile should get hints for both page and subresources. |
| 972 | SetClientHintExpectationsOnMainFrame(true); |
| 973 | SetClientHintExpectationsOnSubresources(true); |
| 974 | ui_test_utils::NavigateToURL( |
| 975 | browser(), without_accept_ch_without_lifetime_img_localhost()); |
| 976 | base::RunLoop().RunUntilIdle(); |
| 977 | content::FetchHistogramsFromChildProcesses(); |
| 978 | SubprocessMetricsProvider::MergeHistogramDeltasForTesting(); |
| 979 | |
| 980 | // The user agent hint is attached to all three requests: |
| 981 | EXPECT_EQ(3u, count_user_agent_hint_headers_seen()); |
| 982 | EXPECT_EQ(3u, count_ua_mobile_client_hints_headers_seen()); |
| 983 | |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 984 | // Expected number of hints attached to the image request, and the same number |
| 985 | // to the main frame request. |
| 986 | EXPECT_EQ(expected_client_hints_number * 2, |
| 987 | count_client_hints_headers_seen()); |
Maks Orlovich | 7227ce0d | 2020-02-28 17:13:16 | [diff] [blame] | 988 | |
| 989 | // OTR profile should get neither. |
| 990 | Browser* otr_browser = CreateIncognitoBrowser(browser()->profile()); |
| 991 | SetClientHintExpectationsOnMainFrame(false); |
| 992 | SetClientHintExpectationsOnSubresources(false); |
| 993 | ui_test_utils::NavigateToURL( |
| 994 | otr_browser, without_accept_ch_without_lifetime_img_localhost()); |
| 995 | } |
| 996 | |
Mike West | e555be86 | 2019-02-20 16:17:30 | [diff] [blame] | 997 | // Verify that we send only major version information in the `Sec-CH-UA` header |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 998 | // by default, regardless of opt-in. |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 999 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, UserAgentVersion) { |
| 1000 | const GURL gurl = accept_ch_with_lifetime_url(); |
Mike West | e555be86 | 2019-02-20 16:17:30 | [diff] [blame] | 1001 | |
| 1002 | blink::UserAgentMetadata ua = ::GetUserAgentMetadata(); |
| 1003 | |
| 1004 | // Navigate to a page that opts-into the header: the value should end with |
| 1005 | // the major version, and not contain the full version. |
| 1006 | SetClientHintExpectationsOnMainFrame(false); |
| 1007 | ui_test_utils::NavigateToURL(browser(), gurl); |
Aaron Tagliaboschi | 9f01b68 | 2020-05-05 21:03:17 | [diff] [blame] | 1008 | std::string expected_ua = ua.SerializeBrandVersionList(); |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1009 | EXPECT_EQ(main_frame_ua_observed(), expected_ua); |
| 1010 | EXPECT_TRUE(main_frame_ua_full_version_observed().empty()); |
Mike West | e555be86 | 2019-02-20 16:17:30 | [diff] [blame] | 1011 | |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1012 | // Navigate again, after the opt-in: the value should stay the major |
Mike West | e555be86 | 2019-02-20 16:17:30 | [diff] [blame] | 1013 | // version. |
| 1014 | SetClientHintExpectationsOnMainFrame(true); |
| 1015 | ui_test_utils::NavigateToURL(browser(), gurl); |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1016 | std::string expected_full_version = "\"" + ua.full_version + "\""; |
| 1017 | EXPECT_EQ(main_frame_ua_observed(), expected_ua); |
| 1018 | EXPECT_EQ(main_frame_ua_full_version_observed(), expected_full_version); |
Mike West | e555be86 | 2019-02-20 16:17:30 | [diff] [blame] | 1019 | } |
| 1020 | |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1021 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, UAHintsTabletMode) { |
| 1022 | const GURL gurl = accept_ch_with_lifetime_url(); |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 1023 | |
| 1024 | blink::UserAgentMetadata ua = ::GetUserAgentMetadata(); |
| 1025 | |
| 1026 | // First request: only minimal hints, no tablet override. |
| 1027 | SetClientHintExpectationsOnMainFrame(false); |
| 1028 | ui_test_utils::NavigateToURL(browser(), gurl); |
Aaron Tagliaboschi | 9f01b68 | 2020-05-05 21:03:17 | [diff] [blame] | 1029 | std::string expected_ua = ua.SerializeBrandVersionList(); |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 1030 | EXPECT_EQ(main_frame_ua_observed(), expected_ua); |
| 1031 | EXPECT_EQ(main_frame_ua_full_version_observed(), ""); |
| 1032 | EXPECT_EQ(main_frame_ua_mobile_observed(), "?0"); |
| 1033 | EXPECT_EQ(main_frame_ua_platform_observed(), ""); |
| 1034 | |
| 1035 | // Second request: table override, all hints. |
| 1036 | chrome::ToggleRequestTabletSite(browser()); |
| 1037 | SetClientHintExpectationsOnMainFrame(true); |
| 1038 | ui_test_utils::NavigateToURL(browser(), gurl); |
| 1039 | EXPECT_EQ(main_frame_ua_observed(), expected_ua); |
| 1040 | std::string expected_full_version = "\"" + ua.full_version + "\""; |
| 1041 | EXPECT_EQ(main_frame_ua_full_version_observed(), expected_full_version); |
| 1042 | EXPECT_EQ(main_frame_ua_mobile_observed(), "?1"); |
| 1043 | EXPECT_EQ(main_frame_ua_platform_observed(), "\"Android\""); |
| 1044 | } |
| 1045 | |
| 1046 | // TODO(morlovich): Move this into WebContentsImplBrowserTest once things are |
| 1047 | // refactored enough that UA client hints actually work in content/ |
| 1048 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, UserAgentOverrideClientHints) { |
| 1049 | content::WebContents* web_contents = |
| 1050 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 1051 | |
| 1052 | ASSERT_TRUE(embedded_test_server()->Start()); |
| 1053 | const std::string kHeaderPath = std::string("/echoheader?") + |
| 1054 | net::HttpRequestHeaders::kUserAgent + |
| 1055 | "&sec-ch-ua&sec-ch-ua-mobile"; |
| 1056 | const GURL kUrl(embedded_test_server()->GetURL(kHeaderPath)); |
| 1057 | |
| 1058 | web_contents->SetUserAgentOverride( |
| 1059 | blink::UserAgentOverride::UserAgentOnly("foo"), false); |
| 1060 | // Not enabled first. |
| 1061 | ui_test_utils::NavigateToURL(browser(), kUrl); |
| 1062 | std::string header_value; |
| 1063 | EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 1064 | web_contents, |
| 1065 | "window.domAutomationController.send(document.body.textContent);", |
| 1066 | &header_value)); |
| 1067 | EXPECT_EQ(std::string::npos, header_value.find("foo")) << header_value; |
| 1068 | |
| 1069 | // Actually turn it on. |
| 1070 | web_contents->GetController() |
| 1071 | .GetLastCommittedEntry() |
| 1072 | ->SetIsOverridingUserAgent(true); |
| 1073 | |
| 1074 | ui_test_utils::NavigateToURL(browser(), kUrl); |
| 1075 | EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 1076 | web_contents, |
| 1077 | "window.domAutomationController.send(document.body.textContent);", |
| 1078 | &header_value)); |
| 1079 | // Since no value was provided for client hints, they are not sent. |
| 1080 | EXPECT_EQ("foo\nNone\nNone", header_value); |
| 1081 | |
| 1082 | // Now actually provide values for the hints. |
| 1083 | blink::UserAgentOverride ua_override; |
| 1084 | ua_override.ua_string_override = "foobar"; |
| 1085 | ua_override.ua_metadata_override.emplace(); |
| 1086 | ua_override.ua_metadata_override->mobile = true; |
Aaron Tagliaboschi | 9f01b68 | 2020-05-05 21:03:17 | [diff] [blame] | 1087 | ua_override.ua_metadata_override->brand_version_list.emplace_back( |
| 1088 | "Foobarnator", "3.14"); |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 1089 | web_contents->SetUserAgentOverride(ua_override, false); |
| 1090 | ui_test_utils::NavigateToURL(browser(), kUrl); |
| 1091 | EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 1092 | web_contents, |
| 1093 | "window.domAutomationController.send(document.body.textContent);", |
| 1094 | &header_value)); |
Aaron Tagliaboschi | 9f01b68 | 2020-05-05 21:03:17 | [diff] [blame] | 1095 | EXPECT_EQ("foobar\n\"Foobarnator\";v=\"3.14\"\n?1", header_value); |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 1096 | } |
| 1097 | |
Maks Orlovich | 7a588d8 | 2020-05-06 15:17:24 | [diff] [blame] | 1098 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, EmptyAcceptCH) { |
| 1099 | // First navigate to a page that enables hints. No CH for it yet, since |
| 1100 | // nothing opted in. |
| 1101 | GURL gurl = accept_ch_with_lifetime_url(); |
| 1102 | SetClientHintExpectationsOnMainFrame(false); |
| 1103 | ui_test_utils::NavigateToURL(browser(), gurl); |
| 1104 | |
| 1105 | // Now go to a page with blank Accept-CH. Should get hints from previous |
| 1106 | // visit. |
| 1107 | gurl = accept_ch_empty(); |
| 1108 | SetClientHintExpectationsOnMainFrame(true); |
| 1109 | ui_test_utils::NavigateToURL(browser(), gurl); |
| 1110 | |
| 1111 | // Visiting again should not expect them since we opted out again. |
| 1112 | SetClientHintExpectationsOnMainFrame(false); |
| 1113 | ui_test_utils::NavigateToURL(browser(), gurl); |
| 1114 | } |
| 1115 | |
| 1116 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, MergeAcceptCH) { |
| 1117 | // Go to page where some hints are enabled by headers, some by |
| 1118 | // http-equiv. It shouldn't get hints itself (due to first visit), |
| 1119 | // but subresources should get all the client hints. |
| 1120 | GURL gurl = http_equiv_accept_ch_merge(); |
| 1121 | SetClientHintExpectationsOnMainFrame(false); |
| 1122 | SetClientHintExpectationsOnSubresources(true); |
| 1123 | ui_test_utils::NavigateToURL(browser(), gurl); |
| 1124 | EXPECT_EQ(expected_client_hints_number, count_client_hints_headers_seen()); |
| 1125 | } |
| 1126 | |
Maks Orlovich | 7227ce0d | 2020-02-28 17:13:16 | [diff] [blame] | 1127 | void ClientHintsBrowserTest::TestProfilesIndependent(Browser* browser_a, |
| 1128 | Browser* browser_b) { |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1129 | const GURL gurl = accept_ch_with_lifetime_url(); |
Maks Orlovich | 7227ce0d | 2020-02-28 17:13:16 | [diff] [blame] | 1130 | |
| 1131 | blink::UserAgentMetadata ua = ::GetUserAgentMetadata(); |
| 1132 | |
| 1133 | // Navigate |browser_a| to a page that opts-into the header: the value should |
| 1134 | // end with the major version, and not contain the full version. |
| 1135 | SetClientHintExpectationsOnMainFrame(false); |
| 1136 | ui_test_utils::NavigateToURL(browser_a, gurl); |
Aaron Tagliaboschi | 9f01b68 | 2020-05-05 21:03:17 | [diff] [blame] | 1137 | std::string expected_ua = ua.SerializeBrandVersionList(); |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1138 | EXPECT_EQ(main_frame_ua_observed(), expected_ua); |
| 1139 | EXPECT_TRUE(main_frame_ua_full_version_observed().empty()); |
Maks Orlovich | 7227ce0d | 2020-02-28 17:13:16 | [diff] [blame] | 1140 | |
| 1141 | // Try again on |browser_a|, the header should have an effect there. |
| 1142 | SetClientHintExpectationsOnMainFrame(true); |
| 1143 | ui_test_utils::NavigateToURL(browser_a, gurl); |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1144 | std::string expected_full_version = "\"" + ua.full_version + "\""; |
| 1145 | EXPECT_EQ(main_frame_ua_observed(), expected_ua); |
| 1146 | EXPECT_EQ(main_frame_ua_full_version_observed(), expected_full_version); |
Maks Orlovich | 7227ce0d | 2020-02-28 17:13:16 | [diff] [blame] | 1147 | |
| 1148 | // Navigate on |browser_b|. That should still only have the major |
| 1149 | // version. |
| 1150 | SetClientHintExpectationsOnMainFrame(false); |
| 1151 | ui_test_utils::NavigateToURL(browser_b, gurl); |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1152 | EXPECT_EQ(main_frame_ua_observed(), expected_ua); |
| 1153 | EXPECT_TRUE(main_frame_ua_full_version_observed().empty()); |
Maks Orlovich | 7227ce0d | 2020-02-28 17:13:16 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | // Check that client hints attached to navigation inside OTR profiles |
| 1157 | // use the right settings, regular -> OTR direction. |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1158 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, OffTheRecordIndependent) { |
Maks Orlovich | 7227ce0d | 2020-02-28 17:13:16 | [diff] [blame] | 1159 | TestProfilesIndependent(browser(), |
| 1160 | CreateIncognitoBrowser(browser()->profile())); |
| 1161 | } |
| 1162 | |
| 1163 | // Check that client hints attached to navigation inside OTR profiles |
| 1164 | // use the right settings, OTR -> regular direction. |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1165 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, OffTheRecordIndependent2) { |
Maks Orlovich | 7227ce0d | 2020-02-28 17:13:16 | [diff] [blame] | 1166 | TestProfilesIndependent(CreateIncognitoBrowser(browser()->profile()), |
| 1167 | browser()); |
| 1168 | } |
| 1169 | |
Tarun Bansal | ea0d826 | 2018-05-21 16:11:50 | [diff] [blame] | 1170 | // Test that client hints are attached to third party subresources if |
| 1171 | // AllowClientHintsToThirdParty feature is enabled. |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1172 | IN_PROC_BROWSER_TEST_P(ClientHintsAllowThirdPartyBrowserTest, |
Tarun Bansal | ea0d826 | 2018-05-21 16:11:50 | [diff] [blame] | 1173 | ClientHintsThirdPartyAllowed) { |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1174 | const GURL gurl = GetParam() |
| 1175 | ? http_equiv_accept_ch_without_lifetime_img_localhost() |
| 1176 | : accept_ch_without_lifetime_img_localhost(); |
| 1177 | |
Tarun Bansal | ea0d826 | 2018-05-21 16:11:50 | [diff] [blame] | 1178 | base::HistogramTester histogram_tester; |
| 1179 | |
| 1180 | SetClientHintExpectationsOnMainFrame(false); |
| 1181 | SetClientHintExpectationsOnSubresources(true); |
| 1182 | |
| 1183 | // Add client hints for the embedded test server. |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1184 | ui_test_utils::NavigateToURL(browser(), gurl); |
Tarun Bansal | ea0d826 | 2018-05-21 16:11:50 | [diff] [blame] | 1185 | histogram_tester.ExpectTotalCount("ClientHints.UpdateEventCount", 0); |
| 1186 | |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1187 | EXPECT_EQ(expected_client_hints_number, count_client_hints_headers_seen()); |
Tarun Bansal | ea0d826 | 2018-05-21 16:11:50 | [diff] [blame] | 1188 | |
| 1189 | // Requests to third party servers should not have client hints attached. |
| 1190 | EXPECT_EQ(1u, third_party_request_count_seen()); |
| 1191 | |
Aaron Tagliaboschi | a09ec44 | 2019-09-18 15:29:03 | [diff] [blame] | 1192 | // Device memory, viewport width, DRP, and UA client hints should be sent to |
| 1193 | // the third-party when feature "AllowClientHintsToThirdParty" is enabled. |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1194 | EXPECT_EQ(5u, third_party_client_hints_count_seen()); |
Tarun Bansal | ea0d826 | 2018-05-21 16:11:50 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | // Test that client hints are not attached to third party subresources if |
| 1198 | // AllowClientHintsToThirdParty feature is not enabled. |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1199 | IN_PROC_BROWSER_TEST_P(ClientHintsBrowserTest, |
Tarun Bansal | ea0d826 | 2018-05-21 16:11:50 | [diff] [blame] | 1200 | ClientHintsThirdPartyNotAllowed) { |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1201 | const GURL gurl = GetParam() |
| 1202 | ? http_equiv_accept_ch_without_lifetime_img_localhost() |
| 1203 | : accept_ch_without_lifetime_img_localhost(); |
| 1204 | |
Tarun Bansal | ea0d826 | 2018-05-21 16:11:50 | [diff] [blame] | 1205 | base::HistogramTester histogram_tester; |
| 1206 | |
| 1207 | SetClientHintExpectationsOnMainFrame(false); |
| 1208 | SetClientHintExpectationsOnSubresources(true); |
| 1209 | |
| 1210 | // Add client hints for the embedded test server. |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1211 | ui_test_utils::NavigateToURL(browser(), gurl); |
Tarun Bansal | ea0d826 | 2018-05-21 16:11:50 | [diff] [blame] | 1212 | histogram_tester.ExpectTotalCount("ClientHints.UpdateEventCount", 0); |
| 1213 | |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1214 | EXPECT_EQ(2u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1215 | EXPECT_EQ(2u, count_ua_mobile_client_hints_headers_seen()); |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1216 | EXPECT_EQ(expected_client_hints_number, count_client_hints_headers_seen()); |
Tarun Bansal | ea0d826 | 2018-05-21 16:11:50 | [diff] [blame] | 1217 | |
| 1218 | // Requests to third party servers should not have client hints attached. |
| 1219 | EXPECT_EQ(1u, third_party_request_count_seen()); |
| 1220 | |
| 1221 | // Client hints should not be sent to the third-party when feature |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1222 | // "AllowClientHintsToThirdParty" is not enabled, with the exception of the |
| 1223 | // `Sec-CH-UA` hint, which is sent with every request. |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1224 | EXPECT_EQ(2u, third_party_client_hints_count_seen()); |
Tarun Bansal | ea0d826 | 2018-05-21 16:11:50 | [diff] [blame] | 1225 | } |
| 1226 | |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 1227 | // Loads a HTTPS webpage that does not request persisting of client hints. |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 1228 | // A same-origin iframe loaded by the webpage requests persistence of client |
| 1229 | // hints. Verify that the request from the iframe is honored, and client hints |
| 1230 | // preference is persisted. |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1231 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 1232 | PersistenceRequestIframe_SameOrigin) { |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1233 | const GURL gurl = accept_ch_without_lifetime_with_iframe_url(); |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 1234 | base::HistogramTester histogram_tester; |
| 1235 | ContentSettingsForOneType host_settings; |
| 1236 | |
| 1237 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1238 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 1239 | &host_settings); |
| 1240 | EXPECT_EQ(0u, host_settings.size()); |
| 1241 | |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1242 | ui_test_utils::NavigateToURL(browser(), gurl); |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 1243 | |
| 1244 | histogram_tester.ExpectTotalCount("ClientHints.UpdateEventCount", 1); |
| 1245 | |
| 1246 | content::FetchHistogramsFromChildProcesses(); |
| 1247 | SubprocessMetricsProvider::MergeHistogramDeltasForTesting(); |
| 1248 | |
| 1249 | // accept_ch_without_lifetime_with_iframe_url() loads |
| 1250 | // accept_ch_with_lifetime() in an iframe. The request to persist client |
| 1251 | // hints from accept_ch_with_lifetime() should be persisted. |
| 1252 | histogram_tester.ExpectTotalCount("ClientHints.UpdateSize", 1); |
| 1253 | histogram_tester.ExpectUniqueSample("ClientHints.PersistDuration", |
| 1254 | 3600 * 1000, 1); |
| 1255 | } |
| 1256 | |
| 1257 | // Loads a HTTPS webpage that does not request persisting of client hints. |
| 1258 | // An iframe loaded by the webpage from an cross origin server requests |
| 1259 | // persistence of client hints. |
| 1260 | // Verify that the request from the cross origin iframe is not honored, and |
| 1261 | // client hints preference is not persisted. |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1262 | IN_PROC_BROWSER_TEST_P(ClientHintsBrowserTest, |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 1263 | DisregardPersistenceRequestIframe_CrossOrigin) { |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1264 | const GURL gurl = |
| 1265 | GetParam() ? http_equiv_accept_ch_without_lifetime_with_iframe_url() |
| 1266 | : accept_ch_without_lifetime_with_iframe_url(); |
| 1267 | |
| 1268 | intercept_iframe_resource_ = gurl.path(); |
| 1269 | intercept_to_http_equiv_iframe_ = GetParam(); |
| 1270 | |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 1271 | base::HistogramTester histogram_tester; |
| 1272 | ContentSettingsForOneType host_settings; |
| 1273 | |
| 1274 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1275 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 1276 | &host_settings); |
| 1277 | EXPECT_EQ(0u, host_settings.size()); |
| 1278 | |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1279 | ui_test_utils::NavigateToURL(browser(), gurl); |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 1280 | |
| 1281 | histogram_tester.ExpectTotalCount("ClientHints.UpdateEventCount", 0); |
| 1282 | |
| 1283 | content::FetchHistogramsFromChildProcesses(); |
| 1284 | SubprocessMetricsProvider::MergeHistogramDeltasForTesting(); |
| 1285 | |
| 1286 | // accept_ch_without_lifetime_with_iframe_url() loads |
Tarun Bansal | 34541863 | 2018-06-29 11:07:04 | [diff] [blame] | 1287 | // accept_ch_with_lifetime() in a cross origin iframe. The request to persist |
| 1288 | // client hints from accept_ch_with_lifetime() should be disregarded. |
Tarun Bansal | add5e181 | 2018-02-09 19:07:58 | [diff] [blame] | 1289 | histogram_tester.ExpectTotalCount("ClientHints.UpdateSize", 0); |
| 1290 | histogram_tester.ExpectTotalCount("ClientHints.PersistDuration", 0); |
| 1291 | } |
| 1292 | |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 1293 | // Loads a HTTPS webpage that does not request persisting of client hints. |
| 1294 | // A subresource loaded by the webpage requests persistence of client hints. |
| 1295 | // Verify that the request from the subresource is not honored, and client hints |
| 1296 | // preference is not persisted. |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1297 | IN_PROC_BROWSER_TEST_P(ClientHintsBrowserTest, |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 1298 | DisregardPersistenceRequestSubresource) { |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1299 | const GURL gurl = |
| 1300 | GetParam() ? http_equiv_accept_ch_without_lifetime_with_subresource_url() |
| 1301 | : accept_ch_without_lifetime_with_subresource_url(); |
| 1302 | |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 1303 | base::HistogramTester histogram_tester; |
| 1304 | ContentSettingsForOneType host_settings; |
| 1305 | |
| 1306 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1307 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 1308 | &host_settings); |
| 1309 | EXPECT_EQ(0u, host_settings.size()); |
| 1310 | |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1311 | ui_test_utils::NavigateToURL(browser(), gurl); |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 1312 | |
| 1313 | histogram_tester.ExpectTotalCount("ClientHints.UpdateEventCount", 0); |
| 1314 | |
| 1315 | content::FetchHistogramsFromChildProcesses(); |
| 1316 | SubprocessMetricsProvider::MergeHistogramDeltasForTesting(); |
| 1317 | |
| 1318 | // accept_ch_without_lifetime_with_subresource_url() loads |
| 1319 | // accept_ch_with_lifetime() as a subresource. The request to persist client |
| 1320 | // hints from accept_ch_with_lifetime() should be disregarded. |
| 1321 | histogram_tester.ExpectTotalCount("ClientHints.UpdateSize", 0); |
| 1322 | histogram_tester.ExpectTotalCount("ClientHints.PersistDuration", 0); |
| 1323 | } |
| 1324 | |
| 1325 | // Loads a HTTPS webpage that does not request persisting of client hints. |
| 1326 | // A subresource loaded by the webpage in an iframe requests persistence of |
| 1327 | // client hints. Verify that the request from the subresource in the iframe |
| 1328 | // is not honored, and client hints preference is not persisted. |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1329 | IN_PROC_BROWSER_TEST_P(ClientHintsBrowserTest, |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 1330 | DisregardPersistenceRequestSubresourceIframe) { |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1331 | const GURL gurl = |
| 1332 | GetParam() |
| 1333 | ? http_equiv_accept_ch_without_lifetime_with_subresource_iframe_url() |
| 1334 | : accept_ch_without_lifetime_with_subresource_iframe_url(); |
| 1335 | |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 1336 | base::HistogramTester histogram_tester; |
| 1337 | ContentSettingsForOneType host_settings; |
| 1338 | |
| 1339 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1340 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 1341 | &host_settings); |
| 1342 | EXPECT_EQ(0u, host_settings.size()); |
| 1343 | |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1344 | ui_test_utils::NavigateToURL(browser(), gurl); |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 1345 | |
| 1346 | histogram_tester.ExpectTotalCount("ClientHints.UpdateEventCount", 0); |
| 1347 | |
| 1348 | content::FetchHistogramsFromChildProcesses(); |
| 1349 | SubprocessMetricsProvider::MergeHistogramDeltasForTesting(); |
| 1350 | |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1351 | // |gurl| loads accept_ch_with_lifetime() or |
| 1352 | // http_equiv_accept_ch_with_lifetime() as a subresource in an iframe. The |
| 1353 | // request to persist client hints from accept_ch_with_lifetime() or |
| 1354 | // http_equiv_accept_ch_with_lifetime() should be disregarded. |
Tarun Bansal | 62cc354 | 2018-06-27 23:53:30 | [diff] [blame] | 1355 | histogram_tester.ExpectTotalCount("ClientHints.UpdateSize", 0); |
| 1356 | histogram_tester.ExpectTotalCount("ClientHints.PersistDuration", 0); |
| 1357 | } |
| 1358 | |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 1359 | // Loads a HTTP local webpage (which qualifies as a secure context) that |
| 1360 | // requests persisting of client hints. Verifies that the browser receives the |
| 1361 | // mojo notification from the renderer and persists the client hints to the |
| 1362 | // disk. |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1363 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 1364 | ClientHintsLifetimeFollowedByNoClientHintHttpLocal) { |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1365 | const GURL gurl = accept_ch_with_lifetime_http_local_url(); |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1366 | |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 1367 | base::HistogramTester histogram_tester; |
| 1368 | ContentSettingsForOneType host_settings; |
| 1369 | |
| 1370 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1371 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 1372 | &host_settings); |
| 1373 | EXPECT_EQ(0u, host_settings.size()); |
| 1374 | |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1375 | ui_test_utils::NavigateToURL(browser(), gurl); |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 1376 | |
| 1377 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateEventCount", 1, 1); |
| 1378 | |
| 1379 | content::FetchHistogramsFromChildProcesses(); |
| 1380 | SubprocessMetricsProvider::MergeHistogramDeltasForTesting(); |
| 1381 | |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1382 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateSize", |
| 1383 | expected_client_hints_number, 1); |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1384 | // |gurl| sets client hints persist duration to 3600 seconds. |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 1385 | histogram_tester.ExpectUniqueSample("ClientHints.PersistDuration", |
| 1386 | 3600 * 1000, 1); |
| 1387 | |
| 1388 | base::RunLoop().RunUntilIdle(); |
| 1389 | |
| 1390 | // Clients hints preferences for one origin should be persisted. |
| 1391 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1392 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 1393 | &host_settings); |
| 1394 | EXPECT_EQ(1u, host_settings.size()); |
| 1395 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1396 | SetClientHintExpectationsOnMainFrame(true); |
| 1397 | SetClientHintExpectationsOnSubresources(true); |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 1398 | ui_test_utils::NavigateToURL(browser(), |
| 1399 | without_accept_ch_without_lifetime_local_url()); |
| 1400 | |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1401 | // The user agent hint is attached to all three requests: |
| 1402 | EXPECT_EQ(3u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1403 | EXPECT_EQ(3u, count_ua_mobile_client_hints_headers_seen()); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1404 | |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1405 | // Expected number of hints attached to the image request, and the same number |
| 1406 | // to the main frame request. |
| 1407 | EXPECT_EQ(expected_client_hints_number * 2, |
| 1408 | count_client_hints_headers_seen()); |
Tarun Bansal | 3b330b0 | 2017-11-09 19:03:14 | [diff] [blame] | 1409 | } |
| 1410 | |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 1411 | // Loads a webpage that does not request persisting of client hints. |
| 1412 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, NoClientHintsHttps) { |
| 1413 | base::HistogramTester histogram_tester; |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1414 | ui_test_utils::NavigateToURL(browser(), |
| 1415 | without_accept_ch_without_lifetime_url()); |
Tarun Bansal | 0b8b7afd | 2017-08-25 03:52:16 | [diff] [blame] | 1416 | |
| 1417 | histogram_tester.ExpectTotalCount("ClientHints.UpdateEventCount", 0); |
| 1418 | |
| 1419 | content::FetchHistogramsFromChildProcesses(); |
| 1420 | SubprocessMetricsProvider::MergeHistogramDeltasForTesting(); |
| 1421 | |
| 1422 | // no_client_hints_url() does not sets the client hints. |
| 1423 | histogram_tester.ExpectTotalCount("ClientHints.UpdateSize", 0); |
| 1424 | histogram_tester.ExpectTotalCount("ClientHints.PersistDuration", 0); |
| 1425 | } |
| 1426 | |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1427 | IN_PROC_BROWSER_TEST_P(ClientHintsBrowserTest, |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1428 | ClientHintsLifetimeFollowedByNoClientHint) { |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1429 | const GURL gurl = GetParam() ? http_equiv_accept_ch_with_lifetime() |
| 1430 | : accept_ch_with_lifetime_url(); |
| 1431 | |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1432 | base::HistogramTester histogram_tester; |
| 1433 | ContentSettingsForOneType host_settings; |
| 1434 | |
| 1435 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1436 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1437 | &host_settings); |
| 1438 | EXPECT_EQ(0u, host_settings.size()); |
| 1439 | |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1440 | // Fetching |gurl| should persist the request for client hints iff using |
| 1441 | // headers and not http-equiv. |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1442 | ui_test_utils::NavigateToURL(browser(), gurl); |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1443 | |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1444 | if (GetParam()) |
| 1445 | histogram_tester.ExpectTotalCount("ClientHints.UpdateEventCount", 0); |
| 1446 | else |
| 1447 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateEventCount", 1, 1); |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1448 | |
| 1449 | content::FetchHistogramsFromChildProcesses(); |
| 1450 | SubprocessMetricsProvider::MergeHistogramDeltasForTesting(); |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1451 | base::RunLoop().RunUntilIdle(); |
| 1452 | |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1453 | if (GetParam()) { |
| 1454 | histogram_tester.ExpectTotalCount("ClientHints.UpdateSize", 0); |
| 1455 | histogram_tester.ExpectTotalCount("ClientHints.PersistDuration", 0); |
| 1456 | } else { |
| 1457 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateSize", |
| 1458 | expected_client_hints_number, 1); |
| 1459 | // accept_ch_with_lifetime_url() sets client hints persist duration to 3600 |
| 1460 | // seconds. |
| 1461 | histogram_tester.ExpectUniqueSample("ClientHints.PersistDuration", |
| 1462 | 3600 * 1000, 1); |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1463 | |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1464 | // Clients hints preferences for one origin should be persisted. |
| 1465 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 1466 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, |
| 1467 | std::string(), &host_settings); |
| 1468 | EXPECT_EQ(1u, host_settings.size()); |
| 1469 | } |
| 1470 | |
| 1471 | SetClientHintExpectationsOnMainFrame(!GetParam()); |
| 1472 | SetClientHintExpectationsOnSubresources(!GetParam()); |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1473 | ui_test_utils::NavigateToURL(browser(), |
| 1474 | without_accept_ch_without_lifetime_url()); |
Tarun Bansal | 6bf5430 | 2017-10-02 07:39:14 | [diff] [blame] | 1475 | |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1476 | // The user agent hint is attached to all three requests: |
| 1477 | EXPECT_EQ(3u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1478 | EXPECT_EQ(3u, count_ua_mobile_client_hints_headers_seen()); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1479 | |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1480 | // Expected number of hints attached to the image request, and the same number |
| 1481 | // to the main frame request. |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1482 | EXPECT_EQ(GetParam() ? 0 : expected_client_hints_number * 2, |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1483 | count_client_hints_headers_seen()); |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1484 | } |
| 1485 | |
Tarun Bansal | 73502f9 | 2019-04-16 21:21:19 | [diff] [blame] | 1486 | // Verify that expired persistent client hint preferences are not used. |
| 1487 | // Verifies this by setting Accept-CH-Lifetime value to 1 second, |
| 1488 | // and loading a page after 1 second to verify that client hints are not |
| 1489 | // attached. |
| 1490 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, |
| 1491 | ShortLifetimeFollowedByNoClientHint) { |
| 1492 | const GURL gurl = accept_ch_with_short_lifetime(); |
| 1493 | |
| 1494 | base::HistogramTester histogram_tester; |
| 1495 | ContentSettingsForOneType host_settings; |
| 1496 | |
| 1497 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1498 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | 73502f9 | 2019-04-16 21:21:19 | [diff] [blame] | 1499 | &host_settings); |
| 1500 | EXPECT_EQ(0u, host_settings.size()); |
| 1501 | |
| 1502 | // Fetching |gurl| should persist the request for client hints. |
| 1503 | ui_test_utils::NavigateToURL(browser(), gurl); |
| 1504 | |
| 1505 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateEventCount", 1, 1); |
| 1506 | |
| 1507 | content::FetchHistogramsFromChildProcesses(); |
| 1508 | SubprocessMetricsProvider::MergeHistogramDeltasForTesting(); |
| 1509 | |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1510 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateSize", |
| 1511 | expected_client_hints_number, 1); |
Tarun Bansal | 73502f9 | 2019-04-16 21:21:19 | [diff] [blame] | 1512 | // |gurl| sets client hints persist duration to 1 second. |
| 1513 | histogram_tester.ExpectUniqueSample("ClientHints.PersistDuration", 1 * 1000, |
| 1514 | 1); |
| 1515 | base::RunLoop().RunUntilIdle(); |
| 1516 | |
| 1517 | // Clients hints preferences for one origin should be persisted. |
| 1518 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1519 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | 73502f9 | 2019-04-16 21:21:19 | [diff] [blame] | 1520 | &host_settings); |
| 1521 | EXPECT_EQ(1u, host_settings.size()); |
| 1522 | |
| 1523 | // Sleep for a duration longer than 1 second (duration of persisted client |
| 1524 | // hints). |
| 1525 | base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1001)); |
| 1526 | |
| 1527 | SetClientHintExpectationsOnMainFrame(false); |
| 1528 | SetClientHintExpectationsOnSubresources(false); |
| 1529 | ui_test_utils::NavigateToURL(browser(), |
| 1530 | without_accept_ch_without_lifetime_url()); |
| 1531 | |
| 1532 | // The user agent hint is attached to all three requests: |
| 1533 | EXPECT_EQ(3u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1534 | EXPECT_EQ(3u, count_ua_mobile_client_hints_headers_seen()); |
Tarun Bansal | 73502f9 | 2019-04-16 21:21:19 | [diff] [blame] | 1535 | |
| 1536 | // No client hints are attached to the requests since the persisted hints must |
| 1537 | // be expired. |
| 1538 | EXPECT_EQ(0u, count_client_hints_headers_seen()); |
| 1539 | } |
| 1540 | |
Tarun Bansal | 293a7b6c | 2018-12-05 17:41:12 | [diff] [blame] | 1541 | // The test first fetches a page that sets Accept-CH-Lifetime. Next, it fetches |
| 1542 | // a URL from a different origin. However, that URL response redirects to the |
| 1543 | // same origin from where the first page was fetched. The test verifies that |
| 1544 | // on receiving redirect to an origin for which the browser has persisted client |
| 1545 | // hints prefs, the browser attaches the client hints headers when fetching the |
| 1546 | // redirected URL. |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1547 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, |
Tarun Bansal | 293a7b6c | 2018-12-05 17:41:12 | [diff] [blame] | 1548 | ClientHintsLifetimeFollowedByRedirectToNoClientHint) { |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1549 | const GURL gurl = accept_ch_with_lifetime_url(); |
Tarun Bansal | 293a7b6c | 2018-12-05 17:41:12 | [diff] [blame] | 1550 | |
| 1551 | base::HistogramTester histogram_tester; |
| 1552 | ContentSettingsForOneType host_settings; |
| 1553 | |
| 1554 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1555 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | 293a7b6c | 2018-12-05 17:41:12 | [diff] [blame] | 1556 | &host_settings); |
| 1557 | EXPECT_EQ(0u, host_settings.size()); |
| 1558 | |
| 1559 | // Fetching |gurl| should persist the request for client hints. |
| 1560 | ui_test_utils::NavigateToURL(browser(), gurl); |
| 1561 | |
| 1562 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateEventCount", 1, 1); |
| 1563 | |
| 1564 | content::FetchHistogramsFromChildProcesses(); |
| 1565 | SubprocessMetricsProvider::MergeHistogramDeltasForTesting(); |
| 1566 | |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1567 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateSize", |
| 1568 | expected_client_hints_number, 1); |
Tarun Bansal | 293a7b6c | 2018-12-05 17:41:12 | [diff] [blame] | 1569 | // accept_ch_with_lifetime_url() sets client hints persist duration to 3600 |
| 1570 | // seconds. |
| 1571 | histogram_tester.ExpectUniqueSample("ClientHints.PersistDuration", |
| 1572 | 3600 * 1000, 1); |
| 1573 | base::RunLoop().RunUntilIdle(); |
| 1574 | |
| 1575 | // Clients hints preferences for one origin should be persisted. |
| 1576 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1577 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | 293a7b6c | 2018-12-05 17:41:12 | [diff] [blame] | 1578 | &host_settings); |
| 1579 | EXPECT_EQ(1u, host_settings.size()); |
| 1580 | |
| 1581 | SetClientHintExpectationsOnMainFrame(true); |
| 1582 | SetClientHintExpectationsOnSubresources(true); |
| 1583 | ui_test_utils::NavigateToURL(browser(), redirect_url()); |
| 1584 | |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1585 | // The user agent hint is attached to all three requests: |
| 1586 | EXPECT_EQ(3u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1587 | EXPECT_EQ(3u, count_ua_mobile_client_hints_headers_seen()); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1588 | |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1589 | // Expected number of hints attached to the image request, and the same number |
| 1590 | // to the main frame request. |
| 1591 | EXPECT_EQ(expected_client_hints_number * 2, |
| 1592 | count_client_hints_headers_seen()); |
Tarun Bansal | 293a7b6c | 2018-12-05 17:41:12 | [diff] [blame] | 1593 | } |
| 1594 | |
Tarun Bansal | a0c1fc3 | 2018-10-03 16:14:52 | [diff] [blame] | 1595 | // Ensure that even when cookies are blocked, client hint preferences are |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1596 | // persisted. |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1597 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, |
Tarun Bansal | a0c1fc3 | 2018-10-03 16:14:52 | [diff] [blame] | 1598 | ClientHintsLifetimePersistedCookiesBlocked) { |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1599 | const GURL gurl_with = accept_ch_with_lifetime_url(); |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1600 | |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1601 | scoped_refptr<content_settings::CookieSettings> cookie_settings_ = |
| 1602 | CookieSettingsFactory::GetForProfile(browser()->profile()); |
| 1603 | base::HistogramTester histogram_tester; |
| 1604 | ContentSettingsForOneType host_settings; |
| 1605 | |
| 1606 | // Block cookies. |
| 1607 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Tarun Bansal | a0c1fc3 | 2018-10-03 16:14:52 | [diff] [blame] | 1608 | ->SetContentSettingDefaultScope(gurl_with, GURL(), |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1609 | ContentSettingsType::COOKIES, |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1610 | std::string(), CONTENT_SETTING_BLOCK); |
| 1611 | |
Tarun Bansal | a0c1fc3 | 2018-10-03 16:14:52 | [diff] [blame] | 1612 | // Fetching |gurl_with| should persist the request for client hints. |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1613 | ui_test_utils::NavigateToURL(browser(), gurl_with); |
Tarun Bansal | a0c1fc3 | 2018-10-03 16:14:52 | [diff] [blame] | 1614 | histogram_tester.ExpectTotalCount("ClientHints.UpdateEventCount", 1); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1615 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1616 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1617 | &host_settings); |
| 1618 | EXPECT_EQ(1u, host_settings.size()); |
Tarun Bansal | a0c1fc3 | 2018-10-03 16:14:52 | [diff] [blame] | 1619 | VerifyContentSettingsNotNotified(); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1620 | } |
| 1621 | |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1622 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, |
Tarun Bansal | a0c1fc3 | 2018-10-03 16:14:52 | [diff] [blame] | 1623 | ClientHintsLifetimeAttachedCookiesBlocked) { |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1624 | const GURL gurl_with = accept_ch_with_lifetime_url(); |
| 1625 | const GURL gurl_without = accept_ch_without_lifetime_url(); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1626 | base::HistogramTester histogram_tester; |
| 1627 | ContentSettingsForOneType host_settings; |
| 1628 | |
| 1629 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1630 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1631 | &host_settings); |
| 1632 | EXPECT_EQ(0u, host_settings.size()); |
| 1633 | |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1634 | // Fetching |gurl_with| should persist the request for client hints. |
| 1635 | ui_test_utils::NavigateToURL(browser(), gurl_with); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1636 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateEventCount", 1, 1); |
| 1637 | content::FetchHistogramsFromChildProcesses(); |
| 1638 | SubprocessMetricsProvider::MergeHistogramDeltasForTesting(); |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1639 | base::RunLoop().RunUntilIdle(); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1640 | |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1641 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateSize", |
| 1642 | expected_client_hints_number, 1); |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1643 | // |gurl_with| tries to set client hints persist duration to 3600 seconds. |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1644 | histogram_tester.ExpectUniqueSample("ClientHints.PersistDuration", |
| 1645 | 3600 * 1000, 1); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1646 | |
| 1647 | // Clients hints preferences for one origin should be persisted. |
| 1648 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1649 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1650 | &host_settings); |
| 1651 | EXPECT_EQ(1u, host_settings.size()); |
| 1652 | |
Tarun Bansal | a0c1fc3 | 2018-10-03 16:14:52 | [diff] [blame] | 1653 | // Block the cookies: Client hints should be attached. |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1654 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1655 | ->SetContentSettingDefaultScope(gurl_without, GURL(), |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1656 | ContentSettingsType::COOKIES, |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1657 | std::string(), CONTENT_SETTING_BLOCK); |
| 1658 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1659 | SetClientHintExpectationsOnMainFrame(true); |
| 1660 | SetClientHintExpectationsOnSubresources(true); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1661 | ui_test_utils::NavigateToURL(browser(), |
| 1662 | without_accept_ch_without_lifetime_url()); |
Tarun Bansal | 79df868e | 2018-03-20 23:01:36 | [diff] [blame] | 1663 | |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1664 | // The user agent hint is attached to all three requests: |
| 1665 | EXPECT_EQ(3u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1666 | EXPECT_EQ(3u, count_ua_mobile_client_hints_headers_seen()); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1667 | |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1668 | // Expected number of hints attached to the image request, and the same number |
| 1669 | // to the main frame request. |
| 1670 | EXPECT_EQ(expected_client_hints_number * 2, |
| 1671 | count_client_hints_headers_seen()); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1672 | |
| 1673 | // Clear settings. |
| 1674 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1675 | ->ClearSettingsForOneType(ContentSettingsType::COOKIES); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | // Ensure that when the JavaScript is blocked, client hint preferences are not |
| 1679 | // persisted. |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1680 | IN_PROC_BROWSER_TEST_P(ClientHintsBrowserTest, |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1681 | ClientHintsLifetimeNotPersistedJavaScriptBlocked) { |
| 1682 | ContentSettingsForOneType host_settings; |
| 1683 | |
| 1684 | // Start a navigation. This navigation makes it possible to block JavaScript |
| 1685 | // later. |
| 1686 | ui_test_utils::NavigateToURL(browser(), |
| 1687 | without_accept_ch_without_lifetime_url()); |
| 1688 | |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1689 | const GURL gurl = |
| 1690 | GetParam() ? http_equiv_accept_ch_without_lifetime_with_iframe_url() |
| 1691 | : accept_ch_with_lifetime_url(); |
| 1692 | |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1693 | // Block the JavaScript: Client hint preferences should not be persisted. |
| 1694 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1695 | ->SetContentSettingDefaultScope(gurl, GURL(), |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1696 | ContentSettingsType::JAVASCRIPT, |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1697 | std::string(), CONTENT_SETTING_BLOCK); |
| 1698 | ui_test_utils::NavigateToURL(browser(), accept_ch_with_lifetime_url()); |
| 1699 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1700 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1701 | &host_settings); |
| 1702 | EXPECT_EQ(0u, host_settings.size()); |
Tarun Bansal | c211d8b | 2018-03-19 19:21:58 | [diff] [blame] | 1703 | VerifyContentSettingsNotNotified(); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1704 | |
| 1705 | // Allow the JavaScript: Client hint preferences should be persisted. |
| 1706 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1707 | ->SetContentSettingDefaultScope(gurl, GURL(), |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1708 | ContentSettingsType::JAVASCRIPT, |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1709 | std::string(), CONTENT_SETTING_ALLOW); |
| 1710 | ui_test_utils::NavigateToURL(browser(), accept_ch_with_lifetime_url()); |
| 1711 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1712 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1713 | &host_settings); |
| 1714 | EXPECT_EQ(1u, host_settings.size()); |
Tarun Bansal | 59379011 | 2018-03-20 04:53:34 | [diff] [blame] | 1715 | |
| 1716 | // Clear settings. |
| 1717 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1718 | ->ClearSettingsForOneType(ContentSettingsType::JAVASCRIPT); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | // Ensure that when the JavaScript is blocked, persisted client hints are not |
| 1722 | // attached to the request headers. |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1723 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1724 | ClientHintsLifetimeNotAttachedJavaScriptBlocked) { |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1725 | const GURL gurl = accept_ch_with_lifetime_url(); |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1726 | |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1727 | base::HistogramTester histogram_tester; |
| 1728 | ContentSettingsForOneType host_settings; |
| 1729 | |
| 1730 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1731 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1732 | &host_settings); |
| 1733 | EXPECT_EQ(0u, host_settings.size()); |
| 1734 | |
| 1735 | // Fetching accept_ch_with_lifetime_url() should persist the request for |
| 1736 | // client hints. |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1737 | ui_test_utils::NavigateToURL(browser(), gurl); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1738 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateEventCount", 1, 1); |
| 1739 | content::FetchHistogramsFromChildProcesses(); |
| 1740 | SubprocessMetricsProvider::MergeHistogramDeltasForTesting(); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1741 | EXPECT_EQ(1u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1742 | EXPECT_EQ(1u, count_ua_mobile_client_hints_headers_seen()); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1743 | |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1744 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateSize", |
| 1745 | expected_client_hints_number, 1); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1746 | // accept_ch_with_lifetime_url() tries to set client hints persist duration to |
| 1747 | // 3600 seconds. |
| 1748 | histogram_tester.ExpectUniqueSample("ClientHints.PersistDuration", |
| 1749 | 3600 * 1000, 1); |
| 1750 | base::RunLoop().RunUntilIdle(); |
| 1751 | |
| 1752 | // Clients hints preferences for one origin should be persisted. |
| 1753 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1754 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1755 | &host_settings); |
| 1756 | EXPECT_EQ(1u, host_settings.size()); |
| 1757 | |
Changwan Ryu | 434c3a3 | 2019-07-30 23:42:58 | [diff] [blame] | 1758 | // Block JavaScript via WebPreferences: Client hints should not be attached. |
| 1759 | SetJsEnabledForActiveView(false); |
| 1760 | |
| 1761 | SetClientHintExpectationsOnMainFrame(false); |
| 1762 | SetClientHintExpectationsOnSubresources(false); |
| 1763 | ui_test_utils::NavigateToURL(browser(), |
| 1764 | without_accept_ch_without_lifetime_url()); |
| 1765 | |
| 1766 | EXPECT_EQ(0u, count_client_hints_headers_seen()); |
| 1767 | VerifyContentSettingsNotNotified(); |
| 1768 | EXPECT_EQ(1u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1769 | EXPECT_EQ(1u, count_ua_mobile_client_hints_headers_seen()); |
Changwan Ryu | 434c3a3 | 2019-07-30 23:42:58 | [diff] [blame] | 1770 | |
| 1771 | SetJsEnabledForActiveView(true); |
| 1772 | |
| 1773 | // Block JavaScript via ContentSetting: Client hints should not be attached. |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1774 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 1775 | ->SetContentSettingDefaultScope(without_accept_ch_without_lifetime_url(), |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1776 | GURL(), ContentSettingsType::JAVASCRIPT, |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1777 | std::string(), CONTENT_SETTING_BLOCK); |
| 1778 | ui_test_utils::NavigateToURL(browser(), |
| 1779 | without_accept_ch_without_lifetime_url()); |
| 1780 | EXPECT_EQ(0u, count_client_hints_headers_seen()); |
Tarun Bansal | c211d8b | 2018-03-19 19:21:58 | [diff] [blame] | 1781 | VerifyContentSettingsNotNotified(); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1782 | EXPECT_EQ(1u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1783 | EXPECT_EQ(1u, count_ua_mobile_client_hints_headers_seen()); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1784 | |
Changwan Ryu | 434c3a3 | 2019-07-30 23:42:58 | [diff] [blame] | 1785 | // Allow JavaScript: Client hints should now be attached. |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1786 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 1787 | ->SetContentSettingDefaultScope(without_accept_ch_without_lifetime_url(), |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1788 | GURL(), ContentSettingsType::JAVASCRIPT, |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1789 | std::string(), CONTENT_SETTING_ALLOW); |
| 1790 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1791 | SetClientHintExpectationsOnMainFrame(true); |
| 1792 | SetClientHintExpectationsOnSubresources(true); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1793 | ui_test_utils::NavigateToURL(browser(), |
| 1794 | without_accept_ch_without_lifetime_url()); |
Tarun Bansal | 79df868e | 2018-03-20 23:01:36 | [diff] [blame] | 1795 | |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1796 | // The user agent hint is attached to all three requests: |
| 1797 | EXPECT_EQ(3u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1798 | EXPECT_EQ(3u, count_ua_mobile_client_hints_headers_seen()); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1799 | |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1800 | // Expected number of hints attached to the image request, and the same number |
| 1801 | // to the main frame request. |
| 1802 | EXPECT_EQ(expected_client_hints_number * 2, |
| 1803 | count_client_hints_headers_seen()); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1804 | |
| 1805 | // Clear settings. |
| 1806 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1807 | ->ClearSettingsForOneType(ContentSettingsType::JAVASCRIPT); |
Tarun Bansal | a61f0f6 | 2017-10-24 23:53:05 | [diff] [blame] | 1808 | } |
| 1809 | |
Tarun Bansal | 73502f9 | 2019-04-16 21:21:19 | [diff] [blame] | 1810 | // Test that if the content settings are malformed, then the browser does not |
| 1811 | // crash. |
| 1812 | IN_PROC_BROWSER_TEST_P(ClientHintsBrowserTest, |
| 1813 | ClientHintsMalformedContentSettings) { |
| 1814 | ContentSettingsForOneType client_hints_settings; |
| 1815 | HostContentSettingsMap* host_content_settings_map = |
| 1816 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()); |
| 1817 | |
| 1818 | // Add setting for the host. |
| 1819 | std::unique_ptr<base::ListValue> expiration_times_list = |
| 1820 | std::make_unique<base::ListValue>(); |
| 1821 | expiration_times_list->AppendInteger(42 /* client hint value */); |
| 1822 | auto expiration_times_dictionary = std::make_unique<base::DictionaryValue>(); |
| 1823 | expiration_times_dictionary->SetList("client_hints", |
| 1824 | std::move(expiration_times_list)); |
Aaron Tagliaboschi | 3c96a68 | 2019-10-29 18:10:28 | [diff] [blame] | 1825 | expiration_times_dictionary->SetDouble( |
| 1826 | "expiration_time", |
| 1827 | (base::Time::Now() + base::TimeDelta::FromDays(1)).ToDoubleT()); |
Tarun Bansal | 73502f9 | 2019-04-16 21:21:19 | [diff] [blame] | 1828 | host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 1829 | without_accept_ch_without_lifetime_url(), GURL(), |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1830 | ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | 73502f9 | 2019-04-16 21:21:19 | [diff] [blame] | 1831 | std::make_unique<base::Value>(expiration_times_dictionary->Clone())); |
| 1832 | |
| 1833 | // Reading the settings should now return one setting. |
| 1834 | host_content_settings_map->GetSettingsForOneType( |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1835 | ContentSettingsType::CLIENT_HINTS, std::string(), &client_hints_settings); |
Tarun Bansal | 73502f9 | 2019-04-16 21:21:19 | [diff] [blame] | 1836 | EXPECT_EQ(1U, client_hints_settings.size()); |
| 1837 | |
| 1838 | SetClientHintExpectationsOnMainFrame(false); |
| 1839 | SetClientHintExpectationsOnSubresources(false); |
| 1840 | ui_test_utils::NavigateToURL(browser(), |
| 1841 | without_accept_ch_without_lifetime_url()); |
| 1842 | } |
| 1843 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1844 | // Ensure that when the JavaScript is blocked, client hints requested using |
Tarun Bansal | 3f343d7c | 2018-03-02 18:48:00 | [diff] [blame] | 1845 | // Accept-CH are not attached to the request headers for subresources. |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1846 | IN_PROC_BROWSER_TEST_P(ClientHintsBrowserTest, |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1847 | ClientHintsNoLifetimeScriptNotAllowed) { |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1848 | const GURL gurl = GetParam() ? http_equiv_accept_ch_with_lifetime() |
| 1849 | : accept_ch_with_lifetime_url(); |
| 1850 | |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1851 | base::HistogramTester histogram_tester; |
| 1852 | ContentSettingsForOneType host_settings; |
| 1853 | |
| 1854 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1855 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1856 | &host_settings); |
| 1857 | EXPECT_EQ(0u, host_settings.size()); |
| 1858 | |
Tarun Bansal | 3f343d7c | 2018-03-02 18:48:00 | [diff] [blame] | 1859 | // Block the Javascript: Client hints should not be attached. |
| 1860 | SetClientHintExpectationsOnSubresources(false); |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1861 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 1862 | ->SetContentSettingDefaultScope( |
| 1863 | accept_ch_without_lifetime_img_localhost(), GURL(), |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1864 | ContentSettingsType::JAVASCRIPT, std::string(), |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1865 | CONTENT_SETTING_BLOCK); |
| 1866 | ui_test_utils::NavigateToURL(browser(), |
| 1867 | accept_ch_without_lifetime_img_localhost()); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1868 | EXPECT_EQ(0u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1869 | EXPECT_EQ(0u, count_ua_mobile_client_hints_headers_seen()); |
Tarun Bansal | 3f343d7c | 2018-03-02 18:48:00 | [diff] [blame] | 1870 | EXPECT_EQ(0u, count_client_hints_headers_seen()); |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1871 | EXPECT_EQ(1u, third_party_request_count_seen()); |
Tarun Bansal | 3f343d7c | 2018-03-02 18:48:00 | [diff] [blame] | 1872 | EXPECT_EQ(0u, third_party_client_hints_count_seen()); |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1873 | |
Tarun Bansal | 3f343d7c | 2018-03-02 18:48:00 | [diff] [blame] | 1874 | // Allow the Javascript: Client hints should now be attached. |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1875 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 1876 | ->SetContentSettingDefaultScope( |
| 1877 | accept_ch_without_lifetime_img_localhost(), GURL(), |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1878 | ContentSettingsType::JAVASCRIPT, std::string(), |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1879 | CONTENT_SETTING_ALLOW); |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1880 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1881 | SetClientHintExpectationsOnSubresources(true); |
| 1882 | ui_test_utils::NavigateToURL(browser(), |
| 1883 | accept_ch_without_lifetime_img_localhost()); |
Tarun Bansal | 3f343d7c | 2018-03-02 18:48:00 | [diff] [blame] | 1884 | |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1885 | EXPECT_EQ(2u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1886 | EXPECT_EQ(2u, count_ua_mobile_client_hints_headers_seen()); |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1887 | EXPECT_EQ(expected_client_hints_number, count_client_hints_headers_seen()); |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1888 | EXPECT_EQ(2u, third_party_request_count_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1889 | EXPECT_EQ(2u, third_party_client_hints_count_seen()); |
Tarun Bansal | c211d8b | 2018-03-19 19:21:58 | [diff] [blame] | 1890 | VerifyContentSettingsNotNotified(); |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1891 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1892 | // Clear settings. |
| 1893 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1894 | ->ClearSettingsForOneType(ContentSettingsType::JAVASCRIPT); |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1895 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1896 | // Block the Javascript again: Client hints should not be attached. |
Tarun Bansal | 3f343d7c | 2018-03-02 18:48:00 | [diff] [blame] | 1897 | SetClientHintExpectationsOnSubresources(false); |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1898 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 1899 | ->SetContentSettingDefaultScope( |
| 1900 | accept_ch_without_lifetime_img_localhost(), GURL(), |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1901 | ContentSettingsType::JAVASCRIPT, std::string(), |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1902 | CONTENT_SETTING_BLOCK); |
| 1903 | ui_test_utils::NavigateToURL(browser(), |
| 1904 | accept_ch_without_lifetime_img_localhost()); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1905 | EXPECT_EQ(2u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1906 | EXPECT_EQ(2u, count_ua_mobile_client_hints_headers_seen()); |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1907 | EXPECT_EQ(expected_client_hints_number, count_client_hints_headers_seen()); |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1908 | EXPECT_EQ(3u, third_party_request_count_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1909 | EXPECT_EQ(2u, third_party_client_hints_count_seen()); |
Tarun Bansal | 59379011 | 2018-03-20 04:53:34 | [diff] [blame] | 1910 | |
| 1911 | // Clear settings. |
| 1912 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1913 | ->ClearSettingsForOneType(ContentSettingsType::JAVASCRIPT); |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1914 | } |
| 1915 | |
Tarun Bansal | a0c1fc3 | 2018-10-03 16:14:52 | [diff] [blame] | 1916 | // Ensure that when the cookies is blocked, client hints are attached to the |
Tarun Bansal | 3f343d7c | 2018-03-02 18:48:00 | [diff] [blame] | 1917 | // request headers. |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1918 | IN_PROC_BROWSER_TEST_P(ClientHintsBrowserTest, |
Tarun Bansal | a0c1fc3 | 2018-10-03 16:14:52 | [diff] [blame] | 1919 | ClientHintsLifetimeCookiesNotAllowed) { |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1920 | const GURL gurl = GetParam() |
| 1921 | ? http_equiv_accept_ch_without_lifetime_img_localhost() |
| 1922 | : accept_ch_without_lifetime_img_localhost(); |
| 1923 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1924 | base::HistogramTester histogram_tester; |
| 1925 | ContentSettingsForOneType host_settings; |
| 1926 | scoped_refptr<content_settings::CookieSettings> cookie_settings_ = |
| 1927 | CookieSettingsFactory::GetForProfile(browser()->profile()); |
| 1928 | |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1929 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1930 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1931 | &host_settings); |
| 1932 | EXPECT_EQ(0u, host_settings.size()); |
| 1933 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1934 | // Block cookies. |
| 1935 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1936 | ->SetContentSettingDefaultScope(gurl, GURL(), |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1937 | ContentSettingsType::COOKIES, |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1938 | std::string(), CONTENT_SETTING_BLOCK); |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1939 | base::RunLoop().RunUntilIdle(); |
| 1940 | |
Tarun Bansal | 229647bd00 | 2018-02-27 17:33:36 | [diff] [blame] | 1941 | SetClientHintExpectationsOnSubresources(true); |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1942 | ui_test_utils::NavigateToURL(browser(), gurl); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1943 | EXPECT_EQ(2u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1944 | EXPECT_EQ(2u, count_ua_mobile_client_hints_headers_seen()); |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1945 | EXPECT_EQ(expected_client_hints_number, count_client_hints_headers_seen()); |
Tarun Bansal | a0c1fc3 | 2018-10-03 16:14:52 | [diff] [blame] | 1946 | EXPECT_EQ(1u, third_party_request_count_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1947 | EXPECT_EQ(2u, third_party_client_hints_count_seen()); |
Tarun Bansal | 59379011 | 2018-03-20 04:53:34 | [diff] [blame] | 1948 | |
| 1949 | // Clear settings. |
| 1950 | HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1951 | ->ClearSettingsForOneType(ContentSettingsType::COOKIES); |
Tarun Bansal | 1965b04 | 2017-09-07 04:59:19 | [diff] [blame] | 1952 | } |
| 1953 | |
Tarun Bansal | 3ce0ca4 | 2018-06-25 22:52:22 | [diff] [blame] | 1954 | // Verify that client hints are sent in the incognito profiles, and server |
| 1955 | // client hint opt-ins are honored within the incognito profile. |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1956 | IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, |
Tarun Bansal | 3ce0ca4 | 2018-06-25 22:52:22 | [diff] [blame] | 1957 | ClientHintsLifetimeFollowedByNoClientHintIncognito) { |
Maks Orlovich | f0a2eed | 2020-05-02 20:08:21 | [diff] [blame] | 1958 | const GURL gurl = accept_ch_with_lifetime_url(); |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1959 | |
Tarun Bansal | 3ce0ca4 | 2018-06-25 22:52:22 | [diff] [blame] | 1960 | base::HistogramTester histogram_tester; |
| 1961 | Browser* incognito = CreateIncognitoBrowser(); |
| 1962 | ContentSettingsForOneType host_settings; |
| 1963 | |
| 1964 | HostContentSettingsMapFactory::GetForProfile(incognito->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1965 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | 3ce0ca4 | 2018-06-25 22:52:22 | [diff] [blame] | 1966 | &host_settings); |
| 1967 | EXPECT_EQ(0u, host_settings.size()); |
| 1968 | |
Tarun Bansal | 9a7051f | 2018-07-10 18:30:05 | [diff] [blame] | 1969 | // Fetching |gurl| should persist the request for client hints. |
| 1970 | ui_test_utils::NavigateToURL(incognito, gurl); |
Tarun Bansal | 3ce0ca4 | 2018-06-25 22:52:22 | [diff] [blame] | 1971 | |
| 1972 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateEventCount", 1, 1); |
| 1973 | |
| 1974 | content::FetchHistogramsFromChildProcesses(); |
| 1975 | SubprocessMetricsProvider::MergeHistogramDeltasForTesting(); |
| 1976 | |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 1977 | histogram_tester.ExpectUniqueSample("ClientHints.UpdateSize", |
| 1978 | expected_client_hints_number, 1); |
Tarun Bansal | 3ce0ca4 | 2018-06-25 22:52:22 | [diff] [blame] | 1979 | // accept_ch_with_lifetime_url() sets client hints persist duration to 3600 |
| 1980 | // seconds. |
| 1981 | histogram_tester.ExpectUniqueSample("ClientHints.PersistDuration", |
| 1982 | 3600 * 1000, 1); |
| 1983 | base::RunLoop().RunUntilIdle(); |
| 1984 | |
| 1985 | // Clients hints preferences for one origin should be persisted. |
| 1986 | HostContentSettingsMapFactory::GetForProfile(incognito->profile()) |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 1987 | ->GetSettingsForOneType(ContentSettingsType::CLIENT_HINTS, std::string(), |
Tarun Bansal | 3ce0ca4 | 2018-06-25 22:52:22 | [diff] [blame] | 1988 | &host_settings); |
| 1989 | EXPECT_EQ(1u, host_settings.size()); |
| 1990 | |
| 1991 | SetClientHintExpectationsOnMainFrame(true); |
| 1992 | SetClientHintExpectationsOnSubresources(true); |
| 1993 | ui_test_utils::NavigateToURL(incognito, |
| 1994 | without_accept_ch_without_lifetime_url()); |
| 1995 | |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1996 | // The user agent hint is attached to all three requests: |
| 1997 | EXPECT_EQ(3u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 1998 | EXPECT_EQ(3u, count_ua_mobile_client_hints_headers_seen()); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 1999 | |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 2000 | // Expected number of hints attached to the image request, and the same number |
| 2001 | // to the main frame request. |
| 2002 | EXPECT_EQ(expected_client_hints_number * 2, |
| 2003 | count_client_hints_headers_seen()); |
Tarun Bansal | 3ce0ca4 | 2018-06-25 22:52:22 | [diff] [blame] | 2004 | |
| 2005 | // Navigate using regular profile. Client hints should not be send. |
| 2006 | SetClientHintExpectationsOnMainFrame(false); |
| 2007 | SetClientHintExpectationsOnSubresources(false); |
| 2008 | ui_test_utils::NavigateToURL(browser(), |
| 2009 | without_accept_ch_without_lifetime_url()); |
| 2010 | |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 2011 | // The user agent hint is attached to the two new requests. |
| 2012 | EXPECT_EQ(5u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 2013 | EXPECT_EQ(5u, count_ua_mobile_client_hints_headers_seen()); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 2014 | |
| 2015 | // No additional hints are sent. |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 2016 | EXPECT_EQ(expected_client_hints_number * 2, |
| 2017 | count_client_hints_headers_seen()); |
Tarun Bansal | 3ce0ca4 | 2018-06-25 22:52:22 | [diff] [blame] | 2018 | } |
Tarun Bansal | bef6d65 | 2018-10-02 18:41:01 | [diff] [blame] | 2019 | |
| 2020 | class ClientHintsWebHoldbackBrowserTest : public ClientHintsBrowserTest { |
| 2021 | public: |
| 2022 | ClientHintsWebHoldbackBrowserTest() : ClientHintsBrowserTest() { |
| 2023 | ConfigureHoldbackExperiment(); |
| 2024 | } |
| 2025 | |
| 2026 | net::EffectiveConnectionType web_effective_connection_type_override() const { |
| 2027 | return web_effective_connection_type_override_; |
| 2028 | } |
| 2029 | |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 2030 | std::unique_ptr<base::FeatureList> EnabledFeatures() override { |
Tarun Bansal | bef6d65 | 2018-10-02 18:41:01 | [diff] [blame] | 2031 | base::FieldTrialParamAssociator::GetInstance()->ClearAllParamsForTesting(); |
| 2032 | const std::string kTrialName = "TrialFoo"; |
| 2033 | const std::string kGroupName = "GroupFoo"; // Value not used |
| 2034 | |
| 2035 | scoped_refptr<base::FieldTrial> trial = |
| 2036 | base::FieldTrialList::CreateFieldTrial(kTrialName, kGroupName); |
| 2037 | |
| 2038 | std::map<std::string, std::string> params; |
| 2039 | |
| 2040 | params["web_effective_connection_type_override"] = |
| 2041 | net::GetNameForEffectiveConnectionType( |
| 2042 | web_effective_connection_type_override_); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 2043 | EXPECT_TRUE( |
Tarun Bansal | bef6d65 | 2018-10-02 18:41:01 | [diff] [blame] | 2044 | base::FieldTrialParamAssociator::GetInstance() |
| 2045 | ->AssociateFieldTrialParams(kTrialName, kGroupName, params)); |
| 2046 | |
| 2047 | std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 2048 | feature_list->InitializeFromCommandLine("UserAgentClientHint", ""); |
Tarun Bansal | bef6d65 | 2018-10-02 18:41:01 | [diff] [blame] | 2049 | feature_list->RegisterFieldTrialOverride( |
| 2050 | features::kNetworkQualityEstimatorWebHoldback.name, |
| 2051 | base::FeatureList::OVERRIDE_ENABLE_FEATURE, trial.get()); |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 2052 | return feature_list; |
Tarun Bansal | bef6d65 | 2018-10-02 18:41:01 | [diff] [blame] | 2053 | } |
| 2054 | |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 2055 | private: |
| 2056 | void ConfigureHoldbackExperiment() {} |
| 2057 | |
Tarun Bansal | bef6d65 | 2018-10-02 18:41:01 | [diff] [blame] | 2058 | const net::EffectiveConnectionType web_effective_connection_type_override_ = |
| 2059 | net::EFFECTIVE_CONNECTION_TYPE_3G; |
Tarun Bansal | bef6d65 | 2018-10-02 18:41:01 | [diff] [blame] | 2060 | }; |
| 2061 | |
| 2062 | // Make sure that when NetInfo holdback experiment is enabled, the NetInfo APIs |
| 2063 | // and client hints return the overridden values. Verify that the client hints |
| 2064 | // are overridden on both main frame and subresource requests. |
| 2065 | IN_PROC_BROWSER_TEST_F(ClientHintsWebHoldbackBrowserTest, |
| 2066 | EffectiveConnectionTypeChangeNotified) { |
| 2067 | SetExpectedEffectiveConnectionType(web_effective_connection_type_override()); |
| 2068 | |
| 2069 | SetClientHintExpectationsOnMainFrame(false); |
| 2070 | SetClientHintExpectationsOnSubresources(true); |
| 2071 | |
| 2072 | base::RunLoop().RunUntilIdle(); |
| 2073 | |
| 2074 | EXPECT_TRUE(embedded_test_server()->Start()); |
| 2075 | ui_test_utils::NavigateToURL(browser(), accept_ch_with_lifetime_url()); |
| 2076 | EXPECT_EQ(0u, count_client_hints_headers_seen()); |
| 2077 | EXPECT_EQ(0u, third_party_request_count_seen()); |
| 2078 | EXPECT_EQ(0u, third_party_client_hints_count_seen()); |
| 2079 | |
| 2080 | SetClientHintExpectationsOnMainFrame(true); |
| 2081 | SetClientHintExpectationsOnSubresources(true); |
| 2082 | ui_test_utils::NavigateToURL( |
| 2083 | browser(), accept_ch_without_lifetime_with_subresource_url()); |
| 2084 | base::RunLoop().RunUntilIdle(); |
| 2085 | content::FetchHistogramsFromChildProcesses(); |
| 2086 | SubprocessMetricsProvider::MergeHistogramDeltasForTesting(); |
| 2087 | |
Mike West | 2fddeeb7 | 2019-02-15 11:29:48 | [diff] [blame] | 2088 | EXPECT_EQ(3u, count_user_agent_hint_headers_seen()); |
Maks Orlovich | 5dcc99c | 2020-02-13 19:07:46 | [diff] [blame] | 2089 | EXPECT_EQ(3u, count_ua_mobile_client_hints_headers_seen()); |
Yoav Weiss | d33bacb | 2020-03-12 06:42:21 | [diff] [blame] | 2090 | EXPECT_EQ(expected_client_hints_number * 2, |
| 2091 | count_client_hints_headers_seen()); |
Tarun Bansal | bef6d65 | 2018-10-02 18:41:01 | [diff] [blame] | 2092 | EXPECT_EQ(0u, third_party_request_count_seen()); |
| 2093 | EXPECT_EQ(0u, third_party_client_hints_count_seen()); |
| 2094 | } |