| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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/extensions/external_registry_loader_win.h" |
| 6 |
| 7 #include "base/compiler_specific.h" |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/run_loop.h" |
| 11 #include "content/public/test/test_browser_thread_bundle.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace extensions { |
| 15 |
| 16 namespace { |
| 17 |
| 18 class TestExternalRegistryLoader : public ExternalRegistryLoader { |
| 19 public: |
| 20 TestExternalRegistryLoader() {} |
| 21 |
| 22 using ExternalRegistryLoader::StartLoading; |
| 23 |
| 24 void WaitForTwoLoadsToFinished() { |
| 25 // Run() returns immediately if Quit() has already been called. |
| 26 run_loop_.Run(); |
| 27 } |
| 28 |
| 29 private: |
| 30 ~TestExternalRegistryLoader() override {} |
| 31 |
| 32 void LoadFinished() override { |
| 33 ExternalRegistryLoader::LoadFinished(); |
| 34 ++load_finished_count_; |
| 35 ASSERT_LE(load_finished_count_, 2); |
| 36 if (load_finished_count_ == 2) |
| 37 run_loop_.Quit(); |
| 38 } |
| 39 |
| 40 base::RunLoop run_loop_; |
| 41 int load_finished_count_ = 0; |
| 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(TestExternalRegistryLoader); |
| 44 }; |
| 45 |
| 46 } // namespace |
| 47 |
| 48 class ExternalRegistryLoaderUnittest : public testing::Test { |
| 49 public: |
| 50 ExternalRegistryLoaderUnittest() |
| 51 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} |
| 52 ~ExternalRegistryLoaderUnittest() override {} |
| 53 |
| 54 private: |
| 55 content::TestBrowserThreadBundle thread_bundle_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(ExternalRegistryLoaderUnittest); |
| 58 }; |
| 59 |
| 60 // Tests that calling StartLoading() more than once doesn't fail DCHECK. |
| 61 // Regression test for https://crbug.com/653045. |
| 62 TEST_F(ExternalRegistryLoaderUnittest, TwoStartLoadingDoesNotCrash) { |
| 63 scoped_refptr<TestExternalRegistryLoader> test_loader = |
| 64 make_scoped_refptr(new TestExternalRegistryLoader()); |
| 65 |
| 66 test_loader->StartLoading(); |
| 67 test_loader->StartLoading(); |
| 68 |
| 69 test_loader->WaitForTwoLoadsToFinished(); |
| 70 // Let registry watcher code complete. |
| 71 base::RunLoop().RunUntilIdle(); |
| 72 } |
| 73 |
| 74 } // namespace extensions |
| OLD | NEW |