Make hitting "Enter" submit the add/change profile dialog.
[chromium-blink-merge.git] / chrome / test / perf / feature_startup_test.cc
blob564dbfeac310d60d041bf7b033d927f89879da58
1 // Copyright (c) 2012 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.
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/perf/perf_test.h"
17 #include "chrome/test/ui/ui_perf_test.h"
18 #include "net/base/net_util.h"
19 #include "ui/gfx/rect.h"
21 using base::TimeDelta;
23 namespace {
25 class NewTabUIStartupTest : public UIPerfTest {
26 public:
27 NewTabUIStartupTest() {
28 show_window_ = true;
31 void SetUp() {}
32 void TearDown() {}
34 static const int kNumCycles = 5;
36 void PrintTimings(const char* label, TimeDelta timings[kNumCycles],
37 bool important) {
38 std::string times;
39 for (int i = 0; i < kNumCycles; ++i)
40 base::StringAppendF(&times, "%.2f,", timings[i].InMillisecondsF());
41 perf_test::PrintResultList("new_tab", "", label, times, "ms", important);
44 void InitProfile(UITestBase::ProfileType profile_type) {
45 profile_type_ = profile_type;
47 // Install the location of the test profile file.
48 set_template_user_data(UITest::ComputeTypicalUserDataSource(
49 profile_type));
52 // Run the test, by bringing up a browser and timing the new tab startup.
53 // |want_warm| is true if we should output warm-disk timings, false if
54 // we should report cold timings.
55 void RunStartupTest(const char* label, bool want_warm, bool important,
56 UITestBase::ProfileType profile_type) {
57 InitProfile(profile_type);
59 TimeDelta timings[kNumCycles];
60 for (int i = 0; i < kNumCycles; ++i) {
61 UITest::SetUp();
63 // Switch to the "new tab" tab, which should be any new tab after the
64 // first (the first is about:blank).
65 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0));
66 ASSERT_TRUE(window.get());
68 // We resize the window so that we hit the normal layout of the NTP and
69 // not the small layout mode.
70 #if defined(OS_WIN)
71 // TODO(port): SetBounds returns false when not implemented.
72 // It is OK to comment out the resize since it will still be useful to
73 // test the default size of the window.
74 ASSERT_TRUE(window->GetWindow().get()->SetBounds(gfx::Rect(1000, 1000)));
75 #endif
76 int tab_count = -1;
77 ASSERT_TRUE(window->GetTabCount(&tab_count));
78 ASSERT_EQ(1, tab_count);
80 // Hit ctl-t and wait for the tab to load.
81 ASSERT_TRUE(window->RunCommand(IDC_NEW_TAB));
82 ASSERT_TRUE(window->GetTabCount(&tab_count));
83 ASSERT_EQ(2, tab_count);
84 int load_time;
85 ASSERT_TRUE(automation()->WaitForInitialNewTabUILoad(&load_time));
87 if (want_warm) {
88 // Bring up a second tab, now that we've already shown one tab.
89 ASSERT_TRUE(window->RunCommand(IDC_NEW_TAB));
90 ASSERT_TRUE(window->GetTabCount(&tab_count));
91 ASSERT_EQ(3, tab_count);
92 ASSERT_TRUE(automation()->WaitForInitialNewTabUILoad(&load_time));
94 timings[i] = TimeDelta::FromMilliseconds(load_time);
96 window = NULL;
97 UITest::TearDown();
100 PrintTimings(label, timings, important);
103 void RunNewTabTimingTest() {
104 InitProfile(UITestBase::DEFAULT_THEME);
106 TimeDelta scriptstart_times[kNumCycles];
107 TimeDelta domcontentloaded_times[kNumCycles];
108 TimeDelta onload_times[kNumCycles];
110 for (int i = 0; i < kNumCycles; ++i) {
111 UITest::SetUp();
113 // Switch to the "new tab" tab, which should be any new tab after the
114 // first (the first is about:blank).
115 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0));
116 ASSERT_TRUE(window.get());
118 // We resize the window so that we hit the normal layout of the NTP and
119 // not the small layout mode.
120 #if defined(OS_WIN)
121 // TODO(port): SetBounds returns false when not implemented.
122 // It is OK to comment out the resize since it will still be useful to
123 // test the default size of the window.
124 ASSERT_TRUE(window->GetWindow().get()->SetBounds(gfx::Rect(1000, 1000)));
125 #endif
126 int tab_count = -1;
127 ASSERT_TRUE(window->GetTabCount(&tab_count));
128 ASSERT_EQ(1, tab_count);
130 // Hit ctl-t and wait for the tab to load.
131 ASSERT_TRUE(window->RunCommand(IDC_NEW_TAB));
132 ASSERT_TRUE(window->GetTabCount(&tab_count));
133 ASSERT_EQ(2, tab_count);
134 int duration;
135 ASSERT_TRUE(automation()->WaitForInitialNewTabUILoad(&duration));
137 // Collect the timing information.
138 ASSERT_TRUE(automation()->GetMetricEventDuration("Tab.NewTabScriptStart",
139 &duration));
140 scriptstart_times[i] = TimeDelta::FromMilliseconds(duration);
142 ASSERT_TRUE(automation()->GetMetricEventDuration(
143 "Tab.NewTabDOMContentLoaded", &duration));
144 domcontentloaded_times[i] = TimeDelta::FromMilliseconds(duration);
146 ASSERT_TRUE(automation()->GetMetricEventDuration("Tab.NewTabOnload",
147 &duration));
148 onload_times[i] = TimeDelta::FromMilliseconds(duration);
150 window = NULL;
151 UITest::TearDown();
154 PrintTimings("script_start", scriptstart_times, false /* important */);
155 PrintTimings("domcontent_loaded", domcontentloaded_times,
156 false /* important */);
157 PrintTimings("onload", onload_times, false /* important */);
161 // FLAKY: http://crbug.com/69940
162 TEST_F(NewTabUIStartupTest, DISABLED_PerfRefCold) {
163 UseReferenceBuild();
164 RunStartupTest("tab_cold_ref", false /* cold */, true /* important */,
165 UITestBase::DEFAULT_THEME);
168 // FLAKY: http://crbug.com/69940
169 TEST_F(NewTabUIStartupTest, DISABLED_PerfCold) {
170 RunStartupTest("tab_cold", false /* cold */, true /* important */,
171 UITestBase::DEFAULT_THEME);
174 // FLAKY: http://crbug.com/69940
175 TEST_F(NewTabUIStartupTest, DISABLED_PerfRefWarm) {
176 UseReferenceBuild();
177 RunStartupTest("tab_warm_ref", true /* warm */, true /* not important */,
178 UITestBase::DEFAULT_THEME);
181 // FLAKY: http://crbug.com/69940
182 TEST_F(NewTabUIStartupTest, DISABLED_PerfWarm) {
183 RunStartupTest("tab_warm", true /* warm */, true /* not important */,
184 UITestBase::DEFAULT_THEME);
187 // FLAKY: http://crbug.com/69940
188 TEST_F(NewTabUIStartupTest, DISABLED_ComplexThemeCold) {
189 RunStartupTest("tab_complex_theme_cold", false /* cold */,
190 false /* not important */,
191 UITestBase::COMPLEX_THEME);
194 // FLAKY: http://crbug.com/69940
195 TEST_F(NewTabUIStartupTest, DISABLED_NewTabTimingTestsCold) {
196 RunNewTabTimingTest();
199 } // namespace