| 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 "base/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "base/file_util.h" |
| 6 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 7 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 8 #include "chrome/common/chrome_paths.h" | 9 #include "chrome/common/chrome_paths.h" |
| 9 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
| 10 #include "chrome/common/extensions/extension_constants.h" | 11 #include "chrome/common/extensions/extension_constants.h" |
| 11 #include "chrome/common/extensions/extension_error_reporter.h" | 12 #include "chrome/common/extensions/extension_error_reporter.h" |
| 12 #include "chrome/common/json_value_serializer.h" | 13 #include "chrome/common/json_value_serializer.h" |
| 14 #include "net/base/mime_sniffer.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 16 |
| 15 namespace keys = extension_manifest_keys; | 17 namespace keys = extension_manifest_keys; |
| 16 namespace values = extension_manifest_values; | 18 namespace values = extension_manifest_values; |
| 17 namespace errors = extension_manifest_errors; | 19 namespace errors = extension_manifest_errors; |
| 18 | 20 |
| 19 class ExtensionTest : public testing::Test { | 21 class ExtensionTest : public testing::Test { |
| 20 }; | 22 }; |
| 21 | 23 |
| 22 TEST(ExtensionTest, InitFromValueInvalid) { | 24 TEST(ExtensionTest, InitFromValueInvalid) { |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 Extension extension; | 424 Extension extension; |
| 423 std::string error; | 425 std::string error; |
| 424 input_value.SetString(keys::kVersion, "1.0"); | 426 input_value.SetString(keys::kVersion, "1.0"); |
| 425 input_value.SetString(keys::kName, "Test"); | 427 input_value.SetString(keys::kName, "Test"); |
| 426 input_value.SetString(keys::kUpdateURL, invalid[i]); | 428 input_value.SetString(keys::kUpdateURL, invalid[i]); |
| 427 | 429 |
| 428 EXPECT_FALSE(extension.InitFromValue(input_value, false, &error)); | 430 EXPECT_FALSE(extension.InitFromValue(input_value, false, &error)); |
| 429 EXPECT_TRUE(MatchPattern(error, errors::kInvalidUpdateURL)); | 431 EXPECT_TRUE(MatchPattern(error, errors::kInvalidUpdateURL)); |
| 430 } | 432 } |
| 431 } | 433 } |
| 434 |
| 435 // This test ensures that the mimetype sniffing code stays in sync with the |
| 436 // actual crx files that we test other parts of the system with. |
| 437 TEST(ExtensionTest, MimeTypeSniffing) { |
| 438 FilePath path; |
| 439 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); |
| 440 path = path.AppendASCII("extensions").AppendASCII("good.crx"); |
| 441 |
| 442 std::string data; |
| 443 ASSERT_TRUE(file_util::ReadFileToString(path, &data)); |
| 444 |
| 445 std::string result; |
| 446 EXPECT_TRUE(net::SniffMimeType(data.c_str(), data.size(), |
| 447 GURL("http://www.example.com/foo.crx"), "", &result)); |
| 448 EXPECT_EQ(std::string(Extension::kMimeType), result); |
| 449 |
| 450 data.clear(); |
| 451 result.clear(); |
| 452 path = path.DirName().AppendASCII("bad_magic.crx"); |
| 453 ASSERT_TRUE(file_util::ReadFileToString(path, &data)); |
| 454 EXPECT_TRUE(net::SniffMimeType(data.c_str(), data.size(), |
| 455 GURL("http://www.example.com/foo.crx"), "", &result)); |
| 456 EXPECT_EQ("application/octet-stream", result); |
| 457 } |
| OLD | NEW |