@@ -395,6 +395,20 @@ class IpfsServiceBrowserTest : public InProcessBrowserTest {
395
395
return http_response;
396
396
}
397
397
398
+ std::unique_ptr<net::test_server::HttpResponse> HandlePublicGatewayRequest (
399
+ const net::test_server::HttpRequest& request) {
400
+ auto http_response =
401
+ std::make_unique<net::test_server::BasicHttpResponse>();
402
+ http_response->set_content_type (" text/html" );
403
+
404
+ // IPFS gateways set this
405
+ http_response->AddCustomHeader (" access-control-allow-origin" , " *" );
406
+ http_response->AddCustomHeader (" x-ipfs-path" , " /ipfs/Qmm" );
407
+ http_response->set_code (net::HTTP_OK);
408
+
409
+ return http_response;
410
+ }
411
+
398
412
std::unique_ptr<net::test_server::HttpResponse> HandleEmbeddedSrvrRequest (
399
413
const net::test_server::HttpRequest& request) {
400
414
auto http_response =
@@ -1053,57 +1067,175 @@ IN_PROC_BROWSER_TEST_F(IpfsServiceBrowserTest, CannotLoadIPFSImageFromHTTP) {
1053
1067
EXPECT_EQ (base::Value (true ), loaded.value );
1054
1068
}
1055
1069
1056
- IN_PROC_BROWSER_TEST_F (IpfsServiceBrowserTest, TopLevelAutoRedirectsOn) {
1070
+ IN_PROC_BROWSER_TEST_F (
1071
+ IpfsServiceBrowserTest,
1072
+ TopLevelAutoRedirectsOn_Gateway_RedirectFromGatewayLikeUrl_IpfsSubDomain) {
1057
1073
ResetTestServer (
1058
- base::BindRepeating (&IpfsServiceBrowserTest::HandleEmbeddedSrvrRequest ,
1074
+ base::BindRepeating (&IpfsServiceBrowserTest::HandlePublicGatewayRequest ,
1059
1075
base::Unretained (this )));
1060
1076
browser ()->profile ()->GetPrefs ()->SetBoolean (kIPFSAutoRedirectGateway , true );
1077
+ browser ()->profile ()->GetPrefs ()->SetInteger (
1078
+ kIPFSResolveMethod ,
1079
+ static_cast <int >(ipfs::IPFSResolveMethodTypes::IPFS_GATEWAY));
1061
1080
GURL gateway = GetURL (" b.com" , " /" );
1062
1081
SetIPFSDefaultGatewayForTest (gateway);
1063
- auto tab_url = GetURL (" a.com" , " /simple.html" );
1082
+
1083
+ auto tab_url = GetURL (
1084
+ " bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq.ipfs.a.com" ,
1085
+ " /simple.html?a=b" );
1086
+
1064
1087
ASSERT_TRUE (ui_test_utils::NavigateToURL (browser (), tab_url));
1065
1088
content::WebContents* contents =
1066
1089
browser ()->tab_strip_model ()->GetActiveWebContents ();
1067
- EXPECT_EQ (contents->GetURL ().host (), tab_url.host ());
1090
+ EXPECT_EQ (
1091
+ contents->GetURL (),
1092
+ GetURL (
1093
+ " b.com" ,
1094
+ " /ipfs/bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/"
1095
+ " simple.html?a=b" ));
1096
+ }
1068
1097
1098
+ IN_PROC_BROWSER_TEST_F (
1099
+ IpfsServiceBrowserTest,
1100
+ TopLevelAutoRedirectsOn_Gateway_RedirectFromGatewayLikeUrl_IpfsPath) {
1101
+ ResetTestServer (
1102
+ base::BindRepeating (&IpfsServiceBrowserTest::HandlePublicGatewayRequest,
1103
+ base::Unretained (this )));
1104
+ browser ()->profile ()->GetPrefs ()->SetBoolean (kIPFSAutoRedirectGateway , true );
1069
1105
browser ()->profile ()->GetPrefs ()->SetInteger (
1070
1106
kIPFSResolveMethod ,
1071
1107
static_cast <int >(ipfs::IPFSResolveMethodTypes::IPFS_GATEWAY));
1072
- tab_url = GURL (" ipfs://Qmc2JTQo4iXf24g98otZmGFQq176eQ2Cdbb88qA5ToMEvC/2" );
1108
+ GURL gateway = GetURL (" b.com" , " /" );
1109
+ SetIPFSDefaultGatewayForTest (gateway);
1110
+
1111
+ auto tab_url = GetURL (
1112
+ " a.com" ,
1113
+ " /ipfs/bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/"
1114
+ " simple.html?a=b" );
1115
+
1073
1116
ASSERT_TRUE (ui_test_utils::NavigateToURL (browser (), tab_url));
1074
- auto domain = GetDomainAndRegistry (
1117
+ content::WebContents* contents =
1118
+ browser ()->tab_strip_model ()->GetActiveWebContents ();
1119
+ EXPECT_EQ (
1075
1120
contents->GetURL (),
1076
- net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
1121
+ GetURL (
1122
+ " b.com" ,
1123
+ " /ipfs/bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/"
1124
+ " simple.html?a=b" ));
1125
+ }
1077
1126
1078
- EXPECT_EQ (domain, gateway.host ());
1127
+ IN_PROC_BROWSER_TEST_F (
1128
+ IpfsServiceBrowserTest,
1129
+ TopLevelAutoRedirectsOn_ASK_RedirectFromGatewayLikeUrl_IpfsPath) {
1130
+ ResetTestServer (
1131
+ base::BindRepeating (&IpfsServiceBrowserTest::HandlePublicGatewayRequest,
1132
+ base::Unretained (this )));
1133
+ browser ()->profile ()->GetPrefs ()->SetBoolean (kIPFSAutoRedirectGateway , true );
1134
+ browser ()->profile ()->GetPrefs ()->SetInteger (
1135
+ kIPFSResolveMethod ,
1136
+ static_cast <int >(ipfs::IPFSResolveMethodTypes::IPFS_ASK));
1137
+ GURL gateway = GetURL (" b.com" , " /" );
1138
+ SetIPFSDefaultGatewayForTest (gateway);
1139
+
1140
+ auto tab_url = GetURL (
1141
+ " a.com" ,
1142
+ " /ipfs/bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/"
1143
+ " simple.html?a=b" );
1144
+
1145
+ ASSERT_TRUE (ui_test_utils::NavigateToURL (browser (), tab_url));
1146
+ content::WebContents* contents =
1147
+ browser ()->tab_strip_model ()->GetActiveWebContents ();
1148
+ EXPECT_EQ (
1149
+ contents->GetURL (),
1150
+ GURL (" ipfs://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/"
1151
+ " simple.html?a=b" ));
1152
+ }
1153
+
1154
+ IN_PROC_BROWSER_TEST_F (
1155
+ IpfsServiceBrowserTest,
1156
+ TopLevelAutoRedirectsOn_ASK_RedirectFromGatewayLikeUrl_IpfsSubDomain) {
1157
+ ResetTestServer (
1158
+ base::BindRepeating (&IpfsServiceBrowserTest::HandlePublicGatewayRequest,
1159
+ base::Unretained (this )));
1160
+ browser ()->profile ()->GetPrefs ()->SetBoolean (kIPFSAutoRedirectGateway , true );
1161
+ browser ()->profile ()->GetPrefs ()->SetInteger (
1162
+ kIPFSResolveMethod ,
1163
+ static_cast <int >(ipfs::IPFSResolveMethodTypes::IPFS_ASK));
1164
+ GURL gateway = GetURL (" b.com" , " /" );
1165
+ SetIPFSDefaultGatewayForTest (gateway);
1166
+
1167
+ auto tab_url = GetURL (
1168
+ " bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq.ipfs.a.com" ,
1169
+ " /simple.html?a=b" );
1170
+
1171
+ ASSERT_TRUE (ui_test_utils::NavigateToURL (browser (), tab_url));
1172
+ content::WebContents* contents =
1173
+ browser ()->tab_strip_model ()->GetActiveWebContents ();
1174
+ EXPECT_EQ (
1175
+ contents->GetURL (),
1176
+ GURL (" ipfs://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/"
1177
+ " simple.html?a=b" ));
1079
1178
}
1080
1179
1081
1180
IN_PROC_BROWSER_TEST_F (IpfsServiceBrowserTest,
1082
- TopLevelAutoRedirectsOnWithQuery ) {
1181
+ TopLevelAutoRedirectsOn_DoNotTranslateSimpleUrls ) {
1083
1182
ResetTestServer (
1084
- base::BindRepeating (&IpfsServiceBrowserTest::HandleEmbeddedSrvrRequest ,
1183
+ base::BindRepeating (&IpfsServiceBrowserTest::HandlePublicGatewayRequest ,
1085
1184
base::Unretained (this )));
1086
1185
browser ()->profile ()->GetPrefs ()->SetBoolean (kIPFSAutoRedirectGateway , true );
1186
+ browser ()->profile ()->GetPrefs ()->SetInteger (
1187
+ kIPFSResolveMethod ,
1188
+ static_cast <int >(ipfs::IPFSResolveMethodTypes::IPFS_ASK));
1087
1189
GURL gateway = GetURL (" b.com" , " /" );
1088
1190
SetIPFSDefaultGatewayForTest (gateway);
1089
- ASSERT_TRUE (ui_test_utils::NavigateToURL (
1090
- browser (), GetURL (" a.com" , " /simple.html?abc=123xyz&other=qwerty" )));
1191
+
1192
+ auto tab_url = GetURL (" a.com" , " /simple.html?a=b" );
1193
+
1194
+ ASSERT_TRUE (ui_test_utils::NavigateToURL (browser (), tab_url));
1091
1195
content::WebContents* contents =
1092
1196
browser ()->tab_strip_model ()->GetActiveWebContents ();
1093
- EXPECT_EQ (contents->GetURL ().query (), " abc=123xyz&other=qwerty" );
1197
+ EXPECT_EQ (contents->GetURL (), tab_url);
1198
+ }
1199
+
1200
+ IN_PROC_BROWSER_TEST_F (IpfsServiceBrowserTest,
1201
+ TopLevelAutoRedirectsOn_DoNotTranslateIncompleteUrls) {
1202
+ ResetTestServer (
1203
+ base::BindRepeating (&IpfsServiceBrowserTest::HandlePublicGatewayRequest,
1204
+ base::Unretained (this )));
1205
+ browser ()->profile ()->GetPrefs ()->SetBoolean (kIPFSAutoRedirectGateway , true );
1206
+ browser ()->profile ()->GetPrefs ()->SetInteger (
1207
+ kIPFSResolveMethod ,
1208
+ static_cast <int >(ipfs::IPFSResolveMethodTypes::IPFS_ASK));
1209
+ GURL gateway = GetURL (" b.com" , " /" );
1210
+ SetIPFSDefaultGatewayForTest (gateway);
1211
+
1212
+ auto tab_url = GetURL (" ipfs.a.com" , " /simple.html?a=b" );
1213
+
1214
+ ASSERT_TRUE (ui_test_utils::NavigateToURL (browser (), tab_url));
1215
+ content::WebContents* contents =
1216
+ browser ()->tab_strip_model ()->GetActiveWebContents ();
1217
+ EXPECT_EQ (contents->GetURL (), tab_url);
1094
1218
}
1095
1219
1096
1220
IN_PROC_BROWSER_TEST_F (IpfsServiceBrowserTest, TopLevelAutoRedirectsOff) {
1097
1221
ResetTestServer (
1098
- base::BindRepeating (&IpfsServiceBrowserTest::HandleEmbeddedSrvrRequest ,
1222
+ base::BindRepeating (&IpfsServiceBrowserTest::HandlePublicGatewayRequest ,
1099
1223
base::Unretained (this )));
1100
- SetIPFSDefaultGatewayForTest (GetURL (" b.com" , " /" ));
1101
- GURL other_gateway = GetURL (" a.com" , " /simple.html" );
1102
- ASSERT_TRUE (
1103
- ui_test_utils::NavigateToURL (browser (), GetURL (" a.com" , " /simple.html" )));
1224
+ browser ()->profile ()->GetPrefs ()->SetBoolean (kIPFSAutoRedirectGateway , false );
1225
+ browser ()->profile ()->GetPrefs ()->SetInteger (
1226
+ kIPFSResolveMethod ,
1227
+ static_cast <int >(ipfs::IPFSResolveMethodTypes::IPFS_ASK));
1228
+ GURL gateway = GetURL (" b.com" , " /" );
1229
+ SetIPFSDefaultGatewayForTest (gateway);
1230
+
1231
+ auto tab_url = GetURL (
1232
+ " bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq.ipfs.a.com" ,
1233
+ " /simple.html?a=b" );
1234
+
1235
+ ASSERT_TRUE (ui_test_utils::NavigateToURL (browser (), tab_url));
1104
1236
content::WebContents* contents =
1105
1237
browser ()->tab_strip_model ()->GetActiveWebContents ();
1106
- EXPECT_EQ (contents->GetURL (). host (), other_gateway. host () );
1238
+ EXPECT_EQ (contents->GetURL (), tab_url );
1107
1239
}
1108
1240
1109
1241
IN_PROC_BROWSER_TEST_F (IpfsServiceBrowserTest, ImportTextToIpfs) {
0 commit comments