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

Side by Side Diff: chrome/test/perf/perf_ui_test_suite.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: Rebase to ToT (and redo changes from TopSites to TopSitesImpl) 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 "chrome/test/perf/perf_ui_test_suite.h"
6
7 #include "base/file_util.h"
8 #include "base/json/json_file_value_serializer.h"
9 #include "base/lazy_instance.h"
10 #include "base/logging.h"
11 #include "base/message_loop.h"
12 #include "base/path_service.h"
13 #include "base/string_util.h"
14 #include "base/threading/platform_thread.h"
15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/themes/browser_theme_pack.h"
17 #include "chrome/common/chrome_paths.h"
18 #include "chrome/common/extensions/extension.h"
19 #include "chrome/test/perf/generate_profile.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 int kNumURLs = 20000;
28
29 const char kThemeExtension[] = "mblmlcbknbnfebdfjnolmcapmdofhmme";
30
31 base::LazyInstance<base::FilePath> g_default_profile_dir =
32 LAZY_INSTANCE_INITIALIZER;
33 base::LazyInstance<base::FilePath> g_complex_profile_dir =
34 LAZY_INSTANCE_INITIALIZER;
35
36 } // namespace
37
38 PerfUITestSuite::PerfUITestSuite(int argc, char** argv)
39 : UITestSuite(argc, argv) {
40 }
41
42 PerfUITestSuite::~PerfUITestSuite() {
43 }
44
45 base::FilePath PerfUITestSuite::GetPathForProfileType(
46 ProfileType profile_type) {
47 switch (profile_type) {
48 case DEFAULT_THEME:
49 return g_default_profile_dir.Get();
50 case COMPLEX_THEME:
51 return g_complex_profile_dir.Get();
52 default:
53 NOTREACHED();
54 return base::FilePath();
55 }
56 }
57
58 void PerfUITestSuite::Initialize() {
59 // We do normal initialization afterwards because we want
Randy Smith (Not in Mondays) 2013/04/30 21:27:36 nit: Dangling sentence?
60 UITestSuite::Initialize();
61
62 if (!default_profile_dir_.CreateUniqueTempDir()) {
63 LOG(FATAL) << "Failed to create default profile directory...";
64 }
65
66 // Build a profile in default profile dir.
67 base::FilePath default_path =
68 default_profile_dir_.path().AppendASCII("Default");
69 if (!GenerateProfile(TOP_SITES, kNumURLs, default_path)) {
70 LOG(FATAL) << "Failed to generate default profile for tests...";
71 }
72
73 g_default_profile_dir.Get() = default_profile_dir_.path();
74
75 if (!complex_profile_dir_.CreateUniqueTempDir()) {
76 LOG(FATAL) << "Failed to create complex profile directory...";
77 }
78
79 if (!file_util::CopyDirectory(default_path,
80 complex_profile_dir_.path(),
81 true)) {
82 LOG(FATAL) << "Failed to copy data to complex profile directory...";
83 }
84
85 base::FilePath complex_profile_default_dir =
86 complex_profile_dir_.path().AppendASCII("Default");
87
88 // Copy the Extensions directory from the template into the
89 // complex_profile_dir dir.
90 base::FilePath base_data_dir;
91 if (!PathService::Get(chrome::DIR_TEST_DATA, &base_data_dir))
92 LOG(FATAL) << "Failed to fetch test data dir";
93
94 base_data_dir = base_data_dir.AppendASCII("profiles");
95 base_data_dir = base_data_dir.AppendASCII("profile_with_complex_theme");
96 base_data_dir = base_data_dir.AppendASCII("Default");
97
98 base::FilePath extensions_dir = base_data_dir.AppendASCII("Extensions");
99
100 if (!file_util::CopyDirectory(extensions_dir,
101 complex_profile_default_dir,
102 true)) {
103 LOG(FATAL) << "Failed to copy Extensions from complex profile template";
104 }
105
106 // Parse the manifest and make a temporary extension object because the
107 // theme system takes extensions as input.
108 base::FilePath extension_base =
109 complex_profile_default_dir.AppendASCII("Extensions")
110 .AppendASCII(kThemeExtension)
111 .AppendASCII("1.1");
112 BuildCachedThemePakIn(extension_base);
113
114 ExpandTemplate(base_data_dir, complex_profile_default_dir);
115
116 g_complex_profile_dir.Get() = complex_profile_dir_.path();
117 }
118
119 void PerfUITestSuite::BuildCachedThemePakIn(
120 const base::FilePath& extension_base) {
121 int error_code = 0;
122 std::string error;
123 JSONFileValueSerializer serializer(
124 extension_base.AppendASCII("manifest.json"));
125 scoped_ptr<DictionaryValue> valid_value(static_cast<DictionaryValue*>(
126 serializer.Deserialize(&error_code, &error)));
127 if (error_code != 0 || !valid_value)
128 LOG(FATAL) << "Error parsing theme manifest: " << error;
129
130 scoped_refptr<Extension> extension =
131 Extension::Create(extension_base,
132 extensions::Manifest::INVALID_LOCATION,
133 *valid_value,
134 Extension::NO_FLAGS,
135 &error);
136 if (!extension)
137 LOG(FATAL) << "Error loading theme extension: " << error;
138
139 // Build the "Cached Theme.pak" file in the template. (It's not committed
140 // both because committing large binary files is bad in a git world and
141 // because people don't remember to update it anyway, meaning we usually
142 // have the theme rebuild penalty in our data.)
143 MessageLoopForUI message_loop_;
144 content::TestBrowserThread ui_thread_(BrowserThread::UI, &message_loop_);
145 content::TestBrowserThread file_thread_(BrowserThread::FILE,
146 &message_loop_);
147
148 scoped_refptr<BrowserThemePack> theme(
149 BrowserThemePack::BuildFromExtension(extension));
150 if (!theme)
151 LOG(FATAL) << "Failed to load theme from extension";
152
153 theme->WriteToDisk(extension_base.AppendASCII("Cached Theme.pak"));
154 }
155
156 void PerfUITestSuite::ExpandTemplate(
157 const base::FilePath& base_data_dir,
158 const base::FilePath& complex_profile_default_dir) {
159 std::string contents;
160 if (!file_util::ReadFileToString(
161 base_data_dir.AppendASCII("PreferencesTemplate"),
162 &contents)) {
163 LOG(FATAL) << "Failed to read preferences template";
164 }
165
166 std::string path;
167 #if defined(OS_WIN)
168 path = UTF16ToUTF8(complex_profile_dir_.path().value());
169 #else
170 path = complex_profile_dir_.path().value();
171 #endif
172
173 std::vector<std::string> subst;
174 subst.push_back(path);
175 std::string expanded = ReplaceStringPlaceholders(contents, subst, NULL);
176
177 if (file_util::WriteFile(
178 complex_profile_default_dir.AppendASCII("Preferences"),
179 expanded.c_str(), expanded.size()) == -1) {
180 LOG(FATAL) << "Failed to write preferences file to profile with theme";
181 }
182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698