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/file_util.h" | |
6 #include "base/path_service.h" | |
7 #include "base/perftimer.h" | |
8 #include "base/stringprintf.h" | |
9 #include "base/time.h" | |
10 #include "chrome/app/chrome_command_ids.h" | |
11 #include "chrome/common/chrome_paths.h" | |
12 #include "chrome/common/chrome_switches.h" | |
13 #include "chrome/test/automation/automation_proxy.h" | |
14 #include "chrome/test/automation/browser_proxy.h" | |
15 #include "chrome/test/automation/window_proxy.h" | |
16 #include "chrome/test/ui/ui_perf_test.h" | |
17 #include "net/base/net_util.h" | |
18 #include "ui/gfx/rect.h" | |
19 | |
20 using base::TimeDelta; | |
21 | |
22 namespace { | |
23 | |
24 class NewTabUIStartupTest : public UIPerfTest { | |
25 public: | |
26 NewTabUIStartupTest() { | |
27 show_window_ = true; | |
28 } | |
29 | |
30 void SetUp() {} | |
31 void TearDown() {} | |
32 | |
33 static const int kNumCycles = 5; | |
34 | |
35 void PrintTimings(const char* label, TimeDelta timings[kNumCycles], | |
36 bool important) { | |
37 std::string times; | |
38 for (int i = 0; i < kNumCycles; ++i) | |
39 base::StringAppendF(×, "%.2f,", timings[i].InMillisecondsF()); | |
40 PrintResultList("new_tab", "", label, times, "ms", important); | |
41 } | |
42 | |
43 void InitProfile(UITestBase::ProfileType profile_type) { | |
44 profile_type_ = profile_type; | |
45 | |
46 // Install the location of the test profile file. | |
47 set_template_user_data(UITest::ComputeTypicalUserDataSource( | |
48 profile_type)); | |
49 | |
50 // Disable the first run notification because it has an animation which | |
51 // masks any real performance regressions. | |
52 launch_arguments_.AppendSwitch(switches::kDisableNewTabFirstRun); | |
53 } | |
54 | |
55 // Run the test, by bringing up a browser and timing the new tab startup. | |
56 // |want_warm| is true if we should output warm-disk timings, false if | |
57 // we should report cold timings. | |
58 void RunStartupTest(const char* label, bool want_warm, bool important, | |
59 UITestBase::ProfileType profile_type) { | |
60 InitProfile(profile_type); | |
61 | |
62 TimeDelta timings[kNumCycles]; | |
63 for (int i = 0; i < kNumCycles; ++i) { | |
64 UITest::SetUp(); | |
65 | |
66 // Switch to the "new tab" tab, which should be any new tab after the | |
67 // first (the first is about:blank). | |
68 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | |
69 ASSERT_TRUE(window.get()); | |
70 | |
71 // We resize the window so that we hit the normal layout of the NTP and | |
72 // not the small layout mode. | |
73 #if defined(OS_WIN) | |
74 // TODO(port): SetBounds returns false when not implemented. | |
75 // It is OK to comment out the resize since it will still be useful to | |
76 // test the default size of the window. | |
77 ASSERT_TRUE(window->GetWindow().get()->SetBounds(gfx::Rect(1000, 1000))); | |
78 #endif | |
79 int tab_count = -1; | |
80 ASSERT_TRUE(window->GetTabCount(&tab_count)); | |
81 ASSERT_EQ(1, tab_count); | |
82 | |
83 // Hit ctl-t and wait for the tab to load. | |
84 ASSERT_TRUE(window->RunCommand(IDC_NEW_TAB)); | |
85 ASSERT_TRUE(window->GetTabCount(&tab_count)); | |
86 ASSERT_EQ(2, tab_count); | |
87 int load_time; | |
88 ASSERT_TRUE(automation()->WaitForInitialNewTabUILoad(&load_time)); | |
89 | |
90 if (want_warm) { | |
91 // Bring up a second tab, now that we've already shown one tab. | |
92 ASSERT_TRUE(window->RunCommand(IDC_NEW_TAB)); | |
93 ASSERT_TRUE(window->GetTabCount(&tab_count)); | |
94 ASSERT_EQ(3, tab_count); | |
95 ASSERT_TRUE(automation()->WaitForInitialNewTabUILoad(&load_time)); | |
96 } | |
97 timings[i] = TimeDelta::FromMilliseconds(load_time); | |
98 | |
99 window = NULL; | |
100 UITest::TearDown(); | |
101 } | |
102 | |
103 PrintTimings(label, timings, important); | |
104 } | |
105 | |
106 void RunNewTabTimingTest() { | |
107 InitProfile(UITestBase::DEFAULT_THEME); | |
108 | |
109 TimeDelta scriptstart_times[kNumCycles]; | |
110 TimeDelta domcontentloaded_times[kNumCycles]; | |
111 TimeDelta onload_times[kNumCycles]; | |
112 | |
113 for (int i = 0; i < kNumCycles; ++i) { | |
114 UITest::SetUp(); | |
115 | |
116 // Switch to the "new tab" tab, which should be any new tab after the | |
117 // first (the first is about:blank). | |
118 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | |
119 ASSERT_TRUE(window.get()); | |
120 | |
121 // We resize the window so that we hit the normal layout of the NTP and | |
122 // not the small layout mode. | |
123 #if defined(OS_WIN) | |
124 // TODO(port): SetBounds returns false when not implemented. | |
125 // It is OK to comment out the resize since it will still be useful to | |
126 // test the default size of the window. | |
127 ASSERT_TRUE(window->GetWindow().get()->SetBounds(gfx::Rect(1000, 1000))); | |
128 #endif | |
129 int tab_count = -1; | |
130 ASSERT_TRUE(window->GetTabCount(&tab_count)); | |
131 ASSERT_EQ(1, tab_count); | |
132 | |
133 // Hit ctl-t and wait for the tab to load. | |
134 ASSERT_TRUE(window->RunCommand(IDC_NEW_TAB)); | |
135 ASSERT_TRUE(window->GetTabCount(&tab_count)); | |
136 ASSERT_EQ(2, tab_count); | |
137 int duration; | |
138 ASSERT_TRUE(automation()->WaitForInitialNewTabUILoad(&duration)); | |
139 | |
140 // Collect the timing information. | |
141 ASSERT_TRUE(automation()->GetMetricEventDuration("Tab.NewTabScriptStart", | |
142 &duration)); | |
143 scriptstart_times[i] = TimeDelta::FromMilliseconds(duration); | |
144 | |
145 ASSERT_TRUE(automation()->GetMetricEventDuration( | |
146 "Tab.NewTabDOMContentLoaded", &duration)); | |
147 domcontentloaded_times[i] = TimeDelta::FromMilliseconds(duration); | |
148 | |
149 ASSERT_TRUE(automation()->GetMetricEventDuration("Tab.NewTabOnload", | |
150 &duration)); | |
151 onload_times[i] = TimeDelta::FromMilliseconds(duration); | |
152 | |
153 window = NULL; | |
154 UITest::TearDown(); | |
155 } | |
156 | |
157 PrintTimings("script_start", scriptstart_times, false /* important */); | |
158 PrintTimings("domcontent_loaded", domcontentloaded_times, | |
159 false /* important */); | |
160 PrintTimings("onload", onload_times, false /* important */); | |
161 } | |
162 }; | |
163 | |
164 // FLAKY: http://crbug.com/69940 | |
165 TEST_F(NewTabUIStartupTest, FLAKY_PerfRefCold) { | |
166 UseReferenceBuild(); | |
167 RunStartupTest("tab_cold_ref", false /* cold */, true /* important */, | |
168 UITestBase::DEFAULT_THEME); | |
169 } | |
170 | |
171 // FLAKY: http://crbug.com/69940 | |
172 TEST_F(NewTabUIStartupTest, FLAKY_PerfCold) { | |
173 RunStartupTest("tab_cold", false /* cold */, true /* important */, | |
174 UITestBase::DEFAULT_THEME); | |
175 } | |
176 | |
177 // FLAKY: http://crbug.com/69940 | |
178 TEST_F(NewTabUIStartupTest, FLAKY_PerfRefWarm) { | |
179 UseReferenceBuild(); | |
180 RunStartupTest("tab_warm_ref", true /* warm */, true /* not important */, | |
181 UITestBase::DEFAULT_THEME); | |
182 } | |
183 | |
184 // FLAKY: http://crbug.com/69940 | |
185 TEST_F(NewTabUIStartupTest, FLAKY_PerfWarm) { | |
186 RunStartupTest("tab_warm", true /* warm */, true /* not important */, | |
187 UITestBase::DEFAULT_THEME); | |
188 } | |
189 | |
190 // FLAKY: http://crbug.com/69940 | |
191 TEST_F(NewTabUIStartupTest, FLAKY_ComplexThemeCold) { | |
192 RunStartupTest("tab_complex_theme_cold", false /* cold */, | |
193 false /* not important */, | |
194 UITestBase::COMPLEX_THEME); | |
195 } | |
196 | |
197 // FLAKY: http://crbug.com/69940 | |
198 TEST_F(NewTabUIStartupTest, FLAKY_NewTabTimingTestsCold) { | |
199 RunNewTabTimingTest(); | |
200 } | |
201 | |
202 #if defined(TOOLKIT_USES_GTK) | |
203 TEST_F(NewTabUIStartupTest, GtkThemeCold) { | |
204 RunStartupTest("tab_gtk_theme_cold", false /* cold */, | |
205 false /* not important */, | |
206 UITestBase::NATIVE_THEME); | |
207 } | |
208 | |
209 TEST_F(NewTabUIStartupTest, NativeFrameCold) { | |
210 RunStartupTest("tab_custom_frame_cold", false /* cold */, | |
211 false /* not important */, | |
212 UITestBase::CUSTOM_FRAME); | |
213 } | |
214 | |
215 TEST_F(NewTabUIStartupTest, NativeFrameGtkThemeCold) { | |
216 RunStartupTest("tab_custom_frame_gtk_theme_cold", false /* cold */, | |
217 false /* not important */, | |
218 UITestBase::CUSTOM_FRAME_NATIVE_THEME); | |
219 } | |
220 #endif | |
221 | |
222 } // namespace | |
OLD | NEW |