OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
6 #include <iterator> | 6 #include <iterator> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/favicon/favicon_service.h" | 13 #include "chrome/browser/favicon/favicon_service.h" |
14 #include "chrome/browser/intents/web_intents_registry.h" | 14 #include "chrome/browser/intents/web_intents_registry.h" |
15 #include "chrome/browser/intents/web_intents_registry_factory.h" | 15 #include "chrome/browser/intents/web_intents_registry_factory.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/intents/web_intent_picker.h" | 18 #include "chrome/browser/ui/intents/web_intent_picker.h" |
19 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" | 19 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
20 #include "chrome/browser/ui/intents/web_intent_picker_model.h" | 20 #include "chrome/browser/ui/intents/web_intent_picker_model.h" |
21 #include "chrome/browser/ui/intents/web_intent_picker_model_observer.h" | 21 #include "chrome/browser/ui/intents/web_intent_picker_model_observer.h" |
22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
23 #include "chrome/browser/webdata/web_data_service.h" | 23 #include "chrome/browser/webdata/web_data_service.h" |
| 24 #include "chrome/browser/webdata/web_data_service_factory.h" |
24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
26 #include "chrome/test/base/in_process_browser_test.h" | 27 #include "chrome/test/base/in_process_browser_test.h" |
27 #include "chrome/test/base/ui_test_utils.h" | 28 #include "chrome/test/base/ui_test_utils.h" |
28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
29 #include "content/public/browser/web_intents_dispatcher.h" | 30 #include "content/public/browser/web_intents_dispatcher.h" |
30 #include "content/test/test_url_fetcher_factory.h" | 31 #include "content/test/test_url_fetcher_factory.h" |
31 #include "net/base/escape.h" | 32 #include "net/base/escape.h" |
32 #include "net/base/mock_host_resolver.h" | 33 #include "net/base/mock_host_resolver.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 } | 207 } |
207 | 208 |
208 virtual void SetUpOnMainThread() OVERRIDE { | 209 virtual void SetUpOnMainThread() OVERRIDE { |
209 // The FakeURLFetcherFactory will return a NULL URLFetcher if a request is | 210 // The FakeURLFetcherFactory will return a NULL URLFetcher if a request is |
210 // created for a URL it doesn't know and there is no default factory. | 211 // created for a URL it doesn't know and there is no default factory. |
211 // Instead, use this dummy factory to infinitely delay the request. | 212 // Instead, use this dummy factory to infinitely delay the request. |
212 default_url_fetcher_factory_.reset(new DummyURLFetcherFactory); | 213 default_url_fetcher_factory_.reset(new DummyURLFetcherFactory); |
213 fake_url_fetcher_factory_.reset( | 214 fake_url_fetcher_factory_.reset( |
214 new FakeURLFetcherFactory(default_url_fetcher_factory_.get())); | 215 new FakeURLFetcherFactory(default_url_fetcher_factory_.get())); |
215 | 216 |
216 web_data_service_ = | 217 web_data_service_ = WebDataServiceFactory::GetForProfile( |
217 GetBrowser()->profile()->GetWebDataService(Profile::EXPLICIT_ACCESS); | 218 GetBrowser()->profile(), Profile::EXPLICIT_ACCESS); |
218 favicon_service_ = | 219 favicon_service_ = |
219 GetBrowser()->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); | 220 GetBrowser()->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); |
220 controller_ = GetBrowser()-> | 221 controller_ = GetBrowser()-> |
221 GetSelectedTabContentsWrapper()->web_intent_picker_controller(); | 222 GetSelectedTabContentsWrapper()->web_intent_picker_controller(); |
222 | 223 |
223 controller_->set_picker(&picker_); | 224 controller_->set_picker(&picker_); |
224 controller_->set_model_observer(&picker_); | 225 controller_->set_model_observer(&picker_); |
225 | 226 |
226 CreateFakeIcon(); | 227 CreateFakeIcon(); |
227 } | 228 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 gfx::Image image(gfx::test::CreateImage()); | 285 gfx::Image image(gfx::test::CreateImage()); |
285 std::vector<unsigned char> image_data; | 286 std::vector<unsigned char> image_data; |
286 bool result = gfx::PNGEncodedDataFromImage(image, &image_data); | 287 bool result = gfx::PNGEncodedDataFromImage(image, &image_data); |
287 DCHECK(result); | 288 DCHECK(result); |
288 | 289 |
289 std::copy(image_data.begin(), image_data.end(), | 290 std::copy(image_data.begin(), image_data.end(), |
290 std::back_inserter(icon_response_)); | 291 std::back_inserter(icon_response_)); |
291 } | 292 } |
292 | 293 |
293 WebIntentPickerMock picker_; | 294 WebIntentPickerMock picker_; |
294 WebDataService* web_data_service_; | 295 scoped_refptr<WebDataService> web_data_service_; |
295 FaviconService* favicon_service_; | 296 FaviconService* favicon_service_; |
296 WebIntentPickerController* controller_; | 297 WebIntentPickerController* controller_; |
297 scoped_ptr<DummyURLFetcherFactory> default_url_fetcher_factory_; | 298 scoped_ptr<DummyURLFetcherFactory> default_url_fetcher_factory_; |
298 scoped_ptr<FakeURLFetcherFactory> fake_url_fetcher_factory_; | 299 scoped_ptr<FakeURLFetcherFactory> fake_url_fetcher_factory_; |
299 std::string icon_response_; | 300 std::string icon_response_; |
300 }; | 301 }; |
301 | 302 |
302 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, ChooseService) { | 303 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, ChooseService) { |
303 AddWebIntentService(kAction1, kServiceURL1); | 304 AddWebIntentService(kAction1, kServiceURL1); |
304 AddWebIntentService(kAction1, kServiceURL2); | 305 AddWebIntentService(kAction1, kServiceURL2); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 picker_.Wait(); | 432 picker_.Wait(); |
432 EXPECT_EQ(1, picker_.num_extensions_installed_); | 433 EXPECT_EQ(1, picker_.num_extensions_installed_); |
433 const Extension* extension = browser()->profile()->GetExtensionService()-> | 434 const Extension* extension = browser()->profile()->GetExtensionService()-> |
434 GetExtensionById(extension_id, false); | 435 GetExtensionById(extension_id, false); |
435 EXPECT_TRUE(extension); | 436 EXPECT_TRUE(extension); |
436 | 437 |
437 // Installing an extension should also choose it. Since this extension uses | 438 // Installing an extension should also choose it. Since this extension uses |
438 // window disposition, it will create a new tab. | 439 // window disposition, it will create a new tab. |
439 ASSERT_EQ(2, browser()->tab_count()); | 440 ASSERT_EQ(2, browser()->tab_count()); |
440 } | 441 } |
OLD | NEW |