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