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

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 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
« no previous file with comments | « chrome/test/perf/perf_ui_test_suite.h ('k') | chrome/test/perf/run_all_perfuitests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 base::PlatformThread::SetName("Tests_Main");
41 }
42
43 PerfUITestSuite::~PerfUITestSuite() {
44 }
45
46 base::FilePath PerfUITestSuite::GetPathForProfileType(
47 ProfileType profile_type) {
48 switch (profile_type) {
49 case DEFAULT_THEME:
50 return g_default_profile_dir.Get();
51 case COMPLEX_THEME:
52 return g_complex_profile_dir.Get();
53 default:
54 NOTREACHED();
55 return base::FilePath();
56 }
57 }
58
59 void PerfUITestSuite::Initialize() {
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 // Copy the Extensions directory from the template into the
86 // complex_profile_dir dir.
87 base::FilePath base_data_dir;
88 if (!PathService::Get(chrome::DIR_TEST_DATA, &base_data_dir))
89 LOG(FATAL) << "Failed to fetch test data dir";
90
91 base_data_dir = base_data_dir.AppendASCII("profiles");
92 base_data_dir = base_data_dir.AppendASCII("profile_with_complex_theme");
93 base_data_dir = base_data_dir.AppendASCII("Default");
94
95 if (!file_util::CopyDirectory(base_data_dir,
96 complex_profile_dir_.path(),
97 true)) {
98 LOG(FATAL) << "Failed to copy default to complex profile";
99 }
100
101 // Parse the manifest and make a temporary extension object because the
102 // theme system takes extensions as input.
103 base::FilePath extension_base =
104 complex_profile_dir_.path()
105 .AppendASCII("Default")
106 .AppendASCII("Extensions")
107 .AppendASCII(kThemeExtension)
108 .AppendASCII("1.1");
109 BuildCachedThemePakIn(extension_base);
110
111 g_complex_profile_dir.Get() = complex_profile_dir_.path();
112 }
113
114 void PerfUITestSuite::BuildCachedThemePakIn(
115 const base::FilePath& extension_base) {
116 int error_code = 0;
117 std::string error;
118 JSONFileValueSerializer serializer(
119 extension_base.AppendASCII("manifest.json"));
120 scoped_ptr<DictionaryValue> valid_value(static_cast<DictionaryValue*>(
121 serializer.Deserialize(&error_code, &error)));
122 if (error_code != 0 || !valid_value)
123 LOG(FATAL) << "Error parsing theme manifest: " << error;
124
125 scoped_refptr<Extension> extension =
126 Extension::Create(extension_base,
127 extensions::Manifest::INVALID_LOCATION,
128 *valid_value,
129 Extension::NO_FLAGS,
130 &error);
131 if (!extension)
132 LOG(FATAL) << "Error loading theme extension: " << error;
133
134 // Build the "Cached Theme.pak" file in the template. (It's not committed
135 // both because committing large binary files is bad in a git world and
136 // because people don't remember to update it anyway, meaning we usually
137 // have the theme rebuild penalty in our data.)
138 MessageLoopForUI message_loop_;
139 content::TestBrowserThread ui_thread_(BrowserThread::UI, &message_loop_);
140 content::TestBrowserThread file_thread_(BrowserThread::FILE,
141 &message_loop_);
142
143 scoped_refptr<BrowserThemePack> theme(
144 BrowserThemePack::BuildFromExtension(extension));
145 if (!theme)
146 LOG(FATAL) << "Failed to load theme from extension";
147
148 theme->WriteToDisk(extension_base.AppendASCII("Cached Theme.pak"));
149 }
OLDNEW
« no previous file with comments | « chrome/test/perf/perf_ui_test_suite.h ('k') | chrome/test/perf/run_all_perfuitests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698