summaryrefslogtreecommitdiffstats
path: root/ios/chrome/app/safe_mode_util_unittest.cc
blob: 3164d59fc7e13ebb4b5589efbc20fac831b2ce37 (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
// Copyright 2013 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.

#include <string.h>

#include "base/files/file_path.h"
#include "base/strings/string_util.h"
#include "ios/chrome/app/safe_mode_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"

using std::string;
using std::vector;

namespace {

typedef PlatformTest SafeModeUtilTest;

TEST_F(SafeModeUtilTest, GetAllImages) {
  vector<string> images = safe_mode_util::GetLoadedImages(nullptr);
  // There should be loaded images.
  EXPECT_GT(images.size(), 0U);

  // The libSystem dylib should always be present.
  bool found_lib_system = false;
  string lib_system_prefix("libSystem");
  for (size_t i = 0; i < images.size(); ++i) {
    string base_name = base::FilePath(images[i]).BaseName().value();
    if (StartsWithASCII(base_name, lib_system_prefix, true)) {
      found_lib_system = true;
      break;
    }
  }
  EXPECT_TRUE(found_lib_system);
}

TEST_F(SafeModeUtilTest, GetSomeImages) {
  vector<string> all_images = safe_mode_util::GetLoadedImages(nullptr);
  vector<string> usr_lib_images = safe_mode_util::GetLoadedImages("/usr/lib/");
  // There should be images under /usr/lib/, but not all of them are.
  EXPECT_GT(usr_lib_images.size(), 0U);
  EXPECT_LT(usr_lib_images.size(), all_images.size());
}

}  // namespace