| Index: content/common/quarantine/quarantine_mac_unittest.mm
|
| diff --git a/content/browser/download/quarantine_mac_unittest.mm b/content/common/quarantine/quarantine_mac_unittest.mm
|
| similarity index 48%
|
| rename from content/browser/download/quarantine_mac_unittest.mm
|
| rename to content/common/quarantine/quarantine_mac_unittest.mm
|
| index babe63454e861189d2a2c3713a240f853aa9f9be..4e3cf6d66322cd8577f12d7cf2b34faa528f8c84 100644
|
| --- a/content/browser/download/quarantine_mac_unittest.mm
|
| +++ b/content/common/quarantine/quarantine_mac_unittest.mm
|
| @@ -13,7 +13,7 @@
|
| #include "base/mac/mac_util.h"
|
| #include "base/mac/scoped_nsobject.h"
|
| #include "base/strings/sys_string_conversions.h"
|
| -#include "content/browser/download/quarantine.h"
|
| +#include "content/public/common/quarantine.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "testing/gtest_mac.h"
|
| #include "url/gurl.h"
|
| @@ -24,13 +24,15 @@ namespace {
|
| class QuarantineMacTest : public testing::Test {
|
| public:
|
| QuarantineMacTest()
|
| - : source_url_("http://www.source.com"),
|
| - referrer_url_("http://www.referrer.com") {}
|
| + : source_url_("http://www.source.example.com"),
|
| + referrer_url_("http://www.referrer.example.com") {}
|
|
|
| protected:
|
| void SetUp() override {
|
| - if (base::mac::IsAtMostOS10_9())
|
| + if (base::mac::IsAtMostOS10_9()) {
|
| + LOG(WARNING) << "Test suite requires Mac OS X 10.10 or later";
|
| return;
|
| + }
|
| ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
|
| ASSERT_TRUE(
|
| base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &test_file_));
|
| @@ -55,32 +57,6 @@ class QuarantineMacTest : public testing::Test {
|
| ASSERT_TRUE(success);
|
| }
|
|
|
| - void VerifyAttributesAreSetCorrectly() {
|
| - base::scoped_nsobject<NSURL> file_url([[NSURL alloc]
|
| - initFileURLWithPath:base::SysUTF8ToNSString(test_file_.value())]);
|
| - ASSERT_TRUE(file_url);
|
| -
|
| - NSError* error = nil;
|
| - NSDictionary* properties = nil;
|
| -// NSURLQuarantinePropertiesKey is only available on macOS 10.10+.
|
| -#pragma clang diagnostic push
|
| -#pragma clang diagnostic ignored "-Wunguarded-availability"
|
| - BOOL success = [file_url getResourceValue:&properties
|
| - forKey:NSURLQuarantinePropertiesKey
|
| - error:&error];
|
| -#pragma clang diagnostic pop
|
| - ASSERT_TRUE(success);
|
| - ASSERT_TRUE(properties);
|
| - ASSERT_NSEQ(
|
| - [[properties valueForKey:static_cast<NSString*>(
|
| - kLSQuarantineOriginURLKey)] description],
|
| - base::SysUTF8ToNSString(referrer_url_.spec()));
|
| - ASSERT_NSEQ([[properties
|
| - valueForKey:static_cast<NSString*>(kLSQuarantineDataURLKey)]
|
| - description],
|
| - base::SysUTF8ToNSString(source_url_.spec()));
|
| - }
|
| -
|
| base::ScopedTempDir temp_dir_;
|
| base::FilePath test_file_;
|
| GURL source_url_;
|
| @@ -91,17 +67,58 @@ class QuarantineMacTest : public testing::Test {
|
| TEST_F(QuarantineMacTest, CheckMetadataSetCorrectly) {
|
| if (base::mac::IsAtMostOS10_9())
|
| return;
|
| - QuarantineFile(test_file_, source_url_, referrer_url_, "");
|
| - VerifyAttributesAreSetCorrectly();
|
| + EXPECT_EQ(QuarantineFileResult::OK,
|
| + QuarantineFile(test_file_, source_url_, referrer_url_, ""));
|
| + EXPECT_TRUE(IsFileQuarantined(test_file_, source_url_, referrer_url_));
|
| }
|
|
|
| TEST_F(QuarantineMacTest, SetMetadataMultipleTimes) {
|
| if (base::mac::IsAtMostOS10_9())
|
| return;
|
| - GURL dummy_url("http://www.dummy.com");
|
| - QuarantineFile(test_file_, source_url_, referrer_url_, "");
|
| - QuarantineFile(test_file_, dummy_url, dummy_url, "");
|
| - VerifyAttributesAreSetCorrectly();
|
| + GURL dummy_url("http://www.dummy.example.com");
|
| + EXPECT_EQ(QuarantineFileResult::OK,
|
| + QuarantineFile(test_file_, source_url_, referrer_url_, ""));
|
| + EXPECT_EQ(QuarantineFileResult::OK,
|
| + QuarantineFile(test_file_, dummy_url, dummy_url, ""));
|
| + EXPECT_TRUE(IsFileQuarantined(test_file_, source_url_, referrer_url_));
|
| +}
|
| +
|
| +TEST_F(QuarantineMacTest, IsFileQuarantined_NoFile) {
|
| + if (base::mac::IsAtMostOS10_9())
|
| + return;
|
| + base::FilePath does_not_exist = temp_dir_.GetPath().AppendASCII("a.jar");
|
| + EXPECT_FALSE(IsFileQuarantined(does_not_exist, GURL(), GURL()));
|
| +}
|
| +
|
| +TEST_F(QuarantineMacTest, IsFileQuarantined_NoAnnotationsOnFile) {
|
| + if (base::mac::IsAtMostOS10_9())
|
| + return;
|
| + EXPECT_FALSE(IsFileQuarantined(test_file_, GURL(), GURL()));
|
| +}
|
| +
|
| +TEST_F(QuarantineMacTest, IsFileQuarantined_SourceUrlOnly) {
|
| + if (base::mac::IsAtMostOS10_9())
|
| + return;
|
| + ASSERT_EQ(QuarantineFileResult::OK,
|
| + QuarantineFile(test_file_, source_url_, GURL(), std::string()));
|
| + EXPECT_TRUE(IsFileQuarantined(test_file_, source_url_, GURL()));
|
| + EXPECT_TRUE(IsFileQuarantined(test_file_, GURL(), GURL()));
|
| + EXPECT_TRUE(IsFileQuarantined(test_file_, GURL(), referrer_url_));
|
| + EXPECT_FALSE(IsFileQuarantined(test_file_, referrer_url_, GURL()));
|
| +}
|
| +
|
| +TEST_F(QuarantineMacTest, IsFileQuarantined_FullMetadata) {
|
| + if (base::mac::IsAtMostOS10_9())
|
| + return;
|
| + ASSERT_EQ(
|
| + QuarantineFileResult::OK,
|
| + QuarantineFile(test_file_, source_url_, referrer_url_, std::string()));
|
| + EXPECT_TRUE(IsFileQuarantined(test_file_, GURL(), GURL()));
|
| + EXPECT_TRUE(IsFileQuarantined(test_file_, source_url_, GURL()));
|
| + EXPECT_TRUE(IsFileQuarantined(test_file_, source_url_, referrer_url_));
|
| + EXPECT_TRUE(IsFileQuarantined(test_file_, GURL(), referrer_url_));
|
| + EXPECT_FALSE(IsFileQuarantined(test_file_, source_url_, source_url_));
|
| + EXPECT_FALSE(IsFileQuarantined(test_file_, referrer_url_, referrer_url_));
|
| }
|
|
|
| } // namespace
|
|
|