OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #import <UIKit/UIKit.h> | 5 #import <UIKit/UIKit.h> |
6 | 6 |
7 #include "base/ios/device_util.h" | 7 #include "base/ios/device_util.h" |
8 #include "base/ios/ios_util.h" | 8 #include "base/ios/ios_util.h" |
9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 [defaults removeObjectForKey:@"ChromeClientID"]; | 92 [defaults removeObjectForKey:@"ChromeClientID"]; |
93 [defaults setObject:@"00000000-0000-0000-0000-000000000000" | 93 [defaults setObject:@"00000000-0000-0000-0000-000000000000" |
94 forKey:@"ChromiumClientID"]; | 94 forKey:@"ChromiumClientID"]; |
95 [defaults synchronize]; | 95 [defaults synchronize]; |
96 std::string new_id = ios::device_util::GetDeviceIdentifier(NULL); | 96 std::string new_id = ios::device_util::GetDeviceIdentifier(NULL); |
97 EXPECT_NE(zero_id, new_id); | 97 EXPECT_NE(zero_id, new_id); |
98 | 98 |
99 CleanNSUserDefaultsForDeviceId(); | 99 CleanNSUserDefaultsForDeviceId(); |
100 } | 100 } |
101 | 101 |
| 102 TEST_F(DeviceUtilTest, GetSaltedStringEquals) { |
| 103 std::string string1("The quick brown fox jumps over the lazy dog"); |
| 104 std::string string2("The quick brown fox jumps over the lazy dog"); |
| 105 std::string salt("salt"); |
| 106 // Same string and same salt should result in the same salted string. |
| 107 EXPECT_EQ(ios::device_util::GetSaltedString(string1, salt), |
| 108 ios::device_util::GetSaltedString(string2, salt)); |
| 109 } |
| 110 |
| 111 TEST_F(DeviceUtilTest, GetSaltedStringNotEquals) { |
| 112 std::string string1("The quick brown fox jumps over the lazy dog"); |
| 113 std::string string2("The lazy brown fox jumps over the quick dog"); |
| 114 std::string salt("salt"); |
| 115 // Different string and same salt should result in different salted strings. |
| 116 EXPECT_NE(ios::device_util::GetSaltedString(string1, salt), |
| 117 ios::device_util::GetSaltedString(string2, salt)); |
| 118 } |
| 119 |
| 120 TEST_F(DeviceUtilTest, GetSaltedStringDifferentSalt) { |
| 121 std::string string1("The quick brown fox jumps over the lazy dog"); |
| 122 std::string salt1("salt"); |
| 123 std::string salt2("pepper"); |
| 124 // Same string with different salt should result in different salted strings. |
| 125 EXPECT_NE(ios::device_util::GetSaltedString(string1, salt1), |
| 126 ios::device_util::GetSaltedString(string1, salt2)); |
| 127 } |
| 128 |
102 TEST_F(DeviceUtilTest, CheckDeviceMigration) { | 129 TEST_F(DeviceUtilTest, CheckDeviceMigration) { |
103 CleanNSUserDefaultsForDeviceId(); | 130 CleanNSUserDefaultsForDeviceId(); |
104 | 131 |
105 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | 132 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
106 [defaults setObject:@"10000000-0000-0000-0000-000000000000" | 133 [defaults setObject:@"10000000-0000-0000-0000-000000000000" |
107 forKey:@"ChromeClientID"]; | 134 forKey:@"ChromeClientID"]; |
108 [defaults synchronize]; | 135 [defaults synchronize]; |
109 std::string base_id = ios::device_util::GetDeviceIdentifier(NULL); | 136 std::string base_id = ios::device_util::GetDeviceIdentifier(NULL); |
110 [defaults setObject:@"Foo" forKey:@"ClientIDGenerationHardwareType"]; | 137 [defaults setObject:@"Foo" forKey:@"ClientIDGenerationHardwareType"]; |
111 [defaults synchronize]; | 138 [defaults synchronize]; |
112 std::string new_id = ios::device_util::GetDeviceIdentifier(NULL); | 139 std::string new_id = ios::device_util::GetDeviceIdentifier(NULL); |
113 EXPECT_NE(new_id, base_id); | 140 EXPECT_NE(new_id, base_id); |
114 | 141 |
115 CleanNSUserDefaultsForDeviceId(); | 142 CleanNSUserDefaultsForDeviceId(); |
116 } | 143 } |
117 | 144 |
118 } // namespace | 145 } // namespace |
OLD | NEW |