15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2010 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <windows.h>
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string_util.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/win_util.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/windows_version.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace win {
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Saves the current thread's locale ID when initialized, and restores it when
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the instance is going out of scope.
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ThreadLocaleSaver {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ThreadLocaleSaver() : original_locale_id_(GetThreadLocale()) {}
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ~ThreadLocaleSaver() { SetThreadLocale(original_locale_id_); }
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  LCID original_locale_id_;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ThreadLocaleSaver);
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The test is somewhat silly, because the Vista bots some have UAC enabled
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// and some have it disabled. At least we check that it does not crash.
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST(BaseWinUtilTest, TestIsUACEnabled) {
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (GetVersion() >= base::win::VERSION_VISTA) {
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    UserAccountControlIsEnabled();
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } else {
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_TRUE(UserAccountControlIsEnabled());
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST(BaseWinUtilTest, TestGetUserSidString) {
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::wstring user_sid;
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(GetUserSidString(&user_sid));
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(!user_sid.empty());
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST(BaseWinUtilTest, TestGetNonClientMetrics) {
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NONCLIENTMETRICS metrics = {0};
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GetNonClientMetrics(&metrics);
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(metrics.cbSize > 0);
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(metrics.iScrollWidth > 0);
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(metrics.iScrollHeight > 0);
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace win
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace base
59