Skip to content

Commit

Permalink
Merge pull request #2032 from /issues/3411-0.62.x
Browse files Browse the repository at this point in the history
Merge pull request #2024 from /issues/3411
  • Loading branch information
bbondy committed Mar 25, 2019
2 parents c23df70 + 8e06e38 commit 2d7b229
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 45 deletions.
13 changes: 1 addition & 12 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,14 @@ bool HandleURLOverrideRewrite(GURL* url,

bool HandleURLReverseOverrideRewrite(GURL* url,
content::BrowserContext* browser_context) {
if (url->host() == chrome::kChromeUIWelcomeHost ||
url->host() == chrome::kChromeUISyncHost) {
GURL::Replacements replacements;
replacements.SetSchemeStr(kBraveUIScheme);
*url = url->ReplaceComponents(replacements);
if (HandleURLOverrideRewrite(url, browser_context))
return true;
}

return false;
}

bool HandleURLRewrite(GURL* url,
content::BrowserContext* browser_context) {
if (url->SchemeIs(kBraveUIScheme)) {
GURL::Replacements replacements;
replacements.SetSchemeStr(content::kChromeUIScheme);
*url = url->ReplaceComponents(replacements);
}

if (HandleURLOverrideRewrite(url, browser_context))
return true;

Expand Down
68 changes: 56 additions & 12 deletions browser/brave_content_browser_client_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <vector>

#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
#include "brave/browser/brave_content_browser_client.h"
#include "brave/common/brave_paths.h"
#include "brave/common/extensions/extension_constants.h"
Expand Down Expand Up @@ -133,9 +134,12 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, CanLoadChromeURL) {
ui_test_utils::NavigateToURL(browser(), GURL(scheme + page + "/"));
ASSERT_TRUE(WaitForLoadStop(contents));

EXPECT_STREQ(base::UTF16ToUTF8(browser()->location_bar_model()
->GetFormattedFullURL()).c_str(),
("brave://" + page).c_str());
EXPECT_STREQ(contents->GetController().GetLastCommittedEntry()
->GetVirtualURL().spec().c_str(),
("brave://" + page + "/").c_str());
("chrome://" + page + "/").c_str());
EXPECT_STREQ(contents->GetController().GetLastCommittedEntry()
->GetURL().spec().c_str(),
("chrome://" + page + "/").c_str());
Expand Down Expand Up @@ -164,9 +168,12 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, CanLoadCustomBravePages) {
ui_test_utils::NavigateToURL(browser(), GURL(scheme + page + "/"));
ASSERT_TRUE(WaitForLoadStop(contents));

EXPECT_STREQ(base::UTF16ToUTF8(browser()->location_bar_model()
->GetFormattedFullURL()).c_str(),
("brave://" + page).c_str());
EXPECT_STREQ(contents->GetController().GetLastCommittedEntry()
->GetVirtualURL().spec().c_str(),
("brave://" + page + "/").c_str());
("chrome://" + page + "/").c_str());
EXPECT_STREQ(contents->GetController().GetLastCommittedEntry()
->GetURL().spec().c_str(),
("chrome://" + page + "/").c_str());
Expand All @@ -186,9 +193,12 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, CanLoadAboutHost) {
ui_test_utils::NavigateToURL(browser(), GURL(scheme + "about/"));
ASSERT_TRUE(WaitForLoadStop(contents));

EXPECT_STREQ(base::UTF16ToUTF8(browser()->location_bar_model()
->GetFormattedFullURL()).c_str(),
"brave://about");
EXPECT_STREQ(contents->GetController().GetLastCommittedEntry()
->GetVirtualURL().spec().c_str(),
"brave://about/");
"chrome://about/");
EXPECT_STREQ(contents->GetController().GetLastCommittedEntry()
->GetURL().spec().c_str(),
"chrome://chrome-urls/");
Expand All @@ -205,15 +215,46 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest,
for (const std::string& scheme : schemes) {
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(), GURL(scheme + "sync-internals/"));
ASSERT_TRUE(WaitForLoadStop(contents));
ui_test_utils::NavigateToURL(
browser(), GURL(scheme + chrome::kChromeUISyncInternalsHost));
ASSERT_TRUE(WaitForLoadStop(contents));

