OLD | NEW |
1 // Copyright (c) 2009 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" | 9 #include "base/path_service.h" |
10 #include "base/test/test_file_util.h" | 10 #include "base/test/test_file_util.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
(...skipping 14 matching lines...) Expand all Loading... |
26 tmp_profile_ = tmp_profile_.AppendASCII("tmp_profile"); | 26 tmp_profile_ = tmp_profile_.AppendASCII("tmp_profile"); |
27 | 27 |
28 // Create a fresh, empty copy of this directory. | 28 // Create a fresh, empty copy of this directory. |
29 file_util::Delete(tmp_profile_, true); | 29 file_util::Delete(tmp_profile_, true); |
30 file_util::CreateDirectory(tmp_profile_); | 30 file_util::CreateDirectory(tmp_profile_); |
31 | 31 |
32 FilePath reference_pref_file = | 32 FilePath reference_pref_file = |
33 test_data_directory_ | 33 test_data_directory_ |
34 .AppendASCII("profiles") | 34 .AppendASCII("profiles") |
35 .AppendASCII("window_placement") | 35 .AppendASCII("window_placement") |
36 .Append(chrome::kLocalStateFilename); | 36 .AppendASCII("Default") |
| 37 .Append(chrome::kPreferencesFilename); |
37 | 38 |
38 tmp_pref_file_ = tmp_profile_.Append(chrome::kLocalStateFilename); | 39 tmp_pref_file_ = tmp_profile_.AppendASCII("Default"); |
39 | 40 |
| 41 ASSERT_TRUE(file_util::CreateDirectory(tmp_pref_file_)); |
| 42 |
| 43 tmp_pref_file_ = tmp_pref_file_.Append(chrome::kPreferencesFilename); |
40 ASSERT_TRUE(file_util::PathExists(reference_pref_file)); | 44 ASSERT_TRUE(file_util::PathExists(reference_pref_file)); |
41 | 45 // Copy only the Preferences file, the rest will be automatically created. |
42 // Copy only the Local State file, the rest will be automatically created | |
43 ASSERT_TRUE(file_util::CopyFile(reference_pref_file, tmp_pref_file_)); | 46 ASSERT_TRUE(file_util::CopyFile(reference_pref_file, tmp_pref_file_)); |
44 | 47 |
45 #if defined(OS_WIN) | 48 #if defined(OS_WIN) |
46 // Make the copy writable. On POSIX we assume the umask allows files | 49 // Make the copy writable. On POSIX we assume the umask allows files |
47 // we create to be writable. | 50 // we create to be writable. |
48 ASSERT_TRUE(::SetFileAttributesW(tmp_pref_file_.value().c_str(), | 51 ASSERT_TRUE(::SetFileAttributesW(tmp_pref_file_.value().c_str(), |
49 FILE_ATTRIBUTE_NORMAL)); | 52 FILE_ATTRIBUTE_NORMAL)); |
50 #endif | 53 #endif |
51 | 54 |
52 launch_arguments_.AppendSwitchPath(switches::kUserDataDir, tmp_profile_); | 55 launch_arguments_.AppendSwitchPath(switches::kUserDataDir, tmp_profile_); |
(...skipping 10 matching lines...) Expand all Loading... |
63 UITest::TearDown(); | 66 UITest::TearDown(); |
64 | 67 |
65 EXPECT_TRUE(file_util::DieFileDie(tmp_profile_, true)); | 68 EXPECT_TRUE(file_util::DieFileDie(tmp_profile_, true)); |
66 } | 69 } |
67 | 70 |
68 public: | 71 public: |
69 FilePath tmp_pref_file_; | 72 FilePath tmp_pref_file_; |
70 FilePath tmp_profile_; | 73 FilePath tmp_profile_; |
71 }; | 74 }; |
72 | 75 |
73 #if defined(OS_WIN) | 76 #if !defined(OS_LINUX) |
74 // This test verifies that the window position from the prefs file is restored | 77 // This test verifies that the window position from the prefs file is restored |
75 // when the app restores. This doesn't really make sense on Linux, where | 78 // when the app restores. This doesn't really make sense on Linux, where |
76 // the window manager might fight with you over positioning. However, we | 79 // the window manager might fight with you over positioning. However, we |
77 // might be able to make this work on buildbots. | 80 // might be able to make this work on buildbots. |
78 // Also, not sure what should happen on the mac. In any case, the code below | |
79 // (minus the Windows bits) compiles fine on my Linux box now. | |
80 // TODO(port): revisit this. | 81 // TODO(port): revisit this. |
81 TEST_F(PreferenceServiceTest, PreservedWindowPlacementIsLoaded) { | 82 TEST_F(PreferenceServiceTest, PreservedWindowPlacementIsLoaded) { |
82 // The window should open with the reference profile | 83 // The window should open with the reference profile |
83 ASSERT_TRUE(LaunchAppWithProfile()); | 84 ASSERT_TRUE(LaunchAppWithProfile()); |
84 | |
85 ASSERT_TRUE(file_util::PathExists(tmp_pref_file_)); | 85 ASSERT_TRUE(file_util::PathExists(tmp_pref_file_)); |
86 | 86 |
87 JSONFileValueSerializer deserializer(tmp_pref_file_); | 87 JSONFileValueSerializer deserializer(tmp_pref_file_); |
88 scoped_ptr<Value> root(deserializer.Deserialize(NULL, NULL)); | 88 scoped_ptr<Value> root(deserializer.Deserialize(NULL, NULL)); |
89 | 89 |
90 ASSERT_TRUE(root.get()); | 90 ASSERT_TRUE(root.get()); |
91 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); | 91 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); |
92 | 92 |
93 DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get()); | 93 DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get()); |
94 | 94 |
(...skipping 30 matching lines...) Expand all Loading... |
125 | 125 |
126 // Find if launched window is maximized. | 126 // Find if launched window is maximized. |
127 bool is_window_maximized = false; | 127 bool is_window_maximized = false; |
128 ASSERT_TRUE(window->IsMaximized(&is_window_maximized)); | 128 ASSERT_TRUE(window->IsMaximized(&is_window_maximized)); |
129 bool is_maximized = false; | 129 bool is_maximized = false; |
130 EXPECT_TRUE(root_dict->GetBoolean(kBrowserWindowPlacement + ".maximized", | 130 EXPECT_TRUE(root_dict->GetBoolean(kBrowserWindowPlacement + ".maximized", |
131 &is_maximized)); | 131 &is_maximized)); |
132 EXPECT_EQ(is_maximized, is_window_maximized); | 132 EXPECT_EQ(is_maximized, is_window_maximized); |
133 } | 133 } |
134 #endif | 134 #endif |
OLD | NEW |