| OLD | NEW | 
|    1 // Copyright 2016 The Chromium Authors. All rights reserved. |    1 // Copyright 2016 The Chromium Authors. All rights reserved. | 
|    2 // Use of this source code is governed by a BSD-style license that can be |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 #include "chrome/common/conflicts/module_watcher_win.h" |    5 #include "chrome/common/conflicts/module_watcher_win.h" | 
|    6  |    6  | 
|    7 #include <memory> |    7 #include <memory> | 
|    8  |    8  | 
|    9 #include "base/bind.h" |    9 #include "base/bind.h" | 
|   10 #include "testing/gtest/include/gtest/gtest.h" |   10 #include "testing/gtest/include/gtest/gtest.h" | 
|   11  |   11  | 
|   12 class ModuleWatcherTest : public testing::Test { |   12 class ModuleWatcherTest : public testing::Test { | 
|   13  protected: |   13  public: | 
|   14   ModuleWatcherTest() |   14   ModuleWatcherTest() | 
|   15       : module_(nullptr), |   15       : module_(nullptr), | 
|   16         module_event_count_(0), |   16         module_event_count_(0), | 
|   17         module_already_loaded_event_count_(0), |   17         module_already_loaded_event_count_(0), | 
|   18         module_loaded_event_count_(0), |   18         module_loaded_event_count_(0), | 
|   19         module_unloaded_event_count_(0) {} |   19         module_unloaded_event_count_(0) {} | 
|   20  |   20  | 
|   21   void OnModuleEvent(const ModuleWatcher::ModuleEvent& event) { |   21   void OnModuleEvent(const mojom::ModuleEvent& event) { | 
|   22     ++module_event_count_; |   22     ++module_event_count_; | 
|   23     switch (event.event_type) { |   23     switch (event.event_type) { | 
|   24       case mojom::ModuleEventType::MODULE_ALREADY_LOADED: |   24       case mojom::ModuleEventType::MODULE_ALREADY_LOADED: | 
|   25         ++module_already_loaded_event_count_; |   25         ++module_already_loaded_event_count_; | 
|   26         break; |   26         break; | 
|   27       case mojom::ModuleEventType::MODULE_LOADED: |   27       case mojom::ModuleEventType::MODULE_LOADED: | 
|   28         ++module_loaded_event_count_; |   28         ++module_loaded_event_count_; | 
|   29         break; |   29         break; | 
|   30       case mojom::ModuleEventType::MODULE_UNLOADED: |   30       case mojom::ModuleEventType::MODULE_UNLOADED: | 
|   31         ++module_unloaded_event_count_; |   31         ++module_unloaded_event_count_; | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
|   56     module_ = nullptr; |   56     module_ = nullptr; | 
|   57   } |   57   } | 
|   58  |   58  | 
|   59   std::unique_ptr<ModuleWatcher> Create() { |   59   std::unique_ptr<ModuleWatcher> Create() { | 
|   60     return ModuleWatcher::Create( |   60     return ModuleWatcher::Create( | 
|   61         base::Bind(&ModuleWatcherTest::OnModuleEvent, base::Unretained(this))); |   61         base::Bind(&ModuleWatcherTest::OnModuleEvent, base::Unretained(this))); | 
|   62   } |   62   } | 
|   63  |   63  | 
|   64   // Holds a handle to a loaded module. |   64   // Holds a handle to a loaded module. | 
|   65   HMODULE module_; |   65   HMODULE module_; | 
 |   66  | 
|   66   // Total number of module events seen. |   67   // Total number of module events seen. | 
|   67   int module_event_count_; |   68   int module_event_count_; | 
|   68   // Total number of MODULE_ALREADY_LOADED events seen. |   69   // Total number of MODULE_ALREADY_LOADED events seen. | 
|   69   int module_already_loaded_event_count_; |   70   int module_already_loaded_event_count_; | 
|   70   // Total number of MODULE_LOADED events seen. |   71   // Total number of MODULE_LOADED events seen. | 
|   71   int module_loaded_event_count_; |   72   int module_loaded_event_count_; | 
|   72   // Total number of MODULE_UNLOADED events seen. |   73   // Total number of MODULE_UNLOADED events seen. | 
|   73   int module_unloaded_event_count_; |   74   int module_unloaded_event_count_; | 
|   74  |   75  | 
|   75  private: |   76  private: | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  109   EXPECT_LT(previous_module_loaded_event_count, module_loaded_event_count_); |  110   EXPECT_LT(previous_module_loaded_event_count, module_loaded_event_count_); | 
|  110  |  111  | 
|  111   // Destroy the module watcher. |  112   // Destroy the module watcher. | 
|  112   mw.reset(); |  113   mw.reset(); | 
|  113  |  114  | 
|  114   // Unload the module and ensure no notification is received this time. |  115   // Unload the module and ensure no notification is received this time. | 
|  115   previous_module_unloaded_event_count = module_unloaded_event_count_; |  116   previous_module_unloaded_event_count = module_unloaded_event_count_; | 
|  116   UnloadModule(); |  117   UnloadModule(); | 
|  117   EXPECT_EQ(previous_module_unloaded_event_count, module_unloaded_event_count_); |  118   EXPECT_EQ(previous_module_unloaded_event_count, module_unloaded_event_count_); | 
|  118 } |  119 } | 
| OLD | NEW |