| 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/time.h" | 11 #include "base/time.h" |
| 12 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
| 13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/env_vars.h" | 15 #include "chrome/common/env_vars.h" |
| 16 #include "chrome/test/ui/ui_test.h" | 16 #include "chrome/test/ui/ui_test.h" |
| 17 #include "chrome/test/ui_test_utils.h" | 17 #include "chrome/test/ui_test_utils.h" |
| 18 #include "net/base/net_util.h" |
| 18 | 19 |
| 19 using base::TimeDelta; | 20 using base::TimeDelta; |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 class ShutdownTest : public UITest { | 24 class ShutdownTest : public UITest { |
| 24 public: | 25 public: |
| 25 ShutdownTest() { | 26 ShutdownTest() { |
| 26 show_window_ = true; | 27 show_window_ = true; |
| 27 } | 28 } |
| 28 void SetUp() {} | 29 void SetUp() {} |
| 29 void TearDown() {} | 30 void TearDown() {} |
| 30 | 31 |
| 32 enum TestSize { |
| 33 SIMPLE, // Runs with no command line arguments (loads about:blank). |
| 34 TWENTY_TABS, // Opens 5 copies of 4 different test pages. |
| 35 }; |
| 36 |
| 31 void SetUpTwentyTabs() { | 37 void SetUpTwentyTabs() { |
| 38 int window_count; |
| 39 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
| 40 ASSERT_EQ(1, window_count); |
| 41 scoped_refptr<BrowserProxy> browser_proxy( |
| 42 automation()->GetBrowserWindow(0)); |
| 43 ASSERT_TRUE(browser_proxy.get()); |
| 44 |
| 32 const FilePath kFastShutdownDir(FILE_PATH_LITERAL("fast_shutdown")); | 45 const FilePath kFastShutdownDir(FILE_PATH_LITERAL("fast_shutdown")); |
| 33 const FilePath kCurrentDir(FilePath::kCurrentDirectory); | 46 const FilePath kCurrentDir(FilePath::kCurrentDirectory); |
| 34 const FilePath test_cases[] = { | 47 const FilePath test_cases[] = { |
| 35 ui_test_utils::GetTestFilePath(kFastShutdownDir, | 48 ui_test_utils::GetTestFilePath(kFastShutdownDir, |
| 36 FilePath(FILE_PATH_LITERAL("on_before_unloader.html"))), | 49 FilePath(FILE_PATH_LITERAL("on_before_unloader.html"))), |
| 37 ui_test_utils::GetTestFilePath(kCurrentDir, | 50 ui_test_utils::GetTestFilePath(kCurrentDir, |
| 38 FilePath(FILE_PATH_LITERAL("animated-gifs.html"))), | 51 FilePath(FILE_PATH_LITERAL("animated-gifs.html"))), |
| 39 ui_test_utils::GetTestFilePath(kCurrentDir, | 52 ui_test_utils::GetTestFilePath(kCurrentDir, |
| 40 FilePath(FILE_PATH_LITERAL("french_page.html"))), | 53 FilePath(FILE_PATH_LITERAL("french_page.html"))), |
| 41 ui_test_utils::GetTestFilePath(kCurrentDir, | 54 ui_test_utils::GetTestFilePath(kCurrentDir, |
| 42 FilePath(FILE_PATH_LITERAL("onunload_cookie.html"))), | 55 FilePath(FILE_PATH_LITERAL("onunload_cookie.html"))), |
| 43 }; | 56 }; |
| 44 | 57 |
| 45 for (size_t i = 0; i < arraysize(test_cases); i++) { | 58 for (size_t i = 0; i < arraysize(test_cases); i++) { |
| 46 ASSERT_TRUE(file_util::PathExists(test_cases[i])); | 59 ASSERT_TRUE(file_util::PathExists(test_cases[i])); |
| 47 for (size_t j = 0; j < 5; j++) { | 60 for (size_t j = 0; j < 5; j++) { |
| 48 launch_arguments_.AppendLooseValue(test_cases[i].ToWStringHack()); | 61 ASSERT_TRUE(browser_proxy->AppendTab( |
| 62 net::FilePathToFileURL(test_cases[i]))); |
| 49 } | 63 } |
| 50 } | 64 } |
| 51 } | 65 } |
| 52 | 66 |
| 53 void RunShutdownTest(const char* graph, const char* trace, bool important, | 67 void RunShutdownTest(const char* graph, const char* trace, |
| 68 bool important, TestSize test_size, |
| 54 UITest::ShutdownType shutdown_type) { | 69 UITest::ShutdownType shutdown_type) { |
| 55 const int kNumCyclesMax = 20; | 70 const int kNumCyclesMax = 20; |
| 56 int numCycles = kNumCyclesMax; | 71 int numCycles = kNumCyclesMax; |
| 57 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); | 72 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); |
| 58 std::string numCyclesEnv; | 73 std::string numCyclesEnv; |
| 59 if (env->GetEnv(env_vars::kStartupTestsNumCycles, &numCyclesEnv) && | 74 if (env->GetEnv(env_vars::kStartupTestsNumCycles, &numCyclesEnv) && |
| 60 StringToInt(numCyclesEnv, &numCycles)) { | 75 StringToInt(numCyclesEnv, &numCycles)) { |
| 61 if (numCycles <= kNumCyclesMax) { | 76 if (numCycles <= kNumCyclesMax) { |
| 62 LOG(INFO) << env_vars::kStartupTestsNumCycles | 77 LOG(INFO) << env_vars::kStartupTestsNumCycles |
| 63 << " set in environment, so setting numCycles to " | 78 << " set in environment, so setting numCycles to " |
| 64 << numCycles; | 79 << numCycles; |
| 65 } else { | 80 } else { |
| 66 LOG(INFO) << env_vars::kStartupTestsNumCycles | 81 LOG(INFO) << env_vars::kStartupTestsNumCycles |
| 67 << " is higher than the max, setting numCycles to " | 82 << " is higher than the max, setting numCycles to " |
| 68 << kNumCyclesMax; | 83 << kNumCyclesMax; |
| 69 numCycles = kNumCyclesMax; | 84 numCycles = kNumCyclesMax; |
| 70 } | 85 } |
| 71 } | 86 } |
| 72 | 87 |
| 73 TimeDelta timings[kNumCyclesMax]; | 88 TimeDelta timings[kNumCyclesMax]; |
| 74 for (int i = 0; i < numCycles; ++i) { | 89 for (int i = 0; i < numCycles; ++i) { |
| 75 UITest::SetUp(); | 90 UITest::SetUp(); |
| 91 if (test_size == TWENTY_TABS) { |
| 92 SetUpTwentyTabs(); |
| 93 } |
| 76 set_shutdown_type(shutdown_type); | 94 set_shutdown_type(shutdown_type); |
| 77 UITest::TearDown(); | 95 UITest::TearDown(); |
| 78 timings[i] = browser_quit_time_; | 96 timings[i] = browser_quit_time_; |
| 79 | 97 |
| 80 if (i == 0) { | 98 if (i == 0) { |
| 81 // Re-use the profile data after first run so that the noise from | 99 // Re-use the profile data after first run so that the noise from |
| 82 // creating databases doesn't impact all the runs. | 100 // creating databases doesn't impact all the runs. |
| 83 clear_profile_ = false; | 101 clear_profile_ = false; |
| 84 // Clear template_user_data_ so we don't try to copy it over each time | 102 // Clear template_user_data_ so we don't try to copy it over each time |
| 85 // through. | 103 // through. |
| 86 set_template_user_data(FilePath()); | 104 set_template_user_data(FilePath()); |
| 87 } | 105 } |
| 88 } | 106 } |
| 89 | 107 |
| 90 std::string times; | 108 std::string times; |
| 91 for (int i = 0; i < numCycles; ++i) | 109 for (int i = 0; i < numCycles; ++i) |
| 92 StringAppendF(×, "%.2f,", timings[i].InMillisecondsF()); | 110 StringAppendF(×, "%.2f,", timings[i].InMillisecondsF()); |
| 93 PrintResultList(graph, "", trace, times, "ms", important); | 111 PrintResultList(graph, "", trace, times, "ms", important); |
| 94 } | 112 } |
| 95 }; | 113 }; |
| 96 | 114 |
| 97 TEST_F(ShutdownTest, SimpleWindowClose) { | 115 TEST_F(ShutdownTest, SimpleWindowClose) { |
| 98 RunShutdownTest("shutdown", "simple-window-close", | 116 RunShutdownTest("shutdown", "simple-window-close", |
| 99 true, /* important */ UITest::WINDOW_CLOSE); | 117 true, /* important */ SIMPLE, UITest::WINDOW_CLOSE); |
| 100 } | 118 } |
| 101 | 119 |
| 102 TEST_F(ShutdownTest, SimpleUserQuit) { | 120 TEST_F(ShutdownTest, SimpleUserQuit) { |
| 103 RunShutdownTest("shutdown", "simple-user-quit", | 121 RunShutdownTest("shutdown", "simple-user-quit", |
| 104 true, /* important */ UITest::USER_QUIT); | 122 true, /* important */ SIMPLE, UITest::USER_QUIT); |
| 105 } | 123 } |
| 106 | 124 |
| 107 TEST_F(ShutdownTest, SimpleSessionEnding) { | 125 TEST_F(ShutdownTest, SimpleSessionEnding) { |
| 108 RunShutdownTest("shutdown", "simple-session-ending", | 126 RunShutdownTest("shutdown", "simple-session-ending", |
| 109 true, /* important */ UITest::SESSION_ENDING); | 127 true, /* important */ SIMPLE, UITest::SESSION_ENDING); |
| 110 } | 128 } |
| 111 | 129 |
| 112 // http://crbug.com/46609 | 130 TEST_F(ShutdownTest, TwentyTabsWindowClose) { |
| 113 #if defined(OS_MACOSX) | |
| 114 #define MAYBE_TwentyTabsWindowClose FLAKY_TwentyTabsWindowClose | |
| 115 #define MAYBE_TwentyTabsUserQuit FLAKY_TwentyTabsUserQuit | |
| 116 #else | |
| 117 #define MAYBE_TwentyTabsWindowClose TwentyTabsWindowClose | |
| 118 #define MAYBE_TwentyTabsUserQuit TwentyTabsUserQuit | |
| 119 #endif | |
| 120 | |
| 121 TEST_F(ShutdownTest, MAYBE_TwentyTabsWindowClose) { | |
| 122 SetUpTwentyTabs(); | |
| 123 RunShutdownTest("shutdown", "twentytabs-window-close", | 131 RunShutdownTest("shutdown", "twentytabs-window-close", |
| 124 true, /* important */ UITest::WINDOW_CLOSE); | 132 true, /* important */ TWENTY_TABS, UITest::WINDOW_CLOSE); |
| 125 } | 133 } |
| 126 | 134 |
| 127 TEST_F(ShutdownTest, MAYBE_TwentyTabsUserQuit) { | 135 TEST_F(ShutdownTest, TwentyTabsUserQuit) { |
| 128 SetUpTwentyTabs(); | |
| 129 RunShutdownTest("shutdown", "twentytabs-user-quit", | 136 RunShutdownTest("shutdown", "twentytabs-user-quit", |
| 130 true, /* important */ UITest::USER_QUIT); | 137 true, /* important */ TWENTY_TABS, UITest::USER_QUIT); |
| 131 } | 138 } |
| 132 | 139 |
| 133 // http://crbug.com/40671 | 140 // http://crbug.com/40671 |
| 134 #if defined(OS_WIN) && !defined(NDEBUG) | 141 #if defined(OS_WIN) && !defined(NDEBUG) |
| 135 #define MAYBE_TwentyTabsSessionEnding DISABLED_TwentyTabsSessionEnding | 142 #define MAYBE_TwentyTabsSessionEnding DISABLED_TwentyTabsSessionEnding |
| 136 #elif defined(OS_MACOSX) | |
| 137 // http://crbug.com/46609 | |
| 138 #define MAYBE_TwentyTabsSessionEnding FLAKY_TwentyTabsSessionEnding | |
| 139 #else | 143 #else |
| 140 #define MAYBE_TwentyTabsSessionEnding TwentyTabsSessionEnding | 144 #define MAYBE_TwentyTabsSessionEnding TwentyTabsSessionEnding |
| 141 #endif | 145 #endif |
| 142 | 146 |
| 143 TEST_F(ShutdownTest, MAYBE_TwentyTabsSessionEnding) { | 147 TEST_F(ShutdownTest, MAYBE_TwentyTabsSessionEnding) { |
| 144 SetUpTwentyTabs(); | |
| 145 RunShutdownTest("shutdown", "twentytabs-session-ending", | 148 RunShutdownTest("shutdown", "twentytabs-session-ending", |
| 146 true, /* important */ UITest::SESSION_ENDING); | 149 true, /* important */ TWENTY_TABS, UITest::SESSION_ENDING); |
| 147 } | 150 } |
| 148 | 151 |
| 149 } // namespace | 152 } // namespace |
| OLD | NEW |