diff options
author | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-16 20:08:20 +0000 |
---|---|---|
committer | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-16 20:08:20 +0000 |
commit | 90e2b34d20d3cf5662ea8776580b9e437b4698a8 (patch) | |
tree | 80f7d78ffa662ec2e7da115e96bfec825df6bf6e /chrome/test | |
parent | df5d5c04bfd7afee66d5eec756d90c79ecfde4e6 (diff) | |
download | chromium_src-90e2b34d20d3cf5662ea8776580b9e437b4698a8.zip chromium_src-90e2b34d20d3cf5662ea8776580b9e437b4698a8.tar.gz chromium_src-90e2b34d20d3cf5662ea8776580b9e437b4698a8.tar.bz2 |
Create a copy of the test directory before using it.
The memory test alters the data, so not doing this
causes the next run to be altered.
Review URL: http://codereview.chromium.org/2861
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2275 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/memory_test/memory_test.cc | 62 |
1 files changed, 52 insertions, 10 deletions
diff --git a/chrome/test/memory_test/memory_test.cc b/chrome/test/memory_test/memory_test.cc index b38ad0a..f3b6892 100644 --- a/chrome/test/memory_test/memory_test.cc +++ b/chrome/test/memory_test/memory_test.cc @@ -23,6 +23,8 @@ namespace {
+static const wchar_t kTempDirName[] = L"memory_test_profile";
+
class MemoryTest : public UITest {
public:
MemoryTest() {
@@ -39,22 +41,39 @@ class MemoryTest : public UITest { CommandLine::AppendSwitch(&launch_arguments_, switches::kNoEvents);
// Get the specified user data dir (optional)
- user_data_dir_ = CommandLine().GetSwitchValue(switches::kUserDataDir);
+ std::wstring profile_dir =
+ CommandLine().GetSwitchValue(switches::kUserDataDir);
- if (user_data_dir_.length() == 0) {
+ if (profile_dir.length() == 0) {
// Compute the user-data-dir which contains our test cache.
- PathService::Get(base::DIR_EXE, &user_data_dir_);
- file_util::UpOneDirectory(&user_data_dir_);
- file_util::UpOneDirectory(&user_data_dir_);
- file_util::AppendToPath(&user_data_dir_, L"data");
- file_util::AppendToPath(&user_data_dir_, L"memory_test");
- file_util::AppendToPath(&user_data_dir_, L"general_mix");
+ PathService::Get(base::DIR_EXE, &profile_dir);
+ file_util::UpOneDirectory(&profile_dir);
+ file_util::UpOneDirectory(&profile_dir);
+ file_util::AppendToPath(&profile_dir, L"data");
+ file_util::AppendToPath(&profile_dir, L"memory_test");
+ file_util::AppendToPath(&profile_dir, L"general_mix");
+ }
+
+ if (!SetupTempDirectory(profile_dir)) {
+ // There isn't really a way to fail gracefully here.
+ // Neither this constuctor nor the SetUp() method return
+ // status to the caller. So, just fall through using the
+ // default profile and log this. The failure will be
+ // obvious.
+ LOG(ERROR) << "Error preparing temp directory for test";
}
+
CommandLine::AppendSwitchWithValue(&launch_arguments_,
switches::kUserDataDir,
user_data_dir_);
}
+ ~MemoryTest() {
+ // Cleanup our temporary directory.
+ if (user_data_dir_.length() > 0)
+ file_util::Delete(user_data_dir_, true);
+ }
+
// TODO(mbelshe): Separate this data to an external file.
// This memory test loads a set of URLs across a set of tabs, maintaining the
// number of concurrent open tabs at num_target_tabs.
@@ -225,7 +244,7 @@ class MemoryTest : public UITest { const int kMaxWaitTime = 5000;
bool timed_out = false;
- tab->NavigateToURLWithTimeout(GURL(urls[counter]), kMaxWaitTime,
+ tab->NavigateToURLWithTimeout(GURL(urls[counter]), kMaxWaitTime,
&timed_out);
if (timed_out)
printf("warning: %s timed out!\n", urls[counter].c_str());
@@ -269,7 +288,7 @@ class MemoryTest : public UITest { ZeroMemory(&io_counters, sizeof(io_counters));
if (process_metrics.get()->GetIOCounters(&io_counters)) {
- std::wstring chrome_name =
+ std::wstring chrome_name =
(pid == chrome_filter.browser_process_id()) ? L"_b" : L"_r";
// Print out IO performance. We assume that the values can be
@@ -346,6 +365,29 @@ class MemoryTest : public UITest { }
private:
+ // Setup a temporary directory to store the profile to use
+ // with these tests.
+ // Input:
+ // src_dir is set to the source directory
+ // Output:
+ // On success, modifies user_data_dir_ to be a new profile directory
+ bool SetupTempDirectory(std::wstring src_dir) {
+ // We create a copy of the test dir and use it so that each
+ // run of this test starts with the same data. Running this
+ // test has the side effect that it will change the profile.
+ std::wstring temp_dir;
+ if (!file_util::CreateNewTempDirectory(kTempDirName, &temp_dir))
+ return false;
+
+ src_dir.append(L"\\*");
+
+ if (!file_util::CopyDirectory(src_dir, temp_dir, true))
+ return false;
+
+ user_data_dir_ = temp_dir;
+ return true;
+ }
+
std::wstring user_data_dir_;
};
|