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

Side by Side Diff: content/common/sandbox_mac_system_access_unittest.mm

Issue 1852433004: Fix NSPasteboard leaks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile error. Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 #include <openssl/rand.h> 6 #include <openssl/rand.h>
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/scoped_file.h" 10 #include "base/files/scoped_file.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ref_counted.h"
12 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
13 #include "content/common/sandbox_mac.h" 14 #include "content/common/sandbox_mac.h"
14 #include "content/common/sandbox_mac_unittest_helper.h" 15 #include "content/common/sandbox_mac_unittest_helper.h"
15 #include "crypto/openssl_util.h" 16 #include "crypto/openssl_util.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #import "ui/base/clipboard/clipboard_util_mac.h"
17 19
18 namespace content { 20 namespace content {
19 21
20 //--------------------- Clipboard Sandboxing ---------------------- 22 //--------------------- Clipboard Sandboxing ----------------------
21 // Test case for checking sandboxing of clipboard access. 23 // Test case for checking sandboxing of clipboard access.
22 class MacSandboxedClipboardTestCase : public MacSandboxTestCase { 24 class MacSandboxedClipboardTestCase : public MacSandboxTestCase {
23 public: 25 public:
24 MacSandboxedClipboardTestCase(); 26 MacSandboxedClipboardTestCase();
25 ~MacSandboxedClipboardTestCase() override; 27 ~MacSandboxedClipboardTestCase() override;
26 28
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 64 }
63 65
64 return true; 66 return true;
65 } 67 }
66 68
67 void MacSandboxedClipboardTestCase::SetTestData(const char* test_data) { 69 void MacSandboxedClipboardTestCase::SetTestData(const char* test_data) {
68 clipboard_name_ = [base::SysUTF8ToNSString(test_data) retain]; 70 clipboard_name_ = [base::SysUTF8ToNSString(test_data) retain];
69 } 71 }
70 72
71 TEST_F(MacSandboxTest, ClipboardAccess) { 73 TEST_F(MacSandboxTest, ClipboardAccess) {
72 NSPasteboard* pb = [NSPasteboard pasteboardWithUniqueName]; 74 scoped_refptr<ui::UniquePasteboard> pb = new ui::UniquePasteboard;
73 EXPECT_EQ([[pb types] count], 0U); 75 ASSERT_TRUE(pb->get());
76 EXPECT_EQ([[pb->get() types] count], 0U);
74 77
75 std::string pasteboard_name = base::SysNSStringToUTF8([pb name]); 78 std::string pasteboard_name = base::SysNSStringToUTF8([pb->get() name]);
76 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedClipboardTestCase", 79 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedClipboardTestCase",
77 pasteboard_name.c_str())); 80 pasteboard_name.c_str()));
78 81
79 // After executing the test, the clipboard should still be empty. 82 // After executing the test, the clipboard should still be empty.
80 EXPECT_EQ([[pb types] count], 0U); 83 EXPECT_EQ([[pb->get() types] count], 0U);
81 } 84 }
82 85
83 //--------------------- File Access Sandboxing ---------------------- 86 //--------------------- File Access Sandboxing ----------------------
84 // Test case for checking sandboxing of filesystem apis. 87 // Test case for checking sandboxing of filesystem apis.
85 class MacSandboxedFileAccessTestCase : public MacSandboxTestCase { 88 class MacSandboxedFileAccessTestCase : public MacSandboxTestCase {
86 public: 89 public:
87 bool SandboxedTest() override; 90 bool SandboxedTest() override;
88 }; 91 };
89 92
90 REGISTER_SANDBOX_TEST_CASE(MacSandboxedFileAccessTestCase); 93 REGISTER_SANDBOX_TEST_CASE(MacSandboxedFileAccessTestCase);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // Ensure that RAND_bytes is functional within the sandbox. 141 // Ensure that RAND_bytes is functional within the sandbox.
139 uint8_t byte; 142 uint8_t byte;
140 return RAND_bytes(&byte, 1) == 1; 143 return RAND_bytes(&byte, 1) == 1;
141 } 144 }
142 145
143 TEST_F(MacSandboxTest, OpenSSLAccess) { 146 TEST_F(MacSandboxTest, OpenSSLAccess) {
144 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedOpenSSLTestCase", NULL)); 147 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedOpenSSLTestCase", NULL));
145 } 148 }
146 149
147 } // namespace content 150 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_drag_source_mac_unittest.mm ('k') | ui/base/clipboard/clipboard_util_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698