Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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++) { | |
|
Peter Kasting
2015/09/25 20:52:27
Tiny nit: There's no formal rule requiring this bu
Patrick Monette
2015/09/28 23:46:38
Done.
| |
| 111 if (tab_strip->GetWebContentsAt(i)->GetURL() == url) | |
| 112 return true; | |
| 113 } | |
| 114 return false; | |
| 115 } | |
| 116 | |
| 117 void ProcessCommandLineAlreadyRunningDefaultProfile(base::CommandLine cmdline) { | |
|
grt (UTC plus 2)
2015/09/28 14:31:05
nit: pass by constref
Patrick Monette
2015/09/28 23:46:38
Done.
| |
| 118 StartupBrowserCreator browser_creator; | |
| 119 | |
| 120 base::FilePath current_dir; | |
| 121 ASSERT_TRUE(base::GetCurrentDirectory(¤t_dir)); | |
| 122 base::FilePath user_data_dir = | |
| 123 g_browser_process->profile_manager()->user_data_dir(); | |
| 124 base::FilePath startup_profile_dir = | |
| 125 g_browser_process->profile_manager()->GetLastUsedProfileDir( | |
| 126 user_data_dir); | |
| 127 | |
| 128 browser_creator.ProcessCommandLineAlreadyRunning(cmdline, current_dir, | |
| 129 startup_profile_dir); | |
| 130 } | |
| 131 | |
| 103 } // namespace | 132 } // namespace |
| 104 | 133 |
| 105 class StartupBrowserCreatorTest : public ExtensionBrowserTest { | 134 class StartupBrowserCreatorTest : public ExtensionBrowserTest { |
| 106 protected: | 135 protected: |
| 107 StartupBrowserCreatorTest() {} | 136 StartupBrowserCreatorTest() {} |
| 108 | 137 |
| 109 bool SetUpUserDataDirectory() override { | 138 bool SetUpUserDataDirectory() override { |
| 110 return ExtensionBrowserTest::SetUpUserDataDirectory(); | 139 return ExtensionBrowserTest::SetUpUserDataDirectory(); |
| 111 } | 140 } |
| 112 | 141 |
| (...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1153 tab_strip->GetWebContentsAt(0)->GetURL()); | 1182 tab_strip->GetWebContentsAt(0)->GetURL()); |
| 1154 EnsureRestoreUIWasShown(tab_strip->GetWebContentsAt(0)); | 1183 EnsureRestoreUIWasShown(tab_strip->GetWebContentsAt(0)); |
| 1155 | 1184 |
| 1156 #if !defined(OS_MACOSX) && !defined(GOOGLE_CHROME_BUILD) | 1185 #if !defined(OS_MACOSX) && !defined(GOOGLE_CHROME_BUILD) |
| 1157 // Each profile should have one session restore bubble shown, so we should | 1186 // Each profile should have one session restore bubble shown, so we should |
| 1158 // observe count 3 in bucket 0 (which represents bubble shown). | 1187 // observe count 3 in bucket 0 (which represents bubble shown). |
| 1159 histogram_tester.ExpectBucketCount("SessionCrashed.Bubble", 0, 3); | 1188 histogram_tester.ExpectBucketCount("SessionCrashed.Bubble", 0, 3); |
| 1160 #endif // !defined(OS_MACOSX) && !defined(GOOGLE_CHROME_BUILD) | 1189 #endif // !defined(OS_MACOSX) && !defined(GOOGLE_CHROME_BUILD) |
| 1161 } | 1190 } |
| 1162 | 1191 |
| 1192 #if defined(OS_WIN) | |
| 1193 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, DefaultBrowserCallback) { | |
| 1194 bool callback_called = false; | |
| 1195 | |
| 1196 // Set the default browser callback. | |
| 1197 StartupBrowserCreator::SetDefaultBrowserCallback( | |
| 1198 base::Bind(&SetTrue, &callback_called)); | |
| 1199 | |
| 1200 // Set the command line to open the default browser url. | |
| 1201 base::CommandLine cmdline(base::CommandLine::NO_PROGRAM); | |
| 1202 cmdline.AppendArgNative(StartupBrowserCreator::GetDefaultBrowserUrl()); | |
| 1203 | |
| 1204 // Open url. | |
| 1205 ProcessCommandLineAlreadyRunningDefaultProfile(cmdline); | |
| 1206 | |
| 1207 // The url should have been intercepted and the callback invoked. | |
| 1208 GURL default_browser_url = | |
| 1209 GURL(StartupBrowserCreator::GetDefaultBrowserUrl()); | |
| 1210 EXPECT_FALSE( | |
| 1211 TabStripContainsUrl(browser()->tab_strip_model(), default_browser_url)); | |
| 1212 EXPECT_TRUE(callback_called); | |
| 1213 | |
| 1214 // Clear default browser callback. | |
| 1215 callback_called = false; | |
| 1216 StartupBrowserCreator::ClearDefaultBrowserCallback(); | |
| 1217 | |
| 1218 // Open url. | |
| 1219 ProcessCommandLineAlreadyRunningDefaultProfile(cmdline); | |
| 1220 | |
| 1221 // The url should not have been intercepted and the callback not invoked. | |
| 1222 EXPECT_TRUE( | |
| 1223 TabStripContainsUrl(browser()->tab_strip_model(), default_browser_url)); | |
| 1224 EXPECT_FALSE(callback_called); | |
| 1225 } | |
| 1226 #endif // defined(OS_WIN) | |
| 1227 | |
| 1163 class SupervisedUserBrowserCreatorTest : public InProcessBrowserTest { | 1228 class SupervisedUserBrowserCreatorTest : public InProcessBrowserTest { |
| 1164 protected: | 1229 protected: |
| 1165 void SetUpCommandLine(base::CommandLine* command_line) override { | 1230 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 1166 InProcessBrowserTest::SetUpCommandLine(command_line); | 1231 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 1167 command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf"); | 1232 command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf"); |
| 1168 } | 1233 } |
| 1169 }; | 1234 }; |
| 1170 | 1235 |
| 1171 IN_PROC_BROWSER_TEST_F(SupervisedUserBrowserCreatorTest, | 1236 IN_PROC_BROWSER_TEST_F(SupervisedUserBrowserCreatorTest, |
| 1172 StartupSupervisedUserProfile) { | 1237 StartupSupervisedUserProfile) { |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1629 ASSERT_EQ(1, tab_strip->count()); | 1694 ASSERT_EQ(1, tab_strip->count()); |
| 1630 EXPECT_EQ("title1.html", | 1695 EXPECT_EQ("title1.html", |
| 1631 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); | 1696 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); |
| 1632 } | 1697 } |
| 1633 #endif // defined(ENABLE_CONFIGURATION_POLICY) | 1698 #endif // defined(ENABLE_CONFIGURATION_POLICY) |
| 1634 | 1699 |
| 1635 #endif // !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) || | 1700 #endif // !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) || |
| 1636 // defined(ENABLE_CONFIGURATION_POLICY) | 1701 // defined(ENABLE_CONFIGURATION_POLICY) |
| 1637 | 1702 |
| 1638 #endif // !defined(OS_CHROMEOS) | 1703 #endif // !defined(OS_CHROMEOS) |
| OLD | NEW |