Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Unified Diff: chrome/browser/ui/startup/startup_browser_creator_browsertest.cc

Issue 1226643002: Welcome page changes for Windows 10 and over. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: simplified recording of welcome run complete Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/startup/startup_browser_creator_browsertest.cc
diff --git a/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc b/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc
index 1e1a055a550f0f221d0f53349bfb6dc77de50fcb..d4a8996016ae36f83443fa9496161b34e6ca25f0 100644
--- a/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc
+++ b/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc
@@ -42,6 +42,7 @@
#include "chrome/test/base/test_switches.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_system.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
@@ -68,6 +69,10 @@ using testing::Return;
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#endif
+#if defined(OS_WIN)
+#include "base/win/windows_version.h"
+#endif
+
using extensions::Extension;
namespace {
@@ -87,6 +92,33 @@ Browser* FindOneOtherBrowser(Browser* browser) {
return other_browser;
}
+bool IsWindows10OrNewer() {
+#if defined(OS_WIN)
+ return base::win::GetVersion() >= base::win::VERSION_WIN10;
+#else
+ return false;
+#endif
+}
+
+// Returns true if the platform supports showing the sync promo on first run.
+bool PlatformSupportsSyncPromo() {
+ return !IsWindows10OrNewer();
+}
+
+// Returns the index of the welcome page for normal first-run startup.
+// Ordinarily it is the second tab. It is the first tab for platforms that do
+// not show the sync promo on first run.
+int GetWelcomePageIndex() {
+ return PlatformSupportsSyncPromo() ? 1 : 0;
+}
+
+// Returns the index of the NTP/sync promo for normal first-run startup.
+// Ordinarily it is the first tab. It is the second tab for platforms that do
+// not show the sync promo on first run.
+int GetNTPIndex() {
+ return PlatformSupportsSyncPromo() ? 0 : 1;
+}
+
} // namespace
class StartupBrowserCreatorTest : public ExtensionBrowserTest {
@@ -211,10 +243,16 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest,
urls.push_back(test_server()->GetURL("files/title1.html"));
urls.push_back(test_server()->GetURL("files/title2.html"));
+ Profile* profile = browser()->profile();
+ chrome::HostDesktopType host_desktop_type = browser()->host_desktop_type();
+
// Set the startup preference to open these URLs.
SessionStartupPref pref(SessionStartupPref::URLS);
pref.urls = urls;
- SessionStartupPref::SetStartupPref(browser()->profile(), pref);
+ SessionStartupPref::SetStartupPref(profile, pref);
+
+ // Keep the browser process running while browsers are closed.
+ g_browser_process->AddRefModule();
// Close the browser.
browser()->window()->Close();
@@ -223,26 +261,71 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest,
base::CommandLine dummy(base::CommandLine::NO_PROGRAM);
chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
- StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run);
- ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false,
- browser()->host_desktop_type()));
+ {
+ StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run);
+ ASSERT_TRUE(
+ launch.Launch(profile, std::vector<GURL>(), false, host_desktop_type));
+ }
// This should have created a new browser window. |browser()| is still
// around at this point, even though we've closed its window.
Browser* new_browser = FindOneOtherBrowser(browser());
ASSERT_TRUE(new_browser);
- // The new browser should have one tab for each URL.
- TabStripModel* tab_strip = new_browser->tab_strip_model();
- ASSERT_EQ(static_cast<int>(urls.size()), tab_strip->count());
- for (size_t i=0; i < urls.size(); i++) {
- EXPECT_EQ(urls[i], tab_strip->GetWebContentsAt(i)->GetURL());
+ if (IsWindows10OrNewer()) {
msw 2015/07/10 22:07:31 Just add the welcome page url to the front of |url
grt (UTC plus 2) 2015/07/11 12:16:08 Done.
+ // The new browser should have the welcome tab and one tab for each URL.
+ TabStripModel* tab_strip = new_browser->tab_strip_model();
+ ASSERT_EQ(static_cast<int>(urls.size()) + 1, tab_strip->count());
+ EXPECT_EQ(internals::GetWelcomePageURL(),
+ tab_strip->GetWebContentsAt(0)->GetURL());
+ for (size_t i = 0; i < urls.size(); i++) {
msw 2015/07/10 22:07:31 nit: curly braces aren't needed
grt (UTC plus 2) 2015/07/11 12:16:07 Done.
+ EXPECT_EQ(urls[i], tab_strip->GetWebContentsAt(i + 1)->GetURL());
+ }
+ } else {
+ // The new browser should have one tab for each URL.
+ TabStripModel* tab_strip = new_browser->tab_strip_model();
+ ASSERT_EQ(static_cast<int>(urls.size()), tab_strip->count());
+ for (size_t i = 0; i < urls.size(); i++) {
msw 2015/07/10 22:07:31 nit: curly braces aren't needed
grt (UTC plus 2) 2015/07/11 12:16:07 Done.
+ EXPECT_EQ(urls[i], tab_strip->GetWebContentsAt(i)->GetURL());
+ }
+
+ // The two tabs, despite having the same site, should be in different
+ // SiteInstances.
+ EXPECT_NE(tab_strip->GetWebContentsAt(0)->GetSiteInstance(),
msw 2015/07/10 22:07:31 This isn't checked in the windows 10 case, but pro
grt (UTC plus 2) 2015/07/11 12:16:08 Done.
+ tab_strip->GetWebContentsAt(1)->GetSiteInstance());
+ }
+
+ // The test is complete if the welcome page wasn't included above.
msw 2015/07/10 22:07:32 Run the remaining checks regardless? the expectati
grt (UTC plus 2) 2015/07/11 12:16:07 Done.
+ if (!IsWindows10OrNewer()) {
+ g_browser_process->ReleaseModule();
+ return;
}
- // The two tabs, despite having the same site, should be in different
- // SiteInstances.
- EXPECT_NE(tab_strip->GetWebContentsAt(0)->GetSiteInstance(),
- tab_strip->GetWebContentsAt(1)->GetSiteInstance());
+ // Close the browser opened above.
+ {
+ content::WindowedNotificationObserver observer(
+ chrome::NOTIFICATION_BROWSER_CLOSED,
+ content::Source<Browser>(new_browser));
+ new_browser->window()->Close();
+ observer.Wait();
+ }
+
+ // Try again to ensure that the welcome page isn't shown the second time.
+ {
+ StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run);
+ ASSERT_TRUE(
+ launch.Launch(profile, std::vector<GURL>(), false, host_desktop_type));
+ }
+
+ // Find the new browser and ensure that it has only the expected URLs this
msw 2015/07/10 22:07:31 nit: s/expected/specified/
grt (UTC plus 2) 2015/07/11 12:16:07 Done.
+ // time. Both the original browser created by the fixture and the one created
+ // above have been closed, so the new browser is the only one remaining.
+ new_browser = FindTabbedBrowser(profile, true, host_desktop_type);
+ ASSERT_TRUE(new_browser);
+ ASSERT_EQ(static_cast<int>(urls.size()),
+ new_browser->tab_strip_model()->count());
+
+ g_browser_process->ReleaseModule();
}
// Verify that startup URLs aren't used when the process already exists
@@ -268,15 +351,47 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest,
base::CommandLine dummy(base::CommandLine::NO_PROGRAM);
chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
- StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run);
- ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false,
- browser()->host_desktop_type()));
+ {
+ StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run);
+ ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false,
+ browser()->host_desktop_type()));
+ }
// This should have created a new browser window.
Browser* new_browser = FindOneOtherBrowser(browser());
ASSERT_TRUE(new_browser);
- // The new browser should have exactly one tab (not the startup URLs).
+ if (IsWindows10OrNewer()) {
+ // The new browser should have two tabs (not the startup URLs).
+ ASSERT_EQ(2, new_browser->tab_strip_model()->count());
+ } else {
+ // The new browser should have exactly one tab (not the startup URLs).
+ ASSERT_EQ(1, new_browser->tab_strip_model()->count());
+ }
+
+ // The test is complete if the welcome page wasn't included above.
msw 2015/07/10 22:07:31 Ditto, run the rest regardless...
grt (UTC plus 2) 2015/07/11 12:16:07 Done.
+ if (!IsWindows10OrNewer())
+ return;
+
+ // Close the browser opened above.
+ {
+ content::WindowedNotificationObserver observer(
+ chrome::NOTIFICATION_BROWSER_CLOSED,
+ content::Source<Browser>(new_browser));
+ new_browser->window()->Close();
+ observer.Wait();
+ }
+
+ // Try again to ensure that the welcome page isn't shown the second time.
+ {
+ StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run);
+ ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false,
+ browser()->host_desktop_type()));
+ }
+
+ // Find the new browser and ensure that it has only the one tab this time.
+ new_browser = FindOneOtherBrowser(browser());
+ ASSERT_TRUE(new_browser);
ASSERT_EQ(1, new_browser->tab_strip_model()->count());
}
@@ -484,12 +599,22 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, SyncPromoNoWelcomePage) {
ASSERT_TRUE(new_browser);
TabStripModel* tab_strip = new_browser->tab_strip_model();
- EXPECT_EQ(1, tab_strip->count());
if (signin::ShouldShowPromoAtStartup(browser()->profile(), true)) {
+ // The browser should show only the promo.
+ ASSERT_EQ(1, tab_strip->count());
EXPECT_EQ(signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false),
tab_strip->GetWebContentsAt(0)->GetURL());
+ } else if (IsWindows10OrNewer()) {
+ // The browser should show the welcome page and the NTP.
+ ASSERT_EQ(2, tab_strip->count());
+ EXPECT_EQ(GURL(internals::GetWelcomePageURL()),
+ tab_strip->GetWebContentsAt(0)->GetURL());
+ EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
+ tab_strip->GetWebContentsAt(1)->GetURL());
} else {
+ // The browser should show only the NTP.
+ ASSERT_EQ(1, tab_strip->count());
EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
tab_strip->GetWebContentsAt(0)->GetURL());
}
@@ -514,13 +639,13 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, SyncPromoWithWelcomePage) {
if (signin::ShouldShowPromoAtStartup(browser()->profile(), true)) {
EXPECT_EQ(signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false),
- tab_strip->GetWebContentsAt(0)->GetURL());
+ tab_strip->GetWebContentsAt(GetNTPIndex())->GetURL());
msw 2015/07/10 22:07:31 If ShouldShowPromoAtStartup was true, are we guara
grt (UTC plus 2) 2015/07/11 12:16:08 Done
} else {
EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
- tab_strip->GetWebContentsAt(0)->GetURL());
+ tab_strip->GetWebContentsAt(GetNTPIndex())->GetURL());
}
EXPECT_EQ(internals::GetWelcomePageURL(),
- tab_strip->GetWebContentsAt(1)->GetURL());
+ tab_strip->GetWebContentsAt(GetWelcomePageIndex())->GetURL());
}
IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, SyncPromoWithFirstRunTabs) {
@@ -654,8 +779,17 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, StartupURLsForTwoProfiles) {
new_browser = FindOneOtherBrowserForProfile(default_profile, browser());
ASSERT_TRUE(new_browser);
TabStripModel* tab_strip = new_browser->tab_strip_model();
- ASSERT_EQ(1, tab_strip->count());
- EXPECT_EQ(urls1[0], tab_strip->GetWebContentsAt(0)->GetURL());
+ if (IsWindows10OrNewer()) {
+ // The new browser should have the welcome tab and the URL for the profile.
+ ASSERT_EQ(2, tab_strip->count());
+ EXPECT_EQ(GURL(internals::GetWelcomePageURL()),
+ tab_strip->GetWebContentsAt(0)->GetURL());
+ EXPECT_EQ(urls1[0], tab_strip->GetWebContentsAt(1)->GetURL());
+ } else {
+ // The new browser should have only the desired URL for the profile.
+ ASSERT_EQ(1, tab_strip->count());
+ EXPECT_EQ(urls1[0], tab_strip->GetWebContentsAt(0)->GetURL());
+ }
ASSERT_EQ(1u, chrome::GetBrowserCount(other_profile,
browser()->host_desktop_type()));
@@ -874,14 +1008,25 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest,
Browser* new_browser = NULL;
// The last open profile (the profile_home1 in this case) will always be
- // launched, even if it will open just the home page.
+ // launched, even if it will open just the NTP (and the welcome page on
+ // relevant platforms).
ASSERT_EQ(1u, chrome::GetBrowserCount(profile_home1, original_desktop_type));
new_browser = FindOneOtherBrowserForProfile(profile_home1, NULL);
ASSERT_TRUE(new_browser);
TabStripModel* tab_strip = new_browser->tab_strip_model();
- ASSERT_EQ(1, tab_strip->count());
- EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
- tab_strip->GetWebContentsAt(0)->GetURL());
+ if (IsWindows10OrNewer()) {
+ // The new browser should have the welcome tab and the NTP.
+ ASSERT_EQ(2, tab_strip->count());
+ EXPECT_EQ(GURL(internals::GetWelcomePageURL()),
+ tab_strip->GetWebContentsAt(0)->GetURL());
+ EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
+ tab_strip->GetWebContentsAt(1)->GetURL());
+ } else {
+ // The new browser should have only the NTP.
+ ASSERT_EQ(1, tab_strip->count());
+ EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
+ tab_strip->GetWebContentsAt(0)->GetURL());
+ }
// profile_urls opened the urls.
ASSERT_EQ(1u, chrome::GetBrowserCount(profile_urls, original_desktop_type));
@@ -987,16 +1132,27 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, ProfilesLaunchedAfterCrash) {
EXPECT_FALSE(SessionRestore::IsRestoring(profile_urls));
// The profile which normally opens the home page displays the new tab page.
+ // The welcome page is also shown for relevant platforms.
Browser* new_browser = NULL;
ASSERT_EQ(1u, chrome::GetBrowserCount(profile_home,
browser()->host_desktop_type()));
new_browser = FindOneOtherBrowserForProfile(profile_home, NULL);
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);
- EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), web_contents->GetURL());
- EnsureRestoreUIWasShown(web_contents);
+ if (IsWindows10OrNewer()) {
+ // The new browser should have the welcome tab and the NTP.
+ ASSERT_EQ(2, tab_strip->count());
+ EXPECT_EQ(GURL(internals::GetWelcomePageURL()),
+ tab_strip->GetWebContentsAt(0)->GetURL());
+ EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
+ tab_strip->GetWebContentsAt(1)->GetURL());
+ } else {
+ // The new browser should have only the NTP.
+ ASSERT_EQ(1, tab_strip->count());
+ EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
+ tab_strip->GetWebContentsAt(0)->GetURL());
+ }
+ EnsureRestoreUIWasShown(tab_strip->GetWebContentsAt(0));
// The profile which normally opens last open pages displays the new tab page.
ASSERT_EQ(1u, chrome::GetBrowserCount(profile_last,
@@ -1005,9 +1161,9 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, ProfilesLaunchedAfterCrash) {
ASSERT_TRUE(new_browser);
tab_strip = new_browser->tab_strip_model();
ASSERT_EQ(1, tab_strip->count());
- web_contents = tab_strip->GetWebContentsAt(0);
- EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), web_contents->GetURL());
- EnsureRestoreUIWasShown(web_contents);
+ EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
+ tab_strip->GetWebContentsAt(0)->GetURL());
+ EnsureRestoreUIWasShown(tab_strip->GetWebContentsAt(0));
// The profile which normally opens URLs displays the new tab page.
ASSERT_EQ(1u, chrome::GetBrowserCount(profile_urls,
@@ -1016,9 +1172,9 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, ProfilesLaunchedAfterCrash) {
ASSERT_TRUE(new_browser);
tab_strip = new_browser->tab_strip_model();
ASSERT_EQ(1, tab_strip->count());
- web_contents = tab_strip->GetWebContentsAt(0);
- EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), web_contents->GetURL());
- EnsureRestoreUIWasShown(web_contents);
+ EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
+ tab_strip->GetWebContentsAt(0)->GetURL());
+ EnsureRestoreUIWasShown(tab_strip->GetWebContentsAt(0));
#if !defined(OS_MACOSX) && !defined(GOOGLE_CHROME_BUILD)
// Each profile should have one session restore bubble shown, so we should
@@ -1139,9 +1295,9 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
TabStripModel* tab_strip = new_browser->tab_strip_model();
ASSERT_EQ(2, tab_strip->count());
EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
- tab_strip->GetWebContentsAt(0)->GetURL());
+ tab_strip->GetWebContentsAt(GetNTPIndex())->GetURL());
EXPECT_EQ(internals::GetWelcomePageURL(),
- tab_strip->GetWebContentsAt(1)->GetURL());
+ tab_strip->GetWebContentsAt(GetWelcomePageIndex())->GetURL());
}
#if defined(GOOGLE_CHROME_BUILD) && defined(OS_MACOSX)
@@ -1152,6 +1308,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
#endif
IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
MAYBE_SyncPromoAllowed) {
+ if (!PlatformSupportsSyncPromo())
+ return;
// Consistently enable the welcome page on all platforms.
first_run::SetShouldShowWelcomePage();
@@ -1193,6 +1351,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
#endif
IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
MAYBE_FirstRunTabsPromoAllowed) {
+ if (!PlatformSupportsSyncPromo())
+ return;
// Simulate the following master_preferences:
// {
// "first_run_tabs" : [
@@ -1236,6 +1396,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
#endif
IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
MAYBE_FirstRunTabsContainSyncPromo) {
+ if (!PlatformSupportsSyncPromo())
+ return;
// Simulate the following master_preferences:
// {
// "first_run_tabs" : [
@@ -1285,6 +1447,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
#endif
IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
MAYBE_FirstRunTabsContainNTPSyncPromoAllowed) {
+ if (!PlatformSupportsSyncPromo())
+ return;
// Simulate the following master_preferences:
// {
// "first_run_tabs" : [
@@ -1332,6 +1496,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
#endif
IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
MAYBE_FirstRunTabsContainNTPSyncPromoForbidden) {
+ if (!PlatformSupportsSyncPromo())
+ return;
// Simulate the following master_preferences:
// {
// "first_run_tabs" : [
@@ -1378,6 +1544,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
#endif
IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
MAYBE_FirstRunTabsSyncPromoForbidden) {
+ if (!PlatformSupportsSyncPromo())
+ return;
// Simulate the following master_preferences:
// {
// "first_run_tabs" : [
@@ -1421,6 +1589,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
#endif
IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
MAYBE_RestoreOnStartupURLsPolicySpecified) {
+ if (!PlatformSupportsSyncPromo())
+ return;
// Simulate the following master_preferences:
// {
// "sync_promo": {

Powered by Google App Engine
This is Rietveld 408576698