summaryrefslogtreecommitdiffstats
path: root/chrome/browser/first_run_migration_mac_unittest.mm
blob: 23955e2ef5cfe213a137def4a82f7fdf7d69af8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import <Foundation/Foundation.h>

#include "base/basictypes.h"
#include "base/logging.h"
#include "base/sys_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"

// This is a test for temporary code, see chrome/browser/first_run_mac.mm
// for details.

namespace old_first_run_mac {

bool IsOldChromeFirstRunFromDictionary(NSDictionary *dict,
                                       bool *usage_stats_enabled);

extern const NSString *kOldUsageStatsPrefName;
}  // namespace google_update


class FirstRunMigrationTest : public PlatformTest {
};

TEST_F(FirstRunMigrationTest, MigrateOldFirstRunSettings) {
  using old_first_run_mac::IsOldChromeFirstRunFromDictionary;
  using old_first_run_mac::kOldUsageStatsPrefName;

  // Stats are off by default.
  bool stats_on;
  NSDictionary* empty_dict = [NSDictionary dictionary];
  EXPECT_FALSE(IsOldChromeFirstRunFromDictionary(empty_dict, &stats_on));
  EXPECT_FALSE(stats_on);

  // Stats reporting is ON.
  NSNumber* stats_enabled = [NSNumber numberWithBool:YES];
  NSDictionary* enabled_dict = [NSDictionary
      dictionaryWithObject:stats_enabled
                    forKey:kOldUsageStatsPrefName];
  EXPECT_TRUE(IsOldChromeFirstRunFromDictionary(enabled_dict, &stats_on));
  EXPECT_TRUE(stats_on);

  // Stats reporting is OFF.
  stats_enabled = [NSNumber numberWithBool:NO];
  enabled_dict = [NSDictionary
      dictionaryWithObject:stats_enabled
                    forKey:kOldUsageStatsPrefName];
  EXPECT_TRUE(IsOldChromeFirstRunFromDictionary(enabled_dict, &stats_on));
  EXPECT_FALSE(stats_on);


  // If an object of the wrong type is present, we still consider this  to
  // be a first run, but stats reporting is disabled.
  NSDictionary* wrong_type_dict = [NSDictionary
      dictionaryWithObject:empty_dict
                    forKey:kOldUsageStatsPrefName];
  EXPECT_TRUE(IsOldChromeFirstRunFromDictionary(wrong_type_dict, &stats_on));
  EXPECT_FALSE(stats_on);
}