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/safe_browsing/settings_reset_prompt/default_settings_fe
tcher.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" |
| 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/run_loop.h" |
| 14 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h" |
| 15 #include "chrome/test/base/in_process_browser_test.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 |
| 19 namespace safe_browsing { |
| 20 namespace { |
| 21 |
| 22 class DefaultSettingsFetcherTest : public InProcessBrowserTest { |
| 23 public: |
| 24 void FetchedSettings(std::unique_ptr<BrandcodedDefaultSettings> settings) { |
| 25 EXPECT_FALSE(settings_); |
| 26 EXPECT_FALSE(fetched_settings_called); |
| 27 |
| 28 fetched_settings_called = true; |
| 29 settings_ = std::move(settings); |
| 30 } |
| 31 |
| 32 protected: |
| 33 bool fetched_settings_called = false; |
| 34 std::unique_ptr<BrandcodedDefaultSettings> settings_; |
| 35 }; |
| 36 |
| 37 IN_PROC_BROWSER_TEST_F(DefaultSettingsFetcherTest, FetchingSettingsSucceeded) { |
| 38 // The default settings that we will pretend were fetched. Keep the raw |
| 39 // pointer here so that we can compare it to what was passed to the callback. |
| 40 BrandcodedDefaultSettings* default_settings = new BrandcodedDefaultSettings(); |
| 41 |
| 42 DefaultSettingsFetcher::FetchDefaultSettingsForTesting( |
| 43 base::Bind(&DefaultSettingsFetcherTest::FetchedSettings, |
| 44 base::Unretained(this)), |
| 45 base::WrapUnique(default_settings)); |
| 46 |
| 47 base::RunLoop().RunUntilIdle(); |
| 48 |
| 49 EXPECT_TRUE(fetched_settings_called); |
| 50 EXPECT_EQ(default_settings, settings_.get()); |
| 51 } |
| 52 |
| 53 IN_PROC_BROWSER_TEST_F(DefaultSettingsFetcherTest, FetchingSettingsFailed) { |
| 54 // Pretend that fetching default settings failed by passing in a nullptr to |
| 55 // |FetchDefaultSettingsForTesting()|. The callback should still receive |
| 56 // default-constructed default settings. |
| 57 DefaultSettingsFetcher::FetchDefaultSettingsForTesting( |
| 58 base::Bind(&DefaultSettingsFetcherTest::FetchedSettings, |
| 59 base::Unretained(this)), |
| 60 nullptr); |
| 61 |
| 62 base::RunLoop().RunUntilIdle(); |
| 63 |
| 64 EXPECT_TRUE(fetched_settings_called); |
| 65 EXPECT_TRUE(settings_); |
| 66 } |
| 67 |
| 68 } // namespace |
| 69 } // namespace safe_browsing |
OLD | NEW |