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" | |
groby-ooo-7-16
2012/05/01 15:28:33
Nice catch :)
| |
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 } | 110 } |
112 | 111 |
113 // WebIntentPicker implementation. | 112 // WebIntentPicker implementation. |
114 virtual void Close() OVERRIDE {} | 113 virtual void Close() OVERRIDE {} |
115 virtual void SetActionString(const string16& action) OVERRIDE {} | 114 virtual void SetActionString(const string16& action) OVERRIDE {} |
116 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE { | 115 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE { |
117 num_extensions_installed_++; | 116 num_extensions_installed_++; |
118 } | 117 } |
119 virtual void OnExtensionInstallFailure(const std::string& id) OVERRIDE {} | 118 virtual void OnExtensionInstallFailure(const std::string& id) OVERRIDE {} |
120 virtual void OnPendingAsyncCompleted() OVERRIDE { | 119 virtual void OnPendingAsyncCompleted() OVERRIDE { |
120 LOG(INFO) << "OnPendingAsyncCompleted()"; | |
groby-ooo-7-16
2012/05/01 15:28:33
Do we really need this? As a LOG, no less? At leas
Greg Billock
2012/05/01 19:17:54
removed
On 2012/05/01 15:28:33, groby wrote:
| |
121 StopWaiting(); | 121 StopWaiting(); |
122 } | 122 } |
123 | 123 |
124 // WebIntentPickerModelObserver implementation. | 124 // WebIntentPickerModelObserver implementation. |
125 virtual void OnModelChanged(WebIntentPickerModel* model) OVERRIDE { | 125 virtual void OnModelChanged(WebIntentPickerModel* model) OVERRIDE { |
126 num_installed_services_ = | 126 num_installed_services_ = |
127 static_cast<int>(model->GetInstalledServiceCount()); | 127 static_cast<int>(model->GetInstalledServiceCount()); |
128 } | 128 } |
129 virtual void OnFaviconChanged( | 129 virtual void OnFaviconChanged( |
130 WebIntentPickerModel* model, size_t index) OVERRIDE { | 130 WebIntentPickerModel* model, size_t index) OVERRIDE { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 extension_id.c_str(), | 279 extension_id.c_str(), |
280 UTF16ToUTF8(action).c_str(), UTF16ToUTF8(type).c_str(), | 280 UTF16ToUTF8(action).c_str(), UTF16ToUTF8(type).c_str(), |
281 icon_url.c_str()); | 281 icon_url.c_str()); |
282 fake_url_fetcher_factory_->SetFakeResponse(cws_query_url.spec(), response, | 282 fake_url_fetcher_factory_->SetFakeResponse(cws_query_url.spec(), response, |
283 true); | 283 true); |
284 | 284 |
285 fake_url_fetcher_factory_->SetFakeResponse(icon_url, icon_response_, | 285 fake_url_fetcher_factory_->SetFakeResponse(icon_url, icon_response_, |
286 true); | 286 true); |
287 } | 287 } |
288 | 288 |
289 void SetDefaultService(const string16& action, | |
290 const std::string& url) { | |
291 DefaultWebIntentService default_service; | |
292 default_service.action = action; | |
293 default_service.type = kType1; | |
294 default_service.user_date = 1000000; | |
295 default_service.service_url = url; | |
296 web_data_service_->AddDefaultWebIntentService(default_service); | |
297 } | |
298 | |
289 void OnSendReturnMessage( | 299 void OnSendReturnMessage( |
290 webkit_glue::WebIntentReplyType reply_type) { | 300 webkit_glue::WebIntentReplyType reply_type) { |
291 controller_->OnSendReturnMessage(reply_type); | 301 controller_->OnSendReturnMessage(reply_type); |
292 } | 302 } |
293 | 303 |
294 void OnServiceChosen(const GURL& url, Disposition disposition) { | 304 void OnServiceChosen(const GURL& url, Disposition disposition) { |
295 controller_->OnServiceChosen(url, disposition); | 305 controller_->OnServiceChosen(url, disposition); |
296 } | 306 } |
297 | 307 |
298 void OnCancelled() { | 308 void OnCancelled() { |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
555 controller_->SetIntentsDispatcher(&dispatcher); | 565 controller_->SetIntentsDispatcher(&dispatcher); |
556 controller_->ShowDialog(browser(), kAction1, kType1); | 566 controller_->ShowDialog(browser(), kAction1, kType1); |
557 | 567 |
558 EXPECT_EQ(1, browser()->tab_count()); | 568 EXPECT_EQ(1, browser()->tab_count()); |
559 EXPECT_EQ(0, picker_.num_inline_disposition_); | 569 EXPECT_EQ(0, picker_.num_inline_disposition_); |
560 | 570 |
561 // num_installed_services_ would be 2 if the intent wasn't explicit. | 571 // num_installed_services_ would be 2 if the intent wasn't explicit. |
562 EXPECT_EQ(0, picker_.num_installed_services_); | 572 EXPECT_EQ(0, picker_.num_installed_services_); |
563 EXPECT_TRUE(dispatcher.replied_); | 573 EXPECT_TRUE(dispatcher.replied_); |
564 } | 574 } |
575 | |
576 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, | |
577 DefaultsTest) { | |
578 AddWebIntentService(kAction1, kServiceURL1); | |
579 AddWebIntentService(kAction1, kServiceURL2); | |
580 | |
581 SetDefaultService(kAction1, kServiceURL1.spec()); | |
582 | |
583 webkit_glue::WebIntentData intent; | |
584 intent.action = ASCIIToUTF16("a"); | |
585 intent.type = ASCIIToUTF16("b"); | |
groby-ooo-7-16
2012/05/01 15:28:33
I'm confused - why would that find any matches? Sh
Greg Billock
2012/05/01 19:17:54
Yeah, this is confused. These action/types aren't
| |
586 IntentsDispatcherMock dispatcher(intent); | |
587 controller_->SetIntentsDispatcher(&dispatcher); | |
588 | |
589 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | |
590 content::Source<content::WebContentsDelegate>(browser()))); | |
591 controller_->ShowDialog(browser(), kAction1, kType1); | |
592 new_tab_observer.Wait(); | |
593 | |
594 EXPECT_EQ(2, picker_.num_installed_services_); | |
595 EXPECT_EQ(0, picker_.num_icons_changed_); | |
groby-ooo-7-16
2012/05/01 15:28:33
How is this significant to defaults? Do they never
Greg Billock
2012/05/01 19:17:54
Basically the picker isn't activated, so they don'
| |
596 | |
597 // The tab is shown immediately without needing to call OnServiceChosen. | |
598 ASSERT_EQ(2, browser()->tab_count()); | |
599 EXPECT_EQ(GURL(kServiceURL1), | |
600 browser()->GetSelectedWebContents()->GetURL()); | |
601 | |
602 EXPECT_TRUE(dispatcher.dispatched_); | |
603 } | |
OLD | NEW |