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

Show welcome page only at first run #130

Merged
merged 3 commits into from
Jun 5, 2018
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
2 changes: 2 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ source_set("ui") {
"webui/basic_ui.h",
"webui/brave_web_ui_controller_factory.cc",
"webui/brave_web_ui_controller_factory.h",
"webui/brave_welcome_ui.cc",
"webui/brave_welcome_ui.h",
"webui/new_tab_html_source.cc",
"webui/new_tab_html_source.h",
]
Expand Down
8 changes: 8 additions & 0 deletions browser/ui/webui/brave_web_ui_controller_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "brave/common/webui_url_constants.h"
#include "brave/browser/ui/webui/basic_ui.h"
#include "brave/browser/ui/webui/brave_welcome_ui.h"
#include "chrome/common/url_constants.h"
#include "components/grit/brave_components_resources.h"
#include "url/gurl.h"
Expand All @@ -26,6 +27,11 @@ WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) {
return new T(web_ui);
}

template<>
WebUIController* NewWebUI<BraveWelcomeUI>(WebUI* web_ui, const GURL& url) {
return new BraveWelcomeUI(web_ui);
}

template<>
WebUIController* NewWebUI<BasicUI>(WebUI* web_ui, const GURL& url) {
auto host = url.host_piece();
Expand All @@ -47,6 +53,8 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
if (url.host_piece() == kPaymentsHost ||
url.host_piece() == chrome::kChromeUINewTabHost) {
return &NewWebUI<BasicUI>;
} else if (url.spec() == kWelcomeRemoteURL) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diracdeltas @bbondy - this isn't directly related to this PR, but I think a remote welcome url is a privacy issue. Is there any reason why it can't be an internal page?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed changing to local welcome page but no one has had time to do that yet. Note that browser-laptop is remote too so we have at least baseline parity with that. But we did talk about wanting to move to a local one.

Copy link
Collaborator

@bridiver bridiver Jun 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like it should be pretty easy to do now that we have a webui for it. Is there a ticket or should I create one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought there was but I couldn't find one, so I posted it here:
brave/brave-browser#276

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's the original issue by @flamsmark brave/browser-laptop#12691. i also feel strongly that this should be baked into brave for privacy reasons.

return &NewWebUI<BraveWelcomeUI>;
}

return nullptr;
Expand Down
25 changes: 25 additions & 0 deletions browser/ui/webui/brave_welcome_ui.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* 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/webui/brave_welcome_ui.h"

#include "brave/browser/brave_browser_process_impl.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"

BraveWelcomeUI::BraveWelcomeUI(content::WebUI* web_ui)
: WebUIController(web_ui) {
Profile* profile = Profile::FromWebUI(web_ui);

profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true);
#if defined(OS_WIN)
g_brave_browser_process->local_state()->SetBoolean(
prefs::kHasSeenWin10PromoPage,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to set this pref even know we don't want a win10 promo page?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked that chrome shows this promo page at first run. Then, it shows welcome page at next run.
So, if we doesn't set, we will show our welcome ui at first run and second run.

true);
#endif
}

BraveWelcomeUI::~BraveWelcomeUI() {
}
20 changes: 20 additions & 0 deletions browser/ui/webui/brave_welcome_ui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* 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_WEBUI_BRAVE_WELCOME_UI_H_
#define BRAVE_BROWSER_UI_WEBUI_BRAVE_WELCOME_UI_H_

#include "base/macros.h"
#include "content/public/browser/web_ui_controller.h"

class BraveWelcomeUI : public content::WebUIController {
public:
explicit BraveWelcomeUI(content::WebUI* web_ui);
~BraveWelcomeUI() override;

private:
DISALLOW_COPY_AND_ASSIGN(BraveWelcomeUI);
};

#endif // BRAVE_BROWSER_UI_WEBUI_BRAVE_WELCOME_UI_H_
56 changes: 56 additions & 0 deletions browser/ui/webui/brave_welcome_ui_browsertest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* 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 "base/command_line.h"
#include "brave/browser/ui/webui/brave_web_ui_controller_factory.h"
#include "brave/common/webui_url_constants.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h"
#include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"

namespace {
Browser* OpenNewBrowser(Profile* profile) {
base::CommandLine dummy(base::CommandLine::NO_PROGRAM);
StartupBrowserCreatorImpl creator(base::FilePath(), dummy,
chrome::startup::IS_FIRST_RUN);
creator.Launch(profile, std::vector<GURL>(), false);
return chrome::FindBrowserWithProfile(profile);
}
}

using BraveWelcomeUIBrowserTest = InProcessBrowserTest;

// Check whether startup url at first run is our welcome page.
IN_PROC_BROWSER_TEST_F(BraveWelcomeUIBrowserTest, PRE_StartupURLTest) {
Browser* new_browser = OpenNewBrowser(browser()->profile());
ASSERT_TRUE(new_browser);
TabStripModel* tab_strip = new_browser->tab_strip_model();
ASSERT_EQ(1, tab_strip->count());
content::WebContents* web_contents = tab_strip->GetWebContentsAt(0);
content::TestNavigationObserver observer(web_contents, 1);
observer.Wait();
EXPECT_EQ(kWelcomeRemoteURL,
tab_strip->GetWebContentsAt(0)->GetURL().possibly_invalid_spec());
}

