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