diff --git a/browser/tor/onion_location_navigation_throttle_browsertest.cc b/browser/tor/onion_location_navigation_throttle_browsertest.cc index fa7293dc4176..cb92d362b9bd 100644 --- a/browser/tor/onion_location_navigation_throttle_browsertest.cc +++ b/browser/tor/onion_location_navigation_throttle_browsertest.cc @@ -107,6 +107,7 @@ IN_PROC_BROWSER_TEST_F(OnionLocationNavigationThrottleBrowserTest, ui_test_utils::NavigateToURL(browser(), GURL("https://brave.com")); EXPECT_EQ(1U, browser_list->size()); ASSERT_FALSE(browser_list->get(0)->profile()->IsTor()); + ASSERT_EQ(browser(), browser_list->get(0)); content::WindowedNotificationObserver tor_browser_creation_observer( chrome::NOTIFICATION_BROWSER_OPENED, @@ -114,10 +115,15 @@ IN_PROC_BROWSER_TEST_F(OnionLocationNavigationThrottleBrowserTest, ui_test_utils::NavigateToURL(browser(), GURL(kTestOnionURL)); tor_browser_creation_observer.Wait(); EXPECT_EQ(2U, browser_list->size()); - ASSERT_TRUE(browser_list->get(1)->profile()->IsTor()); + Browser* tor_browser = browser_list->get(1); + ASSERT_TRUE(tor_browser->profile()->IsTor()); content::WebContents* web_contents = - browser_list->get(1)->tab_strip_model()->GetActiveWebContents(); + tor_browser->tab_strip_model()->GetActiveWebContents(); EXPECT_EQ(web_contents->GetURL(), GURL(kTestOnionURL)); + // We don't close the original tab + EXPECT_EQ(browser()->tab_strip_model()->count(), 1); + // No new tab in Tor window + EXPECT_EQ(tor_browser->tab_strip_model()->count(), 1); } IN_PROC_BROWSER_TEST_F(OnionLocationNavigationThrottleBrowserTest, @@ -145,7 +151,7 @@ IN_PROC_BROWSER_TEST_F(OnionLocationNavigationThrottleBrowserTest, GURL url = test_server()->GetURL("/onion"); ui_test_utils::NavigateToURL(browser(), url); tor_browser_creation_observer.Wait(); - // Last tab will not be closed + // We don't close the original tab EXPECT_EQ(browser()->tab_strip_model()->count(), 1); content::WebContents* web_contents = browser()->tab_strip_model()->GetActiveWebContents(); @@ -161,17 +167,19 @@ IN_PROC_BROWSER_TEST_F(OnionLocationNavigationThrottleBrowserTest, web_contents = tor_browser->tab_strip_model()->GetActiveWebContents(); EXPECT_EQ(web_contents->GetURL(), GURL(kTestOnionURL)); - // Open a new tab + // Open a new tab and navigate to the url again NavigateParams params( NavigateParams(browser(), url, ui::PAGE_TRANSITION_TYPED)); params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; ui_test_utils::NavigateToURL(¶ms); - EXPECT_EQ(browser()->tab_strip_model()->count(), 1); + // We stll don't close the original tab + EXPECT_EQ(browser()->tab_strip_model()->count(), 2); EXPECT_EQ(2U, browser_list->size()); - web_contents = tor_browser->tab_strip_model()->GetWebContentsAt(2); - EXPECT_EQ(tor_browser->tab_strip_model()->count(), 3); + // No new tab in Tor window and unique one tab per site + EXPECT_EQ(tor_browser->tab_strip_model()->count(), 1); + web_contents = tor_browser->tab_strip_model()->GetWebContentsAt(0); EXPECT_EQ(web_contents->GetURL(), GURL(kTestOnionURL)); } diff --git a/browser/tor/onion_location_navigation_throttle_delegate.cc b/browser/tor/onion_location_navigation_throttle_delegate.cc index b593bbc9d0f8..ace78910ac77 100644 --- a/browser/tor/onion_location_navigation_throttle_delegate.cc +++ b/browser/tor/onion_location_navigation_throttle_delegate.cc @@ -22,11 +22,11 @@ void OnTorProfileCreated(GURL onion_location, Profile::CreateStatus status) { if (status != Profile::CreateStatus::CREATE_STATUS_INITIALIZED) return; - Browser* browser = chrome::FindTabbedBrowser(profile, true); + Browser* browser = chrome::FindTabbedBrowser(profile, false); if (!browser) return; content::OpenURLParams open_tor(onion_location, content::Referrer(), - WindowOpenDisposition::NEW_FOREGROUND_TAB, + WindowOpenDisposition::SWITCH_TO_TAB, ui::PAGE_TRANSITION_TYPED, false); browser->OpenURL(open_tor); } @@ -46,11 +46,6 @@ void OnionLocationNavigationThrottleDelegate::OpenInTorWindow( Profile::FromBrowserContext(web_contents->GetBrowserContext()); TorProfileManager::SwitchToTorProfile(profile, base::BindRepeating(&OnTorProfileCreated, std::move(onion_location))); - - // We do not close last tab of the window - Browser* browser = chrome::FindBrowserWithProfile(profile); - if (browser && browser->tab_strip_model()->count() > 1) - web_contents->ClosePage(); } } // namespace tor diff --git a/components/tor/onion_location_navigation_throttle.cc b/components/tor/onion_location_navigation_throttle.cc index e2220419b73f..ecae9de79d2e 100644 --- a/components/tor/onion_location_navigation_throttle.cc +++ b/components/tor/onion_location_navigation_throttle.cc @@ -94,7 +94,6 @@ OnionLocationNavigationThrottle::WillStartRequest() { pref_service_->GetBoolean(prefs::kAutoOnionRedirect)) { delegate_->OpenInTorWindow(navigation_handle()->GetWebContents(), std::move(url)); - return content::NavigationThrottle::CANCEL_AND_IGNORE; } } return content::NavigationThrottle::PROCEED;