// Check wheter startup url is not welcome ui at second run.
IN_PROC_BROWSER_TEST_F(BraveWelcomeUIBrowserTest, StartupURLTest) {
Browser* new_browser = OpenNewBrowser(browser()->profile());
ASSERT_TRUE(new_browser);
TabStripModel* tab_strip = new_browser->tab_strip_model();
ASSERT_EQ(1, tab_strip->count());
content::WebContents* web_contents = tab_strip->GetWebContentsAt(0);
content::TestNavigationObserver observer(web_contents, 1);
observer.Wait();
EXPECT_EQ(chrome::kChromeUINewTabURL,
tab_strip->GetWebContentsAt(0)->GetURL().possibly_invalid_spec());
}
29 changes: 28 additions & 1 deletion test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,36 @@ group("brave_browser_tests_deps") {
]
}

static_library("browser_test_support") {
testonly = true
deps = [
"//chrome/test:test_support",
]

sources = [
"base/brave_test_launcher_delegate.cc",
"base/brave_test_launcher_delegate.h",
"//brave/app/brave_main_delegate.cc",
"//brave/app/brave_main_delegate.h",
]
}

static_library("browser_tests_runner") {
testonly = true

deps = [
":browser_test_support",
]

sources = [
"base/browser_tests_main.cc",
]
}

test("brave_browser_tests") {
sources = [
"//brave/browser/extensions/api/brave_shields_api_browsertest.cc",
"//brave/browser/ui/webui/brave_welcome_ui_browsertest.cc",
"//brave/components/brave_shields/browser/ad_block_service_browsertest.cc",
"//brave/components/brave_shields/browser/https_everywhere_service_browsertest.cc",
"//brave/components/brave_shields/browser/tracking_protection_service_browsertest.cc",
Expand All @@ -90,9 +117,9 @@ test("brave_browser_tests") {
defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
deps = [
"//chrome/browser/ui",
"//chrome/test:browser_tests_runner",
"//ppapi/buildflags",
":brave_browser_tests_deps",
":browser_tests_runner",
]
data_deps = [
"//ppapi:ppapi_tests",
Expand Down
18 changes: 18 additions & 0 deletions test/base/brave_test_launcher_delegate.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* 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/test/base/brave_test_launcher_delegate.h"

#include "brave/app/brave_main_delegate.h"

BraveTestLauncherDelegate::BraveTestLauncherDelegate(
ChromeTestSuiteRunner* runner)
: ChromeTestLauncherDelegate(runner) {}

BraveTestLauncherDelegate::~BraveTestLauncherDelegate() = default;

content::ContentMainDelegate*
BraveTestLauncherDelegate::CreateContentMainDelegate() {
return new BraveMainDelegate();
}
24 changes: 24 additions & 0 deletions test/base/brave_test_launcher_delegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* 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_TEST_BASE_BRAVE_TEST_LAUNCHER_H_
#define BRAVE_TEST_BASE_BRAVE_TEST_LAUNCHER_H_

#include "chrome/test/base/chrome_test_launcher.h"
#include "base/macros.h"

class BraveTestLauncherDelegate : public ChromeTestLauncherDelegate {
public:
// Does not take ownership of ChromeTestSuiteRunner.
explicit BraveTestLauncherDelegate(ChromeTestSuiteRunner* runner);
~BraveTestLauncherDelegate() override;

private:
// ChromeLauncherDelegate:
content::ContentMainDelegate* CreateContentMainDelegate() override;

DISALLOW_COPY_AND_ASSIGN(BraveTestLauncherDelegate);
};

#endif // BRAVE_TEST_BASE_BRAVE_TEST_LAUNCHER_H_
36 changes: 36 additions & 0 deletions test/base/browser_tests_main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* 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 "base/command_line.h"
#include "base/test/launcher/test_launcher.h"
#include "brave/test/base/brave_test_launcher_delegate.h"
#include "build/build_config.h"

#if defined(OS_WIN)
#include "base/test/test_switches.h"
#include "base/win/win_util.h"
#endif // defined(OS_WIN)

int main(int argc, char** argv) {
base::CommandLine::Init(argc, argv);
size_t parallel_jobs = base::NumParallelJobs();
if (parallel_jobs == 0U) {
return 1;
} else if (parallel_jobs > 1U) {
parallel_jobs /= 2U;
}

#if defined(OS_WIN)
// Enable high-DPI for interactive tests where the user is expected to
// manually verify results.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kTestLauncherInteractive)) {
base::win::EnableHighDPISupport();
}
#endif // defined(OS_WIN)

ChromeTestSuiteRunner runner;
BraveTestLauncherDelegate delegate(&runner);
return LaunchChromeTests(parallel_jobs, &delegate, argc, argv);
}