Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: chrome/browser/ui/views/toolbar/toolbar_action_view_unittest.cc

Issue 1216053013: [Extension Toolbar Redesign] Wants to act treatment, redux - left click (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/toolbar/toolbar_action_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "base/run_loop.h" 5 #include "base/run_loop.h"
6 #include "base/strings/string16.h" 6 #include "base/strings/string16.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/sessions/session_tab_helper.h" 8 #include "chrome/browser/sessions/session_tab_helper.h"
9 #include "chrome/browser/ui/toolbar/test_toolbar_action_view_controller.h" 9 #include "chrome/browser/ui/toolbar/test_toolbar_action_view_controller.h"
10 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" 10 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 private: 57 private:
58 bool shown_in_menu_; 58 bool shown_in_menu_;
59 59
60 views::MenuButton* overflow_reference_view_; 60 views::MenuButton* overflow_reference_view_;
61 61
62 content::WebContents* web_contents_; 62 content::WebContents* web_contents_;
63 63
64 DISALLOW_COPY_AND_ASSIGN(TestToolbarActionViewDelegate); 64 DISALLOW_COPY_AND_ASSIGN(TestToolbarActionViewDelegate);
65 }; 65 };
66 66
67 class OpenMenuListener : public views::ContextMenuController {
68 public:
69 explicit OpenMenuListener(views::View* view)
70 : view_(view),
71 opened_menu_(false) {
72 view_->set_context_menu_controller(this);
73 }
74 ~OpenMenuListener() override {
75 view_->set_context_menu_controller(nullptr);
76 }
77
78 void ShowContextMenuForView(views::View* source,
79 const gfx::Point& point,
80 ui::MenuSourceType source_type) override {
81 opened_menu_ = true;
82 };
83
84 bool opened_menu() const { return opened_menu_; }
85
86 private:
87 views::View* view_;
88
89 bool opened_menu_;
90
91 DISALLOW_COPY_AND_ASSIGN(OpenMenuListener);
92 };
93
67 } // namespace 94 } // namespace
68 95
69 class ToolbarActionViewUnitTest : public views::ViewsTestBase { 96 class ToolbarActionViewUnitTest : public views::ViewsTestBase {
70 public: 97 public:
71 ToolbarActionViewUnitTest() 98 ToolbarActionViewUnitTest()
72 : widget_(nullptr), 99 : widget_(nullptr),
73 ui_thread_(content::BrowserThread::UI, message_loop()) {} 100 ui_thread_(content::BrowserThread::UI, message_loop()) {}
74 ~ToolbarActionViewUnitTest() override {} 101 ~ToolbarActionViewUnitTest() override {}
75 102
76 void SetUp() override { 103 void SetUp() override {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 EXPECT_EQ(views::Button::STATE_PRESSED, view.state()); 189 EXPECT_EQ(views::Button::STATE_PRESSED, view.state());
163 controller.HidePopup(); 190 controller.HidePopup();
164 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); 191 EXPECT_EQ(views::Button::STATE_NORMAL, view.state());
165 192
166 // Ensure that the button's enabled state reflects that of the controller. 193 // Ensure that the button's enabled state reflects that of the controller.
167 controller.SetEnabled(false); 194 controller.SetEnabled(false);
168 EXPECT_EQ(views::Button::STATE_DISABLED, view.state()); 195 EXPECT_EQ(views::Button::STATE_DISABLED, view.state());
169 controller.SetEnabled(true); 196 controller.SetEnabled(true);
170 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); 197 EXPECT_EQ(views::Button::STATE_NORMAL, view.state());
171 198
199 // Ensure that clicking on an otherwise-disabled action optionally opens the
200 // context menu.
201 controller.SetDisabledClickOpensMenu(true);
202 controller.SetEnabled(false);
203 EXPECT_EQ(views::Button::STATE_NORMAL, view.state());
204 int old_execute_action_count = controller.execute_action_count();
205 {
206 OpenMenuListener menu_listener(&view);
207 view.Activate();
208 EXPECT_TRUE(menu_listener.opened_menu());
209 EXPECT_EQ(old_execute_action_count, controller.execute_action_count());
210 }
211
172 // Ensure that the button's want-to-run state reflects that of the controller. 212 // Ensure that the button's want-to-run state reflects that of the controller.
173 controller.SetWantsToRun(true); 213 controller.SetWantsToRun(true);
174 EXPECT_TRUE(view.wants_to_run_for_testing()); 214 EXPECT_TRUE(view.wants_to_run_for_testing());
175 controller.SetWantsToRun(false); 215 controller.SetWantsToRun(false);
176 EXPECT_FALSE(view.wants_to_run_for_testing()); 216 EXPECT_FALSE(view.wants_to_run_for_testing());
177 217
178 // Create an overflow button. 218 // Create an overflow button.
179 views::MenuButton overflow_button(nullptr, base::string16(), nullptr, false); 219 views::MenuButton overflow_button(nullptr, base::string16(), nullptr, false);
180 overflow_button.set_owned_by_client(); 220 overflow_button.set_owned_by_client();
181 action_view_delegate.set_overflow_reference_view(&overflow_button); 221 action_view_delegate.set_overflow_reference_view(&overflow_button);
182 222
183 // If the view isn't visible, the overflow button should be pressed for 223 // If the view isn't visible, the overflow button should be pressed for
184 // popups. 224 // popups.
185 view.SetVisible(false); 225 view.SetVisible(false);
186 controller.ShowPopup(true); 226 controller.ShowPopup(true);
187 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); 227 EXPECT_EQ(views::Button::STATE_NORMAL, view.state());
188 EXPECT_EQ(views::Button::STATE_PRESSED, overflow_button.state()); 228 EXPECT_EQ(views::Button::STATE_PRESSED, overflow_button.state());
189 controller.HidePopup(); 229 controller.HidePopup();
190 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); 230 EXPECT_EQ(views::Button::STATE_NORMAL, view.state());
191 EXPECT_EQ(views::Button::STATE_NORMAL, overflow_button.state()); 231 EXPECT_EQ(views::Button::STATE_NORMAL, overflow_button.state());
192 } 232 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/toolbar_action_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698