Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: chrome/test/perf/performance_ui_tests.cc

Issue 14273023: Rebuild test history databases when starting up performance_ui_tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Speed up profile generation Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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/files/scoped_temp_dir.h"
7 #include "base/json/json_file_value_serializer.h"
8 #include "base/logging.h"
9 #include "base/message_loop.h"
10 #include "base/path_service.h"
11 #include "base/string_util.h"
12 #include "base/threading/platform_thread.h"
13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/themes/browser_theme_pack.h"
15 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/extensions/extension.h"
17 #include "chrome/test/perf/generate_profile.h"
18 #include "chrome/test/perf/perf_test.h"
19 #include "chrome/test/ui/ui_test_suite.h"
20 #include "content/public/test/test_browser_thread.h"
21
22 using content::BrowserThread;
23 using extensions::Extension;
24
25 namespace {
26
27 const char kThemeExtension[] = "mblmlcbknbnfebdfjnolmcapmdofhmme";
28
29 class PerfTest : public UITestSuite {
Paweł Hajdan Jr. 2013/04/26 23:19:32 Class name should include TestSuite. It's not a te
30 public:
31 PerfTest(int argc, char** argv) : UITestSuite(argc, argv) {}
32 virtual ~PerfTest() {}
33
34 virtual void Initialize() OVERRIDE {
35 // We do normal initialization afterwards because we want
36 UITestSuite::Initialize();
37
38 if (!default_profile_dir_.CreateUniqueTempDir()) {
39 LOG(ERROR) << "Failed to create default profile directory...";
40 exit(-1);
Paweł Hajdan Jr. 2013/04/26 23:19:32 I prefer CHECK or LOG(FATAL) over LOG + exit. Tota
41 }
42
43 // Build a profile in default profile dir.
44 base::FilePath default_path =
45 default_profile_dir_.path().AppendASCII("Default");
46 if (!GenerateProfile(TOP_SITES, 20000, default_path)) {
Paweł Hajdan Jr. 2013/04/26 23:19:32 Let's extract 20000 to a named constant.
47 LOG(ERROR) << "Failed to generate default profile for tests...";
48 exit(-1);
49 }
50
51 perf_test::SetPathForProfileType(perf_test::DEFAULT_THEME,
52 default_profile_dir_.path());
53
54 if (!complex_profile_dir_.CreateUniqueTempDir()) {
55 LOG(ERROR) << "Failed to create complex profile directory...";
56 exit(-1);
57 }
58
59 if (!file_util::CopyDirectory(default_path,
60 complex_profile_dir_.path(),
61 true)) {
62 LOG(ERROR) << "Failed to copy data to complex profile directory...";
63 exit(-1);
64 }
65
66 base::FilePath complex_profile_default_dir =
67 complex_profile_dir_.path().AppendASCII("Default");
68
69 // Copy the Extensions directory from the template into the
70 // complex_profile_dir dir.
71 base::FilePath base_data_dir;
72 if (!PathService::Get(chrome::DIR_TEST_DATA, &base_data_dir)) {
73 LOG(ERROR) << "Failed to fetch test data dir";
74 exit(-1);
75 }
76 base_data_dir = base_data_dir.AppendASCII("profiles");
77 base_data_dir = base_data_dir.AppendASCII("profile_with_complex_theme");
78 base_data_dir = base_data_dir.AppendASCII("Default");
79
80 base::FilePath extensions_dir = base_data_dir.AppendASCII("Extensions");
81
82 if (!file_util::CopyDirectory(extensions_dir,
83 complex_profile_default_dir,
84 true)) {
85 LOG(ERROR) << "Failed to copy Extensions from complex profile template";
86 exit(-1);
87 }
88
89 // Parse the manifest and make a temporary extension object because the
90 // theme system takes extensions as input.
91 base::FilePath extension_base =
92 complex_profile_default_dir.AppendASCII("Extensions")
93 .AppendASCII(kThemeExtension)
94 .AppendASCII("1.1");
95
96 int error_code = 0;
97 std::string error;
98 JSONFileValueSerializer serializer(
99 extension_base.AppendASCII("manifest.json"));
100 scoped_ptr<DictionaryValue> valid_value(static_cast<DictionaryValue*>(
101 serializer.Deserialize(&error_code, &error)));
102 if (error_code != 0 || !valid_value) {
103 LOG(ERROR) << "Error parsing theme manifest: " << error;
104 exit(-1);
105 }
106
107 scoped_refptr<Extension> extension =
108 Extension::Create(extension_base,
109 extensions::Manifest::INVALID_LOCATION,
110 *valid_value,
111 Extension::NO_FLAGS,
112 &error);
113 if (!extension) {
114 LOG(ERROR) << "Error loading theme extension: " << error;
115 exit(-1);
116 }
117
118 // Build the "Cached Theme.pak" file in the template. (It's not committed
119 // both because committing large binary files is bad in a git world and
120 // because people don't remember to update it anyway, meaning we usually
121 // have the theme rebuild penalty in our data.)
122 MessageLoopForUI message_loop_;
123 content::TestBrowserThread ui_thread_(BrowserThread::UI, &message_loop_);
124 content::TestBrowserThread file_thread_(BrowserThread::FILE,
125 &message_loop_);
126
127 scoped_refptr<BrowserThemePack> theme(
128 BrowserThemePack::BuildFromExtension(extension));
129 if (!theme) {
130 LOG(ERROR) << "Failed to load theme from extension";
131 exit(-1);
132 }
133
134 theme->WriteToDisk(extension_base.AppendASCII("Cached Theme.pak"));
135
136 // Finally, we need to expand the template so that we point to the Cached
137 // Theme.pak.
138 std::string contents;
139 if (!file_util::ReadFileToString(
140 base_data_dir.AppendASCII("PreferencesTemplate"),
141 &contents)) {
142 LOG(ERROR) << "Failed to read preferences template";
143 exit(-1);
144 }
145
146 std::string path;
147 #if defined(OS_WIN)
148 path = UTF16ToUTF8(complex_profile_dir_.path().value());
149 #else
150 path = complex_profile_dir_.path().value();
151 #endif
152
153 std::vector<std::string> subst;
154 subst.push_back(path);
155 std::string expanded = ReplaceStringPlaceholders(contents, subst, NULL);
156
157 if (file_util::WriteFile(
158 complex_profile_default_dir.AppendASCII("Preferences"),
159 expanded.c_str(), expanded.size()) == -1) {
160 LOG(ERROR) << "Failed to write preferences file to profile with theme";
161 exit(-1);
162 }
163
164 perf_test::SetPathForProfileType(perf_test::COMPLEX_THEME,
165 complex_profile_dir_.path());
166 }
167
168 private:
169 base::ScopedTempDir default_profile_dir_;
170 base::ScopedTempDir complex_profile_dir_;
171 };
172
173 } // namespace
174
175 int main(int argc, char **argv) {
176 base::PlatformThread::SetName("Tests_Main");
177 return PerfTest(argc, argv).Run();
Paweł Hajdan Jr. 2013/04/26 23:19:32 This (main) should move to a separate file, like r
178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698