Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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. | |
| 4 | |
| 5 #include "chrome/browser/install_module_verifier_win.h" | |
| 6 | |
| 7 #include <set> | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 #include "base/bind.h" | |
|
sky
2013/09/24 20:16:16
nit: newline between 9/10
erikwright (departed)
2013/09/25 19:58:08
Done.
| |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/strings/string16.h" | |
| 13 #include "base/values.h" | |
| 14 #include "chrome/browser/enumerate_modules_model_win.h" | |
| 15 #include "chrome/browser/expected_install_modules_win.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 void MockCallback(std::vector<unsigned int>* reported_ids, | |
| 21 size_t module_id) { | |
| 22 reported_ids->push_back(module_id); | |
| 23 } | |
| 24 | |
| 25 void AddModule(base::ListValue* list, | |
| 26 ModuleEnumerator::ModuleType type, | |
| 27 const std::string& name) { | |
| 28 scoped_ptr<base::DictionaryValue> data(new DictionaryValue()); | |
| 29 data->SetInteger("type", type); | |
| 30 data->SetString("name", name); | |
| 31 list->Append(data.release()); | |
| 32 } | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 TEST(InstallModuleVerifierTest, ExtractLoadedModuleNames) { | |
| 37 std::set<base::string16> loaded_modules; | |
| 38 scoped_ptr<base::ListValue> list(new ListValue()); | |
| 39 ExtractLoadedModuleNames(*list, &loaded_modules); | |
| 40 ASSERT_TRUE(loaded_modules.empty()); | |
| 41 // WinSock modules are ignored. | |
| 42 AddModule(list.get(), ModuleEnumerator::SHELL_EXTENSION, "chrome.dll"); | |
| 43 // Shell Extension modules are ignored. | |
| 44 AddModule( | |
| 45 list.get(), ModuleEnumerator::WINSOCK_MODULE_REGISTRATION, "chrome.dll"); | |
| 46 AddModule(list.get(), ModuleEnumerator::LOADED_MODULE, "fancy_pants.dll"); | |
| 47 AddModule(list.get(), ModuleEnumerator::LOADED_MODULE, "chrome.dll"); | |
| 48 ExtractLoadedModuleNames(*list, &loaded_modules); | |
| 49 ASSERT_EQ(2, loaded_modules.size()); | |
| 50 ASSERT_NE(loaded_modules.end(), | |
| 51 loaded_modules.find(CanonicalizeModuleName(L"chrome.dll"))); | |
| 52 ASSERT_NE(loaded_modules.end(), | |
| 53 loaded_modules.find(CanonicalizeModuleName(L"fancy_pants.dll"))); | |
| 54 } | |
| 55 | |
| 56 TEST(InstallModuleVerifierTest, VerifyModules) { | |
| 57 std::set<base::string16> loaded_modules; | |
| 58 std::vector<size_t> reported_ids; | |
| 59 | |
| 60 VerifyModules(loaded_modules, | |
| 61 base::Bind(&MockCallback, base::Unretained(&reported_ids))); | |
| 62 ASSERT_TRUE(reported_ids.empty()); | |
| 63 | |
| 64 // Expected, Loaded modules are reported. | |
| 65 loaded_modules.insert(L"chrome.dll"); | |
| 66 // Unexpected modules are ignored. | |
| 67 loaded_modules.insert(L"fancy_pants.dll"); | |
| 68 VerifyModules(loaded_modules, | |
| 69 base::Bind(&MockCallback, base::Unretained(&reported_ids))); | |
| 70 ASSERT_EQ(1, reported_ids.size()); | |
| 71 ASSERT_EQ(CanonicalizeModuleName(L"chrome.dll"), | |
| 72 kExpectedInstallModules[reported_ids[0]]); | |
| 73 } | |
| OLD | NEW |