1 // Copyright 2013 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.
5 #include "chrome/browser/install_verification/win/module_ids.h"
7 #include "base/strings/string_piece.h"
8 #include "chrome/browser/install_verification/win/module_verification_common.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 TEST(ModuleIDsTest
, LoadModuleIDs
) {
13 LoadModuleIDs(&module_ids
);
14 ASSERT_EQ(1u, module_ids
[CalculateModuleNameDigest(L
"chrome.dll")]);
17 TEST(ModuleIDsTest
, ParseAdditionalModuleIDs
) {
20 ParseAdditionalModuleIDs(base::StringPiece(), &module_ids
);
21 ASSERT_EQ(0u, module_ids
.size());
24 ParseAdditionalModuleIDs("hello", &module_ids
);
25 ASSERT_EQ(0u, module_ids
.size());
26 ParseAdditionalModuleIDs("hello world", &module_ids
);
27 ASSERT_EQ(0u, module_ids
.size());
28 ParseAdditionalModuleIDs("hello world\nfoo bar", &module_ids
);
29 ASSERT_EQ(0u, module_ids
.size());
30 ParseAdditionalModuleIDs("123 world\nfoo bar", &module_ids
);
31 ASSERT_EQ(0u, module_ids
.size());
32 ParseAdditionalModuleIDs("hello 0123456789abcdef0123456789abcdef\nfoo bar",
34 ASSERT_EQ(0u, module_ids
.size());
36 // A single valid line followed by an invalid line.
37 ParseAdditionalModuleIDs("123 0123456789abcdef0123456789abcdef\nfoo bar",
39 ASSERT_EQ(1u, module_ids
.size());
40 ASSERT_EQ(123u, module_ids
.begin()->second
);
41 ASSERT_EQ("0123456789abcdef0123456789abcdef", module_ids
.begin()->first
);
44 // The same, but with \r\n.
45 ParseAdditionalModuleIDs("123 0123456789abcdef0123456789abcdef\r\nfoo bar",
47 ASSERT_EQ(1u, module_ids
.size());
48 ASSERT_EQ(123u, module_ids
.begin()->second
);
49 ASSERT_EQ("0123456789abcdef0123456789abcdef", module_ids
.begin()->first
);
52 // Several valid and invalid lines, with varying line terminations etc.
53 ParseAdditionalModuleIDs("123 0123456789abcdef0123456789abcdef\r\n"
54 "456 DEADBEEFDEADBEEF\r"
55 "789 DEADBEEFDEADBEEFDEADBEEFDEADBEEF\n"
58 "321 BAADCAFEBAADCAFEBAADCAFEBAADCAFE\n",
60 ASSERT_EQ(3u, module_ids
.size());
61 ASSERT_EQ(123u, module_ids
["0123456789abcdef0123456789abcdef"]);
62 ASSERT_EQ(789u, module_ids
["DEADBEEFDEADBEEFDEADBEEFDEADBEEF"]);
63 ASSERT_EQ(321u, module_ids
["BAADCAFEBAADCAFEBAADCAFEBAADCAFE"]);
66 // Leading empty lines, no termination on final line.
67 ParseAdditionalModuleIDs("\n"
68 "123 0123456789abcdef0123456789abcdef\r\n"
69 "321 BAADCAFEBAADCAFEBAADCAFEBAADCAFE",
71 ASSERT_EQ(2u, module_ids
.size());
72 ASSERT_EQ(123u, module_ids
["0123456789abcdef0123456789abcdef"]);
73 ASSERT_EQ(321u, module_ids
["BAADCAFEBAADCAFEBAADCAFEBAADCAFE"]);