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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/public/common/quarantine.h"
6
7 #include <iterator>
8 #include <string>
9
10 #include "base/files/file.h"
11 #include "base/files/file_util.h"
12 #include "base/files/scoped_temp_dir.h"
13 #include "base/macros.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "url/gurl.h"
16
17 namespace content {
18
19 namespace {
20
21 const char kTestData[] = "It's okay to have a trailing nul.";
22 const char kInternetURL[] = "http://example.com/some-url";
23 const char kInternetReferrerURL[] = "http://example.com/some-other-url";
24 const char kTestGUID[] = "69f8621d-c46a-4e88-b915-1ce5415cb008";
25
26 } // namespace
27
28 TEST(QuarantineTest, FileCanBeOpenedForReadAfterAnnotation) {
29 base::ScopedTempDir test_dir;
30 ASSERT_TRUE(test_dir.CreateUniqueTempDir());
31
32 base::FilePath test_file = test_dir.GetPath().AppendASCII("foo.class");
33 ASSERT_EQ(static_cast<int>(arraysize(kTestData)),
34 base::WriteFile(test_file, kTestData, arraysize(kTestData)));
35
36 EXPECT_EQ(QuarantineFileResult::OK,
37 QuarantineFile(test_file, GURL(kInternetURL),
38 GURL(kInternetReferrerURL), kTestGUID));
39
40 std::string contents;
41 EXPECT_TRUE(base::ReadFileToString(test_file, &contents));
42 EXPECT_EQ(std::string(std::begin(kTestData), std::end(kTestData)), contents);
43 }
44
45 TEST(QuarantineTest, FileCanBeAnnotatedWithNoGUID) {
46 base::ScopedTempDir test_dir;
47 ASSERT_TRUE(test_dir.CreateUniqueTempDir());
48
49 base::FilePath test_file = test_dir.GetPath().AppendASCII("foo.class");
50 ASSERT_EQ(static_cast<int>(arraysize(kTestData)),
51 base::WriteFile(test_file, kTestData, arraysize(kTestData)));
52
53 EXPECT_EQ(QuarantineFileResult::OK,
54 QuarantineFile(test_file, GURL(kInternetURL),
55 GURL(kInternetReferrerURL), std::string()));
56 }
57
58 } // namespace content
OLDNEW
« 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