Commit ea4a2c90 authored by rfevang@chromium.org's avatar rfevang@chromium.org

Remove print and move bookmark to the top of the action box.

This change removes the print menu entry from the action box,
and moves the bookmark entry so it becomes the first entry in
the list.

Also moved responsibility for populating the menu model into the
controller class, instead of having it split between the model
and the controller.

BUG=226803

Review URL: https://chromiumcodereview.appspot.com/13983002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194758 0039d316-1c4b-4281-b951-d872f2087c98
parent 8d025dbd
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "chrome/browser/ui/cocoa/location_bar/action_box_menu_bubble_controller.h" #import "chrome/browser/ui/cocoa/location_bar/action_box_menu_bubble_controller.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/extensions/extension_system.h"
...@@ -136,7 +137,7 @@ class ActionBoxMenuBubbleControllerTest : public CocoaProfileTest { ...@@ -136,7 +137,7 @@ class ActionBoxMenuBubbleControllerTest : public CocoaProfileTest {
TEST_F(ActionBoxMenuBubbleControllerTest, CreateMenuWithExtensions) { TEST_F(ActionBoxMenuBubbleControllerTest, CreateMenuWithExtensions) {
scoped_ptr<ActionBoxMenuModel> model(new ActionBoxMenuModel( scoped_ptr<ActionBoxMenuModel> model(new ActionBoxMenuModel(
browser(), &menu_delegate_)); profile(), &menu_delegate_));
AddPageLauncherExtension(model.get(), "Launch extension 1", 0); AddPageLauncherExtension(model.get(), "Launch extension 1", 0);
AddPageLauncherExtension(model.get(), "Launch extension 2", 1); AddPageLauncherExtension(model.get(), "Launch extension 2", 1);
CreateController(model.Pass()); CreateController(model.Pass());
...@@ -169,8 +170,9 @@ TEST_F(ActionBoxMenuBubbleControllerTest, CreateMenuWithExtensions) { ...@@ -169,8 +170,9 @@ TEST_F(ActionBoxMenuBubbleControllerTest, CreateMenuWithExtensions) {
TEST_F(ActionBoxMenuBubbleControllerTest, CheckSeparatorWithShortExtensions) { TEST_F(ActionBoxMenuBubbleControllerTest, CheckSeparatorWithShortExtensions) {
scoped_ptr<ActionBoxMenuModel> model(new ActionBoxMenuModel( scoped_ptr<ActionBoxMenuModel> model(new ActionBoxMenuModel(
browser(), &menu_delegate_)); profile(), &menu_delegate_));
AddPageLauncherExtension(model.get(), "Short", 0); model->AddItem(0, ASCIIToUTF16("Bookmark this page"));
AddPageLauncherExtension(model.get(), "Short", 1);
CreateController(model.Pass()); CreateController(model.Pass());
// The width of the menu is dictated by the widest item which in this case // The width of the menu is dictated by the widest item which in this case
...@@ -181,9 +183,10 @@ TEST_F(ActionBoxMenuBubbleControllerTest, CheckSeparatorWithShortExtensions) { ...@@ -181,9 +183,10 @@ TEST_F(ActionBoxMenuBubbleControllerTest, CheckSeparatorWithShortExtensions) {
TEST_F(ActionBoxMenuBubbleControllerTest, CheckSeparatorWithLongExtensions) { TEST_F(ActionBoxMenuBubbleControllerTest, CheckSeparatorWithLongExtensions) {
scoped_ptr<ActionBoxMenuModel> model(new ActionBoxMenuModel( scoped_ptr<ActionBoxMenuModel> model(new ActionBoxMenuModel(
browser(), &menu_delegate_)); profile(), &menu_delegate_));
model->AddItem(0, ASCIIToUTF16("Bookmark this page"));
AddPageLauncherExtension(model.get(), AddPageLauncherExtension(model.get(),
"This is a long page launcher extension title...", 0); "This is a long page launcher extension title...", 1);
CreateController(model.Pass()); CreateController(model.Pass());
// The width of the menu is dictated by the widest item which in this case // The width of the menu is dictated by the widest item which in this case
......
...@@ -8,10 +8,12 @@ ...@@ -8,10 +8,12 @@
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chrome_to_mobile_service.h"
#include "chrome/browser/extensions/api/page_launcher/page_launcher_api.h" #include "chrome/browser/extensions/api/page_launcher/page_launcher_api.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
...@@ -25,6 +27,10 @@ ...@@ -25,6 +27,10 @@
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/user_metrics.h" #include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/resource/resource_bundle.h"
using content::UserMetricsAction; using content::UserMetricsAction;
using content::WebContents; using content::WebContents;
...@@ -48,26 +54,52 @@ ActionBoxButtonController::ActionBoxButtonController(Browser* browser, ...@@ -48,26 +54,52 @@ ActionBoxButtonController::ActionBoxButtonController(Browser* browser,
ActionBoxButtonController::~ActionBoxButtonController() {} ActionBoxButtonController::~ActionBoxButtonController() {}
void ActionBoxButtonController::OnButtonClicked() { scoped_ptr<ActionBoxMenuModel> ActionBoxButtonController::CreateMenuModel() {
// Build a menu model and display the menu. // Build a menu model and display the menu.
scoped_ptr<ActionBoxMenuModel> menu_model( scoped_ptr<ActionBoxMenuModel> menu_model(
new ActionBoxMenuModel(browser_, this)); new ActionBoxMenuModel(browser_->profile(), this));
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
// In some unit tests, GetActiveWebContents can return NULL.
bool starred = browser_->tab_strip_model()->GetActiveWebContents() &&
BookmarkTabHelper::FromWebContents(browser_->tab_strip_model()->
GetActiveWebContents())->is_starred();
menu_model->AddItemWithStringId(
IDC_BOOKMARK_PAGE_FROM_STAR,
starred ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR);
menu_model->SetIcon(
menu_model->GetIndexOfCommandId(IDC_BOOKMARK_PAGE_FROM_STAR),
rb.GetNativeImageNamed(starred ? IDR_STAR_LIT : IDR_STAR));
// TODO(msw): Show the item as disabled for chrome: and file: scheme pages?
if (ChromeToMobileService::UpdateAndGetCommandState(browser_)) {
menu_model->AddItemWithStringId(IDC_CHROME_TO_MOBILE_PAGE,
IDS_CHROME_TO_MOBILE_BUBBLE_TOOLTIP);
menu_model->SetIcon(
menu_model->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE),
rb.GetNativeImageNamed(IDR_MOBILE));
}
const ExtensionSet* extensions = ExtensionService* extension_service =
extensions::ExtensionSystem::Get(browser_->profile())-> extensions::ExtensionSystem::Get(browser_->profile())->
extension_service()->extensions(); extension_service();
for (ExtensionSet::const_iterator it = extensions->begin(); if (extension_service) {
it != extensions->end(); ++it) { const ExtensionSet* extensions = extension_service->extensions();
const extensions::Extension* extension = *it; for (ExtensionSet::const_iterator it = extensions->begin();
if (ActionInfo::GetPageLauncherInfo(extension)) { it != extensions->end(); ++it) {
int command_id = GetCommandIdForExtension(*extension); const extensions::Extension* extension = *it;
menu_model->AddExtension(*extension, command_id); if (ActionInfo::GetPageLauncherInfo(extension)) {
int command_id = GetCommandIdForExtension(*extension);
menu_model->AddExtension(*extension, command_id);
}
} }
} }
content::RecordAction(UserMetricsAction("ActionBox.ClickButton")); return menu_model.Pass();
}
// And show the menu. void ActionBoxButtonController::OnButtonClicked() {
delegate_->ShowMenu(menu_model.Pass()); content::RecordAction(UserMetricsAction("ActionBox.ClickButton"));
delegate_->ShowMenu(CreateMenuModel());
} }
bool ActionBoxButtonController::IsCommandIdChecked(int command_id) const { bool ActionBoxButtonController::IsCommandIdChecked(int command_id) const {
......
...@@ -44,6 +44,10 @@ class ActionBoxButtonController : public ui::SimpleMenuModel::Delegate, ...@@ -44,6 +44,10 @@ class ActionBoxButtonController : public ui::SimpleMenuModel::Delegate,
ActionBoxButtonController(Browser* browser, Delegate* delegate); ActionBoxButtonController(Browser* browser, Delegate* delegate);
virtual ~ActionBoxButtonController(); virtual ~ActionBoxButtonController();
// Creates and populates an ActionBoxMenuModel according to the current
// state of the browser.
scoped_ptr<ActionBoxMenuModel> CreateMenuModel();
// Notifies this that the action box button has been clicked. // Notifies this that the action box button has been clicked.
// Methods on the Delegate may be called re-entrantly. // Methods on the Delegate may be called re-entrantly.
void OnButtonClicked(); void OnButtonClicked();
......
...@@ -6,53 +6,22 @@ ...@@ -6,53 +6,22 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chrome_to_mobile_service.h"
#include "chrome/browser/chrome_to_mobile_service_factory.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/extension_toolbar_model.h" #include "chrome/browser/extensions/extension_toolbar_model.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/extensions/api/extension_action/action_info.h" #include "chrome/common/extensions/api/extension_action/action_info.h"
#include "chrome/common/url_constants.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/resource/resource_bundle.h"
using extensions::ActionInfo; using extensions::ActionInfo;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// ActionBoxMenuModel // ActionBoxMenuModel
ActionBoxMenuModel::ActionBoxMenuModel(Browser* browser, ActionBoxMenuModel::ActionBoxMenuModel(Profile* profile,
ui::SimpleMenuModel::Delegate* delegate) ui::SimpleMenuModel::Delegate* delegate)
: ui::SimpleMenuModel(delegate), : ui::SimpleMenuModel(delegate),
browser_(browser) { profile_(profile) {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
// TODO(msw): Show the item as disabled for chrome: and file: scheme pages?
if (ChromeToMobileService::UpdateAndGetCommandState(browser_)) {
AddItemWithStringId(IDC_CHROME_TO_MOBILE_PAGE,
IDS_CHROME_TO_MOBILE_BUBBLE_TOOLTIP);
SetIcon(GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE),
rb.GetNativeImageNamed(IDR_MOBILE));
}
// In some unit tests, GetActiveWebContents can return NULL.
bool starred = browser_->tab_strip_model()->GetActiveWebContents() &&
BookmarkTabHelper::FromWebContents(browser_->tab_strip_model()->
GetActiveWebContents())->is_starred();
AddItemWithStringId(IDC_BOOKMARK_PAGE_FROM_STAR,
starred ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR);
SetIcon(GetIndexOfCommandId(IDC_BOOKMARK_PAGE_FROM_STAR),
rb.GetNativeImageNamed(starred ? IDR_STAR_LIT : IDR_STAR));
AddItemWithStringId(IDC_PRINT, IDS_PRINT);
} }
ActionBoxMenuModel::~ActionBoxMenuModel() { ActionBoxMenuModel::~ActionBoxMenuModel() {
...@@ -84,8 +53,7 @@ const extensions::Extension* ActionBoxMenuModel::GetExtensionAt(int index) { ...@@ -84,8 +53,7 @@ const extensions::Extension* ActionBoxMenuModel::GetExtensionAt(int index) {
CHECK_LT(index_in_extension_ids, static_cast<int>(extension_ids_.size())); CHECK_LT(index_in_extension_ids, static_cast<int>(extension_ids_.size()));
ExtensionService* extension_service = ExtensionService* extension_service =
extensions::ExtensionSystem::Get(browser_->profile())-> extensions::ExtensionSystem::Get(profile_)->extension_service();
extension_service();
return extension_service->extensions()->GetByID( return extension_service->extensions()->GetByID(
extension_ids_[index_in_extension_ids]); extension_ids_[index_in_extension_ids]);
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "ui/base/models/simple_menu_model.h" #include "ui/base/models/simple_menu_model.h"
class Browser; class Profile;
// A menu model that builds the contents of the action box menu. Effectively, // A menu model that builds the contents of the action box menu. Effectively,
// a ui::SimpleMenuModel with methods specifically for dealing with extension // a ui::SimpleMenuModel with methods specifically for dealing with extension
...@@ -21,7 +21,7 @@ class Browser; ...@@ -21,7 +21,7 @@ class Browser;
// the browser at creation time. // the browser at creation time.
class ActionBoxMenuModel : public ui::SimpleMenuModel { class ActionBoxMenuModel : public ui::SimpleMenuModel {
public: public:
ActionBoxMenuModel(Browser* browser, ui::SimpleMenuModel::Delegate* delegate); ActionBoxMenuModel(Profile* profile, ui::SimpleMenuModel::Delegate* delegate);
virtual ~ActionBoxMenuModel(); virtual ~ActionBoxMenuModel();
// Adds an extension to the model with a given command ID. // Adds an extension to the model with a given command ID.
...@@ -43,7 +43,7 @@ class ActionBoxMenuModel : public ui::SimpleMenuModel { ...@@ -43,7 +43,7 @@ class ActionBoxMenuModel : public ui::SimpleMenuModel {
// total items in the model if there are no extensions installed. // total items in the model if there are no extensions installed.
int GetFirstExtensionIndex(); int GetFirstExtensionIndex();
Browser* browser_; Profile* profile_;
// The list of extensions added to the menu, in order, if any. // The list of extensions added to the menu, in order, if any.
extensions::ExtensionIdList extension_ids_; extensions::ExtensionIdList extension_ids_;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/ui/toolbar/action_box_menu_model.h" #include "chrome/browser/ui/toolbar/action_box_menu_model.h"
#include "base/memory/scoped_ptr.h"
#include "base/prefs/testing_pref_service.h" #include "base/prefs/testing_pref_service.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
...@@ -12,6 +13,7 @@ ...@@ -12,6 +13,7 @@
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_command_controller.h" #include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/toolbar/action_box_button_controller.h"
#include "chrome/common/extensions/feature_switch.h" #include "chrome/common/extensions/feature_switch.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/test/base/browser_with_test_window_test.h" #include "chrome/test/base/browser_with_test_window_test.h"
...@@ -27,25 +29,23 @@ ...@@ -27,25 +29,23 @@
using extensions::FeatureSwitch; using extensions::FeatureSwitch;
class ActionBoxMenuModelTest : public BrowserWithTestWindowTest, class ActionBoxMenuModelTest : public BrowserWithTestWindowTest,
public ui::SimpleMenuModel::Delegate { public ActionBoxButtonController::Delegate {
public: public:
ActionBoxMenuModelTest() {} ActionBoxMenuModelTest() {}
// Testing overrides to ui::SimpleMenuModel::Delegate: virtual void SetUp() OVERRIDE {
virtual bool IsCommandIdChecked(int command_id) const OVERRIDE { BrowserWithTestWindowTest::SetUp();
return false; controller_.reset(new ActionBoxButtonController(browser(), this));
} }
virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE { virtual void TearDown() OVERRIDE {
return false; controller_.reset();
BrowserWithTestWindowTest::TearDown();
} }
virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE {} scoped_ptr<ActionBoxMenuModel> CreateModel() {
return controller_->CreateMenuModel();
// Don't handle accelerators. }
virtual bool GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) OVERRIDE { return false; }
void InitProfile(){ void InitProfile(){
profile()->set_incognito(true); profile()->set_incognito(true);
...@@ -83,6 +83,8 @@ class ActionBoxMenuModelTest : public BrowserWithTestWindowTest, ...@@ -83,6 +83,8 @@ class ActionBoxMenuModelTest : public BrowserWithTestWindowTest,
} }
private: private:
scoped_ptr<ActionBoxButtonController> controller_;
DISALLOW_COPY_AND_ASSIGN(ActionBoxMenuModelTest); DISALLOW_COPY_AND_ASSIGN(ActionBoxMenuModelTest);
}; };
...@@ -91,20 +93,18 @@ TEST_F(ActionBoxMenuModelTest, IncongnitoNoMobiles) { ...@@ -91,20 +93,18 @@ TEST_F(ActionBoxMenuModelTest, IncongnitoNoMobiles) {
InitProfile(); InitProfile();
NavigateToLocalPage(); NavigateToLocalPage();
// Create model. scoped_ptr<ActionBoxMenuModel> model = CreateModel();
ActionBoxMenuModel model(browser(), this);
// Expect no c2m command in model. // Expect no c2m command in model.
EXPECT_EQ(-1, model.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_EQ(-1, model->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
NavigateToBookmarkablePage(); NavigateToBookmarkablePage();
// Create model. scoped_ptr<ActionBoxMenuModel> model2 = CreateModel();
ActionBoxMenuModel model2(browser(), this);
// Expect c2m command not in model. // Expect c2m command not in model.
EXPECT_EQ(-1, model2.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_EQ(-1, model2->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
} }
...@@ -115,20 +115,17 @@ TEST_F(ActionBoxMenuModelTest, IncongnitoHasMobiles) { ...@@ -115,20 +115,17 @@ TEST_F(ActionBoxMenuModelTest, IncongnitoHasMobiles) {
NavigateToLocalPage(); NavigateToLocalPage();
// Create model. scoped_ptr<ActionBoxMenuModel> model = CreateModel();
ActionBoxMenuModel model(browser(), this);
// Expect no c2m command in model. // Expect no c2m command in model.
EXPECT_EQ(-1, model.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_EQ(-1, model->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
NavigateToBookmarkablePage(); NavigateToBookmarkablePage();
// Create model. scoped_ptr<ActionBoxMenuModel> model2 = CreateModel();
ActionBoxMenuModel model2(browser(), this);
// Expect c2m command not in model. // Expect c2m command not in model.
EXPECT_EQ(-1, model2.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_EQ(-1, model2->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
} }
...@@ -141,20 +138,18 @@ TEST_F(ActionBoxMenuModelTest, OnRecordNoMobiles) { ...@@ -141,20 +138,18 @@ TEST_F(ActionBoxMenuModelTest, OnRecordNoMobiles) {
NavigateToLocalPage(); NavigateToLocalPage();
// Create model. scoped_ptr<ActionBoxMenuModel> model = CreateModel();
ActionBoxMenuModel model(browser(), this);
// Expect no c2m command in model. // Expect no c2m command in model.
EXPECT_EQ(-1, model.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_EQ(-1, model->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
NavigateToBookmarkablePage(); NavigateToBookmarkablePage();
// Create model. scoped_ptr<ActionBoxMenuModel> model2 = CreateModel();
ActionBoxMenuModel model2(browser(), this);
// Expect c2m command not in model. // Expect c2m command not in model.
EXPECT_EQ(-1, model2.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_EQ(-1, model2->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
} }
...@@ -169,30 +164,27 @@ TEST_F(ActionBoxMenuModelTest, HasMobilesOnRecordOrIncognito) { ...@@ -169,30 +164,27 @@ TEST_F(ActionBoxMenuModelTest, HasMobilesOnRecordOrIncognito) {
NavigateToLocalPage(); NavigateToLocalPage();
// Create model. scoped_ptr<ActionBoxMenuModel> model = CreateModel();
ActionBoxMenuModel model(browser(), this);
// Expect no c2m command in model. // Expect no c2m command in model.
EXPECT_EQ(-1, model.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_EQ(-1, model->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
NavigateToBookmarkablePage(); NavigateToBookmarkablePage();
// Create model. scoped_ptr<ActionBoxMenuModel> model2 = CreateModel();
ActionBoxMenuModel model2(browser(), this);
// Expect c2m command in model. // Expect c2m command in model.
EXPECT_NE(-1, model2.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_NE(-1, model2->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
// Incognito-ize profile. // Incognito-ize profile.
profile()->set_incognito(true); profile()->set_incognito(true);
// Create another model. scoped_ptr<ActionBoxMenuModel> model3 = CreateModel();
ActionBoxMenuModel model3(browser(), this);
// Expect no c2m command in this model. // Expect no c2m command in this model.
EXPECT_EQ(-1, model3.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_EQ(-1, model3->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
// Un-incognito-ize for shutdown. // Un-incognito-ize for shutdown.
...@@ -211,19 +203,18 @@ TEST_F(ActionBoxMenuModelTest, BookmarkedPage) { ...@@ -211,19 +203,18 @@ TEST_F(ActionBoxMenuModelTest, BookmarkedPage) {
GURL url1("http://www.google.com"); GURL url1("http://www.google.com");
AddTab(browser(), url1); AddTab(browser(), url1);
// Create model. scoped_ptr<ActionBoxMenuModel> model = CreateModel();
ActionBoxMenuModel model(browser(), this);
// Bokomark item should be in menu. // Bokomark item should be in menu.
int bookmark_item_index = model.GetIndexOfCommandId( int bookmark_item_index = model->GetIndexOfCommandId(
IDC_BOOKMARK_PAGE_FROM_STAR); IDC_BOOKMARK_PAGE_FROM_STAR);
EXPECT_NE(-1, bookmark_item_index); ASSERT_NE(-1, bookmark_item_index);
gfx::Image bookmark_icon; gfx::Image bookmark_icon;
gfx::Image unlit_icon; gfx::Image unlit_icon;
gfx::Image lit_icon; gfx::Image lit_icon;
model.GetIconAt(bookmark_item_index, &bookmark_icon); model->GetIconAt(bookmark_item_index, &bookmark_icon);
unlit_icon = unlit_icon =
ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_STAR); ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_STAR);
...@@ -240,10 +231,9 @@ TEST_F(ActionBoxMenuModelTest, BookmarkedPage) { ...@@ -240,10 +231,9 @@ TEST_F(ActionBoxMenuModelTest, BookmarkedPage) {
// Now bookmark it. // Now bookmark it.
chrome::BookmarkCurrentPage(browser()); chrome::BookmarkCurrentPage(browser());
// Create model. scoped_ptr<ActionBoxMenuModel> model2 = CreateModel();
ActionBoxMenuModel model2(browser(), this);
model2.GetIconAt(bookmark_item_index, &bookmark_icon); model2->GetIconAt(bookmark_item_index, &bookmark_icon);
lit_icon = lit_icon =
ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_STAR_LIT); ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_STAR_LIT);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment