Notify the webcontents of the background page of extensions that it's hidden, if...
[chromium-blink-merge.git] / win8 / metro_driver / winrt_utils_unittest.cc
blob9ae869b2520184480581d551e00e1eeae9ab0d28
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
3 // found in the LICENSE file.
4 #include "stdafx.h"
6 #include "winrt_utils.h"
8 #include "base/logging.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace {
13 template <typename Type>
14 static HRESULT CreateProperty(Type value, winfoundtn::IPropertyValue** prop) {
15 return E_NOTIMPL;
18 template <>
19 static HRESULT CreateProperty<const wchar_t*>(
20 const wchar_t* value, winfoundtn::IPropertyValue** prop) {
21 mswrw::HString string_value;
22 string_value.Attach(MakeHString(value));
23 return winrt_utils::CreateStringProperty(string_value.Get(), prop);
26 template <>
27 static HRESULT CreateProperty<INT16>(INT16 value,
28 winfoundtn::IPropertyValue** prop) {
29 return winrt_utils::CreateInt16Property(value, prop);
32 template <>
33 static HRESULT CreateProperty<INT32>(INT32 value,
34 winfoundtn::IPropertyValue** prop) {
35 return winrt_utils::CreateInt32Property(value, prop);
38 template <>
39 static HRESULT CreateProperty<INT64>(INT64 value,
40 winfoundtn::IPropertyValue** prop) {
41 return winrt_utils::CreateInt64Property(value, prop);
44 template <>
45 static HRESULT CreateProperty<UINT8>(UINT8 value,
46 winfoundtn::IPropertyValue** prop) {
47 return winrt_utils::CreateUInt8Property(value, prop);
50 template <>
51 static HRESULT CreateProperty<UINT16>(UINT16 value,
52 winfoundtn::IPropertyValue** prop) {
53 return winrt_utils::CreateUInt16Property(value, prop);
56 template <>
57 static HRESULT CreateProperty<UINT32>(UINT32 value,
58 winfoundtn::IPropertyValue** prop) {
59 return winrt_utils::CreateUInt32Property(value, prop);
62 template <>
63 static HRESULT CreateProperty<UINT64>(UINT64 value,
64 winfoundtn::IPropertyValue** prop) {
65 return winrt_utils::CreateUInt64Property(value, prop);
68 template<typename Type>
69 void TestCompareProperties(Type value1, Type value2) {
70 mswr::ComPtr<winfoundtn::IPropertyValue> property_1;
71 HRESULT hr = CreateProperty<Type>(value1, property_1.GetAddressOf());
72 ASSERT_TRUE(SUCCEEDED(hr)) << "Can't create Property value 1";
74 mswr::ComPtr<winfoundtn::IPropertyValue> other_property_1;
75 hr = CreateProperty<Type>(value1, other_property_1.GetAddressOf());
76 ASSERT_TRUE(SUCCEEDED(hr)) << "Can't create another Property value 1";
78 mswr::ComPtr<winfoundtn::IPropertyValue> property_2;
79 hr = CreateProperty<Type>(value2, property_2.GetAddressOf());
80 ASSERT_TRUE(SUCCEEDED(hr)) << "Can't create Property value 2";
82 INT32 result = 42;
83 hr = winrt_utils::CompareProperties(
84 property_1.Get(), property_1.Get(), &result);
85 ASSERT_TRUE(SUCCEEDED(hr)) << "Can't compare property_1 to itself";
86 EXPECT_EQ(0, result) << "Bad result value while comparing same property";
88 hr = winrt_utils::CompareProperties(
89 property_1.Get(), other_property_1.Get(), &result);
90 ASSERT_TRUE(SUCCEEDED(hr)) << "Can't compare property_1 to other_property_1";
91 EXPECT_EQ(0, result) << "Bad result while comparing equal values";
93 hr = winrt_utils::CompareProperties(
94 property_1.Get(), property_2.Get(), &result);
95 ASSERT_TRUE(SUCCEEDED(hr)) << "Can't compare property_1 to property_2";
96 EXPECT_EQ(-1, result) << "Bad result while comparing values for less than";
98 hr = winrt_utils::CompareProperties(
99 property_2.Get(), property_1.Get(), &result);
100 ASSERT_TRUE(SUCCEEDED(hr)) << "Can't compare property_1 to property_2";
101 EXPECT_EQ(1, result) << "Bad result value while comparing for greater than";
104 TEST(PropertyValueCompareTest, CompareProperties) {
105 TestCompareProperties<INT16>(42, 43);
106 TestCompareProperties<INT32>(42, 43);
107 TestCompareProperties<INT64>(42, 43);
108 TestCompareProperties<UINT8>(42, 43);
109 TestCompareProperties<UINT16>(42, 43);
110 TestCompareProperties<UINT32>(42, 43);
111 TestCompareProperties<UINT64>(42, 43);
112 TestCompareProperties<const wchar_t*>(L"abc", L"bcd");
115 } // namespace