Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: chrome/browser/extensions/external_provider_impl_unittest.cc

Issue 644413003: Replace MockStatisticsProvider with FakeStatisticsProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add clarifying comments. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browser/extensions/external_provider_impl.h" 5 #include "chrome/browser/extensions/external_provider_impl.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 15 matching lines...) Expand all
26 #include "content/public/test/test_utils.h" 26 #include "content/public/test/test_utils.h"
27 #include "net/test/embedded_test_server/embedded_test_server.h" 27 #include "net/test/embedded_test_server/embedded_test_server.h"
28 #include "net/test/embedded_test_server/http_request.h" 28 #include "net/test/embedded_test_server/http_request.h"
29 #include "net/test/embedded_test_server/http_response.h" 29 #include "net/test/embedded_test_server/http_response.h"
30 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
31 31
32 #if defined(OS_CHROMEOS) 32 #if defined(OS_CHROMEOS)
33 #include "chrome/browser/chromeos/customization_document.h" 33 #include "chrome/browser/chromeos/customization_document.h"
34 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" 34 #include "chrome/browser/chromeos/login/users/fake_user_manager.h"
35 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 35 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
36 #include "chromeos/system/mock_statistics_provider.h" 36 #include "chromeos/system/fake_statistics_provider.h"
37 #include "chromeos/system/statistics_provider.h" 37 #include "chromeos/system/statistics_provider.h"
38 #endif 38 #endif
39 39
40 using ::testing::_;
41 using ::testing::NotNull; 40 using ::testing::NotNull;
42 using ::testing::Return; 41 using ::testing::Return;
42 using ::testing::_;
43 43
44 namespace extensions { 44 namespace extensions {
45 45
46 namespace { 46 namespace {
47 47
48 using namespace net::test_server; 48 using namespace net::test_server;
49 49
50 const char kManifestPath[] = "/update_manifest"; 50 const char kManifestPath[] = "/update_manifest";
51 const char kAppPath[] = "/app.crx"; 51 const char kAppPath[] = "/app.crx";
52 52
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 ASSERT_TRUE(test_server_->InitializeAndWaitUntilReady()); 92 ASSERT_TRUE(test_server_->InitializeAndWaitUntilReady());
93 test_server_->RegisterRequestHandler( 93 test_server_->RegisterRequestHandler(
94 base::Bind(&ExternalProviderImplTest::HandleRequest, 94 base::Bind(&ExternalProviderImplTest::HandleRequest,
95 base::Unretained(this))); 95 base::Unretained(this)));
96 96
97 test_extension_cache_.reset(new ExtensionCacheFake()); 97 test_extension_cache_.reset(new ExtensionCacheFake());
98 98
99 CommandLine* cmdline = CommandLine::ForCurrentProcess(); 99 CommandLine* cmdline = CommandLine::ForCurrentProcess();
100 cmdline->AppendSwitchASCII(switches::kAppsGalleryUpdateURL, 100 cmdline->AppendSwitchASCII(switches::kAppsGalleryUpdateURL,
101 test_server_->GetURL(kManifestPath).spec()); 101 test_server_->GetURL(kManifestPath).spec());
102 #if defined(OS_CHROMEOS)
103 chromeos::system::StatisticsProvider::SetTestProvider(
104 &mock_statistics_provider_);
105 EXPECT_CALL(mock_statistics_provider_, GetMachineStatistic(_, NotNull()))
106 .WillRepeatedly(Return(false));
107 #endif
108 } 102 }
109 103
110 virtual void TearDown() override { 104 virtual void TearDown() override {
111 #if defined(OS_CHROMEOS)
112 chromeos::system::StatisticsProvider::SetTestProvider(NULL);
113 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); 105 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL);
114 #endif
115 } 106 }
116 107
117 private: 108 private:
118 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) { 109 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
119 GURL url = test_server_->GetURL(request.relative_url); 110 GURL url = test_server_->GetURL(request.relative_url);
120 if (url.path() == kManifestPath) { 111 if (url.path() == kManifestPath) {
121 scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse); 112 scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse);
122 response->set_code(net::HTTP_OK); 113 response->set_code(net::HTTP_OK);
123 response->set_content(base::StringPrintf( 114 response->set_content(base::StringPrintf(
124 "<?xml version='1.0' encoding='UTF-8'?>\n" 115 "<?xml version='1.0' encoding='UTF-8'?>\n"
(...skipping 19 matching lines...) Expand all
144 response->set_code(net::HTTP_OK); 135 response->set_code(net::HTTP_OK);
145 response->set_content(contents); 136 response->set_content(contents);
146 return response.PassAs<HttpResponse>(); 137 return response.PassAs<HttpResponse>();
147 } 138 }
148 139
149 return scoped_ptr<HttpResponse>(); 140 return scoped_ptr<HttpResponse>();
150 } 141 }
151 142
152 scoped_ptr<EmbeddedTestServer> test_server_; 143 scoped_ptr<EmbeddedTestServer> test_server_;
153 scoped_ptr<ExtensionCacheFake> test_extension_cache_; 144 scoped_ptr<ExtensionCacheFake> test_extension_cache_;
145
154 #if defined(OS_CHROMEOS) 146 #if defined(OS_CHROMEOS)
155 chromeos::system::MockStatisticsProvider mock_statistics_provider_; 147 // chromeos::ServicesCustomizationExternalLoader is hooked up as an
148 // extensions::ExternalLoader and depends on a functioning StatisticsProvider.
149 chromeos::system::ScopedFakeStatisticsProvider fake_statistics_provider_;
156 TestingPrefServiceSimple local_state_; 150 TestingPrefServiceSimple local_state_;
157 #endif 151 #endif
158 152
159 DISALLOW_COPY_AND_ASSIGN(ExternalProviderImplTest); 153 DISALLOW_COPY_AND_ASSIGN(ExternalProviderImplTest);
160 }; 154 };
161 155
162 } // namespace 156 } // namespace
163 157
164 TEST_F(ExternalProviderImplTest, InAppPayments) { 158 TEST_F(ExternalProviderImplTest, InAppPayments) {
165 InitServiceWithExternalProviders(); 159 InitServiceWithExternalProviders();
166 160
167 scoped_refptr<content::MessageLoopRunner> runner = 161 scoped_refptr<content::MessageLoopRunner> runner =
168 new content::MessageLoopRunner; 162 new content::MessageLoopRunner;
169 service_->set_external_updates_finished_callback_for_test( 163 service_->set_external_updates_finished_callback_for_test(
170 runner->QuitClosure()); 164 runner->QuitClosure());
171 165
172 service_->CheckForExternalUpdates(); 166 service_->CheckForExternalUpdates();
173 runner->Run(); 167 runner->Run();
174 168
175 EXPECT_TRUE(service_->GetInstalledExtension( 169 EXPECT_TRUE(service_->GetInstalledExtension(
176 extension_misc::kInAppPaymentsSupportAppId)); 170 extension_misc::kInAppPaymentsSupportAppId));
177 EXPECT_TRUE(service_->IsExtensionEnabled( 171 EXPECT_TRUE(service_->IsExtensionEnabled(
178 extension_misc::kInAppPaymentsSupportAppId)); 172 extension_misc::kInAppPaymentsSupportAppId));
179 } 173 }
180 174
181 } // namespace extensions 175 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/external_provider_impl_chromeos_unittest.cc ('k') | chromeos/chromeos.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698