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

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

Issue 1349163008: Setting chrome as the default browser is now fixed on Windows 10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added detailed metrics Created 5 years, 2 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
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> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 93 }
94 94
95 bool IsWindows10OrNewer() { 95 bool IsWindows10OrNewer() {
96 #if defined(OS_WIN) 96 #if defined(OS_WIN)
97 return base::win::GetVersion() >= base::win::VERSION_WIN10; 97 return base::win::GetVersion() >= base::win::VERSION_WIN10;
98 #else 98 #else
99 return false; 99 return false;
100 #endif 100 #endif
101 } 101 }
102 102
103 // This function is used to verify a callback was successfully invoked.
104 void SetTrue(bool* value) {
105 ASSERT_TRUE(value);
106 *value = true;
107 }
108
109 bool TabStripContainsUrl(TabStripModel* tab_strip, GURL url) {
110 for (int i = 0; i < tab_strip->count(); ++i) {
111 if (tab_strip->GetWebContentsAt(i)->GetURL() == url)
112 return true;
113 }
114 return false;
115 }
116
117 void ProcessCommandLineAlreadyRunningDefaultProfile(
118 const base::CommandLine& cmdline) {
119 StartupBrowserCreator browser_creator;
120
121 base::FilePath current_dir;
122 ASSERT_TRUE(base::GetCurrentDirectory(&current_dir));
123 base::FilePath user_data_dir =
124 g_browser_process->profile_manager()->user_data_dir();
125 base::FilePath startup_profile_dir =
126 g_browser_process->profile_manager()->GetLastUsedProfileDir(
127 user_data_dir);
128
129 browser_creator.ProcessCommandLineAlreadyRunning(cmdline, current_dir,
130 startup_profile_dir);
131 }
132
103 } // namespace 133 } // namespace
104 134
105 class StartupBrowserCreatorTest : public ExtensionBrowserTest { 135 class StartupBrowserCreatorTest : public ExtensionBrowserTest {
106 protected: 136 protected:
107 StartupBrowserCreatorTest() {} 137 StartupBrowserCreatorTest() {}
108 138
109 bool SetUpUserDataDirectory() override { 139 bool SetUpUserDataDirectory() override {
110 return ExtensionBrowserTest::SetUpUserDataDirectory(); 140 return ExtensionBrowserTest::SetUpUserDataDirectory();
111 } 141 }
112 142
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 tab_strip->GetWebContentsAt(0)->GetURL()); 1183 tab_strip->GetWebContentsAt(0)->GetURL());
1154 EnsureRestoreUIWasShown(tab_strip->GetWebContentsAt(0)); 1184 EnsureRestoreUIWasShown(tab_strip->GetWebContentsAt(0));
1155 1185
1156 #if !defined(OS_MACOSX) && !defined(GOOGLE_CHROME_BUILD) 1186 #if !defined(OS_MACOSX) && !defined(GOOGLE_CHROME_BUILD)
1157 // Each profile should have one session restore bubble shown, so we should 1187 // Each profile should have one session restore bubble shown, so we should
1158 // observe count 3 in bucket 0 (which represents bubble shown). 1188 // observe count 3 in bucket 0 (which represents bubble shown).
1159 histogram_tester.ExpectBucketCount("SessionCrashed.Bubble", 0, 3); 1189 histogram_tester.ExpectBucketCount("SessionCrashed.Bubble", 0, 3);
1160 #endif // !defined(OS_MACOSX) && !defined(GOOGLE_CHROME_BUILD) 1190 #endif // !defined(OS_MACOSX) && !defined(GOOGLE_CHROME_BUILD)
1161 } 1191 }
1162 1192
1193 #if defined(OS_WIN)
1194 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, DefaultBrowserCallback) {
1195 bool callback_called = false;
1196
1197 // Set the default browser callback.
1198 StartupBrowserCreator::SetDefaultBrowserCallback(
1199 base::Bind(&SetTrue, &callback_called));
1200
1201 // Set the command line to open the default browser url.
1202 base::CommandLine cmdline(base::CommandLine::NO_PROGRAM);
1203 cmdline.AppendArgNative(StartupBrowserCreator::GetDefaultBrowserUrl());
1204
1205 // Open url.
1206 ProcessCommandLineAlreadyRunningDefaultProfile(cmdline);
1207
1208 // The url should have been intercepted and the callback invoked.
1209 GURL default_browser_url =
1210 GURL(StartupBrowserCreator::GetDefaultBrowserUrl());
1211 EXPECT_FALSE(
1212 TabStripContainsUrl(browser()->tab_strip_model(), default_browser_url));
1213 EXPECT_TRUE(callback_called);
1214
1215 // Clear default browser callback.
1216 callback_called = false;
1217 StartupBrowserCreator::ClearDefaultBrowserCallback();
1218
1219 // Open url.
1220 ProcessCommandLineAlreadyRunningDefaultProfile(cmdline);
1221
1222 // The url should not have been intercepted and the callback not invoked.
1223 EXPECT_TRUE(
1224 TabStripContainsUrl(browser()->tab_strip_model(), default_browser_url));
1225 EXPECT_FALSE(callback_called);
1226 }
1227 #endif // defined(OS_WIN)
1228
1163 class SupervisedUserBrowserCreatorTest : public InProcessBrowserTest { 1229 class SupervisedUserBrowserCreatorTest : public InProcessBrowserTest {
1164 protected: 1230 protected:
1165 void SetUpCommandLine(base::CommandLine* command_line) override { 1231 void SetUpCommandLine(base::CommandLine* command_line) override {
1166 InProcessBrowserTest::SetUpCommandLine(command_line); 1232 InProcessBrowserTest::SetUpCommandLine(command_line);
1167 command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf"); 1233 command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf");
1168 } 1234 }
1169 }; 1235 };
1170 1236
1171 IN_PROC_BROWSER_TEST_F(SupervisedUserBrowserCreatorTest, 1237 IN_PROC_BROWSER_TEST_F(SupervisedUserBrowserCreatorTest,
1172 StartupSupervisedUserProfile) { 1238 StartupSupervisedUserProfile) {
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
1629 ASSERT_EQ(1, tab_strip->count()); 1695 ASSERT_EQ(1, tab_strip->count());
1630 EXPECT_EQ("title1.html", 1696 EXPECT_EQ("title1.html",
1631 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); 1697 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName());
1632 } 1698 }
1633 #endif // defined(ENABLE_CONFIGURATION_POLICY) 1699 #endif // defined(ENABLE_CONFIGURATION_POLICY)
1634 1700
1635 #endif // !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) || 1701 #endif // !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) ||
1636 // defined(ENABLE_CONFIGURATION_POLICY) 1702 // defined(ENABLE_CONFIGURATION_POLICY)
1637 1703
1638 #endif // !defined(OS_CHROMEOS) 1704 #endif // !defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698