Index: chrome/browser/install_module_verifier_unittest_win.cc |
diff --git a/chrome/browser/install_module_verifier_unittest_win.cc b/chrome/browser/install_module_verifier_unittest_win.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..83152f1bd94be58f00e9888bf6b315277d355f10 |
--- /dev/null |
+++ b/chrome/browser/install_module_verifier_unittest_win.cc |
@@ -0,0 +1,74 @@ |
+// Copyright (c) 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 "chrome/browser/install_module_verifier_win.h" |
+ |
+#include <set> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/bind.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/strings/string16.h" |
+#include "base/values.h" |
+#include "chrome/browser/enumerate_modules_model_win.h" |
+#include "chrome/browser/expected_install_modules_win.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace { |
+ |
+void MockCallback(std::vector<unsigned int>* reported_indexes, |
+ size_t module_index) { |
+ reported_indexes->push_back(module_index); |
+} |
+ |
+void AddModule(base::ListValue* list, |
+ ModuleEnumerator::ModuleType type, |
+ const std::string& name) { |
+ scoped_ptr<base::DictionaryValue> data(new DictionaryValue()); |
+ data->SetInteger("type", type); |
+ data->SetString("name", name); |
+ list->Append(data.release()); |
+} |
+ |
+} // namespace |
+ |
+TEST(InstallModuleVerifierTest, ExtractLoadedModuleNames) { |
+ std::set<base::string16> loaded_modules; |
+ scoped_ptr<base::ListValue> list(new ListValue()); |
+ ExtractLoadedModuleNames(*list, &loaded_modules); |
+ ASSERT_TRUE(loaded_modules.empty()); |
+ // WinSock modules are ignored. |
+ AddModule(list.get(), ModuleEnumerator::SHELL_EXTENSION, "chrome.dll"); |
Finnur
2013/09/25 12:54:22
If the aim here is a negative test (make sure that
erikwright (departed)
2013/09/25 19:58:08
You're right. It made sense a few patchsets ago, b
|
+ // Shell Extension modules are ignored. |
+ AddModule( |
+ list.get(), ModuleEnumerator::WINSOCK_MODULE_REGISTRATION, "chrome.dll"); |
+ AddModule(list.get(), ModuleEnumerator::LOADED_MODULE, "fancy_pants.dll"); |
+ AddModule(list.get(), ModuleEnumerator::LOADED_MODULE, "chrome.dll"); |
+ ExtractLoadedModuleNames(*list, &loaded_modules); |
+ ASSERT_EQ(2, loaded_modules.size()); |
+ ASSERT_NE(loaded_modules.end(), |
+ loaded_modules.find(CanonicalizeModuleName(L"chrome.dll"))); |
+ ASSERT_NE(loaded_modules.end(), |
+ loaded_modules.find(CanonicalizeModuleName(L"fancy_pants.dll"))); |
+} |
+ |
+TEST(InstallModuleVerifierTest, VerifyModules) { |
+ std::set<base::string16> loaded_modules; |
+ std::vector<size_t> reported_indexes; |
+ |
+ VerifyModules(loaded_modules, |
+ base::Bind(&MockCallback, base::Unretained(&reported_indexes))); |
+ ASSERT_TRUE(reported_indexes.empty()); |
+ |
+ // Expected, Loaded modules are reported. |
+ loaded_modules.insert(L"chrome.dll"); |
+ // Unexpected modules are ignored. |
+ loaded_modules.insert(L"fancy_pants.dll"); |
+ VerifyModules(loaded_modules, |
+ base::Bind(&MockCallback, base::Unretained(&reported_indexes))); |
+ ASSERT_EQ(1, reported_indexes.size()); |
+ ASSERT_EQ(CanonicalizeModuleName(L"chrome.dll"), |
+ kExpectedInstallModules[reported_indexes[0]]); |
+} |