OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/env_var.h" | 5 #include "base/env_var.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/platform_thread.h" | 8 #include "base/platform_thread.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
11 #include "base/test/test_file_util.h" | 11 #include "base/test/test_file_util.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/env_vars.h" | 16 #include "chrome/common/env_vars.h" |
17 #include "chrome/test/ui/ui_test.h" | 17 #include "chrome/test/ui/ui_test.h" |
18 #include "chrome/test/ui_test_utils.h" | 18 #include "chrome/test/ui_test_utils.h" |
| 19 #include "net/base/net_util.h" |
19 | 20 |
20 using base::TimeDelta; | 21 using base::TimeDelta; |
21 using base::TimeTicks; | 22 using base::TimeTicks; |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 class StartupTest : public UITest { | 26 class StartupTest : public UITest { |
26 public: | 27 public: |
27 StartupTest() { | 28 StartupTest() { |
28 show_window_ = true; | 29 show_window_ = true; |
29 } | 30 } |
30 void SetUp() {} | 31 void SetUp() {} |
31 void TearDown() {} | 32 void TearDown() {} |
32 | 33 |
33 // Load a file on startup rather than about:blank. This tests a longer | 34 // Load a file on startup rather than about:blank. This tests a longer |
34 // startup path, including resource loading and the loading of gears.dll. | 35 // startup path, including resource loading and the loading of gears.dll. |
35 void SetUpWithFileURL() { | 36 void SetUpWithFileURL() { |
36 const FilePath file_url = ui_test_utils::GetTestFilePath( | 37 const FilePath file_url = ui_test_utils::GetTestFilePath( |
37 FilePath(FilePath::kCurrentDirectory), | 38 FilePath(FilePath::kCurrentDirectory), |
38 FilePath(FILE_PATH_LITERAL("simple.html"))); | 39 FilePath(FILE_PATH_LITERAL("simple.html"))); |
39 ASSERT_TRUE(file_util::PathExists(file_url)); | 40 ASSERT_TRUE(file_util::PathExists(file_url)); |
40 launch_arguments_.AppendLooseValue(file_url.ToWStringHack()); | 41 launch_arguments_.AppendLooseValue(file_url.ToWStringHack()); |
41 } | 42 } |
42 | 43 |
| 44 // Load a complex html file on startup represented by |which_tab|. |
| 45 void SetUpWithComplexFileURL(unsigned int which_tab) { |
| 46 const char* const kTestPageCyclerDomains[] = { |
| 47 "www.google.com", "www.nytimes.com", |
| 48 "www.yahoo.com", "espn.go.com", "www.amazon.com" |
| 49 }; |
| 50 unsigned int which_el = which_tab % arraysize(kTestPageCyclerDomains); |
| 51 const char* this_domain = kTestPageCyclerDomains[which_el]; |
| 52 |
| 53 FilePath page_cycler_path; |
| 54 PathService::Get(base::DIR_SOURCE_ROOT, &page_cycler_path); |
| 55 page_cycler_path = page_cycler_path.AppendASCII("data") |
| 56 .AppendASCII("page_cycler").AppendASCII("moz") |
| 57 .AppendASCII(this_domain).AppendASCII("index.html"); |
| 58 GURL file_url = net::FilePathToFileURL(page_cycler_path).Resolve("?skip"); |
| 59 launch_arguments_.AppendLooseValue(ASCIIToWide(file_url.spec())); |
| 60 } |
| 61 |
43 // Use the given profile in the test data extensions/profiles dir. This tests | 62 // Use the given profile in the test data extensions/profiles dir. This tests |
44 // startup with extensions installed. | 63 // startup with extensions installed. |
45 void SetUpWithExtensionsProfile(const char* profile) { | 64 void SetUpWithExtensionsProfile(const char* profile) { |
46 FilePath data_dir; | 65 FilePath data_dir; |
47 PathService::Get(chrome::DIR_TEST_DATA, &data_dir); | 66 PathService::Get(chrome::DIR_TEST_DATA, &data_dir); |
48 data_dir = data_dir.AppendASCII("extensions").AppendASCII("profiles"). | 67 data_dir = data_dir.AppendASCII("extensions").AppendASCII("profiles"). |
49 AppendASCII(profile); | 68 AppendASCII(profile); |
50 set_template_user_data(data_dir); | 69 set_template_user_data(data_dir); |
51 | 70 |
52 // For now, these tests still depend on toolstrips. | 71 // For now, these tests still depend on toolstrips. |
53 launch_arguments_.AppendSwitch(switches::kEnableExtensionToolstrips); | 72 launch_arguments_.AppendSwitch(switches::kEnableExtensionToolstrips); |
54 } | 73 } |
55 | 74 |
| 75 void RunPerfTestWithManyTabs(const char *test_name, |
| 76 int tab_count, bool restore_session); |
| 77 |
56 void RunStartupTest(const char* graph, const char* trace, | 78 void RunStartupTest(const char* graph, const char* trace, |
57 bool test_cold, bool important, UITest::ProfileType profile_type) { | 79 bool test_cold, bool important, UITest::ProfileType profile_type) { |
58 profile_type_ = profile_type; | 80 profile_type_ = profile_type; |
59 | 81 |
60 // Sets the profile data for the run. For now, this is only used for | 82 // Sets the profile data for the run. For now, this is only used for |
61 // the non-default themes test. | 83 // the non-default themes test. |
62 if (profile_type != UITest::DEFAULT_THEME) { | 84 if (profile_type != UITest::DEFAULT_THEME) { |
63 set_template_user_data(UITest::ComputeTypicalUserDataSource( | 85 set_template_user_data(UITest::ComputeTypicalUserDataSource( |
64 profile_type)); | 86 profile_type)); |
65 } | 87 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 true /* important */, UITest::DEFAULT_THEME); | 161 true /* important */, UITest::DEFAULT_THEME); |
140 } | 162 } |
141 | 163 |
142 // TODO(mpcomplete): Should we have reference timings for all these? | 164 // TODO(mpcomplete): Should we have reference timings for all these? |
143 | 165 |
144 TEST_F(StartupTest, PerfCold) { | 166 TEST_F(StartupTest, PerfCold) { |
145 RunStartupTest("cold", "t", true /* cold */, false /* not important */, | 167 RunStartupTest("cold", "t", true /* cold */, false /* not important */, |
146 UITest::DEFAULT_THEME); | 168 UITest::DEFAULT_THEME); |
147 } | 169 } |
148 | 170 |
| 171 void StartupTest::RunPerfTestWithManyTabs(const char *test_name, |
| 172 int tab_count, bool restore_session) { |
| 173 // Initialize session with |tab_count| tabs. |
| 174 for (int i = 0; i < tab_count; ++i) |
| 175 SetUpWithComplexFileURL(i); |
| 176 |
| 177 if (restore_session) { |
| 178 // Start the browser with these urls so we can save the session and exit. |
| 179 UITest::SetUp(); |
| 180 // Set flags to ensure profile is saved and can be restored. |
| 181 #if defined(OS_MACOSX) |
| 182 shutdown_type_ = UITestBase::USER_QUIT; |
| 183 #endif |
| 184 clear_profile_ = false; |
| 185 // Quit and set flags to restore session. |
| 186 UITest::TearDown(); |
| 187 // Clear all arguments for session restore, or the number of open tabs |
| 188 // will grow with each restore. |
| 189 launch_arguments_ = CommandLine(CommandLine::ARGUMENTS_ONLY); |
| 190 // The session will be restored once per cycle for numCycles test cycles, |
| 191 // and each time, UITest::SetUp will wait for |tab_count| tabs to |
| 192 // finish loading. |
| 193 launch_arguments_.AppendSwitchWithValue(switches::kRestoreLastSession, |
| 194 IntToWString(tab_count)); |
| 195 } |
| 196 RunStartupTest("warm", test_name, |
| 197 false, false, |
| 198 UITest::DEFAULT_THEME); |
| 199 } |
| 200 |
| 201 TEST_F(StartupTest, PerfFewTabs) { |
| 202 RunPerfTestWithManyTabs("few_tabs", 5, false); |
| 203 } |
| 204 |
| 205 TEST_F(StartupTest, PerfSeveralTabs) { |
| 206 RunPerfTestWithManyTabs("several_tabs", 20, false); |
| 207 } |
| 208 |
| 209 TEST_F(StartupTest, PerfRestoreFewTabs) { |
| 210 RunPerfTestWithManyTabs("restore_few_tabs", 5, true); |
| 211 } |
| 212 |
| 213 TEST_F(StartupTest, PerfRestoreSeveralTabs) { |
| 214 RunPerfTestWithManyTabs("restore_several_tabs", 20, true); |
| 215 } |
| 216 |
149 TEST_F(StartupTest, PerfExtensionEmpty) { | 217 TEST_F(StartupTest, PerfExtensionEmpty) { |
150 SetUpWithFileURL(); | 218 SetUpWithFileURL(); |
151 SetUpWithExtensionsProfile("empty"); | 219 SetUpWithExtensionsProfile("empty"); |
152 RunStartupTest("warm", "extension_empty", | 220 RunStartupTest("warm", "extension_empty", |
153 false /* cold */, false /* not important */, | 221 false /* cold */, false /* not important */, |
154 UITest::DEFAULT_THEME); | 222 UITest::DEFAULT_THEME); |
155 } | 223 } |
156 | 224 |
157 TEST_F(StartupTest, PerfExtensionToolstrips1) { | 225 TEST_F(StartupTest, PerfExtensionToolstrips1) { |
158 SetUpWithFileURL(); | 226 SetUpWithFileURL(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 false /* not important */, UITest::CUSTOM_FRAME); | 285 false /* not important */, UITest::CUSTOM_FRAME); |
218 } | 286 } |
219 | 287 |
220 TEST_F(StartupTest, PerfColdNativeFrameGtkTheme) { | 288 TEST_F(StartupTest, PerfColdNativeFrameGtkTheme) { |
221 RunStartupTest("warm", "custom-frame-gtk-theme", false /* warm */, | 289 RunStartupTest("warm", "custom-frame-gtk-theme", false /* warm */, |
222 false /* not important */, UITest::CUSTOM_FRAME_NATIVE_THEME); | 290 false /* not important */, UITest::CUSTOM_FRAME_NATIVE_THEME); |
223 } | 291 } |
224 #endif | 292 #endif |
225 | 293 |
226 } // namespace | 294 } // namespace |
OLD | NEW |