| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | |
| 10 #include "base/test/test_file_util.h" | 9 #include "base/test/test_file_util.h" |
| 11 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "base/memory/scoped_temp_dir.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/json_value_serializer.h" | 15 #include "chrome/common/json_value_serializer.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/test/automation/browser_proxy.h" | 17 #include "chrome/test/automation/browser_proxy.h" |
| 18 #include "chrome/test/automation/window_proxy.h" | 18 #include "chrome/test/automation/window_proxy.h" |
| 19 #include "chrome/test/ui/ui_test.h" | 19 #include "chrome/test/ui/ui_test.h" |
| 20 #include "ui/gfx/rect.h" | 20 #include "ui/gfx/rect.h" |
| 21 | 21 |
| 22 class PreferenceServiceTest : public UITest { | 22 class PreferenceServiceTest : public UITest { |
| 23 public: | 23 public: |
| 24 void SetUp() { | 24 void SetUp() { |
| 25 PathService::Get(base::DIR_TEMP, &tmp_profile_); | 25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 26 tmp_profile_ = tmp_profile_.AppendASCII("tmp_profile"); | 26 FilePath tmp_profile = temp_dir_.path().AppendASCII("tmp_profile"); |
| 27 | 27 |
| 28 // Create a fresh, empty copy of this directory. | 28 file_util::CreateDirectory(tmp_profile); |
| 29 file_util::Delete(tmp_profile_, true); | |
| 30 file_util::CreateDirectory(tmp_profile_); | |
| 31 | 29 |
| 32 FilePath reference_pref_file; | 30 FilePath reference_pref_file; |
| 33 if (new_profile_) { | 31 if (new_profile_) { |
| 34 reference_pref_file = test_data_directory_ | 32 reference_pref_file = test_data_directory_ |
| 35 .AppendASCII("profiles") | 33 .AppendASCII("profiles") |
| 36 .AppendASCII("window_placement") | 34 .AppendASCII("window_placement") |
| 37 .AppendASCII("Default") | 35 .AppendASCII("Default") |
| 38 .Append(chrome::kPreferencesFilename); | 36 .Append(chrome::kPreferencesFilename); |
| 39 tmp_pref_file_ = tmp_profile_.AppendASCII("Default"); | 37 tmp_pref_file_ = tmp_profile.AppendASCII("Default"); |
| 40 ASSERT_TRUE(file_util::CreateDirectory(tmp_pref_file_)); | 38 ASSERT_TRUE(file_util::CreateDirectory(tmp_pref_file_)); |
| 41 tmp_pref_file_ = tmp_pref_file_.Append(chrome::kPreferencesFilename); | 39 tmp_pref_file_ = tmp_pref_file_.Append(chrome::kPreferencesFilename); |
| 42 } else { | 40 } else { |
| 43 reference_pref_file = test_data_directory_ | 41 reference_pref_file = test_data_directory_ |
| 44 .AppendASCII("profiles") | 42 .AppendASCII("profiles") |
| 45 .AppendASCII("window_placement") | 43 .AppendASCII("window_placement") |
| 46 .Append(chrome::kLocalStateFilename); | 44 .Append(chrome::kLocalStateFilename); |
| 47 tmp_pref_file_ = tmp_profile_.Append(chrome::kLocalStateFilename); | 45 tmp_pref_file_ = tmp_profile.Append(chrome::kLocalStateFilename); |
| 48 } | 46 } |
| 49 | 47 |
| 50 ASSERT_TRUE(file_util::PathExists(reference_pref_file)); | 48 ASSERT_TRUE(file_util::PathExists(reference_pref_file)); |
| 51 // Copy only the Preferences file if |new_profile_|, or Local State if not, | 49 // Copy only the Preferences file if |new_profile_|, or Local State if not, |
| 52 // and the rest will be automatically created. | 50 // and the rest will be automatically created. |
| 53 ASSERT_TRUE(file_util::CopyFile(reference_pref_file, tmp_pref_file_)); | 51 ASSERT_TRUE(file_util::CopyFile(reference_pref_file, tmp_pref_file_)); |
| 54 | 52 |
| 55 #if defined(OS_WIN) | 53 #if defined(OS_WIN) |
| 56 // Make the copy writable. On POSIX we assume the umask allows files | 54 // Make the copy writable. On POSIX we assume the umask allows files |
| 57 // we create to be writable. | 55 // we create to be writable. |
| 58 ASSERT_TRUE(::SetFileAttributesW(tmp_pref_file_.value().c_str(), | 56 ASSERT_TRUE(::SetFileAttributesW(tmp_pref_file_.value().c_str(), |
| 59 FILE_ATTRIBUTE_NORMAL)); | 57 FILE_ATTRIBUTE_NORMAL)); |
| 60 #endif | 58 #endif |
| 61 | 59 |
| 62 launch_arguments_.AppendSwitchPath(switches::kUserDataDir, tmp_profile_); | 60 launch_arguments_.AppendSwitchPath(switches::kUserDataDir, tmp_profile); |
| 63 } | 61 } |
| 64 | 62 |
| 65 bool LaunchAppWithProfile() { | 63 bool LaunchAppWithProfile() { |
| 66 if (!file_util::PathExists(tmp_pref_file_)) | 64 if (!file_util::PathExists(tmp_pref_file_)) |
| 67 return false; | 65 return false; |
| 68 UITest::SetUp(); | 66 UITest::SetUp(); |
| 69 return true; | 67 return true; |
| 70 } | 68 } |
| 71 | 69 |
| 72 void TearDown() { | 70 void TearDown() { |
| 73 UITest::TearDown(); | 71 UITest::TearDown(); |
| 74 | |
| 75 EXPECT_TRUE(file_util::DieFileDie(tmp_profile_, true)); | |
| 76 } | 72 } |
| 77 | 73 |
| 78 public: | 74 public: |
| 79 bool new_profile_; | 75 bool new_profile_; |
| 80 FilePath tmp_pref_file_; | 76 FilePath tmp_pref_file_; |
| 81 FilePath tmp_profile_; | 77 |
| 78 private: |
| 79 ScopedTempDir temp_dir_; |
| 82 }; | 80 }; |
| 83 | 81 |
| 84 #if !defined(OS_LINUX) | 82 #if !defined(OS_LINUX) |
| 85 // This test verifies that the window position from the prefs file is restored | 83 // This test verifies that the window position from the prefs file is restored |
| 86 // when the app restores. This doesn't really make sense on Linux, where | 84 // when the app restores. This doesn't really make sense on Linux, where |
| 87 // the window manager might fight with you over positioning. However, we | 85 // the window manager might fight with you over positioning. However, we |
| 88 // might be able to make this work on buildbots. | 86 // might be able to make this work on buildbots. |
| 89 // TODO(port): revisit this. | 87 // TODO(port): revisit this. |
| 90 TEST_F(PreferenceServiceTest, PreservedWindowPlacementIsLoaded) { | 88 TEST_F(PreferenceServiceTest, PreservedWindowPlacementIsLoaded) { |
| 91 // The window should open with the new reference profile, with window | 89 // The window should open with the new reference profile, with window |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 // Find if launched window is maximized. | 197 // Find if launched window is maximized. |
| 200 bool is_window_maximized = false; | 198 bool is_window_maximized = false; |
| 201 ASSERT_TRUE(window->IsMaximized(&is_window_maximized)); | 199 ASSERT_TRUE(window->IsMaximized(&is_window_maximized)); |
| 202 bool is_maximized = false; | 200 bool is_maximized = false; |
| 203 EXPECT_TRUE(root_dict->GetBoolean(kBrowserWindowPlacement + ".maximized", | 201 EXPECT_TRUE(root_dict->GetBoolean(kBrowserWindowPlacement + ".maximized", |
| 204 &is_maximized)); | 202 &is_maximized)); |
| 205 EXPECT_EQ(is_maximized, is_window_maximized); | 203 EXPECT_EQ(is_maximized, is_window_maximized); |
| 206 } | 204 } |
| 207 #endif | 205 #endif |
| 208 | 206 |
| OLD | NEW |