| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/platform_thread.h" | 7 #include "base/platform_thread.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/test_file_util.h" | 9 #include "base/test_file_util.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "chrome/common/chrome_constants.h" | 11 #include "chrome/common/chrome_constants.h" |
| 12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
| 13 #include "chrome/test/ui/ui_test.h" | 13 #include "chrome/test/ui/ui_test.h" |
| 14 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
| 15 | 15 |
| 16 using base::TimeDelta; | 16 using base::TimeDelta; |
| 17 using base::TimeTicks; | 17 using base::TimeTicks; |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 class StartupTest : public UITest { | 21 class StartupTest : public UITest { |
| 22 public: | 22 public: |
| 23 StartupTest() { | 23 StartupTest() { |
| 24 show_window_ = true; | 24 show_window_ = true; |
| 25 pages_ = "about:blank"; | 25 pages_ = "about:blank"; |
| 26 } | 26 } |
| 27 void SetUp() {} | 27 void SetUp() {} |
| 28 void TearDown() {} | 28 void TearDown() {} |
| 29 | 29 |
| 30 // Load a file on startup rather than about:blank. This tests a longer |
| 31 // startup path, including resource loading and the loading of gears.dll. |
| 32 void SetUpWithFileURL() { |
| 33 FilePath file_url; |
| 34 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &file_url)); |
| 35 file_url = file_url.AppendASCII("empty.html"); |
| 36 ASSERT_TRUE(file_util::PathExists(file_url)); |
| 37 launch_arguments_.AppendLooseValue(file_url.ToWStringHack()); |
| 38 |
| 39 pages_ = WideToUTF8(file_url.ToWStringHack()); |
| 40 } |
| 41 |
| 42 // Use the given profile in the test data extensions/profiles dir. This tests |
| 43 // startup with extensions installed. |
| 44 void SetUpWithExtensionsProfile(const char* profile) { |
| 45 FilePath data_dir; |
| 46 PathService::Get(chrome::DIR_TEST_DATA, &data_dir); |
| 47 data_dir = data_dir.AppendASCII("extensions").AppendASCII("profiles"). |
| 48 AppendASCII(profile); |
| 49 set_template_user_data(data_dir.ToWStringHack()); |
| 50 } |
| 51 |
| 30 void RunStartupTest(const char* graph, const char* trace, | 52 void RunStartupTest(const char* graph, const char* trace, |
| 31 bool test_cold, bool important, int profile_type) { | 53 bool test_cold, bool important, int profile_type) { |
| 32 profile_type_ = profile_type; | 54 profile_type_ = profile_type; |
| 33 | 55 |
| 34 // Sets the profile data for the run. For now, this is only used for | 56 // Sets the profile data for the run. For now, this is only used for |
| 35 // the non-default themes test. | 57 // the non-default themes test. |
| 36 if (profile_type != UITest::DEFAULT_THEME) { | 58 if (profile_type != UITest::DEFAULT_THEME) { |
| 37 set_template_user_data(UITest::ComputeTypicalUserDataSource( | 59 set_template_user_data(UITest::ComputeTypicalUserDataSource( |
| 38 profile_type).ToWStringHack()); | 60 profile_type).ToWStringHack()); |
| 39 } | 61 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 timings[i] = end_time - browser_launch_time_; | 100 timings[i] = end_time - browser_launch_time_; |
| 79 // TODO(beng): Can't shut down so quickly. Figure out why, and fix. If we | 101 // TODO(beng): Can't shut down so quickly. Figure out why, and fix. If we |
| 80 // do, we crash. | 102 // do, we crash. |
| 81 PlatformThread::Sleep(50); | 103 PlatformThread::Sleep(50); |
| 82 UITest::TearDown(); | 104 UITest::TearDown(); |
| 83 | 105 |
| 84 if (i == 0) { | 106 if (i == 0) { |
| 85 // Re-use the profile data after first run so that the noise from | 107 // Re-use the profile data after first run so that the noise from |
| 86 // creating databases doesn't impact all the runs. | 108 // creating databases doesn't impact all the runs. |
| 87 clear_profile_ = false; | 109 clear_profile_ = false; |
| 88 // Destroy template_user_data_ for complex/gtk themes so we don't try | 110 // Clear template_user_data_ so we don't try to copy it over each time |
| 89 // to rewrite each time through. | 111 // through. |
| 90 if (profile_type != UITest::DEFAULT_THEME) | 112 set_template_user_data(L""); |
| 91 set_template_user_data(L""); | |
| 92 } | 113 } |
| 93 } | 114 } |
| 94 | 115 |
| 95 std::string times; | 116 std::string times; |
| 96 for (int i = 0; i < numCycles; ++i) | 117 for (int i = 0; i < numCycles; ++i) |
| 97 StringAppendF(×, "%.2f,", timings[i].InMillisecondsF()); | 118 StringAppendF(×, "%.2f,", timings[i].InMillisecondsF()); |
| 98 PrintResultList(graph, "", trace, times, "ms", important); | 119 PrintResultList(graph, "", trace, times, "ms", important); |
| 99 } | 120 } |
| 100 | 121 |
| 101 protected: | 122 protected: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 114 dir = dir.AppendASCII("chrome"); | 135 dir = dir.AppendASCII("chrome"); |
| 115 #elif defined(OS_LINUX) | 136 #elif defined(OS_LINUX) |
| 116 dir = dir.AppendASCII("chrome_linux"); | 137 dir = dir.AppendASCII("chrome_linux"); |
| 117 #elif defined(OS_MACOSX) | 138 #elif defined(OS_MACOSX) |
| 118 dir = dir.AppendASCII("chrome_mac"); | 139 dir = dir.AppendASCII("chrome_mac"); |
| 119 #endif | 140 #endif |
| 120 browser_directory_ = dir; | 141 browser_directory_ = dir; |
| 121 } | 142 } |
| 122 }; | 143 }; |
| 123 | 144 |
| 124 class StartupFileTest : public StartupTest { | |
| 125 public: | |
| 126 // Load a file on startup rather than about:blank. This tests a longer | |
| 127 // startup path, including resource loading and the loading of gears.dll. | |
| 128 void SetUp() { | |
| 129 FilePath file_url; | |
| 130 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &file_url)); | |
| 131 file_url = file_url.AppendASCII("empty.html"); | |
| 132 ASSERT_TRUE(file_util::PathExists(file_url)); | |
| 133 launch_arguments_.AppendLooseValue(file_url.ToWStringHack()); | |
| 134 | |
| 135 pages_ = WideToUTF8(file_url.ToWStringHack()); | |
| 136 } | |
| 137 }; | |
| 138 | |
| 139 TEST_F(StartupTest, Perf) { | 145 TEST_F(StartupTest, Perf) { |
| 140 RunStartupTest("warm", "t", false /* not cold */, true /* important */, | 146 RunStartupTest("warm", "t", false /* not cold */, true /* important */, |
| 141 UITest::DEFAULT_THEME); | 147 UITest::DEFAULT_THEME); |
| 142 } | 148 } |
| 143 | 149 |
| 144 // TODO(port): We need a mac reference build checked in for this. | 150 // TODO(port): We need a mac reference build checked in for this. |
| 145 TEST_F(StartupReferenceTest, Perf) { | 151 TEST_F(StartupReferenceTest, Perf) { |
| 146 RunStartupTest("warm", "t_ref", false /* not cold */, | 152 RunStartupTest("warm", "t_ref", false /* not cold */, |
| 147 true /* important */, UITest::DEFAULT_THEME); | 153 true /* important */, UITest::DEFAULT_THEME); |
| 148 } | 154 } |
| 149 | 155 |
| 150 // TODO(mpcomplete): Should we have reference timings for all these? | 156 // TODO(mpcomplete): Should we have reference timings for all these? |
| 151 | 157 |
| 152 TEST_F(StartupTest, PerfCold) { | 158 TEST_F(StartupTest, PerfCold) { |
| 153 RunStartupTest("cold", "t", true /* cold */, false /* not important */, | 159 RunStartupTest("cold", "t", true /* cold */, false /* not important */, |
| 154 UITest::DEFAULT_THEME); | 160 UITest::DEFAULT_THEME); |
| 155 } | 161 } |
| 156 | 162 |
| 163 TEST_F(StartupTest, PerfExtensionEmpty) { |
| 164 SetUpWithFileURL(); |
| 165 SetUpWithExtensionsProfile("empty"); |
| 166 RunStartupTest("warm", "t", false /* cold */, false /* not important */, |
| 167 UITest::DEFAULT_THEME); |
| 168 } |
| 169 |
| 170 TEST_F(StartupTest, PerfExtensionToolstrips1) { |
| 171 SetUpWithFileURL(); |
| 172 SetUpWithExtensionsProfile("toolstrips1"); |
| 173 RunStartupTest("warm", "extension_toolstrip1", |
| 174 false /* cold */, false /* not important */, |
| 175 UITest::DEFAULT_THEME); |
| 176 } |
| 177 |
| 178 TEST_F(StartupTest, PerfExtensionToolstrips50) { |
| 179 SetUpWithFileURL(); |
| 180 SetUpWithExtensionsProfile("toolstrips50"); |
| 181 RunStartupTest("warm", "extension_toolstrip50", |
| 182 false /* cold */, false /* not important */, |
| 183 UITest::DEFAULT_THEME); |
| 184 } |
| 185 |
| 186 TEST_F(StartupTest, PerfExtensionContentScript1) { |
| 187 SetUpWithFileURL(); |
| 188 SetUpWithExtensionsProfile("content_scripts1"); |
| 189 RunStartupTest("warm", "extension_content_scripts1", |
| 190 false /* cold */, false /* not important */, |
| 191 UITest::DEFAULT_THEME); |
| 192 } |
| 193 |
| 194 TEST_F(StartupTest, PerfExtensionContentScript50) { |
| 195 SetUpWithFileURL(); |
| 196 SetUpWithExtensionsProfile("content_scripts50"); |
| 197 RunStartupTest("warm", "extension_content_scripts50", |
| 198 false /* cold */, false /* not important */, |
| 199 UITest::DEFAULT_THEME); |
| 200 } |
| 201 |
| 202 |
| 157 #if defined(OS_WIN) | 203 #if defined(OS_WIN) |
| 158 // TODO(port): Enable gears tests on linux/mac once gears is working. | 204 // TODO(port): Enable gears tests on linux/mac once gears is working. |
| 159 TEST_F(StartupFileTest, PerfGears) { | 205 TEST_F(StartupTest, PerfGears) { |
| 206 SetUpWithFileURL(); |
| 160 RunStartupTest("warm", "gears", false /* not cold */, | 207 RunStartupTest("warm", "gears", false /* not cold */, |
| 161 false /* not important */, UITest::DEFAULT_THEME); | 208 false /* not important */, UITest::DEFAULT_THEME); |
| 162 } | 209 } |
| 163 | 210 |
| 164 TEST_F(StartupFileTest, PerfColdGears) { | 211 TEST_F(StartupTest, PerfColdGears) { |
| 212 SetUpWithFileURL(); |
| 165 RunStartupTest("cold", "gears", true /* cold */, | 213 RunStartupTest("cold", "gears", true /* cold */, |
| 166 false /* not important */, UITest::DEFAULT_THEME); | 214 false /* not important */, UITest::DEFAULT_THEME); |
| 167 } | 215 } |
| 168 #endif | 216 #endif |
| 169 | 217 |
| 170 TEST_F(StartupTest, PerfColdComplexTheme) { | 218 TEST_F(StartupTest, PerfColdComplexTheme) { |
| 171 RunStartupTest("warm", "t-theme", false /* warm */, | 219 RunStartupTest("warm", "t-theme", false /* warm */, |
| 172 false /* not important */, UITest::COMPLEX_THEME); | 220 false /* not important */, UITest::COMPLEX_THEME); |
| 173 } | 221 } |
| 174 | 222 |
| 175 #if defined(OS_LINUX) | 223 #if defined(OS_LINUX) |
| 176 TEST_F(StartupTest, PerfColdGtkTheme) { | 224 TEST_F(StartupTest, PerfColdGtkTheme) { |
| 177 RunStartupTest("warm", "gtk-theme", false /* warm */, | 225 RunStartupTest("warm", "gtk-theme", false /* warm */, |
| 178 false /* not important */, UITest::NATIVE_THEME); | 226 false /* not important */, UITest::NATIVE_THEME); |
| 179 } | 227 } |
| 180 | 228 |
| 181 TEST_F(StartupTest, PrefColdNativeFrame) { | 229 TEST_F(StartupTest, PrefColdNativeFrame) { |
| 182 RunStartupTest("warm", "custom-frame", false /* warm */, | 230 RunStartupTest("warm", "custom-frame", false /* warm */, |
| 183 false /* not important */, UITest::CUSTOM_FRAME); | 231 false /* not important */, UITest::CUSTOM_FRAME); |
| 184 } | 232 } |
| 185 | 233 |
| 186 TEST_F(StartupTest, PerfColdNativeFrameGtkTheme) { | 234 TEST_F(StartupTest, PerfColdNativeFrameGtkTheme) { |
| 187 RunStartupTest("warm", "custom-frame-gtk-theme", false /* warm */, | 235 RunStartupTest("warm", "custom-frame-gtk-theme", false /* warm */, |
| 188 false /* not important */, UITest::CUSTOM_FRAME_NATIVE_THEME); | 236 false /* not important */, UITest::CUSTOM_FRAME_NATIVE_THEME); |
| 189 } | 237 } |
| 190 #endif | 238 #endif |
| 191 | 239 |
| 192 } // namespace | 240 } // namespace |
| OLD | NEW |