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

Side by Side Diff: sandbox/win/src/lpc_policy_test.cc

Issue 1324523008: Windows sbox: Warmup locales before sandbox lockdown (and tests) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add explicit checks of returned values from Win32 calls Created 5 years, 3 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
« no previous file with comments | « sandbox/win/sandbox_win.gypi ('k') | sandbox/win/src/sandbox_policy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 // These tests have been added to specifically tests issues arising from (A)LPC
6 // lock down.
7
8 #include <algorithm>
9 #include <cctype>
10
11 #include <windows.h>
12 #include <winioctl.h>
13
14 #include "sandbox/win/src/sandbox.h"
15 #include "sandbox/win/src/sandbox_factory.h"
16 #include "sandbox/win/src/sandbox_policy.h"
17 #include "sandbox/win/tests/common/controller.h"
18 #include "sandbox/win/tests/common/test_utils.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20
21 namespace sandbox {
22
23 // Converts LCID to std::wstring for passing to sbox tests.
24 std::wstring LcidToWString(LCID lcid) {
25 wchar_t buff[10] = {0};
26 int res = swprintf_s(buff, sizeof(buff)/sizeof(buff[0]), L"%08x", lcid);
27 if (-1 != res) {
28 return std::wstring(buff);
29 }
30 return std::wstring();
31 }
32
33 // Converts LANGID to std::wstring for passing to sbox tests.
34 std::wstring LangidToWString(LANGID langid) {
35 wchar_t buff[10] = {0};
36 int res = swprintf_s(buff, sizeof(buff)/sizeof(buff[0]), L"%04x", langid);
37 if (-1 != res) {
38 return std::wstring(buff);
39 }
40 return std::wstring();
41 }
42
43 SBOX_TESTS_COMMAND int Lpc_GetUserDefaultLangID(int argc, wchar_t **argv) {
44 if (argc != 1)
45 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
46 std::wstring expected_langid_string(argv[0]);
47
48 // This will cause an exception if not warmed up suitably.
49 LANGID langid = ::GetUserDefaultLangID();
50
51 std::wstring langid_string = LangidToWString(langid);
52 if (0 == wcsncmp(langid_string.c_str(), expected_langid_string.c_str(), 4)) {
53 return SBOX_TEST_SUCCEEDED;
54 }
55 return SBOX_TEST_FAILED;
56 }
57
58 TEST(LpcPolicyTest, GetUserDefaultLangID) {
59 LANGID langid = ::GetUserDefaultLangID();
60 std::wstring cmd = L"Lpc_GetUserDefaultLangID " + LangidToWString(langid);
61 TestRunner runner;
62 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(cmd.c_str()));
63 }
64
65 SBOX_TESTS_COMMAND int Lpc_GetUserDefaultLCID(int argc, wchar_t **argv) {
66 if (argc != 1)
67 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
68 std::wstring expected_lcid_string(argv[0]);
69
70 // This will cause an exception if not warmed up suitably.
71 LCID lcid = ::GetUserDefaultLCID();
72
73 std::wstring lcid_string = LcidToWString(lcid);
74 if (0 == wcsncmp(lcid_string.c_str(), expected_lcid_string.c_str(), 8)) {
75 return SBOX_TEST_SUCCEEDED;
76 }
77 return SBOX_TEST_FAILED;
78 }
79
80 TEST(LpcPolicyTest, GetUserDefaultLCID) {
81 LCID lcid = ::GetUserDefaultLCID();
82 std::wstring cmd = L"Lpc_GetUserDefaultLCID " + LcidToWString(lcid);
83 TestRunner runner;
84 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(cmd.c_str()));
85 }
86
87 SBOX_TESTS_COMMAND int Lpc_GetUserDefaultLocaleName(int argc, wchar_t **argv) {
88 if (argc != 1)
89 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
90 std::wstring expected_locale_name(argv[0]);
91
92 wchar_t locale_name[LOCALE_NAME_MAX_LENGTH] = { 0 };
93 // This will cause an exception if not warmed up suitably.
94 int ret = ::GetUserDefaultLocaleName(locale_name, LOCALE_NAME_MAX_LENGTH);
95 if (!ret) {
96 return SBOX_TEST_FAILED;
97 }
98 if (!wcsnlen(locale_name, LOCALE_NAME_MAX_LENGTH)) {
99 return SBOX_TEST_FAILED;
100 }
101 if (0 == wcsncmp(locale_name,
102 expected_locale_name.c_str(),
103 LOCALE_NAME_MAX_LENGTH)) {
104 return SBOX_TEST_SUCCEEDED;
105 }
106 return SBOX_TEST_FAILED;
107 }
108
109 TEST(LpcPolicyTest, GetUserDefaultLocaleName) {
110 wchar_t locale_name[LOCALE_NAME_MAX_LENGTH] = { 0 };
111 int ret = ::GetUserDefaultLocaleName(locale_name, LOCALE_NAME_MAX_LENGTH);
112 EXPECT_NE(ret, 0);
113 std::wstring cmd = L"Lpc_GetUserDefaultLocaleName " + \
114 std::wstring(locale_name);
115 TestRunner runner;
116 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(cmd.c_str()));
117 }
118
119 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/sandbox_win.gypi ('k') | sandbox/win/src/sandbox_policy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698