Skip to content

Commit 169a8e9

Browse files
authored
Merge pull request #13634 from brave/pr13467_bugfix/de-amp/test-cases-looping_1.40.x
Modify tests for looping checks (uplift to 1.40.x)
2 parents b03f70c + 9312fcb commit 169a8e9

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

components/de_amp/browser/test/de_amp_browsertest.cc

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
#endif
3737

3838
const char kTestHost[] = "a.test.com";
39-
const char kTestAmpPage[] = "/test";
39+
const char kTestAmpPage[] = "/test_amp_page";
4040
const char kTestRedirectingAmpPage1[] = "/redirecting_amp_page_1";
4141
const char kTestRedirectingAmpPage2[] = "/redirecting_amp_page_2";
42-
const char kTestSimpleNonAmpPage[] = "/simple";
43-
const char kTestCanonicalPage[] = "/simple_canonical";
42+
const char kTestSimpleNonAmpPage[] = "/simple_page";
43+
const char kTestCanonicalPage[] = "/simple_canonical_page";
4444
const char kTestAmpBody[] =
4545
R"(
4646
<html amp>
@@ -171,9 +171,15 @@ std::unique_ptr<net::test_server::HttpResponse> HandleServerRedirect(
171171
net::HttpStatusCode code,
172172
const std::string& source,
173173
const std::string& dest,
174+
const std::string& body,
174175
const net::test_server::HttpRequest& request) {
175176
GURL request_url = request.GetURL();
176177

178+
if (request.headers.find("X-Brave-De-AMP") != request.headers.end()) {
179+
// This should never happen, abort test
180+
return nullptr;
181+
}
182+
177183
if (request_url.path() == source) {
178184
auto http_response =
179185
std::make_unique<net::test_server::BasicHttpResponse>();
@@ -185,7 +191,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleServerRedirect(
185191
dest.c_str()));
186192
return http_response;
187193
} else {
188-
return nullptr;
194+
return BuildHttpResponseForAmpPage(body, source, request);
189195
}
190196
}
191197

@@ -233,18 +239,16 @@ IN_PROC_BROWSER_TEST_F(DeAmpBrowserTest, AmpPagesPointingAtEachOther) {
233239

234240
IN_PROC_BROWSER_TEST_F(DeAmpBrowserTest, CanonicalRedirectsToAmp) {
235241
TogglePref(true);
236-
https_server_->RegisterRequestHandler(
237-
base::BindRepeating(HandleRequest, kTestCanonicalPage, kTestAmpBody));
238242
https_server_->RegisterRequestHandler(base::BindRepeating(
239243
HandleServerRedirect, net::HttpStatusCode::HTTP_PERMANENT_REDIRECT,
240-
kTestCanonicalPage, kTestAmpPage));
244+
kTestCanonicalPage, kTestAmpPage, kTestAmpBody));
241245
ASSERT_TRUE(https_server_->Start());
242246

243247
const GURL amp_url = https_server_->GetURL(kTestHost, kTestAmpPage);
244248
const GURL canonical_url =
245249
https_server_->GetURL(kTestHost, kTestCanonicalPage);
246250

247-
NavigateToURLAndWaitForRedirects(amp_url, canonical_url);
251+
NavigateToURLAndWaitForRedirects(amp_url, amp_url);
248252
}
249253

250254
IN_PROC_BROWSER_TEST_F(DeAmpBrowserTest, NonHttpScheme) {

0 commit comments

Comments
 (0)