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

Side by Side Diff: chrome/browser/ui/startup/startup_browser_creator_browsertest.cc

Issue 16141008: Do not show sync promo when RestoreOnStartupURLs policy is set (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nit addressed. TODO added. Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/command_line.cc ('k') | chrome/browser/ui/startup/startup_browser_creator_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm>
6 #include <string>
7
5 #include "base/command_line.h" 8 #include "base/command_line.h"
6 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
7 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/extensions/extension_browsertest.h" 13 #include "chrome/browser/extensions/extension_browsertest.h"
10 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/extension_system.h" 15 #include "chrome/browser/extensions/extension_system.h"
12 #include "chrome/browser/first_run/first_run.h" 16 #include "chrome/browser/first_run/first_run.h"
13 #include "chrome/browser/infobars/infobar_service.h" 17 #include "chrome/browser/infobars/infobar_service.h"
14 #include "chrome/browser/prefs/session_startup_pref.h" 18 #include "chrome/browser/prefs/session_startup_pref.h"
15 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/profiles/profile_impl.h" 20 #include "chrome/browser/profiles/profile_impl.h"
17 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile_manager.h"
(...skipping 14 matching lines...) Expand all
32 #include "chrome/common/url_constants.h" 36 #include "chrome/common/url_constants.h"
33 #include "chrome/test/base/in_process_browser_test.h" 37 #include "chrome/test/base/in_process_browser_test.h"
34 #include "chrome/test/base/ui_test_utils.h" 38 #include "chrome/test/base/ui_test_utils.h"
35 #include "content/public/browser/web_contents.h" 39 #include "content/public/browser/web_contents.h"
36 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.h"
37 41
38 #if defined(ENABLE_MANAGED_USERS) 42 #if defined(ENABLE_MANAGED_USERS)
39 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" 43 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h"
40 #include "chrome/browser/managed_mode/managed_user_service.h" 44 #include "chrome/browser/managed_mode/managed_user_service.h"
41 #include "chrome/browser/managed_mode/managed_user_service_factory.h" 45 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
42 #endif 46 #endif // defined(ENABLE_MANAGED_USERS)
47
48 #if defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS)
49 #include "base/run_loop.h"
50 #include "base/values.h"
51 #include "chrome/browser/policy/browser_policy_connector.h"
52 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
53 #include "chrome/browser/policy/policy_map.h"
54 #include "chrome/browser/policy/policy_types.h"
55 #include "policy/policy_constants.h"
56 #include "testing/gmock/include/gmock/gmock.h"
57
58 using testing::_;
59 using testing::AnyNumber;
60 using testing::Return;
61 #endif // defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS)
43 62
44 using extensions::Extension; 63 using extensions::Extension;
45 64
46 namespace { 65 namespace {
47 66
48 // Check that there are two browsers. Find the one that is not |browser|. 67 // Check that there are two browsers. Find the one that is not |browser|.
49 Browser* FindOneOtherBrowser(Browser* browser) { 68 Browser* FindOneOtherBrowser(Browser* browser) {
50 // There should only be one other browser. 69 // There should only be one other browser.
51 EXPECT_EQ(2u, chrome::GetBrowserCount(browser->profile(), 70 EXPECT_EQ(2u, chrome::GetBrowserCount(browser->profile(),
52 browser->host_desktop_type())); 71 browser->host_desktop_type()));
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 981
963 // This should have created a new browser window. 982 // This should have created a new browser window.
964 Browser* new_browser = FindOneOtherBrowser(browser()); 983 Browser* new_browser = FindOneOtherBrowser(browser());
965 ASSERT_TRUE(new_browser); 984 ASSERT_TRUE(new_browser);
966 985
967 TabStripModel* tab_strip = new_browser->tab_strip_model(); 986 TabStripModel* tab_strip = new_browser->tab_strip_model();
968 // There should be only one tab. 987 // There should be only one tab.
969 EXPECT_EQ(1, tab_strip->count()); 988 EXPECT_EQ(1, tab_strip->count());
970 } 989 }
971 990
972 #endif // ENABLE_MANAGED_USERS 991 #endif // defined(ENABLE_MANAGED_USERS)
973 992
974 #endif // !OS_CHROMEOS 993 #endif // !defined(OS_CHROMEOS)
994
995 // These tests are not applicable to Chrome OS as neither master_preferences nor
996 // the sync promo exist there.
997 #if !defined(OS_CHROMEOS)
998
999 // On a branded Linux build, policy is required to suppress the first-run
1000 // dialog.
1001 #if !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) || \
1002 defined(ENABLE_CONFIGURATION_POLICY)
1003
1004 class StartupBrowserCreatorFirstRunTest : public InProcessBrowserTest {
1005 protected:
1006 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
1007
1008 #if defined(ENABLE_CONFIGURATION_POLICY)
1009 policy::MockConfigurationPolicyProvider provider_;
1010 policy::PolicyMap policy_map_;
1011 #endif // defined(ENABLE_CONFIGURATION_POLICY)
1012 };
1013
1014 void StartupBrowserCreatorFirstRunTest::SetUpInProcessBrowserTestFixture() {
1015 // Remove the --no-first-run flag from the command line.
1016 CommandLine* command_line = CommandLine::ForCurrentProcess();
1017 CommandLine::StringVector argv = command_line->argv();
1018 const std::string first_run_flag = std::string("--") + switches::kNoFirstRun;
1019 #if defined(OS_WIN)
1020 argv.erase(std::find(argv.begin(), argv.end(), ASCIIToWide(first_run_flag)));
1021 #else
1022 argv.erase(std::find(argv.begin(), argv.end(), first_run_flag));
1023 #endif
1024 command_line->InitFromArgv(argv);
1025
1026 #if defined(ENABLE_CONFIGURATION_POLICY)
1027 #if defined(OS_LINUX) && defined(GOOGLE_CHROME_BUILD)
1028 // Set a policy that prevents the first-run dialog from being shown.
1029 policy_map_.Set(policy::key::kMetricsReportingEnabled,
1030 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
1031 base::Value::CreateBooleanValue(false));
1032 provider_.UpdateChromePolicy(policy_map_);
1033 #endif // defined(OS_LINUX) && defined(GOOGLE_CHROME_BUILD)
1034
1035 EXPECT_CALL(provider_, IsInitializationComplete(_))
1036 .WillRepeatedly(Return(true));
1037 EXPECT_CALL(provider_, RegisterPolicyDomain(_)).Times(AnyNumber());
1038 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_);
1039 #endif // defined(ENABLE_CONFIGURATION_POLICY)
1040 }
1041
1042 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest, SyncPromoForbidden) {
1043 // Consistently enable the welcome page on all platforms.
1044 first_run::SetShouldShowWelcomePage();
1045
1046 // Simulate the following master_preferences:
1047 // {
1048 // "sync_promo": {
1049 // "show_on_first_run_allowed": false
1050 // }
1051 // }
1052 StartupBrowserCreator browser_creator;
1053 browser()->profile()->GetPrefs()->SetBoolean(
1054 prefs::kSyncPromoShowOnFirstRunAllowed, false);
1055
1056 // Do a process-startup browser launch.
1057 CommandLine dummy(CommandLine::NO_PROGRAM);
1058 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
1059 chrome::startup::IS_FIRST_RUN);
1060 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), true,
1061 browser()->host_desktop_type()));
1062
1063 // This should have created a new browser window.
1064 Browser* new_browser = FindOneOtherBrowser(browser());
1065 ASSERT_TRUE(new_browser);
1066
1067 // Verify that the NTP and the welcome page are shown.
1068 TabStripModel* tab_strip = new_browser->tab_strip_model();
1069 ASSERT_EQ(2, tab_strip->count());
1070 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
1071 tab_strip->GetWebContentsAt(0)->GetURL());
1072 EXPECT_EQ(internals::GetWelcomePageURL(),
1073 tab_strip->GetWebContentsAt(1)->GetURL());
1074 }
1075
1076 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest, SyncPromoAllowed) {
1077 // Consistently enable the welcome page on all platforms.
1078 first_run::SetShouldShowWelcomePage();
1079
1080 // Simulate the following master_preferences:
1081 // {
1082 // "sync_promo": {
1083 // "show_on_first_run_allowed": true
1084 // }
1085 // }
1086 StartupBrowserCreator browser_creator;
1087 browser()->profile()->GetPrefs()->SetBoolean(
1088 prefs::kSyncPromoShowOnFirstRunAllowed, true);
1089
1090 // Do a process-startup browser launch.
1091 CommandLine dummy(CommandLine::NO_PROGRAM);
1092 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
1093 chrome::startup::IS_FIRST_RUN);
1094 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), true,
1095 browser()->host_desktop_type()));
1096
1097 // This should have created a new browser window.
1098 Browser* new_browser = FindOneOtherBrowser(browser());
1099 ASSERT_TRUE(new_browser);
1100
1101 // Verify that the sync promo and the welcome page are shown.
1102 TabStripModel* tab_strip = new_browser->tab_strip_model();
1103 ASSERT_EQ(2, tab_strip->count());
1104 EXPECT_EQ("accounts.google.com",
1105 tab_strip->GetWebContentsAt(0)->GetURL().host());
1106 EXPECT_EQ(internals::GetWelcomePageURL(),
1107 tab_strip->GetWebContentsAt(1)->GetURL());
1108 }
1109
1110 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
1111 FirstRunTabsPromoAllowed) {
1112 // Simulate the following master_preferences:
1113 // {
1114 // "first_run_tabs" : [
1115 // "files/title1.html"
1116 // ],
1117 // "sync_promo": {
1118 // "show_on_first_run_allowed": true
1119 // }
1120 // }
1121 StartupBrowserCreator browser_creator;
1122 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
1123 browser()->profile()->GetPrefs()->SetBoolean(
1124 prefs::kSyncPromoShowOnFirstRunAllowed, true);
1125
1126 // Do a process-startup browser launch.
1127 CommandLine dummy(CommandLine::NO_PROGRAM);
1128 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
1129 chrome::startup::IS_FIRST_RUN);
1130 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), true,
1131 browser()->host_desktop_type()));
1132
1133 // This should have created a new browser window.
1134 Browser* new_browser = FindOneOtherBrowser(browser());
1135 ASSERT_TRUE(new_browser);
1136
1137 // Verify that the first-run tab is shown and the sync promo has been added.
1138 TabStripModel* tab_strip = new_browser->tab_strip_model();
1139 ASSERT_EQ(2, tab_strip->count());
1140 EXPECT_EQ("accounts.google.com",
1141 tab_strip->GetWebContentsAt(0)->GetURL().host());
1142 EXPECT_EQ("title1.html",
1143 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName());
1144 }
1145
1146 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
1147 FirstRunTabsContainSyncPromo) {
1148 // Simulate the following master_preferences:
1149 // {
1150 // "first_run_tabs" : [
1151 // "files/title1.html",
1152 // "chrome://signin/?source=0&next_page=chrome%3A%2F%2Fnewtab%2F"
1153 // ],
1154 // "sync_promo": {
1155 // "show_on_first_run_allowed": true
1156 // }
1157 // }
1158 StartupBrowserCreator browser_creator;
1159 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
1160 browser_creator.AddFirstRunTab(SyncPromoUI::GetSyncPromoURL(
1161 SyncPromoUI::SOURCE_START_PAGE,
1162 false));
1163 browser()->profile()->GetPrefs()->SetBoolean(
1164 prefs::kSyncPromoShowOnFirstRunAllowed, true);
1165
1166 // Do a process-startup browser launch.
1167 CommandLine dummy(CommandLine::NO_PROGRAM);
1168 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
1169 chrome::startup::IS_FIRST_RUN);
1170 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), true,
1171 browser()->host_desktop_type()));
1172
1173 // This should have created a new browser window.
1174 Browser* new_browser = FindOneOtherBrowser(browser());
1175 ASSERT_TRUE(new_browser);
1176
1177 // Verify that the first-run tabs are shown and no sync promo has been added
1178 // as the first-run tabs contain it already.
1179 TabStripModel* tab_strip = new_browser->tab_strip_model();
1180 ASSERT_EQ(2, tab_strip->count());
1181 EXPECT_EQ("title1.html",
1182 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName());
1183 EXPECT_EQ("accounts.google.com",
1184 tab_strip->GetWebContentsAt(1)->GetURL().host());
1185 }
1186
1187 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
1188 FirstRunTabsContainNTPSyncPromoAllowed) {
1189 // Simulate the following master_preferences:
1190 // {
1191 // "first_run_tabs" : [
1192 // "new_tab_page",
1193 // "files/title1.html"
1194 // ],
1195 // "sync_promo": {
1196 // "show_on_first_run_allowed": true
1197 // }
1198 // }
1199 StartupBrowserCreator browser_creator;
1200 browser_creator.AddFirstRunTab(GURL("new_tab_page"));
1201 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
1202 browser()->profile()->GetPrefs()->SetBoolean(
1203 prefs::kSyncPromoShowOnFirstRunAllowed, true);
1204
1205 // Do a process-startup browser launch.
1206 CommandLine dummy(CommandLine::NO_PROGRAM);
1207 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
1208 chrome::startup::IS_FIRST_RUN);
1209 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), true,
1210 browser()->host_desktop_type()));
1211
1212 // This should have created a new browser window.
1213 Browser* new_browser = FindOneOtherBrowser(browser());
1214 ASSERT_TRUE(new_browser);
1215
1216 // Verify that the first-run tabs are shown but the NTP that they contain has
1217 // been replaced by the sync promo.
1218 TabStripModel* tab_strip = new_browser->tab_strip_model();
1219 ASSERT_EQ(2, tab_strip->count());
1220 EXPECT_EQ("accounts.google.com",
1221 tab_strip->GetWebContentsAt(0)->GetURL().host());
1222 EXPECT_EQ("title1.html",
1223 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName());
1224 }
1225
1226 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
1227 FirstRunTabsContainNTPSyncPromoForbidden) {
1228 // Simulate the following master_preferences:
1229 // {
1230 // "first_run_tabs" : [
1231 // "new_tab_page",
1232 // "files/title1.html"
1233 // ],
1234 // "sync_promo": {
1235 // "show_on_first_run_allowed": false
1236 // }
1237 // }
1238 StartupBrowserCreator browser_creator;
1239 browser_creator.AddFirstRunTab(GURL("new_tab_page"));
1240 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
1241 browser()->profile()->GetPrefs()->SetBoolean(
1242 prefs::kSyncPromoShowOnFirstRunAllowed, false);
1243
1244 // Do a process-startup browser launch.
1245 CommandLine dummy(CommandLine::NO_PROGRAM);
1246 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
1247 chrome::startup::IS_FIRST_RUN);
1248 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), true,
1249 browser()->host_desktop_type()));
1250
1251 // This should have created a new browser window.
1252 Browser* new_browser = FindOneOtherBrowser(browser());
1253 ASSERT_TRUE(new_browser);
1254
1255 // Verify that the first-run tabs are shown, the NTP that they contain has not
1256 // not been replaced by the sync promo and no sync promo has been added.
1257 TabStripModel* tab_strip = new_browser->tab_strip_model();
1258 ASSERT_EQ(2, tab_strip->count());
1259 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
1260 tab_strip->GetWebContentsAt(0)->GetURL());
1261 EXPECT_EQ("title1.html",
1262 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName());
1263 }
1264
1265 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
1266 FirstRunTabsSyncPromoForbidden) {
1267 // Simulate the following master_preferences:
1268 // {
1269 // "first_run_tabs" : [
1270 // "files/title1.html"
1271 // ],
1272 // "sync_promo": {
1273 // "show_on_first_run_allowed": false
1274 // }
1275 // }
1276 StartupBrowserCreator browser_creator;
1277 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
1278 browser()->profile()->GetPrefs()->SetBoolean(
1279 prefs::kSyncPromoShowOnFirstRunAllowed, false);
1280
1281 // Do a process-startup browser launch.
1282 CommandLine dummy(CommandLine::NO_PROGRAM);
1283 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
1284 chrome::startup::IS_FIRST_RUN);
1285 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), true,
1286 browser()->host_desktop_type()));
1287
1288 // This should have created a new browser window.
1289 Browser* new_browser = FindOneOtherBrowser(browser());
1290 ASSERT_TRUE(new_browser);
1291
1292 // Verify that the first-run tab is shown and no sync promo has been added.
1293 TabStripModel* tab_strip = new_browser->tab_strip_model();
1294 ASSERT_EQ(1, tab_strip->count());
1295 EXPECT_EQ("title1.html",
1296 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName());
1297 }
1298
1299 #if defined(ENABLE_CONFIGURATION_POLICY)
1300 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest,
1301 RestoreOnStartupURLsPolicySpecified) {
1302 // Simulate the following master_preferences:
1303 // {
1304 // "sync_promo": {
1305 // "show_on_first_run_allowed": true
1306 // }
1307 // }
1308 StartupBrowserCreator browser_creator;
1309 browser()->profile()->GetPrefs()->SetBoolean(
1310 prefs::kSyncPromoShowOnFirstRunAllowed, true);
1311
1312 // Set the following user policies:
1313 // * RestoreOnStartup = RestoreOnStartupIsURLs
1314 // * RestoreOnStartupURLs = [ "files/title1.html" ]
1315 policy_map_.Set(policy::key::kRestoreOnStartup,
1316 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
1317 base::Value::CreateIntegerValue(
1318 SessionStartupPref::kPrefValueURLs));
1319 base::ListValue startup_urls;
1320 startup_urls.Append(base::Value::CreateStringValue(
1321 test_server()->GetURL("files/title1.html").spec()));
1322 policy_map_.Set(policy::key::kRestoreOnStartupURLs,
1323 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
1324 startup_urls.DeepCopy());
1325 provider_.UpdateChromePolicy(policy_map_);
1326 base::RunLoop().RunUntilIdle();
1327
1328 // Do a process-startup browser launch.
1329 CommandLine dummy(CommandLine::NO_PROGRAM);
1330 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
1331 chrome::startup::IS_FIRST_RUN);
1332 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), true,
1333 browser()->host_desktop_type()));
1334
1335 // This should have created a new browser window.
1336 Browser* new_browser = FindOneOtherBrowser(browser());
1337 ASSERT_TRUE(new_browser);
1338
1339 // Verify that the URL specified through policy is shown and no sync promo has
1340 // been added.
1341 TabStripModel* tab_strip = new_browser->tab_strip_model();
1342 ASSERT_EQ(1, tab_strip->count());
1343 EXPECT_EQ("title1.html",
1344 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName());
1345 }
1346 #endif // defined(ENABLE_CONFIGURATION_POLICY)
1347
1348 #endif // !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) ||
1349 // defined(ENABLE_CONFIGURATION_POLICY)
1350
1351 #endif // !defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « base/command_line.cc ('k') | chrome/browser/ui/startup/startup_browser_creator_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698