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/favicon/favicon_service.h" | 15 #include "chrome/browser/favicon/favicon_service.h" |
15 #include "chrome/browser/intents/web_intents_registry.h" | |
16 #include "chrome/browser/intents/web_intents_registry_factory.h" | |
17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/intents/web_intent_picker.h" | 18 #include "chrome/browser/ui/intents/web_intent_picker.h" |
20 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" | 19 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
21 #include "chrome/browser/ui/intents/web_intent_picker_model.h" | 20 #include "chrome/browser/ui/intents/web_intent_picker_model.h" |
22 #include "chrome/browser/ui/intents/web_intent_picker_model_observer.h" | 21 #include "chrome/browser/ui/intents/web_intent_picker_model_observer.h" |
23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
24 #include "chrome/browser/webdata/web_data_service.h" | 23 #include "chrome/browser/webdata/web_data_service.h" |
25 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 extension_id.c_str(), | 278 extension_id.c_str(), |
280 UTF16ToUTF8(action).c_str(), UTF16ToUTF8(type).c_str(), | 279 UTF16ToUTF8(action).c_str(), UTF16ToUTF8(type).c_str(), |
281 icon_url.c_str()); | 280 icon_url.c_str()); |
282 fake_url_fetcher_factory_->SetFakeResponse(cws_query_url.spec(), response, | 281 fake_url_fetcher_factory_->SetFakeResponse(cws_query_url.spec(), response, |
283 true); | 282 true); |
284 | 283 |
285 fake_url_fetcher_factory_->SetFakeResponse(icon_url, icon_response_, | 284 fake_url_fetcher_factory_->SetFakeResponse(icon_url, icon_response_, |
286 true); | 285 true); |
287 } | 286 } |
288 | 287 |
| 288 void SetDefaultService(const string16& action, |
| 289 const std::string& url) { |
| 290 DefaultWebIntentService default_service; |
| 291 default_service.action = action; |
| 292 default_service.type = kType1; |
| 293 default_service.user_date = 1000000; |
| 294 default_service.service_url = url; |
| 295 web_data_service_->AddDefaultWebIntentService(default_service); |
| 296 } |
| 297 |
289 void OnSendReturnMessage( | 298 void OnSendReturnMessage( |
290 webkit_glue::WebIntentReplyType reply_type) { | 299 webkit_glue::WebIntentReplyType reply_type) { |
291 controller_->OnSendReturnMessage(reply_type); | 300 controller_->OnSendReturnMessage(reply_type); |
292 } | 301 } |
293 | 302 |
294 void OnServiceChosen(const GURL& url, Disposition disposition) { | 303 void OnServiceChosen(const GURL& url, Disposition disposition) { |
295 controller_->OnServiceChosen(url, disposition); | 304 controller_->OnServiceChosen(url, disposition); |
296 } | 305 } |
297 | 306 |
298 void OnCancelled() { | 307 void OnCancelled() { |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 controller_->SetIntentsDispatcher(&dispatcher); | 564 controller_->SetIntentsDispatcher(&dispatcher); |
556 controller_->ShowDialog(kAction1, kType1); | 565 controller_->ShowDialog(kAction1, kType1); |
557 | 566 |
558 EXPECT_EQ(1, browser()->tab_count()); | 567 EXPECT_EQ(1, browser()->tab_count()); |
559 EXPECT_EQ(0, picker_.num_inline_disposition_); | 568 EXPECT_EQ(0, picker_.num_inline_disposition_); |
560 | 569 |
561 // num_installed_services_ would be 2 if the intent wasn't explicit. | 570 // num_installed_services_ would be 2 if the intent wasn't explicit. |
562 EXPECT_EQ(0, picker_.num_installed_services_); | 571 EXPECT_EQ(0, picker_.num_installed_services_); |
563 EXPECT_TRUE(dispatcher.replied_); | 572 EXPECT_TRUE(dispatcher.replied_); |
564 } | 573 } |
| 574 |
| 575 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, |
| 576 DefaultsTest) { |
| 577 AddWebIntentService(kAction1, kServiceURL1); |
| 578 AddWebIntentService(kAction1, kServiceURL2); |
| 579 |
| 580 SetDefaultService(kAction1, kServiceURL1.spec()); |
| 581 |
| 582 webkit_glue::WebIntentData intent; |
| 583 intent.action = kAction1; |
| 584 intent.type = kType1; |
| 585 IntentsDispatcherMock dispatcher(intent); |
| 586 controller_->SetIntentsDispatcher(&dispatcher); |
| 587 |
| 588 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( |
| 589 content::Source<content::WebContentsDelegate>(browser()))); |
| 590 controller_->ShowDialog(kAction1, kType1); |
| 591 new_tab_observer.Wait(); |
| 592 |
| 593 EXPECT_EQ(2, picker_.num_installed_services_); |
| 594 |
| 595 // The tab is shown immediately without needing to call OnServiceChosen. |
| 596 ASSERT_EQ(2, browser()->tab_count()); |
| 597 EXPECT_EQ(GURL(kServiceURL1), |
| 598 browser()->GetSelectedWebContents()->GetURL()); |
| 599 |
| 600 EXPECT_TRUE(dispatcher.dispatched_); |
| 601 } |
OLD | NEW |