Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DevToolsWindow using original profile for Tor window (uplift to 1.41.x) #13891

Merged
merged 1 commit into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions browser/tor/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ source_set("unit_tests") {
"//brave/components/tor",
"//brave/components/tor:test_support",
"//brave/components/translate/core/common:buildflags",
"//chrome/browser/devtools",
"//chrome/common",
"//chrome/test:test_support",
"//components/keyed_service/content",
Expand All @@ -88,6 +89,8 @@ source_set("browser_tests") {
testonly = true
if (enable_tor) {
sources = [
"//chrome//browser/net/profile_network_context_service_test_utils.cc",
"//chrome//browser/net/profile_network_context_service_test_utils.h",
"brave_local_state_browsertest.cc",
"brave_tor_client_updater_browsertest.cc",
"onion_location_navigation_throttle_browsertest.cc",
Expand Down
4 changes: 4 additions & 0 deletions browser/tor/tor_profile_manager_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/net/profile_network_context_service_test_utils.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
Expand Down Expand Up @@ -197,6 +198,9 @@ IN_PROC_BROWSER_TEST_F(TorProfileManagerTest,
#if BUILDFLAG(ENABLE_IPFS)
EXPECT_EQ(ipfs::IpfsServiceFactory::GetForContext(tor_profile), nullptr);
#endif
// Ambient Auth should be disabled
EXPECT_FALSE(AmbientAuthenticationTestHelper::IsAmbientAuthAllowedForProfile(
tor_profile));
}

IN_PROC_BROWSER_TEST_F(TorProfileManagerTest, SwitchToTorProfileInheritPrefs) {
Expand Down
19 changes: 16 additions & 3 deletions browser/tor/tor_profile_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h"
#include "brave/components/constants/pref_names.h"
#include "brave/components/translate/core/common/buildflags.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/web_contents_tester.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/peerconnection/webrtc_ip_handling_policy.h"

Expand Down Expand Up @@ -48,6 +50,10 @@ class TorProfileManagerUnitTest : public testing::Test {

Profile* profile() { return profile_; }

Profile* GetProfileForDevToolsWindow(content::WebContents* web_contents) {
return DevToolsWindow::GetProfileForDevToolsWindow(web_contents);
}

private:
content::BrowserTaskEnvironment task_environment_;
raw_ptr<Profile> profile_ = nullptr;
Expand All @@ -65,9 +71,8 @@ TEST_F(TorProfileManagerUnitTest, InitTorProfileUserPrefs) {
ASSERT_TRUE(tor_profile->IsTor());

// Check WebRTC IP handling policy.
EXPECT_EQ(
tor_profile->GetPrefs()->GetString(prefs::kWebRTCIPHandlingPolicy),
blink::kWebRTCIPHandlingDisableNonProxiedUdp);
EXPECT_EQ(tor_profile->GetPrefs()->GetString(prefs::kWebRTCIPHandlingPolicy),
blink::kWebRTCIPHandlingDisableNonProxiedUdp);

// Check SafeBrowsing status
EXPECT_FALSE(
Expand All @@ -84,3 +89,11 @@ TEST_F(TorProfileManagerUnitTest, InitTorProfileUserPrefs) {
translate::prefs::kOfferTranslateEnabled));
#endif
}

TEST_F(TorProfileManagerUnitTest, ProfileForDevToolsWindow) {
Profile* tor_profile =
TorProfileManager::GetInstance().GetTorProfile(profile());
std::unique_ptr<content::WebContents> tor_web_contents =
content::WebContentsTester::CreateTestWebContents(tor_profile, nullptr);
EXPECT_EQ(tor_profile, GetProfileForDevToolsWindow(tor_web_contents.get()));
}
17 changes: 17 additions & 0 deletions chromium_src/chrome/browser/devtools/devtools_window.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright (c) 2022 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_

#define HatsNextWebDialogBrowserTest \
HatsNextWebDialogBrowserTest; \
friend class TorProfileManagerUnitTest;

#include "src/chrome/browser/devtools/devtools_window.h"

#undef HatsNextWebDialogBrowserTest

#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_H_
9 changes: 9 additions & 0 deletions chromium_src/chrome/browser/profiles/profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#define BRAVE_ALLOWS_BROWSER_WINDOWS *this == TorID() ||

#define IsIncognitoProfile IsIncognitoProfile_ChromiumImpl
#define IsPrimaryOTRProfile IsPrimaryOTRProfile_ChromiumImpl
#include "src/chrome/browser/profiles/profile.cc"
#undef IsIncognitoProfile
#undef IsPrimaryOTRProfile

// static
const Profile::OTRProfileID Profile::OTRProfileID::TorID() {
Expand All @@ -27,3 +29,10 @@ bool Profile::IsIncognitoProfile() const {
return true;
return IsIncognitoProfile_ChromiumImpl();
}

// Tor profile should behave like primary OTR profile used in private window
bool Profile::IsPrimaryOTRProfile() const {
if (IsTor())
return true;
return IsPrimaryOTRProfile_ChromiumImpl();
}
4 changes: 4 additions & 0 deletions chromium_src/chrome/browser/profiles/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
#define IsIncognitoProfile \
IsIncognitoProfile_ChromiumImpl() const; \
bool IsIncognitoProfile
#define IsPrimaryOTRProfile \
IsPrimaryOTRProfile_ChromiumImpl() const; \
bool IsPrimaryOTRProfile

#include "src/chrome/browser/profiles/profile.h"

#undef IsPrimaryOTRProfile
#undef IsIncognitoProfile
#undef HasPrimaryOTRProfile
#undef PrimaryID
Expand Down