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

Side by Side Diff: components/policy/core/common/policy_loader_ios_unittest.mm

Issue 213703005: Fixed PolicyLoaderIOS unit tests on iOS 6.1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include <UIKit/UIKit.h> 5 #include <UIKit/UIKit.h>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/ios/ios_util.h"
10 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
11 #include "base/test/test_simple_task_runner.h" 12 #include "base/test/test_simple_task_runner.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "components/policy/core/common/async_policy_provider.h" 14 #include "components/policy/core/common/async_policy_provider.h"
14 #include "components/policy/core/common/configuration_policy_provider_test.h" 15 #include "components/policy/core/common/configuration_policy_provider_test.h"
15 #include "components/policy/core/common/policy_bundle.h" 16 #include "components/policy/core/common/policy_bundle.h"
16 #include "components/policy/core/common/policy_loader_ios.h" 17 #include "components/policy/core/common/policy_loader_ios.h"
17 #include "components/policy/core/common/policy_map.h" 18 #include "components/policy/core/common/policy_map.h"
18 #include "components/policy/core/common/policy_test_utils.h" 19 #include "components/policy/core/common/policy_test_utils.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 }); 138 });
138 } 139 }
139 140
140 // static 141 // static
141 PolicyProviderTestHarness* TestHarness::Create() { 142 PolicyProviderTestHarness* TestHarness::Create() {
142 return new TestHarness(false); 143 return new TestHarness(false);
143 } 144 }
144 145
145 // static 146 // static
146 PolicyProviderTestHarness* TestHarness::CreateWithEncodedKey() { 147 PolicyProviderTestHarness* TestHarness::CreateWithEncodedKey() {
147 return new TestHarness(true); 148 if (base::ios::IsRunningOnIOS7OrLater())
149 return new TestHarness(true);
150 // Earlier versions of iOS don't have the APIs to support this test.
151 // Unfortunately it's not possible to conditionally run this harness using
152 // gtest, so we just fallback to running the non-encoded version.
153 NSLog(@"Skipping test");
154 return new TestHarness(false);
148 } 155 }
149 156
150 void TestHarness::AddPolicies(NSDictionary* policy) { 157 void TestHarness::AddPolicies(NSDictionary* policy) {
151 if (use_encoded_key_) 158 if (use_encoded_key_)
152 AddEncodedChromePolicy(policy); 159 AddEncodedChromePolicy(policy);
153 else 160 else
154 AddChromePolicy(policy); 161 AddChromePolicy(policy);
155 } 162 }
156 163
157 void TestHarness::AddChromePolicy(NSDictionary* policy) { 164 void TestHarness::AddChromePolicy(NSDictionary* policy) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 224
218 INSTANTIATE_TEST_CASE_P( 225 INSTANTIATE_TEST_CASE_P(
219 PolicyProviderIOSEncodedChromePolicyTest, 226 PolicyProviderIOSEncodedChromePolicyTest,
220 ConfigurationPolicyProviderTest, 227 ConfigurationPolicyProviderTest,
221 testing::Values(TestHarness::CreateWithEncodedKey)); 228 testing::Values(TestHarness::CreateWithEncodedKey));
222 229
223 TEST(PolicyProviderIOSTest, ChromePolicyOverEncodedChromePolicy) { 230 TEST(PolicyProviderIOSTest, ChromePolicyOverEncodedChromePolicy) {
224 // This test verifies that if the "ChromePolicy" key is present then the 231 // This test verifies that if the "ChromePolicy" key is present then the
225 // "EncodedChromePolicy" key is ignored. 232 // "EncodedChromePolicy" key is ignored.
226 233
234 if (!base::ios::IsRunningOnIOS7OrLater()) {
235 // Skip this test if running on a version earlier than iOS 7.
236 NSLog(@"Skipping test");
237 return;
238 }
239
227 NSDictionary* policy = @{ 240 NSDictionary* policy = @{
228 @"shared": @"wrong", 241 @"shared": @"wrong",
229 @"key1": @"value1", 242 @"key1": @"value1",
230 }; 243 };
231 NSData* data = [NSPropertyListSerialization 244 NSData* data = [NSPropertyListSerialization
232 dataWithPropertyList:policy 245 dataWithPropertyList:policy
233 format:NSPropertyListXMLFormat_v1_0 246 format:NSPropertyListXMLFormat_v1_0
234 options:0 247 options:0
235 error:NULL]; 248 error:NULL];
236 NSString* encodedChromePolicy = [data base64EncodedStringWithOptions:0]; 249 NSString* encodedChromePolicy = [data base64EncodedStringWithOptions:0];
(...skipping 21 matching lines...) Expand all
258 271
259 scoped_refptr<base::TestSimpleTaskRunner> taskRunner = 272 scoped_refptr<base::TestSimpleTaskRunner> taskRunner =
260 new base::TestSimpleTaskRunner(); 273 new base::TestSimpleTaskRunner();
261 PolicyLoaderIOS loader(taskRunner); 274 PolicyLoaderIOS loader(taskRunner);
262 scoped_ptr<PolicyBundle> bundle = loader.Load(); 275 scoped_ptr<PolicyBundle> bundle = loader.Load();
263 ASSERT_TRUE(bundle); 276 ASSERT_TRUE(bundle);
264 EXPECT_TRUE(bundle->Equals(expected)); 277 EXPECT_TRUE(bundle->Equals(expected));
265 } 278 }
266 279
267 } // namespace policy 280 } // namespace policy
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698