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" |
(...skipping 10 matching lines...) Expand all Loading... |
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.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents.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/browser/webdata/web_data_service_factory.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
27 #include "chrome/test/base/in_process_browser_test.h" | 27 #include "chrome/test/base/in_process_browser_test.h" |
28 #include "chrome/test/base/ui_test_utils.h" | 28 #include "chrome/test/base/ui_test_utils.h" |
29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
30 #include "content/public/browser/web_intents_dispatcher.h" | 30 #include "content/public/browser/web_intents_dispatcher.h" |
31 #include "content/public/test/test_url_fetcher_factory.h" | |
32 #include "net/base/escape.h" | 31 #include "net/base/escape.h" |
33 #include "net/base/mock_host_resolver.h" | 32 #include "net/base/mock_host_resolver.h" |
| 33 #include "net/url_request/test_url_fetcher_factory.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
35 #include "ui/gfx/image/image_unittest_util.h" | 35 #include "ui/gfx/image/image_unittest_util.h" |
36 #include "ui/gfx/image/image_util.h" | 36 #include "ui/gfx/image/image_util.h" |
37 #include "webkit/glue/web_intent_service_data.h" | 37 #include "webkit/glue/web_intent_service_data.h" |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 const string16 kAction1(ASCIIToUTF16("http://webintents.org/share")); | 41 const string16 kAction1(ASCIIToUTF16("http://webintents.org/share")); |
42 const string16 kAction2(ASCIIToUTF16("http://www.example.com/foobar")); | 42 const string16 kAction2(ASCIIToUTF16("http://www.example.com/foobar")); |
43 const string16 kType1(ASCIIToUTF16("image/png")); | 43 const string16 kType1(ASCIIToUTF16("image/png")); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 class DummyURLFetcherFactory : public net::URLFetcherFactory { | 79 class DummyURLFetcherFactory : public net::URLFetcherFactory { |
80 public: | 80 public: |
81 DummyURLFetcherFactory() {} | 81 DummyURLFetcherFactory() {} |
82 virtual ~DummyURLFetcherFactory() {} | 82 virtual ~DummyURLFetcherFactory() {} |
83 | 83 |
84 virtual net::URLFetcher* CreateURLFetcher( | 84 virtual net::URLFetcher* CreateURLFetcher( |
85 int id, | 85 int id, |
86 const GURL& url, | 86 const GURL& url, |
87 net::URLFetcher::RequestType request_type, | 87 net::URLFetcher::RequestType request_type, |
88 net::URLFetcherDelegate* d) OVERRIDE { | 88 net::URLFetcherDelegate* d) OVERRIDE { |
89 return new TestURLFetcher(id, url, d); | 89 return new net::TestURLFetcher(id, url, d); |
90 } | 90 } |
91 }; | 91 }; |
92 | 92 |
93 } // namespace | 93 } // namespace |
94 | 94 |
95 class WebIntentPickerMock : public WebIntentPicker, | 95 class WebIntentPickerMock : public WebIntentPicker, |
96 public WebIntentPickerModelObserver { | 96 public WebIntentPickerModelObserver { |
97 public: | 97 public: |
98 WebIntentPickerMock() | 98 WebIntentPickerMock() |
99 : num_installed_services_(0), | 99 : num_installed_services_(0), |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 222 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
223 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 223 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
224 } | 224 } |
225 | 225 |
226 virtual void SetUpOnMainThread() OVERRIDE { | 226 virtual void SetUpOnMainThread() OVERRIDE { |
227 // The FakeURLFetcherFactory will return a NULL URLFetcher if a request is | 227 // The FakeURLFetcherFactory will return a NULL URLFetcher if a request is |
228 // 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. |
229 // Instead, use this dummy factory to infinitely delay the request. | 229 // Instead, use this dummy factory to infinitely delay the request. |
230 default_url_fetcher_factory_.reset(new DummyURLFetcherFactory); | 230 default_url_fetcher_factory_.reset(new DummyURLFetcherFactory); |
231 fake_url_fetcher_factory_.reset( | 231 fake_url_fetcher_factory_.reset( |
232 new FakeURLFetcherFactory(default_url_fetcher_factory_.get())); | 232 new net::FakeURLFetcherFactory(default_url_fetcher_factory_.get())); |
233 | 233 |
234 web_data_service_ = WebDataServiceFactory::GetForProfile( | 234 web_data_service_ = WebDataServiceFactory::GetForProfile( |
235 GetBrowser()->profile(), Profile::EXPLICIT_ACCESS); | 235 GetBrowser()->profile(), Profile::EXPLICIT_ACCESS); |
236 favicon_service_ = | 236 favicon_service_ = |
237 GetBrowser()->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); | 237 GetBrowser()->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); |
238 controller_ = GetBrowser()-> | 238 controller_ = GetBrowser()-> |
239 GetActiveTabContents()->web_intent_picker_controller(); | 239 GetActiveTabContents()->web_intent_picker_controller(); |
240 | 240 |
241 SetupMockPicker(); | 241 SetupMockPicker(); |
242 controller_->set_model_observer(&picker_); | 242 controller_->set_model_observer(&picker_); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 | 321 |
322 std::copy(image_data.begin(), image_data.end(), | 322 std::copy(image_data.begin(), image_data.end(), |
323 std::back_inserter(icon_response_)); | 323 std::back_inserter(icon_response_)); |
324 } | 324 } |
325 | 325 |
326 WebIntentPickerMock picker_; | 326 WebIntentPickerMock picker_; |
327 scoped_refptr<WebDataService> web_data_service_; | 327 scoped_refptr<WebDataService> web_data_service_; |
328 FaviconService* favicon_service_; | 328 FaviconService* favicon_service_; |
329 WebIntentPickerController* controller_; | 329 WebIntentPickerController* controller_; |
330 scoped_ptr<DummyURLFetcherFactory> default_url_fetcher_factory_; | 330 scoped_ptr<DummyURLFetcherFactory> default_url_fetcher_factory_; |
331 scoped_ptr<FakeURLFetcherFactory> fake_url_fetcher_factory_; | 331 scoped_ptr<net::FakeURLFetcherFactory> fake_url_fetcher_factory_; |
332 std::string icon_response_; | 332 std::string icon_response_; |
333 }; | 333 }; |
334 | 334 |
335 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, ChooseService) { | 335 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, ChooseService) { |
336 AddWebIntentService(kAction1, kServiceURL1); | 336 AddWebIntentService(kAction1, kServiceURL1); |
337 AddWebIntentService(kAction1, kServiceURL2); | 337 AddWebIntentService(kAction1, kServiceURL2); |
338 AddCWSExtensionServiceEmpty(kAction1); | 338 AddCWSExtensionServiceEmpty(kAction1); |
339 | 339 |
340 controller_->ShowDialog(kAction1, kType1); | 340 controller_->ShowDialog(kAction1, kType1); |
341 picker_.Wait(); | 341 picker_.Wait(); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 | 593 |
594 EXPECT_EQ(2, picker_.num_installed_services_); | 594 EXPECT_EQ(2, picker_.num_installed_services_); |
595 | 595 |
596 // The tab is shown immediately without needing to call OnServiceChosen. | 596 // The tab is shown immediately without needing to call OnServiceChosen. |
597 ASSERT_EQ(2, browser()->tab_count()); | 597 ASSERT_EQ(2, browser()->tab_count()); |
598 EXPECT_EQ(GURL(kServiceURL1), | 598 EXPECT_EQ(GURL(kServiceURL1), |
599 browser()->GetActiveWebContents()->GetURL()); | 599 browser()->GetActiveWebContents()->GetURL()); |
600 | 600 |
601 EXPECT_TRUE(dispatcher.dispatched_); | 601 EXPECT_TRUE(dispatcher.dispatched_); |
602 } | 602 } |
OLD | NEW |