OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_SIDEBAR_SIDEBAR_TAB_TEST_HELPER_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_SIDEBAR_SIDEBAR_TAB_TEST_HELPER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <map> |
| 10 #include <string> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/scoped_ptr.h" |
| 14 #include "base/stl_util-inl.h" |
| 15 #include "chrome/browser/sidebar/sidebar_container.h" |
| 16 #include "chrome/browser/sidebar/sidebar_model.h" |
| 17 #include "chrome/browser/ui/views/sidebar/sidebar_base_tab_strip.h" |
| 18 #include "chrome/browser/ui/views/sidebar/sidebar_tab_strip_controller.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 |
| 21 // SidebarModel half mock, half simulated functionality. |
| 22 class MockSidebarModel : public SidebarModel { |
| 23 public: |
| 24 virtual ~MockSidebarModel() { |
| 25 for (TabContentsWrapperToSidebarsMap::const_iterator it = sidebars_.begin(); |
| 26 it != sidebars_.end(); ++it) { |
| 27 STLDeleteContainerPointers(it->second.begin(), it->second.end()); |
| 28 } |
| 29 } |
| 30 |
| 31 // SidebarModel overrides. |
| 32 virtual std::vector<SidebarContainer*> GetAllSidebarsFor( |
| 33 TabContentsWrapper* tab) { |
| 34 TabContentsWrapperToSidebarsMap::const_iterator it = sidebars_.find(tab); |
| 35 if (it == sidebars_.end()) |
| 36 return std::vector<SidebarContainer*>(); |
| 37 return sidebars_[tab]; |
| 38 } |
| 39 MOCK_METHOD1(GetActiveSidebarContainerFor, |
| 40 SidebarContainer*(TabContentsWrapper* tab)); |
| 41 virtual SidebarContainer* GetSidebarContainerFor( |
| 42 TabContentsWrapper* tab, const std::string& content_id) { |
| 43 const Sidebars& tab_sidebars = sidebars_[tab]; |
| 44 for (Sidebars::const_iterator it = tab_sidebars.begin(); |
| 45 it != tab_sidebars.end(); ++it) { |
| 46 if ((*it)->content_id() == content_id) |
| 47 return *it; |
| 48 } |
| 49 return NULL; |
| 50 } |
| 51 MOCK_METHOD2(GetSidebarTabContents, |
| 52 TabContents*(TabContentsWrapper* tab, |
| 53 const std::string& content_id)); |
| 54 MOCK_METHOD2(NotifyStateChanges, |
| 55 void(TabContents* was_active_sidebar_contents, |
| 56 TabContents* active_sidebar_contents)); |
| 57 MOCK_METHOD2(ToggleSidebar, |
| 58 void(TabContentsWrapper* tab, const std::string& content_id)); |
| 59 MOCK_METHOD2(ShowSidebar, |
| 60 void(TabContentsWrapper* tab, const std::string& content_id)); |
| 61 MOCK_METHOD2(ExpandSidebar, |
| 62 void(TabContentsWrapper* tab, const std::string& content_id)); |
| 63 MOCK_METHOD2(CollapseSidebar, |
| 64 void(TabContentsWrapper* tab, const std::string& content_id)); |
| 65 MOCK_METHOD2(HideSidebar, |
| 66 void(TabContentsWrapper* tab, const std::string& content_id)); |
| 67 MOCK_METHOD3(NavigateSidebar, |
| 68 void(TabContentsWrapper* tab, const std::string& content_id, |
| 69 const GURL& url)); |
| 70 MOCK_METHOD3(SetSidebarBadgeText, |
| 71 void(TabContentsWrapper* tab, const std::string& content_id, |
| 72 const string16& badge_text)); |
| 73 MOCK_METHOD3(SetSidebarIcon, |
| 74 void(TabContentsWrapper* tab, const std::string& content_id, |
| 75 const SkBitmap& bitmap)); |
| 76 MOCK_METHOD3(SetSidebarTitle, |
| 77 void(TabContentsWrapper* tab, const std::string& content_id, |
| 78 const string16& title)); |
| 79 |
| 80 // Shortcuts for easier testing. |
| 81 void AddSidebarContainer(SidebarContainer* container) { |
| 82 Sidebars& sidebars = sidebars_[container->tab()]; |
| 83 CHECK(std::find(sidebars.begin(), sidebars.end(), container) == |
| 84 sidebars.end()); |
| 85 sidebars.push_back(container); |
| 86 } |
| 87 |
| 88 private: |
| 89 typedef std::vector<SidebarContainer*> Sidebars; |
| 90 typedef std::map<TabContentsWrapper*, Sidebars> |
| 91 TabContentsWrapperToSidebarsMap; |
| 92 TabContentsWrapperToSidebarsMap sidebars_; |
| 93 }; |
| 94 |
| 95 // SidebarTabStripController::Delegate mock. |
| 96 class MockSidebarTabStripControllerDelegate |
| 97 : public SidebarTabStripController::Delegate { |
| 98 public: |
| 99 virtual ~MockSidebarTabStripControllerDelegate() {} |
| 100 |
| 101 MOCK_METHOD1(OnSidebarTabStripBoundsChanged, void(bool is_animating)); |
| 102 }; |
| 103 |
| 104 // SidebarTabStripController mock. |
| 105 class MockSidebarTabStripController : public SidebarTabStripController { |
| 106 public: |
| 107 virtual ~MockSidebarTabStripController() {} |
| 108 |
| 109 MOCK_METHOD1(IsTabSelected, bool(int model_index)); |
| 110 MOCK_METHOD1(SelectTab, void(int model_index)); |
| 111 MOCK_METHOD1(UpdateTabs, void(TabContentsWrapper* tab_contents)); |
| 112 MOCK_METHOD1(UpdateState, void(const SidebarContainer* sidebar)); |
| 113 MOCK_METHOD1(UpdateLoadingState, void(const SidebarContainer* sidebar)); |
| 114 MOCK_METHOD1(TabStripBoundsChanged, void(bool is_animating)); |
| 115 }; |
| 116 |
| 117 // SidebarBaseTabStrip mock. |
| 118 class MockSidebarBaseTabStrip : public SidebarBaseTabStrip { |
| 119 public: |
| 120 explicit MockSidebarBaseTabStrip(SidebarTabStripController* controller) |
| 121 : SidebarBaseTabStrip(controller) { |
| 122 } |
| 123 virtual ~MockSidebarBaseTabStrip() {} |
| 124 |
| 125 MOCK_METHOD3(AddTabAt, |
| 126 void(int model_index, bool animate, |
| 127 const SidebarTabRendererData& data)); |
| 128 MOCK_METHOD2(RemoveTabAt, void(int model_index, bool animate)); |
| 129 MOCK_METHOD1(SelectTabAt, void(int new_model_index)); |
| 130 MOCK_METHOD2(SetTabData, |
| 131 void(int model_index, const SidebarTabRendererData& data)); |
| 132 MOCK_METHOD0(SetToIdealBounds, void()); |
| 133 |
| 134 protected: |
| 135 MOCK_METHOD0(CreateTab, SidebarBaseTab*()); |
| 136 MOCK_METHOD1(StartInsertTabAnimation, void(int model_index)); |
| 137 MOCK_METHOD1(StartRemoveTabAnimation, void(int model_index)); |
| 138 MOCK_METHOD0(GenerateIdealBounds, void()); |
| 139 }; |
| 140 |
| 141 #endif // CHROME_BROWSER_UI_VIEWS_SIDEBAR_SIDEBAR_TAB_TEST_HELPER_H_ |
| 142 |
OLD | NEW |