Skip to content

Commit 9793983

Browse files
committed
tests
1 parent 67aa8ee commit 9793983

File tree

5 files changed

+114
-1
lines changed

5 files changed

+114
-1
lines changed

browser/test/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ source_set("browser_tests") {
1313
"disabled_features/navigator_bluetooth_browsertest.cc",
1414
"disabled_features/navigator_storage_browsertest.cc",
1515
"disabled_features/reporting_observer_browsertest.cc",
16+
"disabled_features/window_name_browsertest.cc",
1617
]
1718

1819
deps = [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/* Copyright (c) 2022 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#include "base/path_service.h"
7+
#include "brave/browser/brave_content_browser_client.h"
8+
#include "brave/components/constants/brave_paths.h"
9+
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
10+
#include "chrome/browser/profiles/profile.h"
11+
#include "chrome/browser/ui/browser.h"
12+
#include "chrome/common/chrome_content_client.h"
13+
#include "chrome/test/base/in_process_browser_test.h"
14+
#include "chrome/test/base/ui_test_utils.h"
15+
#include "content/public/test/browser_test.h"
16+
#include "content/public/test/browser_test_utils.h"
17+
#include "net/dns/mock_host_resolver.h"
18+
#include "url/gurl.h"
19+
20+
namespace {
21+
22+
const char kEmbeddedTestServerDirectory[] = "window_name";
23+
const char kWindowNameScript[] = "window.name";
24+
25+
} // namespace
26+
27+
class BraveWindowNameBrowserTest : public InProcessBrowserTest {
28+
public:
29+
BraveWindowNameBrowserTest()
30+
: https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {
31+
https_server_.SetSSLConfig(net::EmbeddedTestServer::CERT_TEST_NAMES);
32+
brave::RegisterPathProvider();
33+
base::FilePath test_data_dir;
34+
base::PathService::Get(brave::DIR_TEST_DATA, &test_data_dir);
35+
test_data_dir = test_data_dir.AppendASCII(kEmbeddedTestServerDirectory);
36+
https_server_.ServeFilesFromDirectory(test_data_dir);
37+
EXPECT_TRUE(https_server_.Start());
38+
}
39+
40+
BraveWindowNameBrowserTest(const BraveWindowNameBrowserTest&) = delete;
41+
BraveWindowNameBrowserTest& operator=(const BraveWindowNameBrowserTest&) =
42+
delete;
43+
44+
~BraveWindowNameBrowserTest() override {}
45+
46+
void SetUpOnMainThread() override {
47+
InProcessBrowserTest::SetUpOnMainThread();
48+
content_client_.reset(new ChromeContentClient);
49+
content::SetContentClient(content_client_.get());
50+
browser_content_client_.reset(new BraveContentBrowserClient());
51+
content::SetBrowserClientForTesting(browser_content_client_.get());
52+
host_resolver()->AddRule("*", "127.0.0.1");
53+
}
54+
55+
void TearDown() override {
56+
browser_content_client_.reset();
57+
content_client_.reset();
58+
}
59+
60+
protected:
61+
net::EmbeddedTestServer https_server_;
62+
63+
content::WebContents* web_contents() {
64+
return browser()->tab_strip_model()->GetActiveWebContents();
65+
}
66+
67+
private:
68+
std::unique_ptr<ChromeContentClient> content_client_;
69+
std::unique_ptr<BraveContentBrowserClient> browser_content_client_;
70+
};
71+
72+
IN_PROC_BROWSER_TEST_F(BraveWindowNameBrowserTest, SameOrigin) {
73+
GURL url1 = https_server_.GetURL("a.test", "/set_window_name.html");
74+
GURL url2 = https_server_.GetURL("a.test", "/get_window_name.html");
75+
76+
EXPECT_TRUE(ui_test_utils::NavigateToURL(browser(), url1));
77+
EXPECT_EQ("foo", EvalJs(web_contents(), kWindowNameScript));
78+
EXPECT_TRUE(ui_test_utils::NavigateToURL(browser(), url2));
79+
// Since these URLs are in the same origin, window.name should persist across
80+
// navigation.
81+
EXPECT_EQ("foo", EvalJs(web_contents(), kWindowNameScript));
82+
}
83+
84+
IN_PROC_BROWSER_TEST_F(BraveWindowNameBrowserTest, CrossOrigin) {
85+
GURL url1 = https_server_.GetURL("a.test", "/set_window_name.html");
86+
GURL url2 = https_server_.GetURL("b.test", "/get_window_name.html");
87+
88+
EXPECT_TRUE(ui_test_utils::NavigateToURL(browser(), url1));
89+
EXPECT_EQ("foo", EvalJs(web_contents(), kWindowNameScript));
90+
EXPECT_TRUE(ui_test_utils::NavigateToURL(browser(), url2));
91+
// Since these URLs are in different origins, window.name should be cleared
92+
// during navigation.
93+
EXPECT_EQ("", EvalJs(web_contents(), kWindowNameScript));
94+
}

chromium_src/third_party/blink/renderer/core/page/frame_tree.cc

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
namespace blink {
1616

1717
void FrameTree::CrossSiteCrossBrowsingContextGroupSetNulledName() {
18-
LOG(ERROR) << "1";
1918
SetName(g_null_atom, kReplicate);
2019
CrossSiteCrossBrowsingContextGroupSetNulledName_ChromiumImpl();
2120
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
</head>
6+
<body>
7+
</body>
8+
</html>
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<script>
6+
window.name = "foo";
7+
</script>
8+
</head>
9+
<body>
10+
</body>
11+
</html>

0 commit comments

Comments
 (0)