OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <memory> | 5 #include <memory> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 2872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2883 "ihfokbkgjpifnbbojhneepfflplebdkc"}; | 2883 "ihfokbkgjpifnbbojhneepfflplebdkc"}; |
2884 update_client->Update( | 2884 update_client->Update( |
2885 ids, base::Bind(&DataCallbackFake::Callback), | 2885 ids, base::Bind(&DataCallbackFake::Callback), |
2886 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 2886 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
2887 | 2887 |
2888 RunThreads(); | 2888 RunThreads(); |
2889 | 2889 |
2890 update_client->RemoveObserver(&observer); | 2890 update_client->RemoveObserver(&observer); |
2891 } | 2891 } |
2892 | 2892 |
| 2893 // Tests the scenario where the update check fails. |
| 2894 TEST_F(UpdateClientTest, OneCrxUpdateCheckFails) { |
| 2895 class DataCallbackFake { |
| 2896 public: |
| 2897 static void Callback(const std::vector<std::string>& ids, |
| 2898 std::vector<CrxComponent>* components) { |
| 2899 CrxComponent crx; |
| 2900 crx.name = "test_jebg"; |
| 2901 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 2902 crx.version = base::Version("0.9"); |
| 2903 crx.installer = base::MakeShared<TestInstaller>(); |
| 2904 components->push_back(crx); |
| 2905 } |
| 2906 }; |
| 2907 |
| 2908 class CompletionCallbackFake { |
| 2909 public: |
| 2910 static void Callback(const base::Closure& quit_closure, Error error) { |
| 2911 EXPECT_EQ(Error::UPDATE_CHECK_ERROR, error); |
| 2912 quit_closure.Run(); |
| 2913 } |
| 2914 }; |
| 2915 |
| 2916 class FakeUpdateChecker : public UpdateChecker { |
| 2917 public: |
| 2918 static std::unique_ptr<UpdateChecker> Create( |
| 2919 const scoped_refptr<Configurator>& config, |
| 2920 PersistedData* metadata) { |
| 2921 return base::MakeUnique<FakeUpdateChecker>(); |
| 2922 } |
| 2923 |
| 2924 bool CheckForUpdates( |
| 2925 const std::vector<std::string>& ids_to_check, |
| 2926 const IdToComponentPtrMap& components, |
| 2927 const std::string& additional_attributes, |
| 2928 bool enabled_component_updates, |
| 2929 const UpdateCheckCallback& update_check_callback) override { |
| 2930 EXPECT_TRUE(enabled_component_updates); |
| 2931 EXPECT_EQ(1u, ids_to_check.size()); |
| 2932 const std::string id = "jebgalgnebhfojomionfpkfelancnnkf"; |
| 2933 EXPECT_EQ(id, ids_to_check.front()); |
| 2934 EXPECT_EQ(1u, components.count(id)); |
| 2935 |
| 2936 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 2937 FROM_HERE, base::Bind(update_check_callback, -1, 0)); |
| 2938 |
| 2939 return true; |
| 2940 } |
| 2941 }; |
| 2942 |
| 2943 class FakeCrxDownloader : public CrxDownloader { |
| 2944 public: |
| 2945 static std::unique_ptr<CrxDownloader> Create( |
| 2946 bool is_background_download, |
| 2947 net::URLRequestContextGetter* context_getter, |
| 2948 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 2949 return base::MakeUnique<FakeCrxDownloader>(); |
| 2950 } |
| 2951 |
| 2952 FakeCrxDownloader() |
| 2953 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} |
| 2954 |
| 2955 private: |
| 2956 void DoStartDownload(const GURL& url) override { EXPECT_TRUE(false); } |
| 2957 }; |
| 2958 |
| 2959 class FakePingManager : public FakePingManagerImpl { |
| 2960 public: |
| 2961 explicit FakePingManager(const scoped_refptr<Configurator>& config) |
| 2962 : FakePingManagerImpl(config) {} |
| 2963 ~FakePingManager() override { EXPECT_TRUE(ping_data().empty()); } |
| 2964 }; |
| 2965 |
| 2966 scoped_refptr<UpdateClient> update_client = |
| 2967 base::MakeShared<UpdateClientImpl>( |
| 2968 config(), base::MakeUnique<FakePingManager>(config()), |
| 2969 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create); |
| 2970 |
| 2971 MockObserver observer; |
| 2972 InSequence seq; |
| 2973 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 2974 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2975 .Times(1); |
| 2976 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, |
| 2977 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2978 .Times(1) |
| 2979 .WillOnce(Invoke([&update_client](Events event, const std::string& id) { |
| 2980 CrxUpdateItem item; |
| 2981 update_client->GetCrxUpdateState(id, &item); |
| 2982 EXPECT_EQ(ComponentState::kUpdateError, item.state); |
| 2983 })); |
| 2984 |
| 2985 update_client->AddObserver(&observer); |
| 2986 |
| 2987 const std::vector<std::string> ids = {"jebgalgnebhfojomionfpkfelancnnkf"}; |
| 2988 update_client->Update( |
| 2989 ids, base::Bind(&DataCallbackFake::Callback), |
| 2990 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 2991 |
| 2992 RunThreads(); |
| 2993 |
| 2994 update_client->RemoveObserver(&observer); |
| 2995 } |
| 2996 |
2893 } // namespace update_client | 2997 } // namespace update_client |
OLD | NEW |