EXPECT_STREQ(contents->GetController().GetLastCommittedEntry()
->GetVirtualURL().spec().c_str(),
"brave://sync/");
EXPECT_STREQ(contents->GetController().GetLastCommittedEntry()
->GetURL().spec().c_str(),
"chrome://sync/");
EXPECT_STREQ(base::UTF16ToUTF8(browser()->location_bar_model()
->GetFormattedFullURL()).c_str(),
"brave://sync");
EXPECT_STREQ(contents->GetController().GetLastCommittedEntry()
->GetVirtualURL().spec().c_str(),
"chrome://sync/");
EXPECT_STREQ(contents->GetController().GetLastCommittedEntry()
->GetURL().spec().c_str(),
"chrome://sync/");
}
}

IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest,
RewriteWelcomeWin10Host) {
std::vector<std::string> schemes {
"brave://",
"chrome://",
};

for (const std::string& scheme : schemes) {
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(
browser(),
GURL(scheme + chrome::kChromeUIWelcomeWin10Host));
ASSERT_TRUE(WaitForLoadStop(contents));

EXPECT_STREQ(base::UTF16ToUTF8(browser()->location_bar_model()
->GetFormattedFullURL()).c_str(),
"brave://welcome");
EXPECT_STREQ(contents->GetController().GetLastCommittedEntry()
->GetVirtualURL().spec().c_str(),
"chrome://welcome/");
EXPECT_STREQ(contents->GetController().GetLastCommittedEntry()
->GetURL().spec().c_str(),
"chrome://welcome/");
}
}

Expand All @@ -230,9 +271,12 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest,
ui_test_utils::NavigateToURL(browser(), GURL(scheme + "welcome-win10/"));
ASSERT_TRUE(WaitForLoadStop(contents));

EXPECT_STREQ(base::UTF16ToUTF8(browser()->location_bar_model()
->GetFormattedFullURL()).c_str(),
"brave://welcome");
EXPECT_STREQ(contents->GetController().GetLastCommittedEntry()
->GetVirtualURL().spec().c_str(),
"brave://welcome/");
"chrome://welcome/");
EXPECT_STREQ(contents->GetController().GetLastCommittedEntry()
->GetURL().spec().c_str(),
"chrome://welcome/");
Expand Down
17 changes: 11 additions & 6 deletions browser/brave_scheme_load_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "base/path_service.h"
#include "base/strings/pattern.h"
#include "base/strings/utf_string_conversions.h"
#include "brave/common/brave_paths.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
Expand Down Expand Up @@ -59,7 +60,7 @@ class BraveSchemeLoadBrowserTest : public InProcessBrowserTest,

