| Index: base/ios/device_util_unittest.mm
|
| diff --git a/base/ios/device_util_unittest.mm b/base/ios/device_util_unittest.mm
|
| index b8ba10f289d365d9d805e008882af88a29e7d2a4..12bfe09a17e86884531483f31a7877d0c60109bb 100644
|
| --- a/base/ios/device_util_unittest.mm
|
| +++ b/base/ios/device_util_unittest.mm
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#import <Foundation/Foundation.h>
|
| +#import <UIKit/UIKit.h>
|
|
|
| #include "base/ios/device_util.h"
|
| #include "base/ios/ios_util.h"
|
| @@ -18,6 +18,13 @@ namespace {
|
|
|
| typedef PlatformTest DeviceUtilTest;
|
|
|
| +void CleanNSUserDefaultsForDeviceId() {
|
| + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
| + [defaults removeObjectForKey:@"ChromeClientID"];
|
| + [defaults removeObjectForKey:@"ChromiumClientID"];
|
| + [defaults synchronize];
|
| +}
|
| +
|
| TEST_F(DeviceUtilTest, GetPlatform) {
|
| GTEST_ASSERT_GT(ios::device_util::GetPlatform().length(), 0U);
|
| }
|
| @@ -39,19 +46,60 @@ TEST_F(DeviceUtilTest, GetRandomId) {
|
| }
|
|
|
| TEST_F(DeviceUtilTest, GetDeviceIdentifier) {
|
| + CleanNSUserDefaultsForDeviceId();
|
| +
|
| std::string default_id = ios::device_util::GetDeviceIdentifier(NULL);
|
| std::string other_id = ios::device_util::GetDeviceIdentifier("ForTest");
|
| EXPECT_NE(default_id, other_id);
|
|
|
| - NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
| - [defaults removeObjectForKey:@"ChromiumClientID"];
|
| - [defaults synchronize];
|
| + CleanNSUserDefaultsForDeviceId();
|
|
|
| std::string new_default_id = ios::device_util::GetDeviceIdentifier(NULL);
|
| - if (base::ios::IsRunningOnIOS6OrLater())
|
| + if (base::ios::IsRunningOnIOS6OrLater() &&
|
| + ![[[[UIDevice currentDevice] identifierForVendor] UUIDString]
|
| + isEqualToString:@"00000000-0000-0000-0000-000000000000"]) {
|
| EXPECT_EQ(default_id, new_default_id);
|
| - else
|
| + } else {
|
| EXPECT_NE(default_id, new_default_id);
|
| + }
|
| +
|
| + CleanNSUserDefaultsForDeviceId();
|
| +}
|
| +
|
| +TEST_F(DeviceUtilTest, CheckMigration) {
|
| + CleanNSUserDefaultsForDeviceId();
|
| +
|
| + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
| + [defaults setObject:@"10000000-0000-0000-0000-000000000000"
|
| + forKey:@"ChromeClientID"];
|
| + [defaults synchronize];
|
| + std::string expected_id = ios::device_util::GetDeviceIdentifier(NULL);
|
| + [defaults removeObjectForKey:@"ChromeClientID"];
|
| + [defaults setObject:@"10000000-0000-0000-0000-000000000000"
|
| + forKey:@"ChromiumClientID"];
|
| + [defaults synchronize];
|
| + std::string new_id = ios::device_util::GetDeviceIdentifier(NULL);
|
| + EXPECT_EQ(expected_id, new_id);
|
| +
|
| + CleanNSUserDefaultsForDeviceId();
|
| +}
|
| +
|
| +TEST_F(DeviceUtilTest, CheckMigrationFromZero) {
|
| + CleanNSUserDefaultsForDeviceId();
|
| +
|
| + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
| + [defaults setObject:@"00000000-0000-0000-0000-000000000000"
|
| + forKey:@"ChromeClientID"];
|
| + [defaults synchronize];
|
| + std::string zero_id = ios::device_util::GetDeviceIdentifier(NULL);
|
| + [defaults removeObjectForKey:@"ChromeClientID"];
|
| + [defaults setObject:@"00000000-0000-0000-0000-000000000000"
|
| + forKey:@"ChromiumClientID"];
|
| + [defaults synchronize];
|
| + std::string new_id = ios::device_util::GetDeviceIdentifier(NULL);
|
| + EXPECT_NE(zero_id, new_id);
|
| +
|
| + CleanNSUserDefaultsForDeviceId();
|
| }
|
|
|
| } // namespace
|
|
|