OLD | NEW |
---|---|
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 "chrome/common/extensions/extension.h" | |
6 | |
7 #include "base/format_macros.h" | |
5 #include "base/file_path.h" | 8 #include "base/file_path.h" |
6 #include "base/file_util.h" | 9 #include "base/file_util.h" |
7 #include "base/string_util.h" | 10 #include "base/string_util.h" |
8 #include "base/path_service.h" | 11 #include "base/path_service.h" |
9 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
10 #include "chrome/common/extensions/extension.h" | |
11 #include "chrome/common/extensions/extension_constants.h" | 13 #include "chrome/common/extensions/extension_constants.h" |
12 #include "chrome/common/extensions/extension_error_reporter.h" | 14 #include "chrome/common/extensions/extension_error_reporter.h" |
13 #include "chrome/common/json_value_serializer.h" | 15 #include "chrome/common/json_value_serializer.h" |
14 #include "net/base/mime_sniffer.h" | 16 #include "net/base/mime_sniffer.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
16 | 18 |
17 namespace keys = extension_manifest_keys; | 19 namespace keys = extension_manifest_keys; |
18 namespace values = extension_manifest_values; | 20 namespace values = extension_manifest_values; |
19 namespace errors = extension_manifest_errors; | 21 namespace errors = extension_manifest_errors; |
20 | 22 |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
454 valid.push_back("http://test.com"); | 456 valid.push_back("http://test.com"); |
455 valid.push_back("http://test.com/"); | 457 valid.push_back("http://test.com/"); |
456 valid.push_back("http://test.com/update"); | 458 valid.push_back("http://test.com/update"); |
457 valid.push_back("http://test.com/update?check=true"); | 459 valid.push_back("http://test.com/update?check=true"); |
458 for (size_t i = 0; i < valid.size(); i++) { | 460 for (size_t i = 0; i < valid.size(); i++) { |
459 GURL url(valid[i]); | 461 GURL url(valid[i]); |
460 EXPECT_TRUE(url.is_valid()); | 462 EXPECT_TRUE(url.is_valid()); |
461 | 463 |
462 DictionaryValue input_value; | 464 DictionaryValue input_value; |
463 #if defined(OS_WIN) | 465 #if defined(OS_WIN) |
464 FilePath path(StringPrintf(L"c:\\extension%i", i)); | 466 // (Why %d below? This is the single place in the whole code base that |
467 // might make use of a WidePRIuS; let's not encourage any more.) | |
Mark Mentovai
2009/11/18 20:55:27
OK, that's fair enough. But wouldn't it be L"%Iu"
| |
468 FilePath path(StringPrintf(L"c:\\extension%d", i)); | |
465 #else | 469 #else |
466 FilePath path(StringPrintf("/extension%i", i)); | 470 FilePath path(StringPrintf("/extension%" PRIuS, i)); |
467 #endif | 471 #endif |
468 Extension extension(path); | 472 Extension extension(path); |
469 std::string error; | 473 std::string error; |
470 | 474 |
471 input_value.SetString(keys::kVersion, "1.0"); | 475 input_value.SetString(keys::kVersion, "1.0"); |
472 input_value.SetString(keys::kName, "Test"); | 476 input_value.SetString(keys::kName, "Test"); |
473 input_value.SetString(keys::kUpdateURL, url.spec()); | 477 input_value.SetString(keys::kUpdateURL, url.spec()); |
474 | 478 |
475 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error)); | 479 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error)); |
476 } | 480 } |
477 | 481 |
478 // Test some invalid update urls | 482 // Test some invalid update urls |
479 std::vector<std::string> invalid; | 483 std::vector<std::string> invalid; |
480 invalid.push_back(""); | 484 invalid.push_back(""); |
481 invalid.push_back("test.com"); | 485 invalid.push_back("test.com"); |
482 valid.push_back("http://test.com/update#whatever"); | 486 valid.push_back("http://test.com/update#whatever"); |
483 for (size_t i = 0; i < invalid.size(); i++) { | 487 for (size_t i = 0; i < invalid.size(); i++) { |
484 DictionaryValue input_value; | 488 DictionaryValue input_value; |
485 #if defined(OS_WIN) | 489 #if defined(OS_WIN) |
486 FilePath path(StringPrintf(L"c:\\extension%i", i)); | 490 // We should use PRIuS here, but it's a wide string. This is the only |
491 // instance of a wide string needing PRIuS in the entire code base, so | |
492 // let's just work around it here. | |
Mark Mentovai
2009/11/18 20:55:27
Same.
Oh, I guess there are two locations...
| |
493 FilePath path(StringPrintf(L"c:\\extension%d", i)); | |
487 #else | 494 #else |
488 FilePath path(StringPrintf("/extension%i", i)); | 495 FilePath path(StringPrintf("/extension%" PRIuS, i)); |
489 #endif | 496 #endif |
490 Extension extension(path); | 497 Extension extension(path); |
491 std::string error; | 498 std::string error; |
492 input_value.SetString(keys::kVersion, "1.0"); | 499 input_value.SetString(keys::kVersion, "1.0"); |
493 input_value.SetString(keys::kName, "Test"); | 500 input_value.SetString(keys::kName, "Test"); |
494 input_value.SetString(keys::kUpdateURL, invalid[i]); | 501 input_value.SetString(keys::kUpdateURL, invalid[i]); |
495 | 502 |
496 EXPECT_FALSE(extension.InitFromValue(input_value, false, &error)); | 503 EXPECT_FALSE(extension.InitFromValue(input_value, false, &error)); |
497 EXPECT_TRUE(MatchPattern(error, errors::kInvalidUpdateURL)); | 504 EXPECT_TRUE(MatchPattern(error, errors::kInvalidUpdateURL)); |
498 } | 505 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 scoped_ptr<Extension> new_extension( | 662 scoped_ptr<Extension> new_extension( |
656 LoadManifest("allow_silent_upgrade", | 663 LoadManifest("allow_silent_upgrade", |
657 std::string(kTests[i].base_name) + "_new.json")); | 664 std::string(kTests[i].base_name) + "_new.json")); |
658 | 665 |
659 EXPECT_EQ(kTests[i].expect_success, | 666 EXPECT_EQ(kTests[i].expect_success, |
660 Extension::IsPrivilegeIncrease(old_extension.get(), | 667 Extension::IsPrivilegeIncrease(old_extension.get(), |
661 new_extension.get())) | 668 new_extension.get())) |
662 << kTests[i].base_name; | 669 << kTests[i].base_name; |
663 } | 670 } |
664 } | 671 } |
OLD | NEW |