// Check loading |url| in private window is redirected to normal
// window.
void TestURLIsNotLoadedInPrivateWindow(const GURL& url) {
void TestURLIsNotLoadedInPrivateWindow(const std::string& url) {
Browser* private_browser = CreateIncognitoBrowser(nullptr);
TabStripModel* private_model = private_browser->tab_strip_model();

Expand All @@ -73,12 +74,16 @@ class BraveSchemeLoadBrowserTest : public InProcessBrowserTest,
browser()->tab_strip_model()->AddObserver(this);

// Load url to private window.
NavigateParams params(private_browser, url, ui::PAGE_TRANSITION_TYPED);
NavigateParams params(
private_browser, GURL(url), ui::PAGE_TRANSITION_TYPED);
Navigate(&params);

browser()->tab_strip_model()->RemoveObserver(this);

EXPECT_EQ(url, active_contents()->GetVisibleURL());
EXPECT_STREQ(url.c_str(),
base::UTF16ToUTF8(browser()->location_bar_model()
->GetFormattedFullURL()).c_str());
// EXPECT_EQ(url, active_contents()->GetVisibleURL());
EXPECT_EQ(2, browser()->tab_strip_model()->count());
// Private window stays as initial state.
EXPECT_EQ("about:blank",
Expand Down Expand Up @@ -232,15 +237,15 @@ IN_PROC_BROWSER_TEST_F(BraveSchemeLoadBrowserTest,
// window.
IN_PROC_BROWSER_TEST_F(BraveSchemeLoadBrowserTest,
SettingsPageIsNotAllowedInPrivateWindow) {
TestURLIsNotLoadedInPrivateWindow(GURL("brave://settings/"));
TestURLIsNotLoadedInPrivateWindow("brave://settings");
}

IN_PROC_BROWSER_TEST_F(BraveSchemeLoadBrowserTest,
SyncPageIsNotAllowedInPrivateWindow) {
TestURLIsNotLoadedInPrivateWindow(GURL("brave://sync/"));
TestURLIsNotLoadedInPrivateWindow("brave://sync");
}

IN_PROC_BROWSER_TEST_F(BraveSchemeLoadBrowserTest,
RewardsPageIsNotAllowedInPrivateWindow) {
TestURLIsNotLoadedInPrivateWindow(GURL("brave://rewards/"));
TestURLIsNotLoadedInPrivateWindow("brave://rewards");
}
2 changes: 2 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ source_set("ui") {
"omnibox/brave_omnibox_client.h",
"toolbar/brave_app_menu_model.cc",
"toolbar/brave_app_menu_model.h",
"toolbar/brave_location_bar_model_delegate.cc",
"toolbar/brave_location_bar_model_delegate.h",
"toolbar/brave_toolbar_actions_model.cc",
"toolbar/brave_toolbar_actions_model.h",
"views/brave_layout_provider.cc",
Expand Down
32 changes: 32 additions & 0 deletions browser/ui/toolbar/brave_location_bar_model_delegate.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Copyright (c) 2019 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/. */

#include "brave/browser/ui/toolbar/brave_location_bar_model_delegate.h"

#include "base/strings/utf_string_conversions.h"

BraveLocationBarModelDelegate::BraveLocationBarModelDelegate(
Browser* browser) : BrowserLocationBarModelDelegate(browser) {}

BraveLocationBarModelDelegate::~BraveLocationBarModelDelegate() {}

base::string16
BraveLocationBarModelDelegate::FormattedStringWithEquivalentMeaning(
const GURL& url,
const base::string16& formatted_url) const {
base::string16 new_formatted_url =
BrowserLocationBarModelDelegate::FormattedStringWithEquivalentMeaning(
url, formatted_url);

if (url.SchemeIs("chrome")) {
base::ReplaceFirstSubstringAfterOffset(
&new_formatted_url,
0,
base::UTF8ToUTF16("chrome://"),
base::UTF8ToUTF16("brave://"));
}

return new_formatted_url;
}
28 changes: 28 additions & 0 deletions browser/ui/toolbar/brave_location_bar_model_delegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Copyright (c) 2019 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_BROWSER_UI_TOOLBAR_BRAVE_LOCATION_BAR_MODEL_DELEGATE_H_
#define BRAVE_BROWSER_UI_TOOLBAR_BRAVE_LOCATION_BAR_MODEL_DELEGATE_H_

#include "base/compiler_specific.h"
#include "base/macros.h"
#include "chrome/browser/ui/browser_location_bar_model_delegate.h"

class Browser;

class BraveLocationBarModelDelegate : public BrowserLocationBarModelDelegate {
public:
explicit BraveLocationBarModelDelegate(Browser* browser);
~BraveLocationBarModelDelegate() override;

private:
base::string16 FormattedStringWithEquivalentMeaning(
const GURL& url,
const base::string16& formatted_url) const override;

DISALLOW_COPY_AND_ASSIGN(BraveLocationBarModelDelegate);
};

#endif // BRAVE_BROWSER_UI_TOOLBAR_BRAVE_LOCATION_BAR_MODEL_DELEGATE_H_
2 changes: 1 addition & 1 deletion browser/ui/webui/brave_welcome_ui_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ IN_PROC_BROWSER_TEST_F(BraveWelcomeUIBrowserTest, PRE_StartupURLTest) {
content::WebContents* web_contents = tab_strip->GetWebContentsAt(0);
content::TestNavigationObserver observer(web_contents, 1);
observer.Wait();
EXPECT_STREQ("brave://welcome/",
EXPECT_STREQ("chrome://welcome/",
tab_strip->GetWebContentsAt(0)
->GetController().GetLastCommittedEntry()
->GetVirtualURL().possibly_invalid_spec().c_str());
Expand Down
5 changes: 2 additions & 3 deletions chromium_src/chrome/browser/browser_about_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ bool FixupBrowserAboutURL(GURL* url,
*url = url->ReplaceComponents(replacements);
}

if (url->SchemeIs(content::kChromeUIScheme) &&
url->host() != chrome::kChromeUINewTabHost) {
if (url->SchemeIs(kBraveUIScheme)) {
GURL::Replacements replacements;
replacements.SetSchemeStr(kBraveUIScheme);
replacements.SetSchemeStr(content::kChromeUIScheme);
*url = url->ReplaceComponents(replacements);
}

Expand Down
3 changes: 3 additions & 0 deletions chromium_src/chrome/browser/ui/browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
#include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
#include "brave/browser/ui/brave_browser_content_setting_bubble_model_delegate.h"
#include "brave/browser/ui/brave_browser_command_controller.h"
#include "brave/browser/ui/toolbar/brave_location_bar_model_delegate.h"

#define BrowserContentSettingBubbleModelDelegate \
BraveBrowserContentSettingBubbleModelDelegate
#define BrowserCommandController BraveBrowserCommandController
#define BrowserLocationBarModelDelegate BraveLocationBarModelDelegate
#include "../../../../../chrome/browser/ui/browser.cc" // NOLINT
#undef BrowserLocationBarModelDelegate
#undef BrowserContentSettingBubbleModelDelegate
#undef BrowserCommandController
26 changes: 15 additions & 11 deletions components/brave_rewards/browser/rewards_service_browsertest.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* Copyright (c) 2019 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/. */

Expand Down Expand Up @@ -30,7 +31,7 @@ namespace brave_test_resp {

namespace brave_net {
class BraveURLFetcher : public net::TestURLFetcher {
public:
public:
BraveURLFetcher(bool success,
const GURL& url,
const std::string& results,
Expand All @@ -48,19 +49,19 @@ class BraveURLFetcher : public net::TestURLFetcher {
DISALLOW_COPY_AND_ASSIGN(BraveURLFetcher);
};

void split(std::vector<std::string>& tmp, std::string query, char delimiter) {
void split(std::vector<std::string>* tmp, std::string query, char delimiter) {
std::stringstream ss(query);
std::string item;
while (std::getline(ss, item, delimiter)) {
if (query[0] != '\n') {
tmp.push_back(item);
tmp->push_back(item);
}
}
}

void BraveURLFetcher::DetermineURLResponsePath(std::string url) {
std::vector<std::string> tmp;
brave_net::split(tmp, url, '/');
brave_net::split(&tmp, url, '/');
if (url.find(braveledger_bat_helper::buildURL(REGISTER_PERSONA, PREFIX_V2,
braveledger_bat_helper::SERVER_TYPES::LEDGER)) == 0
&& tmp.size() == 6) {
Expand Down Expand Up @@ -174,7 +175,7 @@ class BraveRewardsBrowserTest : public InProcessBrowserTest {
// Load rewards page
ui_test_utils::NavigateToURL(browser(), rewards_url());
WaitForLoadStop(contents());
//opt in and create wallet to enable rewards
// opt in and create wallet to enable rewards
ASSERT_TRUE(ExecJs(contents(),
"document.querySelector(\"[data-test-id='optInAction']\").click();",
content::EXECUTE_SCRIPT_DEFAULT_OPTIONS,
Expand Down Expand Up @@ -213,7 +214,8 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, RenderWelcome) {
// Enable Rewards
EnableRewards();
EXPECT_STREQ(contents()->GetLastCommittedURL().spec().c_str(),
rewards_url().spec().c_str());
// actual url is always chrome://
"chrome://rewards/");
}

IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, ToggleRewards) {
Expand Down Expand Up @@ -287,10 +289,12 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, ToggleAutoContribute) {
" if (document.querySelector(\"[data-test-id2='autoContribution']\")) {"
" if (!toggleClicked) {"
" toggleClicked = true;"
" document.querySelector(\"[data-test-id2='autoContribution']\").click();"
" document.querySelector("
" \"[data-test-id2='autoContribution']\").click();"
" } else {"
" clearInterval(interval);"
" resolve(document.querySelector(\"[data-test-id2='autoContribution']\")"
" resolve(document.querySelector("
" \"[data-test-id2='autoContribution']\")"
" .getAttribute(\"data-toggled\") === 'false');"
" }"
" }"
Expand Down Expand Up @@ -406,8 +410,8 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsSingleArg) {
GetReconcileTime();
RunUntilIdle();

EXPECT_CALL(*this, OnGetShortRetries(true)); // on
EXPECT_CALL(*this, OnGetShortRetries(false)); // off
EXPECT_CALL(*this, OnGetShortRetries(true)); // on
EXPECT_CALL(*this, OnGetShortRetries(false)); // off

// Short retries - on
rewards_service()->SetShortRetries(false);
Expand Down
Loading

0 comments on commit 2d7b229

Please sign in to comment.