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

Unified Diff: chrome/common/extensions/extension_unittest.cc

Issue 160254: Merge 21612 - Implement mimetype sniffing for extensions.... (Closed) Base URL: svn://chrome-svn/chrome/branches/195/src/
Patch Set: Created 11 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | net/base/mime_sniffer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/extension_unittest.cc
===================================================================
--- chrome/common/extensions/extension_unittest.cc (revision 21813)
+++ chrome/common/extensions/extension_unittest.cc (working copy)
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/file_path.h"
+#include "base/file_util.h"
#include "base/string_util.h"
#include "base/path_service.h"
#include "chrome/common/chrome_paths.h"
@@ -10,6 +11,7 @@
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/extension_error_reporter.h"
#include "chrome/common/json_value_serializer.h"
+#include "net/base/mime_sniffer.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace keys = extension_manifest_keys;
@@ -429,3 +431,27 @@
EXPECT_TRUE(MatchPattern(error, errors::kInvalidUpdateURL));
}
}
+
+// This test ensures that the mimetype sniffing code stays in sync with the
+// actual crx files that we test other parts of the system with.
+TEST(ExtensionTest, MimeTypeSniffing) {
+ FilePath path;
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
+ path = path.AppendASCII("extensions").AppendASCII("good.crx");
+
+ std::string data;
+ ASSERT_TRUE(file_util::ReadFileToString(path, &data));
+
+ std::string result;
+ EXPECT_TRUE(net::SniffMimeType(data.c_str(), data.size(),
+ GURL("http://www.example.com/foo.crx"), "", &result));
+ EXPECT_EQ(std::string(Extension::kMimeType), result);
+
+ data.clear();
+ result.clear();
+ path = path.DirName().AppendASCII("bad_magic.crx");
+ ASSERT_TRUE(file_util::ReadFileToString(path, &data));
+ EXPECT_TRUE(net::SniffMimeType(data.c_str(), data.size(),
+ GURL("http://www.example.com/foo.crx"), "", &result));
+ EXPECT_EQ("application/octet-stream", result);
+}
Property changes on: chrome\common\extensions\extension_unittest.cc
___________________________________________________________________
Modified: svn:mergeinfo
Merged /trunk/src/chrome/common/extensions/extension_unittest.cc:r21612
« 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