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/common/chrome_switches.h" |
23 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
24 #include "chrome/test/base/in_process_browser_test.h" | 25 #include "chrome/test/base/in_process_browser_test.h" |
25 #include "chrome/test/base/ui_test_utils.h" | 26 #include "chrome/test/base/ui_test_utils.h" |
26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
27 #include "content/public/browser/web_intents_dispatcher.h" | 28 #include "content/public/browser/web_intents_dispatcher.h" |
28 #include "content/test/test_url_fetcher_factory.h" | 29 #include "content/test/test_url_fetcher_factory.h" |
29 #include "net/base/escape.h" | 30 #include "net/base/escape.h" |
| 31 #include "net/base/mock_host_resolver.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
31 #include "ui/gfx/image/image_unittest_util.h" | 33 #include "ui/gfx/image/image_unittest_util.h" |
32 #include "ui/gfx/image/image_util.h" | 34 #include "ui/gfx/image/image_util.h" |
33 #include "webkit/glue/web_intent_service_data.h" | 35 #include "webkit/glue/web_intent_service_data.h" |
34 | 36 |
35 namespace { | 37 namespace { |
36 | 38 |
37 const string16 kAction1(ASCIIToUTF16("http://www.example.com/share")); | 39 const string16 kAction1(ASCIIToUTF16("http://webintents.org/share")); |
38 const string16 kAction2(ASCIIToUTF16("http://www.example.com/foobar")); | 40 const string16 kAction2(ASCIIToUTF16("http://www.example.com/foobar")); |
39 const string16 kType(ASCIIToUTF16("image/png")); | 41 const string16 kType1(ASCIIToUTF16("image/png")); |
| 42 const string16 kType2(ASCIIToUTF16("text/*")); |
40 const GURL kServiceURL1("http://www.google.com"); | 43 const GURL kServiceURL1("http://www.google.com"); |
41 const GURL kServiceURL2("http://www.chromium.org"); | 44 const GURL kServiceURL2("http://www.chromium.org"); |
| 45 const char kDummyExtensionId[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; |
42 const char kCWSResponseEmpty[] = | 46 const char kCWSResponseEmpty[] = |
43 "{\"kind\":\"chromewebstore#itemList\",\"total_items\":0,\"start_index\":0," | 47 "{\"kind\":\"chromewebstore#itemList\",\"total_items\":0,\"start_index\":0," |
44 "\"items\":[]}"; | 48 "\"items\":[]}"; |
45 | 49 |
46 const char kCWSResponseResultFormat[] = | 50 const char kCWSResponseResultFormat[] = |
47 "{\"kind\":\"chromewebstore#itemList\"," | 51 "{\"kind\":\"chromewebstore#itemList\"," |
48 "\"total_items\":1," | 52 "\"total_items\":1," |
49 "\"start_index\":0," | 53 "\"start_index\":0," |
50 "\"items\":[{" | 54 "\"items\":[{" |
51 "\"kind\":\"chromewebstore#item\"," | 55 "\"kind\":\"chromewebstore#item\"," |
52 "\"id\":\"nhkckhebbbncbkefhcpcgepcgfaclehe\"," | 56 "\"id\":\"%s\"," |
53 "\"type\":\"APPLICATION\"," | 57 "\"type\":\"APPLICATION\"," |
54 "\"num_ratings\":0," | 58 "\"num_ratings\":0," |
55 "\"average_rating\":0.0," | 59 "\"average_rating\":0.0," |
56 "\"manifest\": \"{\\n" | 60 "\"manifest\": \"{\\n" |
57 "\\\"update_url\\\":\\" | 61 "\\\"name\\\": \\\"Dummy Share\\\",\\n" |
58 "\"http://0.tbhome_staging.dserver.download-qa.td.borg.google.com/" | 62 "\\\"version\\\": \\\"1.0.0.0\\\",\\n" |
59 "service/update2/crx\\\",\\n " | 63 "\\\"intents\\\": {\\n" |
60 "\\\"name\\\": \\\"Sidd's Intent App\\\",\\n " | 64 "\\\"%s\\\" : {\\n" |
61 "\\\"description\\\": \\\"Do stuff\\\",\\n " | 65 "\\\"type\\\" : [\\\"%s\\\"],\\n" |
62 "\\\"version\\\": \\\"1.2.19\\\",\\n " | 66 "\\\"path\\\" : \\\"share.html\\\",\\n" |
63 "\\\"app\\\": {\\n " | 67 "\\\"title\\\" : \\\"Dummy share!\\\",\\n" |
64 "\\\"urls\\\": [ \\n ],\\n " | 68 "\\\"disposition\\\": \\\"inline\\\"\\n" |
65 "\\\"launch\\\": {\\n " | 69 "}\\n" |
66 "\\\"web_url\\\": \\\"http://siddharthasaha.net/\\\"\\n " | |
67 "}\\n " | |
68 "},\\n " | |
69 "\\\"icons\\\": {\\n \\\"128\\\": \\\"icon128.png\\\"\\n },\\n " | |
70 "\\\"permissions\\\":" " [\\n " | |
71 "\\\"unlimitedStorage\\\",\\n \\\"notifications\\\"\\n " | |
72 "],\\n" | |
73 " \\\"intents\\\": {\\n " | |
74 "\\\"%s\\\" : {\\n " | |
75 "\\\"type\\\" : [\\\"%s\\\"],\\n " | |
76 "\\\"path\\\" : \\\"//services/edit\\\",\\n " | |
77 "\\\"title\\\" : \\\"Sample Editing Intent\\\",\\n " | |
78 "\\\"disposition\\\" : \\\"inline\\\"\\n " | |
79 "}\\n " | |
80 "}\\n" | 70 "}\\n" |
81 "}\\n\"," | 71 "}\\n\"," |
82 "\"family_safe\":true," | 72 "\"family_safe\":true," |
83 "\"icon_url\": \"%s\"}]}"; | 73 "\"icon_url\": \"%s\"}]}"; |
84 | 74 |
85 const char kCWSFakeIconURLFormat[] = "http://example.com/%s/icon.png"; | 75 const char kCWSFakeIconURLFormat[] = "http://example.com/%s/icon.png"; |
86 | 76 |
87 class DummyURLFetcherFactory : public content::URLFetcherFactory { | 77 class DummyURLFetcherFactory : public content::URLFetcherFactory { |
88 public: | 78 public: |
89 DummyURLFetcherFactory() {} | 79 DummyURLFetcherFactory() {} |
(...skipping 10 matching lines...) Expand all Loading... |
100 | 90 |
101 } // namespace | 91 } // namespace |
102 | 92 |
103 class WebIntentPickerMock : public WebIntentPicker, | 93 class WebIntentPickerMock : public WebIntentPicker, |
104 public WebIntentPickerModelObserver { | 94 public WebIntentPickerModelObserver { |
105 public: | 95 public: |
106 WebIntentPickerMock() | 96 WebIntentPickerMock() |
107 : num_installed_services_(0), | 97 : num_installed_services_(0), |
108 num_icons_changed_(0), | 98 num_icons_changed_(0), |
109 num_extension_icons_changed_(0), | 99 num_extension_icons_changed_(0), |
| 100 num_extensions_installed_(0), |
110 message_loop_started_(false), | 101 message_loop_started_(false), |
111 pending_async_completed_(false) { | 102 pending_async_completed_(false) { |
112 } | 103 } |
113 | 104 |
114 virtual void OnModelChanged(WebIntentPickerModel* model) OVERRIDE { | 105 virtual void OnModelChanged(WebIntentPickerModel* model) OVERRIDE { |
115 num_installed_services_ = | 106 num_installed_services_ = |
116 static_cast<int>(model->GetInstalledServiceCount()); | 107 static_cast<int>(model->GetInstalledServiceCount()); |
117 } | 108 } |
118 | 109 |
119 virtual void OnFaviconChanged( | 110 virtual void OnFaviconChanged( |
120 WebIntentPickerModel* model, size_t index) OVERRIDE { | 111 WebIntentPickerModel* model, size_t index) OVERRIDE { |
121 num_icons_changed_++; | 112 num_icons_changed_++; |
122 } | 113 } |
123 | 114 |
124 virtual void OnExtensionIconChanged( | 115 virtual void OnExtensionIconChanged( |
125 WebIntentPickerModel* model, const string16& extension_id) OVERRIDE { | 116 WebIntentPickerModel* model, const string16& extension_id) OVERRIDE { |
126 num_extension_icons_changed_++; | 117 num_extension_icons_changed_++; |
127 } | 118 } |
128 | 119 |
129 virtual void OnInlineDisposition( | 120 virtual void OnInlineDisposition( |
130 WebIntentPickerModel* model, const GURL& url) OVERRIDE {} | 121 WebIntentPickerModel* model, const GURL& url) OVERRIDE {} |
131 virtual void Close() OVERRIDE {} | 122 virtual void Close() OVERRIDE {} |
132 | 123 |
133 virtual void OnPendingAsyncCompleted() OVERRIDE { | 124 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE { |
134 pending_async_completed_ = true; | 125 num_extensions_installed_++; |
135 | |
136 if (message_loop_started_) | |
137 MessageLoop::current()->Quit(); | |
138 } | 126 } |
139 | 127 |
140 void WaitForPendingAsync() { | 128 virtual void OnExtensionInstallFailure(const std::string& id) OVERRIDE { |
| 129 } |
| 130 |
| 131 virtual void OnPendingAsyncCompleted() OVERRIDE { |
| 132 StopWaiting(); |
| 133 } |
| 134 |
| 135 void Wait() { |
141 if (!pending_async_completed_) { | 136 if (!pending_async_completed_) { |
142 message_loop_started_ = true; | 137 message_loop_started_ = true; |
143 ui_test_utils::RunMessageLoop(); | 138 ui_test_utils::RunMessageLoop(); |
| 139 pending_async_completed_ = false; |
144 } | 140 } |
145 } | 141 } |
146 | 142 |
| 143 void StopWaiting() { |
| 144 pending_async_completed_ = true; |
| 145 if (message_loop_started_) |
| 146 MessageLoop::current()->Quit(); |
| 147 } |
| 148 |
147 int num_installed_services_; | 149 int num_installed_services_; |
148 int num_icons_changed_; | 150 int num_icons_changed_; |
149 int num_extension_icons_changed_; | 151 int num_extension_icons_changed_; |
| 152 int num_extensions_installed_; |
150 bool message_loop_started_; | 153 bool message_loop_started_; |
151 bool pending_async_completed_; | 154 bool pending_async_completed_; |
152 }; | 155 }; |
153 | 156 |
154 class IntentsDispatcherMock : public content::WebIntentsDispatcher { | 157 class IntentsDispatcherMock : public content::WebIntentsDispatcher { |
155 public: | 158 public: |
156 explicit IntentsDispatcherMock(const webkit_glue::WebIntentData& intent) | 159 explicit IntentsDispatcherMock(const webkit_glue::WebIntentData& intent) |
157 : intent_(intent), | 160 : intent_(intent), |
158 dispatched_(false) {} | 161 dispatched_(false) {} |
159 | 162 |
(...skipping 16 matching lines...) Expand all Loading... |
176 webkit_glue::WebIntentData intent_; | 179 webkit_glue::WebIntentData intent_; |
177 bool dispatched_; | 180 bool dispatched_; |
178 }; | 181 }; |
179 | 182 |
180 class WebIntentPickerControllerBrowserTest : public InProcessBrowserTest { | 183 class WebIntentPickerControllerBrowserTest : public InProcessBrowserTest { |
181 protected: | 184 protected: |
182 typedef WebIntentPickerModel::Disposition Disposition; | 185 typedef WebIntentPickerModel::Disposition Disposition; |
183 | 186 |
184 WebIntentPickerControllerBrowserTest() {} | 187 WebIntentPickerControllerBrowserTest() {} |
185 | 188 |
| 189 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 190 // We start the test server now instead of in |
| 191 // SetUpInProcessBrowserTestFixture so that we can get its port number. |
| 192 ASSERT_TRUE(test_server()->Start()); |
| 193 |
| 194 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 195 |
| 196 net::HostPortPair host_port = test_server()->host_port_pair(); |
| 197 command_line->AppendSwitchASCII( |
| 198 switches::kAppsGalleryDownloadURL, |
| 199 base::StringPrintf( |
| 200 "http://www.example.com:%d/files/extensions/intents/%%s.crx", |
| 201 host_port.port())); |
| 202 command_line->AppendSwitchASCII( |
| 203 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); |
| 204 } |
| 205 |
| 206 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 207 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 208 } |
| 209 |
186 virtual void SetUpOnMainThread() OVERRIDE { | 210 virtual void SetUpOnMainThread() OVERRIDE { |
187 // The FakeURLFetcherFactory will return a NULL URLFetcher if a request is | 211 // The FakeURLFetcherFactory will return a NULL URLFetcher if a request is |
188 // created for a URL it doesn't know and there is no default factory. | 212 // created for a URL it doesn't know and there is no default factory. |
189 // Instead, use this dummy factory to infinitely delay the request. | 213 // Instead, use this dummy factory to infinitely delay the request. |
190 default_url_fetcher_factory_.reset(new DummyURLFetcherFactory); | 214 default_url_fetcher_factory_.reset(new DummyURLFetcherFactory); |
191 fake_url_fetcher_factory_.reset( | 215 fake_url_fetcher_factory_.reset( |
192 new FakeURLFetcherFactory(default_url_fetcher_factory_.get())); | 216 new FakeURLFetcherFactory(default_url_fetcher_factory_.get())); |
193 | 217 |
194 web_data_service_ = | 218 web_data_service_ = |
195 browser()->profile()->GetWebDataService(Profile::EXPLICIT_ACCESS); | 219 browser()->profile()->GetWebDataService(Profile::EXPLICIT_ACCESS); |
196 favicon_service_ = | 220 favicon_service_ = |
197 browser()->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); | 221 browser()->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); |
198 controller_ = browser()-> | 222 controller_ = browser()-> |
199 GetSelectedTabContentsWrapper()->web_intent_picker_controller(); | 223 GetSelectedTabContentsWrapper()->web_intent_picker_controller(); |
200 | 224 |
201 controller_->set_picker(&picker_); | 225 controller_->set_picker(&picker_); |
202 controller_->set_model_observer(&picker_); | 226 controller_->set_model_observer(&picker_); |
203 | 227 |
204 CreateFakeIcon(); | 228 CreateFakeIcon(); |
205 } | 229 } |
206 | 230 |
207 void AddWebIntentService(const string16& action, const GURL& service_url) { | 231 void AddWebIntentService(const string16& action, const GURL& service_url) { |
208 webkit_glue::WebIntentServiceData service; | 232 webkit_glue::WebIntentServiceData service; |
209 service.action = action; | 233 service.action = action; |
210 service.type = kType; | 234 service.type = kType1; |
211 service.service_url = service_url; | 235 service.service_url = service_url; |
212 web_data_service_->AddWebIntentService(service); | 236 web_data_service_->AddWebIntentService(service); |
213 } | 237 } |
214 | 238 |
215 void AddCWSExtensionServiceEmpty(const string16& action) { | 239 void AddCWSExtensionServiceEmpty(const string16& action) { |
216 GURL cws_query_url = CWSIntentsRegistry::BuildQueryURL(action, kType); | 240 GURL cws_query_url = CWSIntentsRegistry::BuildQueryURL(action, kType1); |
217 fake_url_fetcher_factory_->SetFakeResponse(cws_query_url.spec(), | 241 fake_url_fetcher_factory_->SetFakeResponse(cws_query_url.spec(), |
218 kCWSResponseEmpty, true); | 242 kCWSResponseEmpty, true); |
219 } | 243 } |
220 | 244 |
221 void AddCWSExtensionServiceWithResult(const string16& action) { | 245 void AddCWSExtensionServiceWithResult(const std::string& extension_id, |
222 GURL cws_query_url = CWSIntentsRegistry::BuildQueryURL(action, kType); | 246 const string16& action, |
| 247 const string16& type) { |
| 248 GURL cws_query_url = CWSIntentsRegistry::BuildQueryURL(action, type); |
223 std::string icon_url; | 249 std::string icon_url; |
224 std::string escaped_action = net::EscapePath(UTF16ToUTF8(action)); | 250 std::string escaped_action = net::EscapePath(UTF16ToUTF8(action)); |
225 base::SStringPrintf(&icon_url, kCWSFakeIconURLFormat, | 251 base::SStringPrintf(&icon_url, kCWSFakeIconURLFormat, |
226 escaped_action.c_str()); | 252 escaped_action.c_str()); |
227 | 253 |
228 std::string response; | 254 std::string response; |
229 base::SStringPrintf(&response, kCWSResponseResultFormat, | 255 base::SStringPrintf(&response, kCWSResponseResultFormat, |
230 UTF16ToUTF8(action).c_str(), UTF16ToUTF8(kType).c_str(), | 256 extension_id.c_str(), |
231 icon_url.c_str()); | 257 UTF16ToUTF8(action).c_str(), UTF16ToUTF8(type).c_str(), |
| 258 icon_url.c_str()); |
232 fake_url_fetcher_factory_->SetFakeResponse(cws_query_url.spec(), response, | 259 fake_url_fetcher_factory_->SetFakeResponse(cws_query_url.spec(), response, |
233 true); | 260 true); |
234 | 261 |
235 fake_url_fetcher_factory_->SetFakeResponse(icon_url, icon_response_, | 262 fake_url_fetcher_factory_->SetFakeResponse(icon_url, icon_response_, |
236 true); | 263 true); |
237 } | 264 } |
238 | 265 |
239 void OnSendReturnMessage( | 266 void OnSendReturnMessage( |
240 webkit_glue::WebIntentReplyType reply_type) { | 267 webkit_glue::WebIntentReplyType reply_type) { |
241 controller_->OnSendReturnMessage(reply_type); | 268 controller_->OnSendReturnMessage(reply_type); |
242 } | 269 } |
243 | 270 |
244 void OnServiceChosen(const GURL& url, Disposition disposition) { | 271 void OnServiceChosen(const GURL& url, Disposition disposition) { |
245 controller_->OnServiceChosen(url, disposition); | 272 controller_->OnServiceChosen(url, disposition); |
246 } | 273 } |
247 | 274 |
248 void OnCancelled() { | 275 void OnCancelled() { |
249 controller_->OnCancelled(); | 276 controller_->OnCancelled(); |
250 } | 277 } |
251 | 278 |
| 279 void OnExtensionInstallRequested(const std::string& extension_id) { |
| 280 controller_->OnExtensionInstallRequested(extension_id); |
| 281 } |
| 282 |
252 void CreateFakeIcon() { | 283 void CreateFakeIcon() { |
253 gfx::Image image(gfx::test::CreateImage()); | 284 gfx::Image image(gfx::test::CreateImage()); |
254 std::vector<unsigned char> image_data; | 285 std::vector<unsigned char> image_data; |
255 bool result = gfx::PNGEncodedDataFromImage(image, &image_data); | 286 bool result = gfx::PNGEncodedDataFromImage(image, &image_data); |
256 DCHECK(result); | 287 DCHECK(result); |
257 | 288 |
258 std::copy(image_data.begin(), image_data.end(), | 289 std::copy(image_data.begin(), image_data.end(), |
259 std::back_inserter(icon_response_)); | 290 std::back_inserter(icon_response_)); |
260 } | 291 } |
261 | 292 |
262 WebIntentPickerMock picker_; | 293 WebIntentPickerMock picker_; |
263 WebDataService* web_data_service_; | 294 WebDataService* web_data_service_; |
264 FaviconService* favicon_service_; | 295 FaviconService* favicon_service_; |
265 WebIntentPickerController* controller_; | 296 WebIntentPickerController* controller_; |
266 scoped_ptr<DummyURLFetcherFactory> default_url_fetcher_factory_; | 297 scoped_ptr<DummyURLFetcherFactory> default_url_fetcher_factory_; |
267 scoped_ptr<FakeURLFetcherFactory> fake_url_fetcher_factory_; | 298 scoped_ptr<FakeURLFetcherFactory> fake_url_fetcher_factory_; |
268 std::string icon_response_; | 299 std::string icon_response_; |
269 }; | 300 }; |
270 | 301 |
271 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, ChooseService) { | 302 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, ChooseService) { |
272 AddWebIntentService(kAction1, kServiceURL1); | 303 AddWebIntentService(kAction1, kServiceURL1); |
273 AddWebIntentService(kAction1, kServiceURL2); | 304 AddWebIntentService(kAction1, kServiceURL2); |
274 AddCWSExtensionServiceEmpty(kAction1); | 305 AddCWSExtensionServiceEmpty(kAction1); |
275 | 306 |
276 controller_->ShowDialog(browser(), kAction1, kType); | 307 controller_->ShowDialog(browser(), kAction1, kType1); |
277 picker_.WaitForPendingAsync(); | 308 picker_.Wait(); |
278 EXPECT_EQ(2, picker_.num_installed_services_); | 309 EXPECT_EQ(2, picker_.num_installed_services_); |
279 EXPECT_EQ(0, picker_.num_icons_changed_); | 310 EXPECT_EQ(0, picker_.num_icons_changed_); |
280 | 311 |
281 webkit_glue::WebIntentData intent; | 312 webkit_glue::WebIntentData intent; |
282 intent.action = ASCIIToUTF16("a"); | 313 intent.action = ASCIIToUTF16("a"); |
283 intent.type = ASCIIToUTF16("b"); | 314 intent.type = ASCIIToUTF16("b"); |
284 IntentsDispatcherMock dispatcher(intent); | 315 IntentsDispatcherMock dispatcher(intent); |
285 controller_->SetIntentsDispatcher(&dispatcher); | 316 controller_->SetIntentsDispatcher(&dispatcher); |
286 | 317 |
287 OnServiceChosen(kServiceURL2, WebIntentPickerModel::DISPOSITION_WINDOW); | 318 OnServiceChosen(kServiceURL2, WebIntentPickerModel::DISPOSITION_WINDOW); |
288 ASSERT_EQ(2, browser()->tab_count()); | 319 ASSERT_EQ(2, browser()->tab_count()); |
289 EXPECT_EQ(GURL(kServiceURL2), | 320 EXPECT_EQ(GURL(kServiceURL2), |
290 browser()->GetSelectedWebContents()->GetURL()); | 321 browser()->GetSelectedWebContents()->GetURL()); |
291 | 322 |
292 EXPECT_TRUE(dispatcher.dispatched_); | 323 EXPECT_TRUE(dispatcher.dispatched_); |
293 | 324 |
294 OnSendReturnMessage(webkit_glue::WEB_INTENT_REPLY_SUCCESS); | 325 OnSendReturnMessage(webkit_glue::WEB_INTENT_REPLY_SUCCESS); |
295 ASSERT_EQ(1, browser()->tab_count()); | 326 ASSERT_EQ(1, browser()->tab_count()); |
296 } | 327 } |
297 | 328 |
298 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, | 329 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, |
299 FetchExtensionIcon) { | 330 FetchExtensionIcon) { |
300 AddWebIntentService(kAction1, kServiceURL1); | 331 AddWebIntentService(kAction1, kServiceURL1); |
301 AddWebIntentService(kAction1, kServiceURL2); | 332 AddWebIntentService(kAction1, kServiceURL2); |
302 AddCWSExtensionServiceWithResult(kAction1); | 333 AddCWSExtensionServiceWithResult(kDummyExtensionId, kAction1, kType1); |
303 | 334 |
304 controller_->ShowDialog(browser(), kAction1, kType); | 335 controller_->ShowDialog(browser(), kAction1, kType1); |
305 picker_.WaitForPendingAsync(); | 336 picker_.Wait(); |
306 EXPECT_EQ(2, picker_.num_installed_services_); | 337 EXPECT_EQ(2, picker_.num_installed_services_); |
307 EXPECT_EQ(0, picker_.num_icons_changed_); | 338 EXPECT_EQ(0, picker_.num_icons_changed_); |
308 EXPECT_EQ(1, picker_.num_extension_icons_changed_); | 339 EXPECT_EQ(1, picker_.num_extension_icons_changed_); |
309 } | 340 } |
310 | 341 |
311 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, OpenCancelOpen) { | 342 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, OpenCancelOpen) { |
312 AddWebIntentService(kAction1, kServiceURL1); | 343 AddWebIntentService(kAction1, kServiceURL1); |
313 AddWebIntentService(kAction1, kServiceURL2); | 344 AddWebIntentService(kAction1, kServiceURL2); |
314 AddCWSExtensionServiceEmpty(kAction1); | 345 AddCWSExtensionServiceEmpty(kAction1); |
315 | 346 |
316 controller_->ShowDialog(browser(), kAction1, kType); | 347 controller_->ShowDialog(browser(), kAction1, kType1); |
317 picker_.WaitForPendingAsync(); | 348 picker_.Wait(); |
318 OnCancelled(); | 349 OnCancelled(); |
319 | 350 |
320 controller_->ShowDialog(browser(), kAction1, kType); | 351 controller_->ShowDialog(browser(), kAction1, kType1); |
321 OnCancelled(); | 352 OnCancelled(); |
322 } | 353 } |
323 | 354 |
324 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, | 355 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, |
325 CloseTargetTabReturnToSource) { | 356 CloseTargetTabReturnToSource) { |
326 AddWebIntentService(kAction1, kServiceURL1); | 357 AddWebIntentService(kAction1, kServiceURL1); |
327 AddCWSExtensionServiceEmpty(kAction1); | 358 AddCWSExtensionServiceEmpty(kAction1); |
328 | 359 |
329 GURL original = browser()->GetSelectedWebContents()->GetURL(); | 360 GURL original = browser()->GetSelectedWebContents()->GetURL(); |
330 | 361 |
331 // Open a new page, but keep focus on original. | 362 // Open a new page, but keep focus on original. |
332 ui_test_utils::NavigateToURLWithDisposition( | 363 ui_test_utils::NavigateToURLWithDisposition( |
333 browser(), GURL(chrome::kChromeUINewTabURL), NEW_BACKGROUND_TAB, | 364 browser(), GURL(chrome::kChromeUINewTabURL), NEW_BACKGROUND_TAB, |
334 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 365 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
335 ASSERT_EQ(2, browser()->tab_count()); | 366 ASSERT_EQ(2, browser()->tab_count()); |
336 EXPECT_EQ(original, browser()->GetSelectedWebContents()->GetURL()); | 367 EXPECT_EQ(original, browser()->GetSelectedWebContents()->GetURL()); |
337 | 368 |
338 controller_->ShowDialog(browser(), kAction1, kType); | 369 controller_->ShowDialog(browser(), kAction1, kType1); |
339 picker_.WaitForPendingAsync(); | 370 picker_.Wait(); |
340 EXPECT_EQ(1, picker_.num_installed_services_); | 371 EXPECT_EQ(1, picker_.num_installed_services_); |
341 | 372 |
342 webkit_glue::WebIntentData intent; | 373 webkit_glue::WebIntentData intent; |
343 intent.action = ASCIIToUTF16("a"); | 374 intent.action = ASCIIToUTF16("a"); |
344 intent.type = ASCIIToUTF16("b"); | 375 intent.type = ASCIIToUTF16("b"); |
345 IntentsDispatcherMock dispatcher(intent); | 376 IntentsDispatcherMock dispatcher(intent); |
346 controller_->SetIntentsDispatcher(&dispatcher); | 377 controller_->SetIntentsDispatcher(&dispatcher); |
347 | 378 |
348 OnServiceChosen(kServiceURL1, WebIntentPickerModel::DISPOSITION_WINDOW); | 379 OnServiceChosen(kServiceURL1, WebIntentPickerModel::DISPOSITION_WINDOW); |
349 ASSERT_EQ(3, browser()->tab_count()); | 380 ASSERT_EQ(3, browser()->tab_count()); |
350 EXPECT_EQ(GURL(kServiceURL1), | 381 EXPECT_EQ(GURL(kServiceURL1), |
351 browser()->GetSelectedWebContents()->GetURL()); | 382 browser()->GetSelectedWebContents()->GetURL()); |
352 | 383 |
353 EXPECT_TRUE(dispatcher.dispatched_); | 384 EXPECT_TRUE(dispatcher.dispatched_); |
354 | 385 |
355 OnSendReturnMessage(webkit_glue::WEB_INTENT_REPLY_SUCCESS); | 386 OnSendReturnMessage(webkit_glue::WEB_INTENT_REPLY_SUCCESS); |
356 ASSERT_EQ(2, browser()->tab_count()); | 387 ASSERT_EQ(2, browser()->tab_count()); |
357 EXPECT_EQ(original, browser()->GetSelectedWebContents()->GetURL()); | 388 EXPECT_EQ(original, browser()->GetSelectedWebContents()->GetURL()); |
358 } | 389 } |
| 390 |
| 391 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, |
| 392 ExtensionInstallSuccess) { |
| 393 const char extension_id[] = "ooodacpbmglpoagccnepcbfhfhpdgddn"; |
| 394 AddCWSExtensionServiceWithResult(extension_id, kAction1, kType2); |
| 395 |
| 396 controller_->ShowDialog(browser(), kAction1, kType2); |
| 397 picker_.Wait(); |
| 398 |
| 399 webkit_glue::WebIntentData intent; |
| 400 intent.action = kAction1; |
| 401 intent.type = kType2; |
| 402 IntentsDispatcherMock dispatcher(intent); |
| 403 controller_->SetIntentsDispatcher(&dispatcher); |
| 404 |
| 405 OnExtensionInstallRequested(extension_id); |
| 406 picker_.Wait(); |
| 407 EXPECT_EQ(1, picker_.num_extensions_installed_); |
| 408 const Extension* extension = browser()->profile()->GetExtensionService()-> |
| 409 GetExtensionById(extension_id, false); |
| 410 EXPECT_TRUE(extension); |
| 411 |
| 412 // Installing an extension should also choose it. Since this extension uses |
| 413 // window disposition, it will create a new tab. |
| 414 ASSERT_EQ(2, browser()->tab_count()); |
| 415 } |
OLD | NEW |