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

Side by Side Diff: base/ios/device_util_unittest.mm

Issue 1647803004: Move base to DEPS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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 | « base/ios/device_util.mm ('k') | base/ios/ios_util.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) 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
5 #import <UIKit/UIKit.h>
6
7 #include "base/ios/device_util.h"
8 #include "base/strings/sys_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/gtest_mac.h"
11 #include "testing/platform_test.h"
12
13 namespace {
14 // The behavior of most of these utility functions depends on what they are run
15 // on, so there is not much to unittest them. The APIs are run to make sure they
16 // don't choke. Additional checks are added for particular APIs when needed.
17
18 typedef PlatformTest DeviceUtilTest;
19
20 void CleanNSUserDefaultsForDeviceId() {
21 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
22 [defaults removeObjectForKey:@"ChromeClientID"];
23 [defaults removeObjectForKey:@"ChromiumClientID"];
24 [defaults removeObjectForKey:@"ClientIDGenerationHardwareType"];
25 [defaults synchronize];
26 }
27
28 TEST_F(DeviceUtilTest, GetPlatform) {
29 GTEST_ASSERT_GT(ios::device_util::GetPlatform().length(), 0U);
30 }
31
32 TEST_F(DeviceUtilTest, IsSingleCoreDevice) {
33 ios::device_util::IsSingleCoreDevice();
34 }
35
36 TEST_F(DeviceUtilTest, GetMacAddress) {
37 GTEST_ASSERT_GT(ios::device_util::GetMacAddress("en0").length(), 0U);
38 }
39
40 TEST_F(DeviceUtilTest, GetRandomId) {
41 GTEST_ASSERT_GT(ios::device_util::GetRandomId().length(), 0U);
42 }
43
44 TEST_F(DeviceUtilTest, GetDeviceIdentifier) {
45 CleanNSUserDefaultsForDeviceId();
46
47 std::string default_id = ios::device_util::GetDeviceIdentifier(NULL);
48 std::string other_id = ios::device_util::GetDeviceIdentifier("ForTest");
49 EXPECT_NE(default_id, other_id);
50
51 CleanNSUserDefaultsForDeviceId();
52
53 std::string new_default_id = ios::device_util::GetDeviceIdentifier(NULL);
54 if (![[[[UIDevice currentDevice] identifierForVendor] UUIDString]
55 isEqualToString:@"00000000-0000-0000-0000-000000000000"]) {
56 EXPECT_EQ(default_id, new_default_id);
57 } else {
58 EXPECT_NE(default_id, new_default_id);
59 }
60
61 CleanNSUserDefaultsForDeviceId();
62 }
63
64 TEST_F(DeviceUtilTest, CheckMigration) {
65 CleanNSUserDefaultsForDeviceId();
66
67 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
68 [defaults setObject:@"10000000-0000-0000-0000-000000000000"
69 forKey:@"ChromeClientID"];
70 [defaults synchronize];
71 std::string expected_id = ios::device_util::GetDeviceIdentifier(NULL);
72 [defaults removeObjectForKey:@"ChromeClientID"];
73 [defaults setObject:@"10000000-0000-0000-0000-000000000000"
74 forKey:@"ChromiumClientID"];
75 [defaults synchronize];
76 std::string new_id = ios::device_util::GetDeviceIdentifier(NULL);
77 EXPECT_EQ(expected_id, new_id);
78
79 CleanNSUserDefaultsForDeviceId();
80 }
81
82 TEST_F(DeviceUtilTest, CheckMigrationFromZero) {
83 CleanNSUserDefaultsForDeviceId();
84
85 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
86 [defaults setObject:@"00000000-0000-0000-0000-000000000000"
87 forKey:@"ChromeClientID"];
88 [defaults synchronize];
89 std::string zero_id = ios::device_util::GetDeviceIdentifier(NULL);
90 [defaults removeObjectForKey:@"ChromeClientID"];
91 [defaults setObject:@"00000000-0000-0000-0000-000000000000"
92 forKey:@"ChromiumClientID"];
93 [defaults synchronize];
94 std::string new_id = ios::device_util::GetDeviceIdentifier(NULL);
95 EXPECT_NE(zero_id, new_id);
96
97 CleanNSUserDefaultsForDeviceId();
98 }
99
100 TEST_F(DeviceUtilTest, GetSaltedStringEquals) {
101 std::string string1("The quick brown fox jumps over the lazy dog");
102 std::string string2("The quick brown fox jumps over the lazy dog");
103 std::string salt("salt");
104 // Same string and same salt should result in the same salted string.
105 EXPECT_EQ(ios::device_util::GetSaltedString(string1, salt),
106 ios::device_util::GetSaltedString(string2, salt));
107 }
108
109 TEST_F(DeviceUtilTest, GetSaltedStringNotEquals) {
110 std::string string1("The quick brown fox jumps over the lazy dog");
111 std::string string2("The lazy brown fox jumps over the quick dog");
112 std::string salt("salt");
113 // Different string and same salt should result in different salted strings.
114 EXPECT_NE(ios::device_util::GetSaltedString(string1, salt),
115 ios::device_util::GetSaltedString(string2, salt));
116 }
117
118 TEST_F(DeviceUtilTest, GetSaltedStringDifferentSalt) {
119 std::string string1("The quick brown fox jumps over the lazy dog");
120 std::string salt1("salt");
121 std::string salt2("pepper");
122 // Same string with different salt should result in different salted strings.
123 EXPECT_NE(ios::device_util::GetSaltedString(string1, salt1),
124 ios::device_util::GetSaltedString(string1, salt2));
125 }
126
127 TEST_F(DeviceUtilTest, CheckDeviceMigration) {
128 CleanNSUserDefaultsForDeviceId();
129
130 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
131 [defaults setObject:@"10000000-0000-0000-0000-000000000000"
132 forKey:@"ChromeClientID"];
133 [defaults synchronize];
134 std::string base_id = ios::device_util::GetDeviceIdentifier(NULL);
135 [defaults setObject:@"Foo" forKey:@"ClientIDGenerationHardwareType"];
136 [defaults synchronize];
137 std::string new_id = ios::device_util::GetDeviceIdentifier(NULL);
138 EXPECT_NE(new_id, base_id);
139
140 CleanNSUserDefaultsForDeviceId();
141 }
142
143 } // namespace
OLDNEW
« no previous file with comments | « base/ios/device_util.mm ('k') | base/ios/ios_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698