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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/perf/performance_ui_tests.cc
diff --git a/chrome/test/perf/performance_ui_tests.cc b/chrome/test/perf/performance_ui_tests.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0f8de3070062990745aa8c9ba32683d5314ca458
--- /dev/null
+++ b/chrome/test/perf/performance_ui_tests.cc
@@ -0,0 +1,178 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/file_util.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/json/json_file_value_serializer.h"
+#include "base/logging.h"
+#include "base/message_loop.h"
+#include "base/path_service.h"
+#include "base/string_util.h"
+#include "base/threading/platform_thread.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/themes/browser_theme_pack.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/common/extensions/extension.h"
+#include "chrome/test/perf/generate_profile.h"
+#include "chrome/test/perf/perf_test.h"
+#include "chrome/test/ui/ui_test_suite.h"
+#include "content/public/test/test_browser_thread.h"
+
+using content::BrowserThread;
+using extensions::Extension;
+
+namespace {
+
+const char kThemeExtension[] = "mblmlcbknbnfebdfjnolmcapmdofhmme";
+
+class PerfTest : public UITestSuite {
Paweł Hajdan Jr. 2013/04/26 23:19:32 Class name should include TestSuite. It's not a te
+ public:
+ PerfTest(int argc, char** argv) : UITestSuite(argc, argv) {}
+ virtual ~PerfTest() {}
+
+ virtual void Initialize() OVERRIDE {
+ // We do normal initialization afterwards because we want
+ UITestSuite::Initialize();
+
+ if (!default_profile_dir_.CreateUniqueTempDir()) {
+ LOG(ERROR) << "Failed to create default profile directory...";
+ exit(-1);
Paweł Hajdan Jr. 2013/04/26 23:19:32 I prefer CHECK or LOG(FATAL) over LOG + exit. Tota
+ }
+
+ // Build a profile in default profile dir.
+ base::FilePath default_path =
+ default_profile_dir_.path().AppendASCII("Default");
+ if (!GenerateProfile(TOP_SITES, 20000, default_path)) {
Paweł Hajdan Jr. 2013/04/26 23:19:32 Let's extract 20000 to a named constant.
+ LOG(ERROR) << "Failed to generate default profile for tests...";
+ exit(-1);
+ }
+
+ perf_test::SetPathForProfileType(perf_test::DEFAULT_THEME,
+ default_profile_dir_.path());
+
+ if (!complex_profile_dir_.CreateUniqueTempDir()) {
+ LOG(ERROR) << "Failed to create complex profile directory...";
+ exit(-1);
+ }
+
+ if (!file_util::CopyDirectory(default_path,
+ complex_profile_dir_.path(),
+ true)) {
+ LOG(ERROR) << "Failed to copy data to complex profile directory...";
+ exit(-1);
+ }
+
+ base::FilePath complex_profile_default_dir =
+ complex_profile_dir_.path().AppendASCII("Default");
+
+ // Copy the Extensions directory from the template into the
+ // complex_profile_dir dir.
+ base::FilePath base_data_dir;
+ if (!PathService::Get(chrome::DIR_TEST_DATA, &base_data_dir)) {
+ LOG(ERROR) << "Failed to fetch test data dir";
+ exit(-1);
+ }
+ base_data_dir = base_data_dir.AppendASCII("profiles");
+ base_data_dir = base_data_dir.AppendASCII("profile_with_complex_theme");
+ base_data_dir = base_data_dir.AppendASCII("Default");
+
+ base::FilePath extensions_dir = base_data_dir.AppendASCII("Extensions");
+
+ if (!file_util::CopyDirectory(extensions_dir,
+ complex_profile_default_dir,
+ true)) {
+ LOG(ERROR) << "Failed to copy Extensions from complex profile template";
+ exit(-1);
+ }
+
+ // Parse the manifest and make a temporary extension object because the
+ // theme system takes extensions as input.
+ base::FilePath extension_base =
+ complex_profile_default_dir.AppendASCII("Extensions")
+ .AppendASCII(kThemeExtension)
+ .AppendASCII("1.1");
+
+ int error_code = 0;
+ std::string error;
+ JSONFileValueSerializer serializer(
+ extension_base.AppendASCII("manifest.json"));
+ scoped_ptr<DictionaryValue> valid_value(static_cast<DictionaryValue*>(
+ serializer.Deserialize(&error_code, &error)));
+ if (error_code != 0 || !valid_value) {
+ LOG(ERROR) << "Error parsing theme manifest: " << error;
+ exit(-1);
+ }
+
+ scoped_refptr<Extension> extension =
+ Extension::Create(extension_base,
+ extensions::Manifest::INVALID_LOCATION,
+ *valid_value,
+ Extension::NO_FLAGS,
+ &error);
+ if (!extension) {
+ LOG(ERROR) << "Error loading theme extension: " << error;
+ exit(-1);
+ }
+
+ // Build the "Cached Theme.pak" file in the template. (It's not committed
+ // both because committing large binary files is bad in a git world and
+ // because people don't remember to update it anyway, meaning we usually
+ // have the theme rebuild penalty in our data.)
+ MessageLoopForUI message_loop_;
+ content::TestBrowserThread ui_thread_(BrowserThread::UI, &message_loop_);
+ content::TestBrowserThread file_thread_(BrowserThread::FILE,
+ &message_loop_);
+
+ scoped_refptr<BrowserThemePack> theme(
+ BrowserThemePack::BuildFromExtension(extension));
+ if (!theme) {
+ LOG(ERROR) << "Failed to load theme from extension";
+ exit(-1);
+ }
+
+ theme->WriteToDisk(extension_base.AppendASCII("Cached Theme.pak"));
+
+ // Finally, we need to expand the template so that we point to the Cached
+ // Theme.pak.
+ std::string contents;
+ if (!file_util::ReadFileToString(
+ base_data_dir.AppendASCII("PreferencesTemplate"),
+ &contents)) {
+ LOG(ERROR) << "Failed to read preferences template";
+ exit(-1);
+ }
+
+ std::string path;
+#if defined(OS_WIN)
+ path = UTF16ToUTF8(complex_profile_dir_.path().value());
+#else
+ path = complex_profile_dir_.path().value();
+#endif
+
+ std::vector<std::string> subst;
+ subst.push_back(path);
+ std::string expanded = ReplaceStringPlaceholders(contents, subst, NULL);
+
+ if (file_util::WriteFile(
+ complex_profile_default_dir.AppendASCII("Preferences"),
+ expanded.c_str(), expanded.size()) == -1) {
+ LOG(ERROR) << "Failed to write preferences file to profile with theme";
+ exit(-1);
+ }
+
+ perf_test::SetPathForProfileType(perf_test::COMPLEX_THEME,
+ complex_profile_dir_.path());
+ }
+
+ private:
+ base::ScopedTempDir default_profile_dir_;
+ base::ScopedTempDir complex_profile_dir_;
+};
+
+} // namespace
+
+int main(int argc, char **argv) {
+ base::PlatformThread::SetName("Tests_Main");
+ return PerfTest(argc, argv).Run();
Paweł Hajdan Jr. 2013/04/26 23:19:32 This (main) should move to a separate file, like r
+}

Powered by Google App Engine
This is Rietveld 408576698