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

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

Issue 159483: Revert 21800 - Merge 21612 Implement mimetype sniffing for extensions.... (Closed) Base URL: svn://chrome-svn/chrome/branches/195/src/
Patch Set: Created 11 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | net/base/mime_sniffer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Modified: svn:mergeinfo
Reverse-merged /branches/chrome_webkit_merge_branch/chrome/common/extensions/extension_unittest.cc:r69-2775
Reverse-merged /trunk/src/chrome/common/extensions/extension_unittest.cc:r21612
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"
7 #include "base/string_util.h" 6 #include "base/string_util.h"
8 #include "base/path_service.h" 7 #include "base/path_service.h"
9 #include "chrome/common/chrome_paths.h" 8 #include "chrome/common/chrome_paths.h"
10 #include "chrome/common/extensions/extension.h" 9 #include "chrome/common/extensions/extension.h"
11 #include "chrome/common/extensions/extension_constants.h" 10 #include "chrome/common/extensions/extension_constants.h"
12 #include "chrome/common/extensions/extension_error_reporter.h" 11 #include "chrome/common/extensions/extension_error_reporter.h"
13 #include "chrome/common/json_value_serializer.h" 12 #include "chrome/common/json_value_serializer.h"
14 #include "net/base/mime_sniffer.h"
15 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
16 14
17 namespace keys = extension_manifest_keys; 15 namespace keys = extension_manifest_keys;
18 namespace values = extension_manifest_values; 16 namespace values = extension_manifest_values;
19 namespace errors = extension_manifest_errors; 17 namespace errors = extension_manifest_errors;
20 18
21 class ExtensionTest : public testing::Test { 19 class ExtensionTest : public testing::Test {
22 }; 20 };
23 21
24 TEST(ExtensionTest, InitFromValueInvalid) { 22 TEST(ExtensionTest, InitFromValueInvalid) {
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 Extension extension; 422 Extension extension;
425 std::string error; 423 std::string error;
426 input_value.SetString(keys::kVersion, "1.0"); 424 input_value.SetString(keys::kVersion, "1.0");
427 input_value.SetString(keys::kName, "Test"); 425 input_value.SetString(keys::kName, "Test");
428 input_value.SetString(keys::kUpdateURL, invalid[i]); 426 input_value.SetString(keys::kUpdateURL, invalid[i]);
429 427
430 EXPECT_FALSE(extension.InitFromValue(input_value, false, &error)); 428 EXPECT_FALSE(extension.InitFromValue(input_value, false, &error));
431 EXPECT_TRUE(MatchPattern(error, errors::kInvalidUpdateURL)); 429 EXPECT_TRUE(MatchPattern(error, errors::kInvalidUpdateURL));
432 } 430 }
433 } 431 }
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 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | net/base/mime_sniffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698