@@ -5802,6 +5802,131 @@ IN_PROC_BROWSER_TEST_F(ThirdPartyPartitionedCookiesOriginTrialBrowserTest,
5802
5802
EXPECT_FALSE (cookies[0 ].IsPartitioned ());
5803
5803
}
5804
5804
5805
+ class EmbeddedPartitionedCookiesOriginTrialBrowserTest
5806
+ : public PartitionedCookiesOriginTrialBrowserTest {
5807
+ public:
5808
+ EmbeddedPartitionedCookiesOriginTrialBrowserTest () = default ;
5809
+
5810
+ void SetUpOnMainThread () override {
5811
+ // We use a URLLoaderInterceptor, rather than the EmbeddedTestServer, since
5812
+ // the origin trial token in the response is associated with a fixed
5813
+ // origin, whereas EmbeddedTestServer serves content on a random port.
5814
+ url_loader_interceptor_ =
5815
+ std::make_unique<URLLoaderInterceptor>(base::BindRepeating (
5816
+ &EmbeddedPartitionedCookiesOriginTrialBrowserTest::InterceptRequest,
5817
+ base::Unretained (this )));
5818
+ InProcessBrowserTest::SetUpOnMainThread ();
5819
+ }
5820
+
5821
+ // URLLoaderInterceptor callback
5822
+ bool InterceptRequest (URLLoaderInterceptor::RequestParams* params) {
5823
+ if (expected_request_urls_.find (params->url_request .url ) ==
5824
+ expected_request_urls_.end ())
5825
+ return false ;
5826
+
5827
+ if (params->url_request .url .path () ==
5828
+ base::StrCat ({" /partitioned_cookies_embedder.html" })) {
5829
+ std::string headers = " HTTP/1.1 200 OK\n Content-Type: text/html\n " ;
5830
+ std::string body = " <html><head>" ;
5831
+ base::StrAppend (&body, {" </head><body>" });
5832
+ base::StrAppend (&body, {BuildIframeHTML ()});
5833
+ base::StrAppend (&body, {" </body></html>" });
5834
+ URLLoaderInterceptor::WriteResponse (headers, body, params->client .get ());
5835
+ return true ;
5836
+ }
5837
+
5838
+ if (params->url_request .url .path () ==
5839
+ base::StrCat ({" /partitioned_cookies_embeddee.html" })) {
5840
+ std::string headers = " HTTP/1.1 200 OK\n Content-Type: text/html\n " ;
5841
+ base::StrAppend (&headers, {BuildOriginTrialHeader ()});
5842
+ URLLoaderInterceptor::WriteResponse (
5843
+ " chrome/test/data/client_hints/partitioned_cookies_embeddee.html" ,
5844
+ params->client .get (), &headers, absl::nullopt,
5845
+ params->url_request .url );
5846
+ return true ;
5847
+ }
5848
+
5849
+ NOTREACHED ();
5850
+ return false ;
5851
+ }
5852
+
5853
+ GURL embedder_url () const {
5854
+ return GURL (base::StrCat (
5855
+ {kFirstPartyOriginUrl , " /partitioned_cookies_embedder.html" }));
5856
+ }
5857
+
5858
+ // In this test, the OT participant is the embedded site.
5859
+ GURL origin_trial_participant_url () const {
5860
+ return GURL (
5861
+ base::StrCat ({kCookieOriginUrl , " /partitioned_cookies_embeddee.html" }));
5862
+ }
5863
+
5864
+ // The URL that was used to register the Origin Trial token as the first
5865
+ // party. Requests to this origin should be handled by URLLoader interceptor.
5866
+ static constexpr const char kFirstPartyOriginUrl [] =
5867
+ " https://my-site.com:44444" ;
5868
+
5869
+ // The URL of the site receiving cookies.
5870
+ // Requests to this origin should be handled by the test server.
5871
+ static constexpr char kCookieOriginUrl [] = " https://127.0.0.1:44444" ;
5872
+
5873
+ std::string BuildOriginTrialHeader () const override {
5874
+ std::string headers;
5875
+
5876
+ static constexpr const char kOriginTrialToken [] =
5877
+ " A1mBOyrOKGAaaoT8mjM1qSNrOSrdDUa9WyqicVLlDGW3feIBSdWqSiHDAXUeKkGKaVqUiC"
5878
+ " X8avwCM0gpG5LtxgAAAAByeyJvcmlnaW4iOiAiaHR0cHM6Ly8xMjcuMC4wLjE6NDQ0NDQi"
5879
+ " LCAiZmVhdHVyZSI6ICJQYXJ0aXRpb25lZENvb2tpZXMiLCAiZXhwaXJ5IjogMjAwMDAwMD"
5880
+ " AwMCwgImlzVGhpcmRQYXJ0eSI6IHRydWV9" ;
5881
+
5882
+ if (test_options_.has_accept_ch_header ) {
5883
+ base::StrAppend (&headers,
5884
+ {" Accept-CH: " , " sec-ch-partitioned-cookies" , " \n " });
5885
+ }
5886
+ if (test_options_.has_critical_ch_header ) {
5887
+ base::StrAppend (&headers,
5888
+ {" Critical-CH: " , " sec-ch-partitioned-cookies" , " \n " });
5889
+ }
5890
+ if (test_options_.has_ot_token ) {
5891
+ base::StrAppend (
5892
+ &headers,
5893
+ {" Origin-Trial: " ,
5894
+ test_options_.valid_ot_token ? kOriginTrialToken : " invalid" , " \n " });
5895
+ }
5896
+
5897
+ return headers;
5898
+ }
5899
+
5900
+ private:
5901
+ std::string BuildIframeHTML () {
5902
+ std::string html = " <iframe src=\" " ;
5903
+ base::StrAppend (&html,
5904
+ {kCookieOriginUrl , " /partitioned_cookies_embeddee.html" ,
5905
+ " \" ></iframe>" });
5906
+ return html;
5907
+ }
5908
+ };
5909
+
5910
+ IN_PROC_BROWSER_TEST_F (EmbeddedPartitionedCookiesOriginTrialBrowserTest,
5911
+ ValidTokenAndHeaderPresent) {
5912
+ SetTestOptions (
5913
+ {/* has_ot_token=*/ true , /* valid_ot_token=*/ true ,
5914
+ /* has_accept_ch_header=*/ true , /* has_critical_ch_header=*/ false },
5915
+ {embedder_url (), origin_trial_participant_url ()});
5916
+
5917
+ NavigateTwiceAndCheckClientHint (embedder_url (), true , true );
5918
+ }
5919
+
5920
+ IN_PROC_BROWSER_TEST_F (EmbeddedPartitionedCookiesOriginTrialBrowserTest,
5921
+ InvalidToken) {
5922
+ SetTestOptions (
5923
+ {/* has_ot_token=*/ false , /* valid_ot_token=*/ true ,
5924
+ /* has_accept_ch_header=*/ true , /* has_critical_ch_header=*/ false },
5925
+ {embedder_url (), origin_trial_participant_url ()});
5926
+
5927
+ NavigateTwiceAndCheckClientHint (embedder_url (), false , false );
5928
+ }
5929
+
5805
5930
class PartitionedCookiesBypassOriginTrialBrowserTest
5806
5931
: public PartitionedCookiesOriginTrialBrowserTest {
5807
5932
public:
0 commit comments