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

Side by Side Diff: chrome/common/extensions/extension_unittest.cc

Issue 337035: Replace ExtensionAction with ExtensionAction2. (Closed)
Patch Set: Remove todo Created 11 years, 1 month 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
« no previous file with comments | « chrome/common/extensions/extension_action_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/file_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "chrome/common/chrome_paths.h" 9 #include "chrome/common/chrome_paths.h"
10 #include "chrome/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 290 }
291 291
292 TEST(ExtensionTest, LoadPageActionHelper) { 292 TEST(ExtensionTest, LoadPageActionHelper) {
293 #if defined(OS_WIN) 293 #if defined(OS_WIN)
294 FilePath path(StringPrintf(L"c:\\extension")); 294 FilePath path(StringPrintf(L"c:\\extension"));
295 #else 295 #else
296 FilePath path(StringPrintf("/extension")); 296 FilePath path(StringPrintf("/extension"));
297 #endif 297 #endif
298 Extension extension(path); 298 Extension extension(path);
299 std::string error_msg; 299 std::string error_msg;
300 scoped_ptr<ExtensionAction2> action; 300 scoped_ptr<ExtensionAction> action;
301 DictionaryValue input; 301 DictionaryValue input;
302 302
303 // First try with an empty dictionary. We should get nothing back. 303 // First try with an empty dictionary. We should get nothing back.
304 ASSERT_TRUE(extension.LoadExtensionAction2Helper( 304 ASSERT_TRUE(extension.LoadExtensionActionHelper(
305 &input, &error_msg) == NULL); 305 &input, &error_msg) == NULL);
306 ASSERT_STRNE("", error_msg.c_str()); 306 ASSERT_STRNE("", error_msg.c_str());
307 error_msg = ""; 307 error_msg = "";
308 308
309 // Now try the same, but as a browser action. Ensure same results. 309 // Now try the same, but as a browser action. Ensure same results.
310 ASSERT_TRUE(extension.LoadExtensionAction2Helper( 310 ASSERT_TRUE(extension.LoadExtensionActionHelper(
311 &input, &error_msg) == NULL); 311 &input, &error_msg) == NULL);
312 ASSERT_STRNE("", error_msg.c_str()); 312 ASSERT_STRNE("", error_msg.c_str());
313 error_msg = ""; 313 error_msg = "";
314 314
315 // Now setup some values to use in the page action. 315 // Now setup some values to use in the page action.
316 const std::string id("MyExtensionActionId"); 316 const std::string id("MyExtensionActionId");
317 const std::string name("MyExtensionActionName"); 317 const std::string name("MyExtensionActionName");
318 std::string img1("image1.png"); 318 std::string img1("image1.png");
319 std::string img2("image2.png"); 319 std::string img2("image2.png");
320 320
321 // Add the dictionary for the contextual action. 321 // Add the dictionary for the contextual action.
322 input.SetString(keys::kPageActionId, id); 322 input.SetString(keys::kPageActionId, id);
323 input.SetString(keys::kName, name); 323 input.SetString(keys::kName, name);
324 ListValue* icons = new ListValue; 324 ListValue* icons = new ListValue;
325 icons->Set(0, Value::CreateStringValue(img1)); 325 icons->Set(0, Value::CreateStringValue(img1));
326 icons->Set(1, Value::CreateStringValue(img2)); 326 icons->Set(1, Value::CreateStringValue(img2));
327 input.Set(keys::kPageActionIcons, icons); 327 input.Set(keys::kPageActionIcons, icons);
328 328
329 // Parse and read back the values from the object. 329 // Parse and read back the values from the object.
330 action.reset(extension.LoadExtensionAction2Helper( 330 action.reset(extension.LoadExtensionActionHelper(
331 &input, &error_msg)); 331 &input, &error_msg));
332 ASSERT_TRUE(NULL != action.get()); 332 ASSERT_TRUE(NULL != action.get());
333 ASSERT_STREQ("", error_msg.c_str()); 333 ASSERT_STREQ("", error_msg.c_str());
334 ASSERT_STREQ(id.c_str(), action->id().c_str()); 334 ASSERT_STREQ(id.c_str(), action->id().c_str());
335 ASSERT_STREQ(name.c_str(), action->GetTitle(1).c_str()); 335 ASSERT_STREQ(name.c_str(), action->GetTitle(1).c_str());
336 ASSERT_EQ(2u, action->icon_paths()->size()); 336 ASSERT_EQ(2u, action->icon_paths()->size());
337 ASSERT_STREQ(img1.c_str(), action->icon_paths()->at(0).c_str()); 337 ASSERT_STREQ(img1.c_str(), action->icon_paths()->at(0).c_str());
338 ASSERT_STREQ(img2.c_str(), action->icon_paths()->at(1).c_str()); 338 ASSERT_STREQ(img2.c_str(), action->icon_paths()->at(1).c_str());
339 339
340 // Explicitly set the same type and parse again. 340 // Explicitly set the same type and parse again.
341 input.SetString(keys::kType, values::kPageActionTypeTab); 341 input.SetString(keys::kType, values::kPageActionTypeTab);
342 action.reset(extension.LoadExtensionAction2Helper( 342 action.reset(extension.LoadExtensionActionHelper(
343 &input, &error_msg)); 343 &input, &error_msg));
344 ASSERT_TRUE(NULL != action.get()); 344 ASSERT_TRUE(NULL != action.get());
345 ASSERT_STREQ("", error_msg.c_str()); 345 ASSERT_STREQ("", error_msg.c_str());
346 346
347 // Make a deep copy of the input and remove one key at a time and see if we 347 // Make a deep copy of the input and remove one key at a time and see if we
348 // get the right error. 348 // get the right error.
349 scoped_ptr<DictionaryValue> copy; 349 scoped_ptr<DictionaryValue> copy;
350 350
351 // First remove id key. 351 // First remove id key.
352 copy.reset(static_cast<DictionaryValue*>(input.DeepCopy())); 352 copy.reset(static_cast<DictionaryValue*>(input.DeepCopy()));
353 copy->Remove(keys::kPageActionId, NULL); 353 copy->Remove(keys::kPageActionId, NULL);
354 action.reset(extension.LoadExtensionAction2Helper( 354 action.reset(extension.LoadExtensionActionHelper(
355 copy.get(), &error_msg)); 355 copy.get(), &error_msg));
356 ASSERT_TRUE(NULL != action.get()); 356 ASSERT_TRUE(NULL != action.get());
357 ASSERT_STREQ("", error_msg.c_str()); 357 ASSERT_STREQ("", error_msg.c_str());
358 error_msg = ""; 358 error_msg = "";
359 359
360 // Then remove the name key. 360 // Then remove the name key.
361 copy.reset(static_cast<DictionaryValue*>(input.DeepCopy())); 361 copy.reset(static_cast<DictionaryValue*>(input.DeepCopy()));
362 copy->Remove(keys::kName, NULL); 362 copy->Remove(keys::kName, NULL);
363 action.reset(extension.LoadExtensionAction2Helper( 363 action.reset(extension.LoadExtensionActionHelper(
364 copy.get(), &error_msg)); 364 copy.get(), &error_msg));
365 ASSERT_TRUE(NULL == action.get()); 365 ASSERT_TRUE(NULL == action.get());
366 ASSERT_TRUE(MatchPattern(error_msg.c_str(), 366 ASSERT_TRUE(MatchPattern(error_msg.c_str(),
367 errors::kInvalidPageActionDefaultTitle)); 367 errors::kInvalidPageActionDefaultTitle));
368 error_msg = ""; 368 error_msg = "";
369 369
370 // Then remove the icon paths key. 370 // Then remove the icon paths key.
371 copy.reset(static_cast<DictionaryValue*>(input.DeepCopy())); 371 copy.reset(static_cast<DictionaryValue*>(input.DeepCopy()));
372 copy->Remove(keys::kPageActionIcons, NULL); 372 copy->Remove(keys::kPageActionIcons, NULL);
373 action.reset(extension.LoadExtensionAction2Helper( 373 action.reset(extension.LoadExtensionActionHelper(
374 copy.get(), &error_msg)); 374 copy.get(), &error_msg));
375 ASSERT_TRUE(NULL != action.get()); 375 ASSERT_TRUE(NULL != action.get());
376 error_msg = ""; 376 error_msg = "";
377 377
378 // Now test that we can parse the new format for page actions. 378 // Now test that we can parse the new format for page actions.
379 379
380 // Now setup some values to use in the page action. 380 // Now setup some values to use in the page action.
381 const std::string kTitle("MyExtensionActionTitle"); 381 const std::string kTitle("MyExtensionActionTitle");
382 const std::string kIcon("image1.png"); 382 const std::string kIcon("image1.png");
383 383
384 // Add the dictionary for the contextual action. 384 // Add the dictionary for the contextual action.
385 input.Clear(); 385 input.Clear();
386 input.SetString(keys::kPageActionDefaultTitle, kTitle); 386 input.SetString(keys::kPageActionDefaultTitle, kTitle);
387 input.SetString(keys::kPageActionDefaultIcon, kIcon); 387 input.SetString(keys::kPageActionDefaultIcon, kIcon);
388 388
389 // Parse and read back the values from the object. 389 // Parse and read back the values from the object.
390 action.reset(extension.LoadExtensionAction2Helper( 390 action.reset(extension.LoadExtensionActionHelper(
391 &input, &error_msg)); 391 &input, &error_msg));
392 ASSERT_TRUE(action.get()); 392 ASSERT_TRUE(action.get());
393 ASSERT_STREQ("", error_msg.c_str()); 393 ASSERT_STREQ("", error_msg.c_str());
394 ASSERT_EQ(kTitle, action->GetTitle(1)); 394 ASSERT_EQ(kTitle, action->GetTitle(1));
395 ASSERT_EQ(0u, action->icon_paths()->size()); 395 ASSERT_EQ(0u, action->icon_paths()->size());
396 } 396 }
397 397
398 TEST(ExtensionTest, IdIsValid) { 398 TEST(ExtensionTest, IdIsValid) {
399 EXPECT_TRUE(Extension::IdIsValid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); 399 EXPECT_TRUE(Extension::IdIsValid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
400 EXPECT_TRUE(Extension::IdIsValid("pppppppppppppppppppppppppppppppp")); 400 EXPECT_TRUE(Extension::IdIsValid("pppppppppppppppppppppppppppppppp"));
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 scoped_ptr<Extension> new_extension( 641 scoped_ptr<Extension> new_extension(
642 LoadManifest("allow_silent_upgrade", 642 LoadManifest("allow_silent_upgrade",
643 std::string(kTests[i].base_name) + "_new.json")); 643 std::string(kTests[i].base_name) + "_new.json"));
644 644
645 EXPECT_EQ(kTests[i].expect_success, 645 EXPECT_EQ(kTests[i].expect_success,
646 Extension::IsPrivilegeIncrease(old_extension.get(), 646 Extension::IsPrivilegeIncrease(old_extension.get(),
647 new_extension.get())) 647 new_extension.get()))
648 << kTests[i].base_name; 648 << kTests[i].base_name;
649 } 649 }
650 } 650 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_action_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698