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

Side by Side Diff: chrome/browser/extensions/extension_ui_unittest.cc

Issue 104493005: Update some uses of Value in chrome/browser to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/json/json_file_value_serializer.h" 6 #include "base/json/json_file_value_serializer.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 management_policy_)); 47 management_policy_));
48 } 48 }
49 49
50 virtual void TearDown() OVERRIDE { 50 virtual void TearDown() OVERRIDE {
51 handler_.reset(); 51 handler_.reset();
52 profile_.reset(); 52 profile_.reset();
53 // Execute any pending deletion tasks. 53 // Execute any pending deletion tasks.
54 message_loop_.RunUntilIdle(); 54 message_loop_.RunUntilIdle();
55 } 55 }
56 56
57 static DictionaryValue* DeserializeJSONTestData(const base::FilePath& path, 57 static base::DictionaryValue* DeserializeJSONTestData(
58 const base::FilePath& path,
58 std::string *error) { 59 std::string *error) {
59 Value* value; 60 base::Value* value;
60 61
61 JSONFileValueSerializer serializer(path); 62 JSONFileValueSerializer serializer(path);
62 value = serializer.Deserialize(NULL, error); 63 value = serializer.Deserialize(NULL, error);
63 64
64 return static_cast<DictionaryValue*>(value); 65 return static_cast<base::DictionaryValue*>(value);
65 } 66 }
66 67
67 DictionaryValue* CreateExtensionDetailViewFromPath( 68 base::DictionaryValue* CreateExtensionDetailViewFromPath(
68 const base::FilePath& extension_path, 69 const base::FilePath& extension_path,
69 const std::vector<ExtensionPage>& pages, 70 const std::vector<ExtensionPage>& pages,
70 Manifest::Location location) { 71 Manifest::Location location) {
71 std::string error; 72 std::string error;
72 73
73 base::FilePath manifest_path = extension_path.Append(kManifestFilename); 74 base::FilePath manifest_path = extension_path.Append(kManifestFilename);
74 scoped_ptr<DictionaryValue> extension_data(DeserializeJSONTestData( 75 scoped_ptr<base::DictionaryValue> extension_data(DeserializeJSONTestData(
75 manifest_path, &error)); 76 manifest_path, &error));
76 EXPECT_EQ("", error); 77 EXPECT_EQ("", error);
77 78
78 scoped_refptr<Extension> extension(Extension::Create( 79 scoped_refptr<Extension> extension(Extension::Create(
79 extension_path, location, *extension_data, Extension::REQUIRE_KEY, 80 extension_path, location, *extension_data, Extension::REQUIRE_KEY,
80 &error)); 81 &error));
81 EXPECT_TRUE(extension.get()); 82 EXPECT_TRUE(extension.get());
82 EXPECT_EQ("", error); 83 EXPECT_EQ("", error);
83 84
84 return handler_->CreateExtensionDetailValue(extension.get(), pages, NULL); 85 return handler_->CreateExtensionDetailValue(extension.get(), pages, NULL);
85 } 86 }
86 87
87 void CompareExpectedAndActualOutput( 88 void CompareExpectedAndActualOutput(
88 const base::FilePath& extension_path, 89 const base::FilePath& extension_path,
89 const std::vector<ExtensionPage>& pages, 90 const std::vector<ExtensionPage>& pages,
90 const base::FilePath& expected_output_path) { 91 const base::FilePath& expected_output_path) {
91 std::string error; 92 std::string error;
92 93
93 scoped_ptr<DictionaryValue> expected_output_data(DeserializeJSONTestData( 94 scoped_ptr<base::DictionaryValue> expected_output_data(
94 expected_output_path, &error)); 95 DeserializeJSONTestData(expected_output_path, &error));
95 EXPECT_EQ("", error); 96 EXPECT_EQ("", error);
96 97
97 // Produce test output. 98 // Produce test output.
98 scoped_ptr<DictionaryValue> actual_output_data( 99 scoped_ptr<base::DictionaryValue> actual_output_data(
99 CreateExtensionDetailViewFromPath( 100 CreateExtensionDetailViewFromPath(
100 extension_path, pages, Manifest::INVALID_LOCATION)); 101 extension_path, pages, Manifest::INVALID_LOCATION));
101 102
102 // Compare the outputs. 103 // Compare the outputs.
103 // Ignore unknown fields in the actual output data. 104 // Ignore unknown fields in the actual output data.
104 std::string paths_details = " - expected (" + 105 std::string paths_details = " - expected (" +
105 expected_output_path.MaybeAsASCII() + ") vs. actual (" + 106 expected_output_path.MaybeAsASCII() + ") vs. actual (" +
106 extension_path.MaybeAsASCII() + ")"; 107 extension_path.MaybeAsASCII() + ")";
107 for (DictionaryValue::Iterator field(*expected_output_data); 108 for (base::DictionaryValue::Iterator field(*expected_output_data);
108 !field.IsAtEnd(); field.Advance()) { 109 !field.IsAtEnd(); field.Advance()) {
109 const Value* expected_value = &field.value(); 110 const base::Value* expected_value = &field.value();
110 Value* actual_value = NULL; 111 base::Value* actual_value = NULL;
111 EXPECT_TRUE(actual_output_data->Get(field.key(), &actual_value)) << 112 EXPECT_TRUE(actual_output_data->Get(field.key(), &actual_value)) <<
112 field.key() + " is missing" + paths_details; 113 field.key() + " is missing" + paths_details;
113 EXPECT_TRUE(expected_value->Equals(actual_value)) << field.key() + 114 EXPECT_TRUE(expected_value->Equals(actual_value)) << field.key() +
114 paths_details; 115 paths_details;
115 } 116 }
116 } 117 }
117 118
118 base::MessageLoop message_loop_; 119 base::MessageLoop message_loop_;
119 content::TestBrowserThread ui_thread_; 120 content::TestBrowserThread ui_thread_;
120 content::TestBrowserThread file_thread_; 121 content::TestBrowserThread file_thread_;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); 200 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path));
200 201
201 extension_path = data_test_dir_path.AppendASCII("extensions") 202 extension_path = data_test_dir_path.AppendASCII("extensions")
202 .AppendASCII("good") 203 .AppendASCII("good")
203 .AppendASCII("Extensions") 204 .AppendASCII("Extensions")
204 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 205 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
205 .AppendASCII("1.0.0.0"); 206 .AppendASCII("1.0.0.0");
206 207
207 std::vector<ExtensionPage> pages; 208 std::vector<ExtensionPage> pages;
208 209
209 scoped_ptr<DictionaryValue> extension_details( 210 scoped_ptr<base::DictionaryValue> extension_details(
210 CreateExtensionDetailViewFromPath( 211 CreateExtensionDetailViewFromPath(
211 extension_path, pages, Manifest::UNPACKED)); 212 extension_path, pages, Manifest::UNPACKED));
212 213
213 bool ui_allow_reload = false; 214 bool ui_allow_reload = false;
214 bool ui_is_unpacked = false; 215 bool ui_is_unpacked = false;
215 base::FilePath::StringType ui_path; 216 base::FilePath::StringType ui_path;
216 217
217 EXPECT_TRUE(extension_details->GetBoolean("allow_reload", &ui_allow_reload)); 218 EXPECT_TRUE(extension_details->GetBoolean("allow_reload", &ui_allow_reload));
218 EXPECT_TRUE(extension_details->GetBoolean("isUnpacked", &ui_is_unpacked)); 219 EXPECT_TRUE(extension_details->GetBoolean("isUnpacked", &ui_is_unpacked));
219 EXPECT_TRUE(extension_details->GetString("path", &ui_path)); 220 EXPECT_TRUE(extension_details->GetString("path", &ui_path));
(...skipping 11 matching lines...) Expand all
231 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); 232 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path));
232 233
233 extension_path = data_test_dir_path.AppendASCII("extensions") 234 extension_path = data_test_dir_path.AppendASCII("extensions")
234 .AppendASCII("good") 235 .AppendASCII("good")
235 .AppendASCII("Extensions") 236 .AppendASCII("Extensions")
236 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 237 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
237 .AppendASCII("1.0.0.0"); 238 .AppendASCII("1.0.0.0");
238 239
239 std::vector<ExtensionPage> pages; 240 std::vector<ExtensionPage> pages;
240 241
241 scoped_ptr<DictionaryValue> extension_details( 242 scoped_ptr<base::DictionaryValue> extension_details(
242 CreateExtensionDetailViewFromPath( 243 CreateExtensionDetailViewFromPath(
243 extension_path, pages, Manifest::EXTERNAL_PREF)); 244 extension_path, pages, Manifest::EXTERNAL_PREF));
244 245
245 bool ui_allow_reload = true; 246 bool ui_allow_reload = true;
246 bool ui_is_unpacked = true; 247 bool ui_is_unpacked = true;
247 base::FilePath::StringType ui_path; 248 base::FilePath::StringType ui_path;
248 249
249 EXPECT_TRUE(extension_details->GetBoolean("allow_reload", &ui_allow_reload)); 250 EXPECT_TRUE(extension_details->GetBoolean("allow_reload", &ui_allow_reload));
250 EXPECT_TRUE(extension_details->GetBoolean("isUnpacked", &ui_is_unpacked)); 251 EXPECT_TRUE(extension_details->GetBoolean("isUnpacked", &ui_is_unpacked));
251 EXPECT_FALSE(extension_details->GetString("path", &ui_path)); 252 EXPECT_FALSE(extension_details->GetString("path", &ui_path));
252 EXPECT_FALSE(ui_allow_reload); 253 EXPECT_FALSE(ui_allow_reload);
253 EXPECT_FALSE(ui_is_unpacked); 254 EXPECT_FALSE(ui_is_unpacked);
254 } 255 }
255 256
256 // Test that the extension path is correctly propagated into the extension 257 // Test that the extension path is correctly propagated into the extension
257 // details. 258 // details.
258 TEST_F(ExtensionUITest, PathPropagation) { 259 TEST_F(ExtensionUITest, PathPropagation) {
259 base::FilePath data_test_dir_path, extension_path; 260 base::FilePath data_test_dir_path, extension_path;
260 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); 261 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path));
261 262
262 extension_path = data_test_dir_path.AppendASCII("extensions") 263 extension_path = data_test_dir_path.AppendASCII("extensions")
263 .AppendASCII("good") 264 .AppendASCII("good")
264 .AppendASCII("Extensions") 265 .AppendASCII("Extensions")
265 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 266 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
266 .AppendASCII("1.0.0.0"); 267 .AppendASCII("1.0.0.0");
267 268
268 std::vector<ExtensionPage> pages; 269 std::vector<ExtensionPage> pages;
269 270
270 scoped_ptr<DictionaryValue> extension_details( 271 scoped_ptr<base::DictionaryValue> extension_details(
271 CreateExtensionDetailViewFromPath( 272 CreateExtensionDetailViewFromPath(
272 extension_path, pages, Manifest::UNPACKED)); 273 extension_path, pages, Manifest::UNPACKED));
273 274
274 base::FilePath::StringType ui_path; 275 base::FilePath::StringType ui_path;
275 276
276 EXPECT_TRUE(extension_details->GetString("path", &ui_path)); 277 EXPECT_TRUE(extension_details->GetString("path", &ui_path));
277 EXPECT_EQ(extension_path, base::FilePath(ui_path)); 278 EXPECT_EQ(extension_path, base::FilePath(ui_path));
278 } 279 }
279 280
280 } // namespace extensions 281 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_tab_util_android.cc ('k') | chrome/browser/extensions/extension_web_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698