diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-06 21:05:25 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-06 21:05:25 +0000 |
commit | 2aa336ea9a0edfa52a58a4856655370ddca794f3 (patch) | |
tree | 46223555bc23d93d72234181976499cd42b2708c /chrome/test/startup | |
parent | a8e91124532061d21f0114605530c605582144e8 (diff) | |
download | chromium_src-2aa336ea9a0edfa52a58a4856655370ddca794f3.zip chromium_src-2aa336ea9a0edfa52a58a4856655370ddca794f3.tar.gz chromium_src-2aa336ea9a0edfa52a58a4856655370ddca794f3.tar.bz2 |
Add some shutdown perf tests. We measure shutdown for the combination of
shutdown method: {Close all windows, clicking exit, terminating process}
and number of tabs open: {just about:blank, twenty tabs}
BUG=23118
TEST=This CL adds a test.
Review URL: http://codereview.chromium.org/1594008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43758 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/startup')
-rw-r--r-- | chrome/test/startup/shutdown_test.cc | 122 | ||||
-rw-r--r-- | chrome/test/startup/startup_test.cc | 35 |
2 files changed, 136 insertions, 21 deletions
diff --git a/chrome/test/startup/shutdown_test.cc b/chrome/test/startup/shutdown_test.cc new file mode 100644 index 0000000..fcb620a --- /dev/null +++ b/chrome/test/startup/shutdown_test.cc @@ -0,0 +1,122 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/env_var.h" +#include "base/file_util.h" +#include "base/path_service.h" +#include "base/platform_thread.h" +#include "base/string_util.h" +#include "base/sys_info.h" +#include "base/time.h" +#include "chrome/common/chrome_constants.h" +#include "chrome/common/chrome_paths.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/env_vars.h" +#include "chrome/test/ui/ui_test.h" +#include "chrome/test/ui_test_utils.h" + +using base::TimeDelta; + +namespace { + +class ShutdownTest : public UITest { + public: + ShutdownTest() { + show_window_ = true; + } + void SetUp() {} + void TearDown() {} + + void SetUpTwentyTabs() { + const FilePath kFastShutdownDir(FILE_PATH_LITERAL("fast_shutdown")); + const FilePath kCurrentDir(FilePath::kCurrentDirectory); + const FilePath test_cases[] = { + ui_test_utils::GetTestFilePath(kFastShutdownDir, + FilePath(FILE_PATH_LITERAL("on_before_unloader.html"))), + ui_test_utils::GetTestFilePath(kCurrentDir, + FilePath(FILE_PATH_LITERAL("animated-gifs.html"))), + ui_test_utils::GetTestFilePath(kCurrentDir, + FilePath(FILE_PATH_LITERAL("french_page.html"))), + ui_test_utils::GetTestFilePath(kCurrentDir, + FilePath(FILE_PATH_LITERAL("onunload_cookie.html"))), + }; + + for (size_t i = 0; i < arraysize(test_cases); i++) { + ASSERT_TRUE(file_util::PathExists(test_cases[i])); + for (size_t j = 0; j < 5; j++) { + launch_arguments_.AppendLooseValue(test_cases[i].ToWStringHack()); + } + } + } + + void RunShutdownTest(const char* graph, const char* trace, bool important, + UITest::ShutdownType shutdown_type) { + const int kNumCyclesMax = 20; + int numCycles = kNumCyclesMax; + scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); + std::string numCyclesEnv; + if (env->GetEnv(env_vars::kStartupTestsNumCycles, &numCyclesEnv) && + StringToInt(numCyclesEnv, &numCycles)) { + LOG(INFO) << env_vars::kStartupTestsNumCycles << " set in environment, " + << "so setting numCycles to " << numCycles; + } + + TimeDelta timings[kNumCyclesMax]; + for (int i = 0; i < numCycles; ++i) { + UITest::SetUp(); + set_shutdown_type(shutdown_type); + UITest::TearDown(); + timings[i] = browser_quit_time_; + + if (i == 0) { + // Re-use the profile data after first run so that the noise from + // creating databases doesn't impact all the runs. + clear_profile_ = false; + // Clear template_user_data_ so we don't try to copy it over each time + // through. + set_template_user_data(FilePath()); + } + } + + std::string times; + for (int i = 0; i < numCycles; ++i) + StringAppendF(×, "%.2f,", timings[i].InMillisecondsF()); + PrintResultList(graph, "", trace, times, "ms", important); + } +}; + +TEST_F(ShutdownTest, SimpleWindowClose) { + RunShutdownTest("shutdown", "simple-window-close", + true, /* important */ UITest::WINDOW_CLOSE); +} + +TEST_F(ShutdownTest, SimpleUserQuit) { + RunShutdownTest("shutdown", "simple-user-quit", + true, /* important */ UITest::USER_QUIT); +} + +TEST_F(ShutdownTest, SimpleSessionEnding) { + RunShutdownTest("shutdown", "simple-session-ending", + true, /* important */ UITest::SESSION_ENDING); +} + +TEST_F(ShutdownTest, TwentyTabsWindowClose) { + SetUpTwentyTabs(); + RunShutdownTest("shutdown", "twentytabs-window-close", + true, /* important */ UITest::WINDOW_CLOSE); +} + +TEST_F(ShutdownTest, TwentyTabsUserQuit) { + SetUpTwentyTabs(); + RunShutdownTest("shutdown", "twentytabs-user-quit", + true, /* important */ UITest::USER_QUIT); +} + +TEST_F(ShutdownTest, TwentyTabsSessionEnding) { + SetUpTwentyTabs(); + RunShutdownTest("shutdown", "twentytabs-session-ending", + true, /* important */ UITest::SESSION_ENDING); +} + +} // namespace diff --git a/chrome/test/startup/startup_test.cc b/chrome/test/startup/startup_test.cc index 9611bc1..ff9ec7e 100644 --- a/chrome/test/startup/startup_test.cc +++ b/chrome/test/startup/startup_test.cc @@ -1,18 +1,21 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/env_var.h" #include "base/file_util.h" #include "base/path_service.h" #include "base/platform_thread.h" #include "base/string_util.h" +#include "base/sys_info.h" #include "base/test/test_file_util.h" #include "base/time.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/env_vars.h" #include "chrome/test/ui/ui_test.h" -#include "net/base/net_util.h" +#include "chrome/test/ui_test_utils.h" using base::TimeDelta; using base::TimeTicks; @@ -23,7 +26,6 @@ class StartupTest : public UITest { public: StartupTest() { show_window_ = true; - pages_ = "about:blank"; } void SetUp() {} void TearDown() {} @@ -31,13 +33,11 @@ class StartupTest : public UITest { // Load a file on startup rather than about:blank. This tests a longer // startup path, including resource loading and the loading of gears.dll. void SetUpWithFileURL() { - FilePath file_url; - ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &file_url)); - file_url = file_url.AppendASCII("simple.html"); + const FilePath file_url = ui_test_utils::GetTestFilePath( + FilePath(FilePath::kCurrentDirectory), + FilePath(FILE_PATH_LITERAL("simple.html"))); ASSERT_TRUE(file_util::PathExists(file_url)); launch_arguments_.AppendLooseValue(file_url.ToWStringHack()); - - pages_ = WideToUTF8(file_url.ToWStringHack()); } // Use the given profile in the test data extensions/profiles dir. This tests @@ -66,14 +66,13 @@ class StartupTest : public UITest { const int kNumCyclesMax = 20; int numCycles = kNumCyclesMax; -// It's ok for unit test code to use getenv(), isn't it? -#if defined(OS_WIN) -#pragma warning( disable : 4996 ) -#endif - const char* numCyclesEnv = getenv("STARTUP_TESTS_NUMCYCLES"); - if (numCyclesEnv && StringToInt(numCyclesEnv, &numCycles)) - LOG(INFO) << "STARTUP_TESTS_NUMCYCLES set in environment, " + scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); + std::string numCyclesEnv; + if (env->GetEnv(env_vars::kStartupTestsNumCycles, &numCyclesEnv) && + StringToInt(numCyclesEnv, &numCycles)) { + LOG(INFO) << env_vars::kStartupTestsNumCycles << " set in environment, " << "so setting numCycles to " << numCycles; + } TimeDelta timings[kNumCyclesMax]; for (int i = 0; i < numCycles; ++i) { @@ -102,9 +101,6 @@ class StartupTest : public UITest { UITest::SetUp(); TimeTicks end_time = TimeTicks::Now(); timings[i] = end_time - browser_launch_time_; - // TODO(beng): Can't shut down so quickly. Figure out why, and fix. If we - // do, we crash. - PlatformThread::Sleep(50); UITest::TearDown(); if (i == 0) { @@ -122,9 +118,6 @@ class StartupTest : public UITest { StringAppendF(×, "%.2f,", timings[i].InMillisecondsF()); PrintResultList(graph, "", trace, times, "ms", important); } - - protected: - std::string pages_; }; TEST_F(StartupTest, PerfWarm) { |