| 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 browser()->profile()->GetWebDataService(Profile::EXPLICIT_ACCESS); | 195 browser()->profile()->GetWebDataService(Profile::EXPLICIT_ACCESS); |
| 220 favicon_service_ = | 196 favicon_service_ = |
| 221 browser()->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); | 197 browser()->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); |
| 222 controller_ = browser()-> | 198 controller_ = browser()-> |
| 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 void AddWebIntentService(const string16& action, const GURL& service_url) { | 207 void AddWebIntentService(const string16& action, const GURL& service_url) { |
| 232 webkit_glue::WebIntentServiceData service; | 208 webkit_glue::WebIntentServiceData service; |
| 233 service.action = action; | 209 service.action = action; |
| 234 service.type = kType1; | 210 service.type = kType; |
| 235 service.service_url = service_url; | 211 service.service_url = service_url; |
| 236 web_data_service_->AddWebIntentService(service); | 212 web_data_service_->AddWebIntentService(service); |
| 237 } | 213 } |
| 238 | 214 |
| 239 void AddCWSExtensionServiceEmpty(const string16& action) { | 215 void AddCWSExtensionServiceEmpty(const string16& action) { |
| 240 GURL cws_query_url = CWSIntentsRegistry::BuildQueryURL(action, kType1); | 216 GURL cws_query_url = CWSIntentsRegistry::BuildQueryURL(action, kType); |
| 241 fake_url_fetcher_factory_->SetFakeResponse(cws_query_url.spec(), | 217 fake_url_fetcher_factory_->SetFakeResponse(cws_query_url.spec(), |
| 242 kCWSResponseEmpty, true); | 218 kCWSResponseEmpty, true); |
| 243 } | 219 } |
| 244 | 220 |
| 245 void AddCWSExtensionServiceWithResult(const std::string& extension_id, | 221 void AddCWSExtensionServiceWithResult(const string16& action) { |
| 246 const string16& action, | 222 GURL cws_query_url = CWSIntentsRegistry::BuildQueryURL(action, kType); |
| 247 const string16& type) { | |
| 248 GURL cws_query_url = CWSIntentsRegistry::BuildQueryURL(action, type); | |
| 249 std::string icon_url; | 223 std::string icon_url; |
| 250 std::string escaped_action = net::EscapePath(UTF16ToUTF8(action)); | 224 std::string escaped_action = net::EscapePath(UTF16ToUTF8(action)); |
| 251 base::SStringPrintf(&icon_url, kCWSFakeIconURLFormat, | 225 base::SStringPrintf(&icon_url, kCWSFakeIconURLFormat, |
| 252 escaped_action.c_str()); | 226 escaped_action.c_str()); |
| 253 | 227 |
| 254 std::string response; | 228 std::string response; |
| 255 base::SStringPrintf(&response, kCWSResponseResultFormat, | 229 base::SStringPrintf(&response, kCWSResponseResultFormat, |
| 256 extension_id.c_str(), | 230 UTF16ToUTF8(action).c_str(), UTF16ToUTF8(kType).c_str(), |
| 257 UTF16ToUTF8(action).c_str(), UTF16ToUTF8(type).c_str(), | 231 icon_url.c_str()); |
| 258 icon_url.c_str()); | |
| 259 fake_url_fetcher_factory_->SetFakeResponse(cws_query_url.spec(), response, | 232 fake_url_fetcher_factory_->SetFakeResponse(cws_query_url.spec(), response, |
| 260 true); | 233 true); |
| 261 | 234 |
| 262 fake_url_fetcher_factory_->SetFakeResponse(icon_url, icon_response_, | 235 fake_url_fetcher_factory_->SetFakeResponse(icon_url, icon_response_, |
| 263 true); | 236 true); |
| 264 } | 237 } |
| 265 | 238 |
| 266 void OnSendReturnMessage( | 239 void OnSendReturnMessage( |
| 267 webkit_glue::WebIntentReplyType reply_type) { | 240 webkit_glue::WebIntentReplyType reply_type) { |
| 268 controller_->OnSendReturnMessage(reply_type); | 241 controller_->OnSendReturnMessage(reply_type); |
| 269 } | 242 } |
| 270 | 243 |
| 271 void OnServiceChosen(const GURL& url, Disposition disposition) { | 244 void OnServiceChosen(const GURL& url, Disposition disposition) { |
| 272 controller_->OnServiceChosen(url, disposition); | 245 controller_->OnServiceChosen(url, disposition); |
| 273 } | 246 } |
| 274 | 247 |
| 275 void OnCancelled() { | 248 void OnCancelled() { |
| 276 controller_->OnCancelled(); | 249 controller_->OnCancelled(); |
| 277 } | 250 } |
| 278 | 251 |
| 279 void OnExtensionInstallRequested(const std::string& extension_id) { | |
| 280 controller_->OnExtensionInstallRequested(extension_id); | |
| 281 } | |
| 282 | |
| 283 void CreateFakeIcon() { | 252 void CreateFakeIcon() { |
| 284 gfx::Image image(gfx::test::CreateImage()); | 253 gfx::Image image(gfx::test::CreateImage()); |
| 285 std::vector<unsigned char> image_data; | 254 std::vector<unsigned char> image_data; |
| 286 bool result = gfx::PNGEncodedDataFromImage(image, &image_data); | 255 bool result = gfx::PNGEncodedDataFromImage(image, &image_data); |
| 287 DCHECK(result); | 256 DCHECK(result); |
| 288 | 257 |
| 289 std::copy(image_data.begin(), image_data.end(), | 258 std::copy(image_data.begin(), image_data.end(), |
| 290 std::back_inserter(icon_response_)); | 259 std::back_inserter(icon_response_)); |
| 291 } | 260 } |
| 292 | 261 |
| 293 WebIntentPickerMock picker_; | 262 WebIntentPickerMock picker_; |
| 294 WebDataService* web_data_service_; | 263 WebDataService* web_data_service_; |
| 295 FaviconService* favicon_service_; | 264 FaviconService* favicon_service_; |
| 296 WebIntentPickerController* controller_; | 265 WebIntentPickerController* controller_; |
| 297 scoped_ptr<DummyURLFetcherFactory> default_url_fetcher_factory_; | 266 scoped_ptr<DummyURLFetcherFactory> default_url_fetcher_factory_; |
| 298 scoped_ptr<FakeURLFetcherFactory> fake_url_fetcher_factory_; | 267 scoped_ptr<FakeURLFetcherFactory> fake_url_fetcher_factory_; |
| 299 std::string icon_response_; | 268 std::string icon_response_; |
| 300 }; | 269 }; |
| 301 | 270 |
| 302 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, ChooseService) { | 271 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, ChooseService) { |
| 303 AddWebIntentService(kAction1, kServiceURL1); | 272 AddWebIntentService(kAction1, kServiceURL1); |
| 304 AddWebIntentService(kAction1, kServiceURL2); | 273 AddWebIntentService(kAction1, kServiceURL2); |
| 305 AddCWSExtensionServiceEmpty(kAction1); | 274 AddCWSExtensionServiceEmpty(kAction1); |
| 306 | 275 |
| 307 controller_->ShowDialog(browser(), kAction1, kType1); | 276 controller_->ShowDialog(browser(), kAction1, kType); |
| 308 picker_.Wait(); | 277 picker_.WaitForPendingAsync(); |
| 309 EXPECT_EQ(2, picker_.num_installed_services_); | 278 EXPECT_EQ(2, picker_.num_installed_services_); |
| 310 EXPECT_EQ(0, picker_.num_icons_changed_); | 279 EXPECT_EQ(0, picker_.num_icons_changed_); |
| 311 | 280 |
| 312 webkit_glue::WebIntentData intent; | 281 webkit_glue::WebIntentData intent; |
| 313 intent.action = ASCIIToUTF16("a"); | 282 intent.action = ASCIIToUTF16("a"); |
| 314 intent.type = ASCIIToUTF16("b"); | 283 intent.type = ASCIIToUTF16("b"); |
| 315 IntentsDispatcherMock dispatcher(intent); | 284 IntentsDispatcherMock dispatcher(intent); |
| 316 controller_->SetIntentsDispatcher(&dispatcher); | 285 controller_->SetIntentsDispatcher(&dispatcher); |
| 317 | 286 |
| 318 OnServiceChosen(kServiceURL2, WebIntentPickerModel::DISPOSITION_WINDOW); | 287 OnServiceChosen(kServiceURL2, WebIntentPickerModel::DISPOSITION_WINDOW); |
| 319 ASSERT_EQ(2, browser()->tab_count()); | 288 ASSERT_EQ(2, browser()->tab_count()); |
| 320 EXPECT_EQ(GURL(kServiceURL2), | 289 EXPECT_EQ(GURL(kServiceURL2), |
| 321 browser()->GetSelectedWebContents()->GetURL()); | 290 browser()->GetSelectedWebContents()->GetURL()); |
| 322 | 291 |
| 323 EXPECT_TRUE(dispatcher.dispatched_); | 292 EXPECT_TRUE(dispatcher.dispatched_); |
| 324 | 293 |
| 325 OnSendReturnMessage(webkit_glue::WEB_INTENT_REPLY_SUCCESS); | 294 OnSendReturnMessage(webkit_glue::WEB_INTENT_REPLY_SUCCESS); |
| 326 ASSERT_EQ(1, browser()->tab_count()); | 295 ASSERT_EQ(1, browser()->tab_count()); |
| 327 } | 296 } |
| 328 | 297 |
| 329 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, | 298 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, |
| 330 FetchExtensionIcon) { | 299 FetchExtensionIcon) { |
| 331 AddWebIntentService(kAction1, kServiceURL1); | 300 AddWebIntentService(kAction1, kServiceURL1); |
| 332 AddWebIntentService(kAction1, kServiceURL2); | 301 AddWebIntentService(kAction1, kServiceURL2); |
| 333 AddCWSExtensionServiceWithResult(kDummyExtensionId, kAction1, kType1); | 302 AddCWSExtensionServiceWithResult(kAction1); |
| 334 | 303 |
| 335 controller_->ShowDialog(browser(), kAction1, kType1); | 304 controller_->ShowDialog(browser(), kAction1, kType); |
| 336 picker_.Wait(); | 305 picker_.WaitForPendingAsync(); |
| 337 EXPECT_EQ(2, picker_.num_installed_services_); | 306 EXPECT_EQ(2, picker_.num_installed_services_); |
| 338 EXPECT_EQ(0, picker_.num_icons_changed_); | 307 EXPECT_EQ(0, picker_.num_icons_changed_); |
| 339 EXPECT_EQ(1, picker_.num_extension_icons_changed_); | 308 EXPECT_EQ(1, picker_.num_extension_icons_changed_); |
| 340 } | 309 } |
| 341 | 310 |
| 342 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, OpenCancelOpen) { | 311 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, OpenCancelOpen) { |
| 343 AddWebIntentService(kAction1, kServiceURL1); | 312 AddWebIntentService(kAction1, kServiceURL1); |
| 344 AddWebIntentService(kAction1, kServiceURL2); | 313 AddWebIntentService(kAction1, kServiceURL2); |
| 345 AddCWSExtensionServiceEmpty(kAction1); | 314 AddCWSExtensionServiceEmpty(kAction1); |
| 346 | 315 |
| 347 controller_->ShowDialog(browser(), kAction1, kType1); | 316 controller_->ShowDialog(browser(), kAction1, kType); |
| 348 picker_.Wait(); | 317 picker_.WaitForPendingAsync(); |
| 349 OnCancelled(); | 318 OnCancelled(); |
| 350 | 319 |
| 351 controller_->ShowDialog(browser(), kAction1, kType1); | 320 controller_->ShowDialog(browser(), kAction1, kType); |
| 352 OnCancelled(); | 321 OnCancelled(); |
| 353 } | 322 } |
| 354 | 323 |
| 355 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, | 324 IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, |
| 356 CloseTargetTabReturnToSource) { | 325 CloseTargetTabReturnToSource) { |
| 357 AddWebIntentService(kAction1, kServiceURL1); | 326 AddWebIntentService(kAction1, kServiceURL1); |
| 358 AddCWSExtensionServiceEmpty(kAction1); | 327 AddCWSExtensionServiceEmpty(kAction1); |
| 359 | 328 |
| 360 GURL original = browser()->GetSelectedWebContents()->GetURL(); | 329 GURL original = browser()->GetSelectedWebContents()->GetURL(); |
| 361 | 330 |
| 362 // Open a new page, but keep focus on original. | 331 // Open a new page, but keep focus on original. |
| 363 ui_test_utils::NavigateToURLWithDisposition( | 332 ui_test_utils::NavigateToURLWithDisposition( |
| 364 browser(), GURL(chrome::kChromeUINewTabURL), NEW_BACKGROUND_TAB, | 333 browser(), GURL(chrome::kChromeUINewTabURL), NEW_BACKGROUND_TAB, |
| 365 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 334 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 366 ASSERT_EQ(2, browser()->tab_count()); | 335 ASSERT_EQ(2, browser()->tab_count()); |
| 367 EXPECT_EQ(original, browser()->GetSelectedWebContents()->GetURL()); | 336 EXPECT_EQ(original, browser()->GetSelectedWebContents()->GetURL()); |
| 368 | 337 |
| 369 controller_->ShowDialog(browser(), kAction1, kType1); | 338 controller_->ShowDialog(browser(), kAction1, kType); |
| 370 picker_.Wait(); | 339 picker_.WaitForPendingAsync(); |
| 371 EXPECT_EQ(1, picker_.num_installed_services_); | 340 EXPECT_EQ(1, picker_.num_installed_services_); |
| 372 | 341 |
| 373 webkit_glue::WebIntentData intent; | 342 webkit_glue::WebIntentData intent; |
| 374 intent.action = ASCIIToUTF16("a"); | 343 intent.action = ASCIIToUTF16("a"); |
| 375 intent.type = ASCIIToUTF16("b"); | 344 intent.type = ASCIIToUTF16("b"); |
| 376 IntentsDispatcherMock dispatcher(intent); | 345 IntentsDispatcherMock dispatcher(intent); |
| 377 controller_->SetIntentsDispatcher(&dispatcher); | 346 controller_->SetIntentsDispatcher(&dispatcher); |
| 378 | 347 |
| 379 OnServiceChosen(kServiceURL1, WebIntentPickerModel::DISPOSITION_WINDOW); | 348 OnServiceChosen(kServiceURL1, WebIntentPickerModel::DISPOSITION_WINDOW); |
| 380 ASSERT_EQ(3, browser()->tab_count()); | 349 ASSERT_EQ(3, browser()->tab_count()); |
| 381 EXPECT_EQ(GURL(kServiceURL1), | 350 EXPECT_EQ(GURL(kServiceURL1), |
| 382 browser()->GetSelectedWebContents()->GetURL()); | 351 browser()->GetSelectedWebContents()->GetURL()); |
| 383 | 352 |
| 384 EXPECT_TRUE(dispatcher.dispatched_); | 353 EXPECT_TRUE(dispatcher.dispatched_); |
| 385 | 354 |
| 386 OnSendReturnMessage(webkit_glue::WEB_INTENT_REPLY_SUCCESS); | 355 OnSendReturnMessage(webkit_glue::WEB_INTENT_REPLY_SUCCESS); |
| 387 ASSERT_EQ(2, browser()->tab_count()); | 356 ASSERT_EQ(2, browser()->tab_count()); |
| 388 EXPECT_EQ(original, browser()->GetSelectedWebContents()->GetURL()); | 357 EXPECT_EQ(original, browser()->GetSelectedWebContents()->GetURL()); |
| 389 } | 358 } |
| 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 |