OLD | NEW |
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/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/prefs/testing_pref_service.h" |
12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
13 #include "base/test/scoped_path_override.h" | 14 #include "base/test/scoped_path_override.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/extensions/extension_service_unittest.h" | 16 #include "chrome/browser/extensions/extension_service_unittest.h" |
16 #include "chrome/browser/extensions/updater/extension_cache_fake.h" | 17 #include "chrome/browser/extensions/updater/extension_cache_fake.h" |
17 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/test/base/testing_browser_process.h" |
19 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
20 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
21 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
22 #include "net/test/embedded_test_server/embedded_test_server.h" | 24 #include "net/test/embedded_test_server/embedded_test_server.h" |
23 #include "net/test/embedded_test_server/http_request.h" | 25 #include "net/test/embedded_test_server/http_request.h" |
24 #include "net/test/embedded_test_server/http_response.h" | 26 #include "net/test/embedded_test_server/http_response.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
26 | 28 |
27 #if defined(OS_CHROMEOS) | 29 #if defined(OS_CHROMEOS) |
| 30 #include "chrome/browser/chromeos/customization_document.h" |
28 #include "chromeos/system/mock_statistics_provider.h" | 31 #include "chromeos/system/mock_statistics_provider.h" |
29 #include "chromeos/system/statistics_provider.h" | 32 #include "chromeos/system/statistics_provider.h" |
30 #endif | 33 #endif |
31 | 34 |
32 using ::testing::_; | 35 using ::testing::_; |
33 using ::testing::NotNull; | 36 using ::testing::NotNull; |
34 using ::testing::Return; | 37 using ::testing::Return; |
35 | 38 |
36 namespace extensions { | 39 namespace extensions { |
37 | 40 |
(...skipping 20 matching lines...) Expand all Loading... |
58 i != providers.end(); | 61 i != providers.end(); |
59 ++i) { | 62 ++i) { |
60 service_->AddProviderForTesting(i->release()); | 63 service_->AddProviderForTesting(i->release()); |
61 } | 64 } |
62 } | 65 } |
63 | 66 |
64 // ExtensionServiceTestBase overrides: | 67 // ExtensionServiceTestBase overrides: |
65 virtual void SetUp() OVERRIDE { | 68 virtual void SetUp() OVERRIDE { |
66 ExtensionServiceTestBase::SetUp(); | 69 ExtensionServiceTestBase::SetUp(); |
67 test_server_.reset(new EmbeddedTestServer()); | 70 test_server_.reset(new EmbeddedTestServer()); |
| 71 |
| 72 #if defined(OS_CHROMEOS) |
| 73 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); |
| 74 chromeos::ServicesCustomizationDocument::RegisterPrefs( |
| 75 local_state_.registry()); |
| 76 #endif |
| 77 |
68 ASSERT_TRUE(test_server_->InitializeAndWaitUntilReady()); | 78 ASSERT_TRUE(test_server_->InitializeAndWaitUntilReady()); |
69 test_server_->RegisterRequestHandler( | 79 test_server_->RegisterRequestHandler( |
70 base::Bind(&ExternalProviderImplTest::HandleRequest, | 80 base::Bind(&ExternalProviderImplTest::HandleRequest, |
71 base::Unretained(this))); | 81 base::Unretained(this))); |
72 | 82 |
73 test_extension_cache_.reset(new ExtensionCacheFake()); | 83 test_extension_cache_.reset(new ExtensionCacheFake()); |
74 | 84 |
75 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 85 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
76 cmdline->AppendSwitchASCII(switches::kAppsGalleryUpdateURL, | 86 cmdline->AppendSwitchASCII(switches::kAppsGalleryUpdateURL, |
77 test_server_->GetURL(kManifestPath).spec()); | 87 test_server_->GetURL(kManifestPath).spec()); |
78 #if defined(OS_CHROMEOS) | 88 #if defined(OS_CHROMEOS) |
79 chromeos::system::StatisticsProvider::SetTestProvider( | 89 chromeos::system::StatisticsProvider::SetTestProvider( |
80 &mock_statistics_provider_); | 90 &mock_statistics_provider_); |
81 EXPECT_CALL(mock_statistics_provider_, GetMachineStatistic(_, NotNull())) | 91 EXPECT_CALL(mock_statistics_provider_, GetMachineStatistic(_, NotNull())) |
82 .WillRepeatedly(Return(false)); | 92 .WillRepeatedly(Return(false)); |
83 #endif | 93 #endif |
84 } | 94 } |
85 | 95 |
86 virtual void TearDown() OVERRIDE { | 96 virtual void TearDown() OVERRIDE { |
87 #if defined(OS_CHROMEOS) | 97 #if defined(OS_CHROMEOS) |
88 chromeos::system::StatisticsProvider::SetTestProvider(NULL); | 98 chromeos::system::StatisticsProvider::SetTestProvider(NULL); |
| 99 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); |
89 #endif | 100 #endif |
90 } | 101 } |
91 | 102 |
92 private: | 103 private: |
93 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) { | 104 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) { |
94 GURL url = test_server_->GetURL(request.relative_url); | 105 GURL url = test_server_->GetURL(request.relative_url); |
95 if (url.path() == kManifestPath) { | 106 if (url.path() == kManifestPath) { |
96 scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse); | 107 scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse); |
97 response->set_code(net::HTTP_OK); | 108 response->set_code(net::HTTP_OK); |
98 response->set_content(base::StringPrintf( | 109 response->set_content(base::StringPrintf( |
(...skipping 22 matching lines...) Expand all Loading... |
121 return response.PassAs<HttpResponse>(); | 132 return response.PassAs<HttpResponse>(); |
122 } | 133 } |
123 | 134 |
124 return scoped_ptr<HttpResponse>(); | 135 return scoped_ptr<HttpResponse>(); |
125 } | 136 } |
126 | 137 |
127 scoped_ptr<EmbeddedTestServer> test_server_; | 138 scoped_ptr<EmbeddedTestServer> test_server_; |
128 scoped_ptr<ExtensionCacheFake> test_extension_cache_; | 139 scoped_ptr<ExtensionCacheFake> test_extension_cache_; |
129 #if defined(OS_CHROMEOS) | 140 #if defined(OS_CHROMEOS) |
130 chromeos::system::MockStatisticsProvider mock_statistics_provider_; | 141 chromeos::system::MockStatisticsProvider mock_statistics_provider_; |
| 142 TestingPrefServiceSimple local_state_; |
131 #endif | 143 #endif |
132 | 144 |
133 DISALLOW_COPY_AND_ASSIGN(ExternalProviderImplTest); | 145 DISALLOW_COPY_AND_ASSIGN(ExternalProviderImplTest); |
134 }; | 146 }; |
135 | 147 |
136 } // namespace | 148 } // namespace |
137 | 149 |
138 TEST_F(ExternalProviderImplTest, InAppPayments) { | 150 TEST_F(ExternalProviderImplTest, InAppPayments) { |
139 InitServiceWithExternalProviders(); | 151 InitServiceWithExternalProviders(); |
140 | 152 |
141 scoped_refptr<content::MessageLoopRunner> runner = | 153 scoped_refptr<content::MessageLoopRunner> runner = |
142 new content::MessageLoopRunner; | 154 new content::MessageLoopRunner; |
143 service_->set_external_updates_finished_callback_for_test( | 155 service_->set_external_updates_finished_callback_for_test( |
144 runner->QuitClosure()); | 156 runner->QuitClosure()); |
145 | 157 |
146 service_->CheckForExternalUpdates(); | 158 service_->CheckForExternalUpdates(); |
147 runner->Run(); | 159 runner->Run(); |
148 | 160 |
149 EXPECT_TRUE(service_->GetInstalledExtension( | 161 EXPECT_TRUE(service_->GetInstalledExtension( |
150 extension_misc::kInAppPaymentsSupportAppId)); | 162 extension_misc::kInAppPaymentsSupportAppId)); |
151 EXPECT_TRUE(service_->IsExtensionEnabled( | 163 EXPECT_TRUE(service_->IsExtensionEnabled( |
152 extension_misc::kInAppPaymentsSupportAppId)); | 164 extension_misc::kInAppPaymentsSupportAppId)); |
153 } | 165 } |
154 | 166 |
155 } // namespace extensions | 167 } // namespace extensions |
OLD | NEW |