Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/05/03 20:11:47
Sentence still dangling :-}.
| |
| 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 | |
|
Yoyo Zhou
2013/05/06 20:31:02
Should we do this before loading the extension?
Elliot Glaysher
2013/05/06 20:43:22
No, because the theme system takes the Extension o
| |
| 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 } | |
| OLD | NEW |