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

Unified Diff: content/common/quarantine/quarantine_unittest.cc

Issue 2124373002: [PPAPI] Quarantine files that are writeable by a Pepper plugin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@consolidate-file-metadata
Patch Set: Address comments. Created 4 years 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 | « content/common/quarantine/quarantine_mac_unittest.mm ('k') | content/common/quarantine/quarantine_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/quarantine/quarantine_unittest.cc
diff --git a/content/common/quarantine/quarantine_unittest.cc b/content/common/quarantine/quarantine_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9e4f3bc51b9e279308acd92b93876899abd77791
--- /dev/null
+++ b/content/common/quarantine/quarantine_unittest.cc
@@ -0,0 +1,58 @@
+// Copyright 2016 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 "content/public/common/quarantine.h"
+
+#include <iterator>
+#include <string>
+
+#include "base/files/file.h"
+#include "base/files/file_util.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/macros.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+namespace content {
+
+namespace {
+
+const char kTestData[] = "It's okay to have a trailing nul.";
+const char kInternetURL[] = "http://example.com/some-url";
+const char kInternetReferrerURL[] = "http://example.com/some-other-url";
+const char kTestGUID[] = "69f8621d-c46a-4e88-b915-1ce5415cb008";
+
+} // namespace
+
+TEST(QuarantineTest, FileCanBeOpenedForReadAfterAnnotation) {
+ base::ScopedTempDir test_dir;
+ ASSERT_TRUE(test_dir.CreateUniqueTempDir());
+
+ base::FilePath test_file = test_dir.GetPath().AppendASCII("foo.class");
+ ASSERT_EQ(static_cast<int>(arraysize(kTestData)),
+ base::WriteFile(test_file, kTestData, arraysize(kTestData)));
+
+ EXPECT_EQ(QuarantineFileResult::OK,
+ QuarantineFile(test_file, GURL(kInternetURL),
+ GURL(kInternetReferrerURL), kTestGUID));
+
+ std::string contents;
+ EXPECT_TRUE(base::ReadFileToString(test_file, &contents));
+ EXPECT_EQ(std::string(std::begin(kTestData), std::end(kTestData)), contents);
+}
+
+TEST(QuarantineTest, FileCanBeAnnotatedWithNoGUID) {
+ base::ScopedTempDir test_dir;
+ ASSERT_TRUE(test_dir.CreateUniqueTempDir());
+
+ base::FilePath test_file = test_dir.GetPath().AppendASCII("foo.class");
+ ASSERT_EQ(static_cast<int>(arraysize(kTestData)),
+ base::WriteFile(test_file, kTestData, arraysize(kTestData)));
+
+ EXPECT_EQ(QuarantineFileResult::OK,
+ QuarantineFile(test_file, GURL(kInternetURL),
+ GURL(kInternetReferrerURL), std::string()));
+}
+
+} // namespace content
« no previous file with comments | « content/common/quarantine/quarantine_mac_unittest.mm ('k') | content/common/quarantine/quarantine_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698