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

Side by Side Diff: chrome/test/chromedriver/chrome_launcher_unittest.cc

Issue 2321573002: //chrome misc: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Fix Win compilation Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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 "chrome/test/chromedriver/chrome_launcher.h" 5 #include "chrome/test/chromedriver/chrome_launcher.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 base::ScopedTempDir extension_dir; 53 base::ScopedTempDir extension_dir;
54 Switches switches; 54 Switches switches;
55 std::vector<std::string> bg_pages; 55 std::vector<std::string> bg_pages;
56 56
57 ASSERT_TRUE(AddExtensionForInstall("no_key_in_manifest.crx", &extensions)); 57 ASSERT_TRUE(AddExtensionForInstall("no_key_in_manifest.crx", &extensions));
58 ASSERT_TRUE(AddExtensionForInstall("same_key_as_header.crx", &extensions)); 58 ASSERT_TRUE(AddExtensionForInstall("same_key_as_header.crx", &extensions));
59 ASSERT_TRUE(AddExtensionForInstall("diff_key_from_header.crx", &extensions)); 59 ASSERT_TRUE(AddExtensionForInstall("diff_key_from_header.crx", &extensions));
60 60
61 ASSERT_TRUE(extension_dir.CreateUniqueTempDir()); 61 ASSERT_TRUE(extension_dir.CreateUniqueTempDir());
62 62
63 Status status = internal::ProcessExtensions(extensions, extension_dir.path(), 63 Status status = internal::ProcessExtensions(
64 false, &switches, &bg_pages); 64 extensions, extension_dir.GetPath(), false, &switches, &bg_pages);
65 65
66 ASSERT_EQ(kOk, status.code()) << status.message(); 66 ASSERT_EQ(kOk, status.code()) << status.message();
67 ASSERT_EQ(3u, bg_pages.size()); 67 ASSERT_EQ(3u, bg_pages.size());
68 ASSERT_EQ("chrome-extension://llphabdmknikmpmkioimgdfbohinlekl/" 68 ASSERT_EQ("chrome-extension://llphabdmknikmpmkioimgdfbohinlekl/"
69 "_generated_background_page.html", bg_pages[0]); 69 "_generated_background_page.html", bg_pages[0]);
70 ASSERT_EQ("chrome-extension://dfdeoklpcichfcnoaomfpagfiibhomnh/" 70 ASSERT_EQ("chrome-extension://dfdeoklpcichfcnoaomfpagfiibhomnh/"
71 "_generated_background_page.html", bg_pages[1]); 71 "_generated_background_page.html", bg_pages[1]);
72 ASSERT_EQ("chrome-extension://ioccpomhcpklobebcbeohnmffkmcokbm/" 72 ASSERT_EQ("chrome-extension://ioccpomhcpklobebcbeohnmffkmcokbm/"
73 "_generated_background_page.html", bg_pages[2]); 73 "_generated_background_page.html", bg_pages[2]);
74 } 74 }
75 75
76 TEST(ProcessExtensions, SingleExtensionWithBgPage) { 76 TEST(ProcessExtensions, SingleExtensionWithBgPage) {
77 std::vector<std::string> extensions; 77 std::vector<std::string> extensions;
78 ASSERT_TRUE(AddExtensionForInstall("ext_slow_loader.crx", &extensions)); 78 ASSERT_TRUE(AddExtensionForInstall("ext_slow_loader.crx", &extensions));
79 79
80 base::ScopedTempDir extension_dir; 80 base::ScopedTempDir extension_dir;
81 ASSERT_TRUE(extension_dir.CreateUniqueTempDir()); 81 ASSERT_TRUE(extension_dir.CreateUniqueTempDir());
82 82
83 Switches switches; 83 Switches switches;
84 std::vector<std::string> bg_pages; 84 std::vector<std::string> bg_pages;
85 Status status = internal::ProcessExtensions(extensions, extension_dir.path(), 85 Status status = internal::ProcessExtensions(
86 false, &switches, &bg_pages); 86 extensions, extension_dir.GetPath(), false, &switches, &bg_pages);
87 ASSERT_TRUE(status.IsOk()); 87 ASSERT_TRUE(status.IsOk());
88 ASSERT_TRUE(switches.HasSwitch("load-extension")); 88 ASSERT_TRUE(switches.HasSwitch("load-extension"));
89 base::FilePath temp_ext_path(switches.GetSwitchValueNative("load-extension")); 89 base::FilePath temp_ext_path(switches.GetSwitchValueNative("load-extension"));
90 ASSERT_TRUE(base::PathExists(temp_ext_path)); 90 ASSERT_TRUE(base::PathExists(temp_ext_path));
91 std::string manifest_txt; 91 std::string manifest_txt;
92 ASSERT_TRUE(base::ReadFileToString( 92 ASSERT_TRUE(base::ReadFileToString(
93 temp_ext_path.AppendASCII("manifest.json"), &manifest_txt)); 93 temp_ext_path.AppendASCII("manifest.json"), &manifest_txt));
94 std::unique_ptr<base::Value> manifest = base::JSONReader::Read(manifest_txt); 94 std::unique_ptr<base::Value> manifest = base::JSONReader::Read(manifest_txt);
95 ASSERT_TRUE(manifest); 95 ASSERT_TRUE(manifest);
96 base::DictionaryValue* manifest_dict = NULL; 96 base::DictionaryValue* manifest_dict = NULL;
(...skipping 16 matching lines...) Expand all
113 TEST(ProcessExtensions, MultipleExtensionsNoBgPages) { 113 TEST(ProcessExtensions, MultipleExtensionsNoBgPages) {
114 std::vector<std::string> extensions; 114 std::vector<std::string> extensions;
115 ASSERT_TRUE(AddExtensionForInstall("ext_test_1.crx", &extensions)); 115 ASSERT_TRUE(AddExtensionForInstall("ext_test_1.crx", &extensions));
116 ASSERT_TRUE(AddExtensionForInstall("ext_test_2.crx", &extensions)); 116 ASSERT_TRUE(AddExtensionForInstall("ext_test_2.crx", &extensions));
117 117
118 base::ScopedTempDir extension_dir; 118 base::ScopedTempDir extension_dir;
119 ASSERT_TRUE(extension_dir.CreateUniqueTempDir()); 119 ASSERT_TRUE(extension_dir.CreateUniqueTempDir());
120 120
121 Switches switches; 121 Switches switches;
122 std::vector<std::string> bg_pages; 122 std::vector<std::string> bg_pages;
123 Status status = internal::ProcessExtensions(extensions, extension_dir.path(), 123 Status status = internal::ProcessExtensions(
124 false, &switches, &bg_pages); 124 extensions, extension_dir.GetPath(), false, &switches, &bg_pages);
125 ASSERT_TRUE(status.IsOk()); 125 ASSERT_TRUE(status.IsOk());
126 ASSERT_TRUE(switches.HasSwitch("load-extension")); 126 ASSERT_TRUE(switches.HasSwitch("load-extension"));
127 base::CommandLine::StringType ext_paths = 127 base::CommandLine::StringType ext_paths =
128 switches.GetSwitchValueNative("load-extension"); 128 switches.GetSwitchValueNative("load-extension");
129 std::vector<base::CommandLine::StringType> ext_path_list = 129 std::vector<base::CommandLine::StringType> ext_path_list =
130 base::SplitString(ext_paths, base::CommandLine::StringType(1, ','), 130 base::SplitString(ext_paths, base::CommandLine::StringType(1, ','),
131 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 131 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
132 ASSERT_EQ(2u, ext_path_list.size()); 132 ASSERT_EQ(2u, ext_path_list.size());
133 ASSERT_TRUE(base::PathExists(base::FilePath(ext_path_list[0]))); 133 ASSERT_TRUE(base::PathExists(base::FilePath(ext_path_list[0])));
134 ASSERT_TRUE(base::PathExists(base::FilePath(ext_path_list[1]))); 134 ASSERT_TRUE(base::PathExists(base::FilePath(ext_path_list[1])));
135 ASSERT_EQ(0u, bg_pages.size()); 135 ASSERT_EQ(0u, bg_pages.size());
136 } 136 }
137 137
138 TEST(ProcessExtensions, CommandLineExtensions) { 138 TEST(ProcessExtensions, CommandLineExtensions) {
139 std::vector<std::string> extensions; 139 std::vector<std::string> extensions;
140 ASSERT_TRUE(AddExtensionForInstall("ext_test_1.crx", &extensions)); 140 ASSERT_TRUE(AddExtensionForInstall("ext_test_1.crx", &extensions));
141 base::ScopedTempDir extension_dir; 141 base::ScopedTempDir extension_dir;
142 ASSERT_TRUE(extension_dir.CreateUniqueTempDir()); 142 ASSERT_TRUE(extension_dir.CreateUniqueTempDir());
143 143
144 Switches switches; 144 Switches switches;
145 switches.SetSwitch("load-extension", "/a"); 145 switches.SetSwitch("load-extension", "/a");
146 std::vector<std::string> bg_pages; 146 std::vector<std::string> bg_pages;
147 Status status = internal::ProcessExtensions(extensions, extension_dir.path(), 147 Status status = internal::ProcessExtensions(
148 false, &switches, &bg_pages); 148 extensions, extension_dir.GetPath(), false, &switches, &bg_pages);
149 ASSERT_EQ(kOk, status.code()); 149 ASSERT_EQ(kOk, status.code());
150 base::FilePath::StringType load = switches.GetSwitchValueNative( 150 base::FilePath::StringType load = switches.GetSwitchValueNative(
151 "load-extension"); 151 "load-extension");
152 ASSERT_EQ(FILE_PATH_LITERAL("/a,"), load.substr(0, 3)); 152 ASSERT_EQ(FILE_PATH_LITERAL("/a,"), load.substr(0, 3));
153 ASSERT_TRUE(base::PathExists(base::FilePath(load.substr(3)))); 153 ASSERT_TRUE(base::PathExists(base::FilePath(load.substr(3))));
154 } 154 }
155 155
156 namespace { 156 namespace {
157 157
158 void AssertEQ(const base::DictionaryValue& dict, const std::string& key, 158 void AssertEQ(const base::DictionaryValue& dict, const std::string& key,
159 const char* expected_value) { 159 const char* expected_value) {
160 std::string value; 160 std::string value;
161 ASSERT_TRUE(dict.GetString(key, &value)); 161 ASSERT_TRUE(dict.GetString(key, &value));
162 ASSERT_STREQ(value.c_str(), expected_value); 162 ASSERT_STREQ(value.c_str(), expected_value);
163 } 163 }
164 164
165 } // namespace 165 } // namespace
166 166
167 TEST(PrepareUserDataDir, CustomPrefs) { 167 TEST(PrepareUserDataDir, CustomPrefs) {
168 base::ScopedTempDir temp_dir; 168 base::ScopedTempDir temp_dir;
169 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 169 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
170 170
171 base::DictionaryValue prefs; 171 base::DictionaryValue prefs;
172 prefs.SetString("myPrefsKey", "ok"); 172 prefs.SetString("myPrefsKey", "ok");
173 prefs.SetStringWithoutPathExpansion("pref.sub", "1"); 173 prefs.SetStringWithoutPathExpansion("pref.sub", "1");
174 base::DictionaryValue local_state; 174 base::DictionaryValue local_state;
175 local_state.SetString("myLocalKey", "ok"); 175 local_state.SetString("myLocalKey", "ok");
176 local_state.SetStringWithoutPathExpansion("local.state.sub", "2"); 176 local_state.SetStringWithoutPathExpansion("local.state.sub", "2");
177 Status status = internal::PrepareUserDataDir( 177 Status status =
178 temp_dir.path(), &prefs, &local_state); 178 internal::PrepareUserDataDir(temp_dir.GetPath(), &prefs, &local_state);
179 ASSERT_EQ(kOk, status.code()); 179 ASSERT_EQ(kOk, status.code());
180 180
181 base::FilePath prefs_file = 181 base::FilePath prefs_file = temp_dir.GetPath()
182 temp_dir.path().AppendASCII(chrome::kInitialProfile).Append( 182 .AppendASCII(chrome::kInitialProfile)
183 chrome::kPreferencesFilename); 183 .Append(chrome::kPreferencesFilename);
184 std::string prefs_str; 184 std::string prefs_str;
185 ASSERT_TRUE(base::ReadFileToString(prefs_file, &prefs_str)); 185 ASSERT_TRUE(base::ReadFileToString(prefs_file, &prefs_str));
186 std::unique_ptr<base::Value> prefs_value = base::JSONReader::Read(prefs_str); 186 std::unique_ptr<base::Value> prefs_value = base::JSONReader::Read(prefs_str);
187 const base::DictionaryValue* prefs_dict = NULL; 187 const base::DictionaryValue* prefs_dict = NULL;
188 ASSERT_TRUE(prefs_value->GetAsDictionary(&prefs_dict)); 188 ASSERT_TRUE(prefs_value->GetAsDictionary(&prefs_dict));
189 AssertEQ(*prefs_dict, "myPrefsKey", "ok"); 189 AssertEQ(*prefs_dict, "myPrefsKey", "ok");
190 AssertEQ(*prefs_dict, "pref.sub", "1"); 190 AssertEQ(*prefs_dict, "pref.sub", "1");
191 191
192 base::FilePath local_state_file = 192 base::FilePath local_state_file =
193 temp_dir.path().Append(chrome::kLocalStateFilename); 193 temp_dir.GetPath().Append(chrome::kLocalStateFilename);
194 std::string local_state_str; 194 std::string local_state_str;
195 ASSERT_TRUE(base::ReadFileToString(local_state_file, &local_state_str)); 195 ASSERT_TRUE(base::ReadFileToString(local_state_file, &local_state_str));
196 std::unique_ptr<base::Value> local_state_value = 196 std::unique_ptr<base::Value> local_state_value =
197 base::JSONReader::Read(local_state_str); 197 base::JSONReader::Read(local_state_str);
198 const base::DictionaryValue* local_state_dict = NULL; 198 const base::DictionaryValue* local_state_dict = NULL;
199 ASSERT_TRUE(local_state_value->GetAsDictionary(&local_state_dict)); 199 ASSERT_TRUE(local_state_value->GetAsDictionary(&local_state_dict));
200 AssertEQ(*local_state_dict, "myLocalKey", "ok"); 200 AssertEQ(*local_state_dict, "myLocalKey", "ok");
201 AssertEQ(*local_state_dict, "local.state.sub", "2"); 201 AssertEQ(*local_state_dict, "local.state.sub", "2");
202 } 202 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/chrome_launcher.cc ('k') | chrome/test/chromedriver/session_commands.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698