OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/environment.h" | |
6 #include "base/file_util.h" | |
7 #include "base/path_service.h" | |
8 #include "base/stringprintf.h" | |
9 #include "base/string_number_conversions.h" | |
10 #include "base/sys_info.h" | |
11 #include "base/time.h" | |
12 #include "chrome/common/chrome_constants.h" | |
13 #include "chrome/common/chrome_paths.h" | |
14 #include "chrome/common/env_vars.h" | |
15 #include "chrome/test/automation/automation_proxy.h" | |
16 #include "chrome/test/base/ui_test_utils.h" | |
17 #include "chrome/test/ui/ui_perf_test.h" | |
18 #include "net/base/net_util.h" | |
19 | |
20 using base::TimeDelta; | |
21 | |
22 namespace { | |
23 | |
24 class ShutdownTest : public UIPerfTest { | |
25 public: | |
26 ShutdownTest() { | |
27 show_window_ = true; | |
28 } | |
29 void SetUp() {} | |
30 void TearDown() {} | |
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 | |
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 | |
45 const FilePath kFastShutdownDir(FILE_PATH_LITERAL("fast_shutdown")); | |
46 const FilePath kCurrentDir(FilePath::kCurrentDirectory); | |
47 const FilePath test_cases[] = { | |
48 ui_test_utils::GetTestFilePath(kFastShutdownDir, | |
49 FilePath(FILE_PATH_LITERAL("on_before_unloader.html"))), | |
50 ui_test_utils::GetTestFilePath(kCurrentDir, | |
51 FilePath(FILE_PATH_LITERAL("animated-gifs.html"))), | |
52 ui_test_utils::GetTestFilePath(kCurrentDir, | |
53 FilePath(FILE_PATH_LITERAL("french_page.html"))), | |
54 ui_test_utils::GetTestFilePath(kCurrentDir, | |
55 FilePath(FILE_PATH_LITERAL("onunload_cookie.html"))), | |
56 }; | |
57 | |
58 for (size_t i = 0; i < arraysize(test_cases); i++) { | |
59 ASSERT_TRUE(file_util::PathExists(test_cases[i])); | |
60 for (size_t j = 0; j < 5; j++) { | |
61 ASSERT_TRUE(browser_proxy->AppendTab( | |
62 net::FilePathToFileURL(test_cases[i]))); | |
63 } | |
64 } | |
65 } | |
66 | |
67 void RunShutdownTest(const char* graph, const char* trace, | |
68 bool important, TestSize test_size, | |
69 ProxyLauncher::ShutdownType shutdown_type) { | |
70 const int kNumCyclesMax = 20; | |
71 int numCycles = kNumCyclesMax; | |
72 scoped_ptr<base::Environment> env(base::Environment::Create()); | |
73 std::string numCyclesEnv; | |
74 if (env->GetVar(env_vars::kStartupTestsNumCycles, &numCyclesEnv) && | |
75 base::StringToInt(numCyclesEnv, &numCycles)) { | |
76 if (numCycles <= kNumCyclesMax) { | |
77 VLOG(1) << env_vars::kStartupTestsNumCycles | |
78 << " set in environment, so setting numCycles to " << numCycles; | |
79 } else { | |
80 VLOG(1) << env_vars::kStartupTestsNumCycles | |
81 << " is higher than the max, setting numCycles to " | |
82 << kNumCyclesMax; | |
83 numCycles = kNumCyclesMax; | |
84 } | |
85 } | |
86 | |
87 TimeDelta timings[kNumCyclesMax]; | |
88 for (int i = 0; i < numCycles; ++i) { | |
89 UITest::SetUp(); | |
90 if (test_size == TWENTY_TABS) { | |
91 SetUpTwentyTabs(); | |
92 } | |
93 set_shutdown_type(shutdown_type); | |
94 UITest::TearDown(); | |
95 timings[i] = browser_quit_time(); | |
96 | |
97 if (i == 0) { | |
98 // Re-use the profile data after first run so that the noise from | |
99 // creating databases doesn't impact all the runs. | |
100 clear_profile_ = false; | |
101 // Clear template_user_data_ so we don't try to copy it over each time | |
102 // through. | |
103 set_template_user_data(FilePath()); | |
104 } | |
105 } | |
106 | |
107 std::string times; | |
108 for (int i = 0; i < numCycles; ++i) | |
109 base::StringAppendF(×, "%.2f,", timings[i].InMillisecondsF()); | |
110 PrintResultList(graph, "", trace, times, "ms", important); | |
111 } | |
112 }; | |
113 | |
114 TEST_F(ShutdownTest, SimpleWindowClose) { | |
115 RunShutdownTest("shutdown", "simple-window-close", | |
116 true, /* important */ SIMPLE, ProxyLauncher::WINDOW_CLOSE); | |
117 } | |
118 | |
119 TEST_F(ShutdownTest, SimpleUserQuit) { | |
120 RunShutdownTest("shutdown", "simple-user-quit", | |
121 true, /* important */ SIMPLE, ProxyLauncher::USER_QUIT); | |
122 } | |
123 | |
124 TEST_F(ShutdownTest, SimpleSessionEnding) { | |
125 RunShutdownTest("shutdown", "simple-session-ending", | |
126 true, /* important */ SIMPLE, ProxyLauncher::SESSION_ENDING); | |
127 } | |
128 | |
129 TEST_F(ShutdownTest, TwentyTabsWindowClose) { | |
130 RunShutdownTest("shutdown", "twentytabs-window-close", | |
131 true, /* important */ TWENTY_TABS, | |
132 ProxyLauncher::WINDOW_CLOSE); | |
133 } | |
134 | |
135 TEST_F(ShutdownTest, TwentyTabsUserQuit) { | |
136 RunShutdownTest("shutdown", "twentytabs-user-quit", | |
137 true, /* important */ TWENTY_TABS, ProxyLauncher::USER_QUIT); | |
138 } | |
139 | |
140 // http://crbug.com/40671 | |
141 #if defined(OS_WIN) && !defined(NDEBUG) | |
142 #define MAYBE_TwentyTabsSessionEnding DISABLED_TwentyTabsSessionEnding | |
143 #else | |
144 #define MAYBE_TwentyTabsSessionEnding TwentyTabsSessionEnding | |
145 #endif | |
146 | |
147 TEST_F(ShutdownTest, MAYBE_TwentyTabsSessionEnding) { | |
148 RunShutdownTest("shutdown", "twentytabs-session-ending", | |
149 true, /* important */ TWENTY_TABS, | |
150 ProxyLauncher::SESSION_ENDING); | |
151 } | |
152 | |
153 } // namespace | |
OLD | NEW |