Chromium Code Reviews| Index: chrome/browser/ui/intents/web_intent_picker_controller_browsertest.cc |
| diff --git a/chrome/browser/ui/intents/web_intent_picker_controller_browsertest.cc b/chrome/browser/ui/intents/web_intent_picker_controller_browsertest.cc |
| index c8c2e446de40e69de53d7c730a2037b596c4508d..b9713689314f909e9127ca46af16a9b431f0e7ba 100644 |
| --- a/chrome/browser/ui/intents/web_intent_picker_controller_browsertest.cc |
| +++ b/chrome/browser/ui/intents/web_intent_picker_controller_browsertest.cc |
| @@ -1,4 +1,4 @@ |
| -// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @@ -13,23 +13,17 @@ |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/intents/web_intent_picker.h" |
| #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
| -#include "chrome/browser/ui/intents/web_intent_picker_factory.h" |
| +#include "chrome/browser/ui/intents/web_intent_picker_model.h" |
| +#include "chrome/browser/ui/intents/web_intent_picker_model_observer.h" |
| #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| #include "chrome/browser/webdata/web_data_service.h" |
| #include "chrome/test/base/in_process_browser_test.h" |
| #include "chrome/test/base/ui_test_utils.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/browser/web_intents_dispatcher.h" |
| -#include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "webkit/glue/web_intent_service_data.h" |
| -using content::WebContents; |
| -using testing::_; |
| -using testing::DoAll; |
| -using testing::Return; |
| -using testing::SaveArg; |
| - |
| namespace { |
| const string16 kAction1(ASCIIToUTF16("http://www.example.com/share")); |
| @@ -38,66 +32,39 @@ const string16 kType(ASCIIToUTF16("image/png")); |
| const GURL kServiceURL1("http://www.google.com"); |
| const GURL kServiceURL2("http://www.chromium.org"); |
| -MATCHER_P(VectorIsOfSize, n, "") { |
| - return arg.size() == static_cast<size_t>(n); |
| -} |
| - |
| } // namespace |
| -class WebIntentPickerMock : public WebIntentPicker { |
| +class WebIntentPickerMock : public WebIntentPicker, |
| + public WebIntentPickerModelObserver { |
| public: |
| - WebIntentPickerMock() : num_urls_(0), num_default_icons_(0) {} |
| - |
| - virtual void SetServiceURLs(const std::vector<GURL>& urls) { |
| - num_urls_ = urls.size(); |
| + WebIntentPickerMock() : num_items_(0), num_default_icons_(0) { |
| } |
| - virtual void SetServiceIcon(size_t index, const SkBitmap& icon) {} |
| - |
| - virtual void SetDefaultServiceIcon(size_t index) { |
| - num_default_icons_++; |
| + virtual void OnModelChanged(WebIntentPickerModel* model) { |
|
groby-ooo-7-16
2012/01/25 22:03:13
nit: OVERRIDE, here and elsewhere
binji
2012/01/26 00:27:41
Done.
|
| + num_items_ = static_cast<int>(model->GetItemCount()); |
| + num_default_icons_ = GetNumDefaultIcons(model); |
| } |
| - virtual void WaitFor(int target_num_urls, int target_num_default_icons) { |
| - while (num_urls_ != target_num_urls || |
| - num_default_icons_ != target_num_default_icons) { |
| - MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| - ui_test_utils::RunAllPendingInMessageLoop(); |
| - } |
| + virtual void OnFaviconChanged(WebIntentPickerModel* model, size_t index) { |
| + num_default_icons_ = GetNumDefaultIcons(model); |
| } |
| + virtual void OnInlineDisposition(WebIntentPickerModel* model) {} |
| virtual void Close() {} |
| - WebContents* SetInlineDisposition(const GURL& url) { return NULL; } |
| - |
| - int num_urls_; |
| - int num_default_icons_; |
| -}; |
| - |
| - |
| -class WebIntentPickerFactoryMock : public WebIntentPickerFactory { |
| - public: |
| - explicit WebIntentPickerFactoryMock(WebIntentPickerMock* mock) |
| - : picker_(mock) {} |
| - |
| - virtual WebIntentPicker* Create(Browser* browser, |
| - TabContentsWrapper* wrapper, |
| - WebIntentPickerDelegate* delegate) { |
| - return picker_; |
| - } |
| - |
| - virtual void ClosePicker(WebIntentPicker* picker) { |
| - if (picker_) { |
| - picker_->Close(); |
| - picker_ = NULL; |
| + int GetNumDefaultIcons(WebIntentPickerModel* model) const { |
| + int num_default_icons = 0; |
| + for (size_t i = 0; i < model->GetItemCount(); ++i) { |
| + const WebIntentPickerModel::Item& item = model->GetItemAt(i); |
| + if (item.favicon.get() == NULL) |
| + ++num_default_icons; |
| } |
| - } |
| - void Close() { |
| - picker_ = NULL; |
| + return num_default_icons; |
| } |
| - WebIntentPicker* picker_; |
| + int num_items_; |
| + int num_default_icons_; |
| }; |
| class IntentsDispatcherMock : public content::WebIntentsDispatcher { |
| @@ -110,7 +77,7 @@ class IntentsDispatcherMock : public content::WebIntentsDispatcher { |
| return intent_; |
| } |
| - virtual void DispatchIntent(WebContents* tab_contents) { |
| + virtual void DispatchIntent(content::WebContents* web_contents) { |
| dispatched_ = true; |
| } |
| @@ -127,6 +94,22 @@ class IntentsDispatcherMock : public content::WebIntentsDispatcher { |
| class WebIntentPickerControllerBrowserTest : public InProcessBrowserTest { |
| protected: |
| + typedef WebIntentPickerModel::Disposition Disposition; |
| + |
| + WebIntentPickerControllerBrowserTest() {} |
| + |
| + virtual void SetUpOnMainThread() OVERRIDE { |
| + web_data_service_ = |
| + browser()->profile()->GetWebDataService(Profile::EXPLICIT_ACCESS); |
| + favicon_service_ = |
| + browser()->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); |
| + controller_ = browser()-> |
| + GetSelectedTabContentsWrapper()->web_intent_picker_controller(); |
| + |
| + controller_->set_picker(&picker_); |
| + controller_->set_model_observer(&picker_); |
| + } |
| + |
| void AddWebIntentService(const string16& action, |
| const GURL& service_url) { |
| webkit_glue::WebIntentServiceData service; |
| @@ -136,60 +119,75 @@ class WebIntentPickerControllerBrowserTest : public InProcessBrowserTest { |
| web_data_service_->AddWebIntentService(service); |
| } |
| - void OnSendReturnMessage(WebIntentPickerController* controller) { |
| - controller->OnSendReturnMessage(); |
| + void OnSendReturnMessage() { |
| + controller_->OnSendReturnMessage(); |
| } |
| - void OnServiceChosen(WebIntentPickerController* controller, size_t index) { |
| - controller->OnServiceChosen(index); |
| + void OnServiceChosen(size_t index, Disposition disposition) { |
| + controller_->OnServiceChosen(index, disposition); |
| } |
| - void SetPickerFactory(WebIntentPickerController* controller, |
| - WebIntentPickerFactory* factory) { |
| - controller->picker_factory_.reset(factory); |
| + void OnCancelled() { |
| + controller_->OnCancelled(); |
| } |
| - WebIntentPickerMock picker_; |
| + void CheckPendingAsync() { |
| + if (controller_->pending_async_count() > 0) { |
| + MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&WebIntentPickerControllerBrowserTest::CheckPendingAsync, |
| + base::Unretained(this))); |
| + return; |
| + } |
| + |
| + MessageLoop::current()->Quit(); |
| + } |
| - // The picker controller takes ownership. |
| - WebIntentPickerFactoryMock* picker_factory_; |
| + void WaitForPendingAsync() { |
| + CheckPendingAsync(); |
| + MessageLoop::current()->Run(); |
| + } |
| + WebIntentPickerMock picker_; |
| WebDataService* web_data_service_; |
| FaviconService* favicon_service_; |
| + WebIntentPickerController* controller_; |
| }; |
| IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, ChooseService) { |
| - web_data_service_ = |
| - browser()->profile()->GetWebDataService(Profile::EXPLICIT_ACCESS); |
| AddWebIntentService(kAction1, kServiceURL1); |
| AddWebIntentService(kAction1, kServiceURL2); |
| - favicon_service_ = |
| - browser()->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); |
| - |
| - picker_factory_ = new WebIntentPickerFactoryMock(&picker_); |
| - WebIntentPickerController* controller = browser()-> |
| - GetSelectedTabContentsWrapper()->web_intent_picker_controller(); |
| - SetPickerFactory(controller, picker_factory_); |
| - |
| - controller->ShowDialog(browser(), kAction1, kType); |
| - picker_.WaitFor(2, 2); |
| - EXPECT_EQ(2, picker_.num_urls_); |
| + controller_->ShowDialog(browser(), kAction1, kType); |
| + WaitForPendingAsync(); |
| + EXPECT_EQ(2, picker_.num_items_); |
| EXPECT_EQ(2, picker_.num_default_icons_); |
| webkit_glue::WebIntentData intent; |
| intent.action = ASCIIToUTF16("a"); |
| intent.type = ASCIIToUTF16("b"); |
| IntentsDispatcherMock* host = new IntentsDispatcherMock(intent); |
| - controller->SetIntentsDispatcher(host); |
| + controller_->SetIntentsDispatcher(host); |
| - OnServiceChosen(controller, 1); |
| + OnServiceChosen(1, WebIntentPickerModel::DISPOSITION_WINDOW); |
| ASSERT_EQ(2, browser()->tab_count()); |
| EXPECT_EQ(GURL(kServiceURL2), |
| browser()->GetSelectedWebContents()->GetURL()); |
| EXPECT_TRUE(host->dispatched_); |
| - OnSendReturnMessage(controller); |
| + OnSendReturnMessage(); |
| ASSERT_EQ(1, browser()->tab_count()); |
| } |
| + |
| +IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, OpenCancelOpen) { |
| + AddWebIntentService(kAction1, kServiceURL1); |
| + AddWebIntentService(kAction1, kServiceURL2); |
| + |
| + controller_->ShowDialog(browser(), kAction1, kType); |
| + WaitForPendingAsync(); |
| + OnCancelled(); |
| + |
| + controller_->ShowDialog(browser(), kAction1, kType); |
| + OnCancelled(); |
| +} |