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