diff --git a/browser/tor/BUILD.gn b/browser/tor/BUILD.gn index d2092c125b6f..c37b07db949f 100644 --- a/browser/tor/BUILD.gn +++ b/browser/tor/BUILD.gn @@ -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", @@ -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", diff --git a/browser/tor/tor_profile_manager_browsertest.cc b/browser/tor/tor_profile_manager_browsertest.cc index d7c7268f34e9..da153256f7db 100644 --- a/browser/tor/tor_profile_manager_browsertest.cc +++ b/browser/tor/tor_profile_manager_browsertest.cc @@ -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" @@ -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) { diff --git a/browser/tor/tor_profile_manager_unittest.cc b/browser/tor/tor_profile_manager_unittest.cc index 93ecded3e196..544ab7d5c1c0 100644 --- a/browser/tor/tor_profile_manager_unittest.cc +++ b/browser/tor/tor_profile_manager_unittest.cc @@ -11,6 +11,7 @@ #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" @@ -18,6 +19,7 @@ #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" @@ -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_ = nullptr; @@ -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( @@ -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 tor_web_contents = + content::WebContentsTester::CreateTestWebContents(tor_profile, nullptr); + EXPECT_EQ(tor_profile, GetProfileForDevToolsWindow(tor_web_contents.get())); +} diff --git a/chromium_src/chrome/browser/devtools/devtools_window.h b/chromium_src/chrome/browser/devtools/devtools_window.h new file mode 100644 index 000000000000..27a0170bf425 --- /dev/null +++ b/chromium_src/chrome/browser/devtools/devtools_window.h @@ -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_ diff --git a/chromium_src/chrome/browser/profiles/profile.cc b/chromium_src/chrome/browser/profiles/profile.cc index 6ed8a9e65b53..251ddfaaf36b 100644 --- a/chromium_src/chrome/browser/profiles/profile.cc +++ b/chromium_src/chrome/browser/profiles/profile.cc @@ -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() { @@ -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(); +} diff --git a/chromium_src/chrome/browser/profiles/profile.h b/chromium_src/chrome/browser/profiles/profile.h index fe6b7ac0a2a6..753727015d63 100644 --- a/chromium_src/chrome/browser/profiles/profile.h +++ b/chromium_src/chrome/browser/profiles/profile.h @@ -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