HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Lollipop
|
5.0.1_r1
下载
查看原文件
收藏
根目录
external
chromium_org
net
base
mime_sniffer_unittest.cc
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/basictypes.h" #include "net/base/mime_sniffer.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" namespace net { struct SnifferTest { const char* content; size_t content_len; std::string url; std::string type_hint; const char* mime_type; }; static void TestArray(SnifferTest* tests, size_t count) { std::string mime_type; for (size_t i = 0; i < count; ++i) { SniffMimeType(tests[i].content, tests[i].content_len, GURL(tests[i].url), tests[i].type_hint, &mime_type); EXPECT_EQ(tests[i].mime_type, mime_type); } } // TODO(evanm): convert other tests to use SniffMimeType instead of TestArray, // so the error messages produced by test failures are more useful. static std::string SniffMimeType(const std::string& content, const std::string& url, const std::string& mime_type_hint) { std::string mime_type; SniffMimeType(content.data(), content.size(), GURL(url), mime_type_hint, &mime_type); return mime_type; } TEST(MimeSnifferTest, BoundaryConditionsTest) { std::string mime_type; std::string type_hint; char buf[] = { 'd', '\x1f', '\xFF' }; GURL url; SniffMimeType(buf, 0, url, type_hint, &mime_type); EXPECT_EQ("text/plain", mime_type); SniffMimeType(buf, 1, url, type_hint, &mime_type); EXPECT_EQ("text/plain", mime_type); SniffMimeType(buf, 2, url, type_hint, &mime_type); EXPECT_EQ("application/octet-stream", mime_type); } TEST(MimeSnifferTest, BasicSniffingTest) { SnifferTest tests[] = { { "