Skip to content

Commit 211170a

Browse files
committed
test: make back-to-opener tests self-contained
The DaoBackToOpenerBrowserTest fixture previously loaded an opener page from engine/src/chrome/test/data/back_to_opener_opener.html, which is not version-controlled (engine/ is gitignored). A fresh checkout would fail these tests because the fixture file was missing. Serve the opener page inline via embedded_test_server()'s request handler so the tests no longer depend on any custom on-disk fixture. The link target /title1.html is a stock Chromium test fixture provided by ServeFilesFromSourceDirectory("chrome/test/data") and remains available from any Chromium checkout.
1 parent ef63cc7 commit 211170a

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/dao/browser/ui/views/dao_browser_browsertest.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "base/files/file_path.h"
66
#include "base/files/file_util.h"
77
#include "base/files/scoped_temp_dir.h"
8+
#include "base/functional/bind.h"
89
#include "base/run_loop.h"
910
#include "base/strings/strcat.h"
1011
#include "base/strings/string_util.h"
@@ -70,6 +71,8 @@
7071
#include "ui/base/l10n/l10n_util.h"
7172
#include "net/dns/mock_host_resolver.h"
7273
#include "net/test/embedded_test_server/embedded_test_server.h"
74+
#include "net/test/embedded_test_server/http_request.h"
75+
#include "net/test/embedded_test_server/http_response.h"
7376
#include "third_party/blink/public/common/features.h"
7477
#include "third_party/blink/public/mojom/devtools/console_message.mojom-shared.h"
7578
#include "ui/compositor/layer.h"
@@ -2268,6 +2271,12 @@ class DaoBackToOpenerBrowserTest : public InProcessBrowserTest {
22682271
void SetUpOnMainThread() override {
22692272
InProcessBrowserTest::SetUpOnMainThread();
22702273
host_resolver()->AddRule("*", "127.0.0.1");
2274+
// Serve the opener page inline so the test does not depend on any file
2275+
// under engine/src/chrome/test/data/ (which is gitignored). The link
2276+
// target /title1.html is a stock Chromium test fixture and is provided
2277+
// by ServeFilesFromSourceDirectory below.
2278+
embedded_test_server()->RegisterRequestHandler(base::BindRepeating(
2279+
&DaoBackToOpenerBrowserTest::HandleOpenerRequest));
22712280
embedded_test_server()->ServeFilesFromSourceDirectory("chrome/test/data");
22722281
ASSERT_TRUE(embedded_test_server()->Start());
22732282
}
@@ -2291,6 +2300,27 @@ class DaoBackToOpenerBrowserTest : public InProcessBrowserTest {
22912300
EXPECT_TRUE(content::WaitForLoadStop(dest_contents));
22922301
return dest_contents;
22932302
}
2303+
2304+
private:
2305+
// Returns an inline opener page with a target=_blank link to a stock
2306+
// Chromium fixture. Returns nullptr for unrelated paths so the static file
2307+
// handler installed via ServeFilesFromSourceDirectory can handle them.
2308+
static std::unique_ptr<net::test_server::HttpResponse> HandleOpenerRequest(
2309+
const net::test_server::HttpRequest& request) {
2310+
if (request.relative_url != "/back_to_opener_opener.html") {
2311+
return nullptr;
2312+
}
2313+
auto response =
2314+
std::make_unique<net::test_server::BasicHttpResponse>();
2315+
response->set_code(net::HTTP_OK);
2316+
response->set_content_type("text/html");
2317+
response->set_content(
2318+
"<!DOCTYPE html><html><head>"
2319+
"<title>Back to Opener Test - Opener Page</title></head><body>"
2320+
"<a id=\"link\" href=\"/title1.html\" target=\"_blank\">child</a>"
2321+
"</body></html>");
2322+
return response;
2323+
}
22942324
};
22952325

22962326
// 1. Clicking back in a child tab whose in-tab history is empty should close

0 commit comments

Comments
 (0)