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/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/intents/default_web_intent_service.h" | 14 #include "chrome/browser/intents/default_web_intent_service.h" |
15 #include "chrome/browser/favicon/favicon_service.h" | 15 #include "chrome/browser/favicon/favicon_service.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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 } | 224 } |
224 | 225 |
225 virtual void SetUpOnMainThread() OVERRIDE { | 226 virtual void SetUpOnMainThread() OVERRIDE { |
226 // The FakeURLFetcherFactory will return a NULL URLFetcher if a request is | 227 // The FakeURLFetcherFactory will return a NULL URLFetcher if a request is |
227 // created for a URL it doesn't know and there is no default factory. | 228 // created for a URL it doesn't know and there is no default factory. |
228 // Instead, use this dummy factory to infinitely delay the request. | 229 // Instead, use this dummy factory to infinitely delay the request. |
229 default_url_fetcher_factory_.reset(new DummyURLFetcherFactory); | 230 default_url_fetcher_factory_.reset(new DummyURLFetcherFactory); |
230 fake_url_fetcher_factory_.reset( | 231 fake_url_fetcher_factory_.reset( |
231 new FakeURLFetcherFactory(default_url_fetcher_factory_.get())); | 232 new FakeURLFetcherFactory(default_url_fetcher_factory_.get())); |
232 | 233 |
233 web_data_service_ = | 234 web_data_service_ = WebDataServiceFactory::GetForProfile( |
234 GetBrowser()->profile()->GetWebDataService(Profile::EXPLICIT_ACCESS); | 235 GetBrowser()->profile(), Profile::EXPLICIT_ACCESS); |
235 favicon_service_ = | 236 favicon_service_ = |
236 GetBrowser()->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); | 237 GetBrowser()->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); |
237 controller_ = GetBrowser()-> | 238 controller_ = GetBrowser()-> |
238 GetSelectedTabContentsWrapper()->web_intent_picker_controller(); | 239 GetSelectedTabContentsWrapper()->web_intent_picker_controller(); |
239 | 240 |
240 SetupMockPicker(); | 241 SetupMockPicker(); |
241 controller_->set_model_observer(&picker_); | 242 controller_->set_model_observer(&picker_); |
242 picker_.delegate_ = controller_; | 243 picker_.delegate_ = controller_; |
243 | 244 |
244 CreateFakeIcon(); | 245 CreateFakeIcon(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 gfx::Image image(gfx::test::CreateImage()); | 317 gfx::Image image(gfx::test::CreateImage()); |
317 std::vector<unsigned char> image_data; | 318 std::vector<unsigned char> image_data; |
318 bool result = gfx::PNGEncodedDataFromImage(image, &image_data); | 319 bool result = gfx::PNGEncodedDataFromImage(image, &image_data); |
319 DCHECK(result); | 320 DCHECK(result); |
320 | 321 |
321 std::copy(image_data.begin(), image_data.end(), | 322 std::copy(image_data.begin(), image_data.end(), |
322 std::back_inserter(icon_response_)); | 323 std::back_inserter(icon_response_)); |
323 } | 324 } |
324 | 325 |
325 WebIntentPickerMock picker_; | 326 WebIntentPickerMock picker_; |
326 WebDataService* web_data_service_; | 327 scoped_refptr<WebDataService> web_data_service_; |
327 FaviconService* favicon_service_; | 328 FaviconService* favicon_service_; |
328 WebIntentPickerController* controller_; | 329 WebIntentPickerController* controller_; |
329 scoped_ptr<DummyURLFetcherFactory> default_url_fetcher_factory_; | 330 scoped_ptr<DummyURLFetcherFactory> default_url_fetcher_factory_; |
330 scoped_ptr<FakeURLFetcherFactory> fake_url_fetcher_factory_; | 331 scoped_ptr<FakeURLFetcherFactory> fake_url_fetcher_factory_; |
331 std::string icon_response_; | 332 std::string icon_response_; |
332 }; | 333 }; |
333 | 334 |
334 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, ChooseService) { | 335 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, ChooseService) { |
335 AddWebIntentService(kAction1, kServiceURL1); | 336 AddWebIntentService(kAction1, kServiceURL1); |
336 AddWebIntentService(kAction1, kServiceURL2); | 337 AddWebIntentService(kAction1, kServiceURL2); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 | 593 |
593 EXPECT_EQ(2, picker_.num_installed_services_); | 594 EXPECT_EQ(2, picker_.num_installed_services_); |
594 | 595 |
595 // The tab is shown immediately without needing to call OnServiceChosen. | 596 // The tab is shown immediately without needing to call OnServiceChosen. |
596 ASSERT_EQ(2, browser()->tab_count()); | 597 ASSERT_EQ(2, browser()->tab_count()); |
597 EXPECT_EQ(GURL(kServiceURL1), | 598 EXPECT_EQ(GURL(kServiceURL1), |
598 browser()->GetSelectedWebContents()->GetURL()); | 599 browser()->GetSelectedWebContents()->GetURL()); |
599 | 600 |
600 EXPECT_TRUE(dispatcher.dispatched_); | 601 EXPECT_TRUE(dispatcher.dispatched_); |
601 } | 602 } |
OLD | NEW |