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

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

Issue 2206693002: Improve settings override bubble to indicate policy installed extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tests added; Addressed code review comments patch 5 Created 4 years, 3 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.h" 5 #include "chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/ui/toolbar/test_toolbar_actions_bar_bubble_delegate.h" 11 #include "chrome/browser/ui/toolbar/test_toolbar_actions_bar_bubble_delegate.h"
12 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "components/grit/components_scaled_resources.h"
15 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/events/event_utils.h" 16 #include "ui/events/event_utils.h"
13 #include "ui/events/test/event_generator.h" 17 #include "ui/events/test/event_generator.h"
14 #include "ui/views/controls/button/label_button.h" 18 #include "ui/views/controls/button/label_button.h"
15 #include "ui/views/controls/link.h" 19 #include "ui/views/controls/link.h"
16 #include "ui/views/test/test_widget_observer.h" 20 #include "ui/views/test/test_widget_observer.h"
17 #include "ui/views/test/views_test_base.h" 21 #include "ui/views/test/views_test_base.h"
18 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
19 #include "ui/views/window/dialog_client_view.h" 23 #include "ui/views/window/dialog_client_view.h"
20 24
21 class ToolbarActionsBarBubbleViewsTest : public views::ViewsTestBase { 25 class ToolbarActionsBarBubbleViewsTest : public views::ViewsTestBase {
26 public:
27 views::View* TestCreateExtraView() {
28 return (bubble_) ? bubble_->CreateExtraView() : nullptr;
29 }
30
22 protected: 31 protected:
23 ToolbarActionsBarBubbleViewsTest() {} 32 ToolbarActionsBarBubbleViewsTest() {}
24 ~ToolbarActionsBarBubbleViewsTest() override {} 33 ~ToolbarActionsBarBubbleViewsTest() override {}
25 34
26 void TearDown() override { 35 void TearDown() override {
27 anchor_widget_.reset(); 36 anchor_widget_.reset();
28 views::ViewsTestBase::TearDown(); 37 views::ViewsTestBase::TearDown();
29 } 38 }
30 39
31 std::unique_ptr<views::Widget> CreateAnchorWidget() { 40 std::unique_ptr<views::Widget> CreateAnchorWidget() {
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 ShowBubble(&delegate); 262 ShowBubble(&delegate);
254 views::test::TestWidgetObserver bubble_observer(bubble_widget()); 263 views::test::TestWidgetObserver bubble_observer(bubble_widget());
255 264
256 EXPECT_FALSE(delegate.close_action()); 265 EXPECT_FALSE(delegate.close_action());
257 // Activate another widget. The bubble shouldn't close. 266 // Activate another widget. The bubble shouldn't close.
258 anchor_widget()->Activate(); 267 anchor_widget()->Activate();
259 base::RunLoop().RunUntilIdle(); 268 base::RunLoop().RunUntilIdle();
260 EXPECT_FALSE(delegate.close_action()); 269 EXPECT_FALSE(delegate.close_action());
261 CloseBubble(); 270 CloseBubble();
262 } 271 }
272
273 TEST_F(ToolbarActionsBarBubbleViewsTest, TestCreateExtraViewEmpty) {
274 TestToolbarActionsBarBubbleDelegate delegate(HeadingString(), BodyString(),
275 ActionString());
276 ToolbarActionsBarBubbleDelegate::ExtraViewInfo extra_view_info;
277
278 ShowBubble(&delegate);
279
280 views::View* extra_view = TestCreateExtraView();
281 EXPECT_FALSE(extra_view);
282 CloseBubble();
283 }
284
285 TEST_F(ToolbarActionsBarBubbleViewsTest, TestCreateExtraViewIconOnly) {
286 TestToolbarActionsBarBubbleDelegate delegate(HeadingString(), BodyString(),
287 ActionString());
288 ToolbarActionsBarBubbleDelegate::ExtraViewInfo extra_view_info;
289
290 extra_view_info.resource_id = IDR_OMNIBOX_HTTPS_POLICY_WARNING;
291 delegate.set_extra_view_info(extra_view_info);
292 ShowBubble(&delegate);
293 std::unique_ptr<views::View> extra_view(TestCreateExtraView());
catmullings 2016/09/22 00:00:11 Should I wrap this in a unique_ptr to ensure the v
Devlin 2016/09/26 20:13:09 Wrapping the result is good. You could change the
294 EXPECT_TRUE(extra_view);
295 EXPECT_EQ("ImageView", std::string(extra_view->GetClassName()));
catmullings 2016/09/22 00:00:11 Is this a sufficient way to check? The same questi
Devlin 2016/09/26 20:13:09 You should be able to use AreImagesEqual() to comp
catmullings 2016/10/06 18:24:19 Done.
296 CloseBubble();
297 }
298
299 TEST_F(ToolbarActionsBarBubbleViewsTest, TestCreateExtraViewLinkedTextOnly) {
300 TestToolbarActionsBarBubbleDelegate delegate(HeadingString(), BodyString(),
301 ActionString());
302 ToolbarActionsBarBubbleDelegate::ExtraViewInfo extra_view_info_linked_text;
303
304 extra_view_info_linked_text.text =
305 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSTALLED_BY_ADMIN);
306 extra_view_info_linked_text.is_text_linked = true;
307 delegate.set_extra_view_info(extra_view_info_linked_text);
308
309 ShowBubble(&delegate);
310
311 views::View* extra_view = TestCreateExtraView();
312 EXPECT_TRUE(extra_view);
313 EXPECT_EQ("Link", std::string(extra_view->GetClassName()));
314 CloseBubble();
315 }
316
317 TEST_F(ToolbarActionsBarBubbleViewsTest, TestCreateExtraViewLabelTextOnly) {
318 TestToolbarActionsBarBubbleDelegate delegate(HeadingString(), BodyString(),
319 ActionString());
320 ToolbarActionsBarBubbleDelegate::ExtraViewInfo extra_view_info;
321
322 extra_view_info.text =
323 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSTALLED_BY_ADMIN);
324 extra_view_info.is_text_linked = false;
325 delegate.set_extra_view_info(extra_view_info);
326
327 ShowBubble(&delegate);
328
329 views::View* extra_view = TestCreateExtraView();
330 EXPECT_TRUE(extra_view);
331 EXPECT_EQ("Label", std::string(extra_view->GetClassName()));
332 CloseBubble();
333 }
334
335 TEST_F(ToolbarActionsBarBubbleViewsTest, TestCreateExtraViewImageAndText) {
336 TestToolbarActionsBarBubbleDelegate delegate(HeadingString(), BodyString(),
337 ActionString());
338 ToolbarActionsBarBubbleDelegate::ExtraViewInfo extra_view_info;
339 extra_view_info.resource_id = IDR_OMNIBOX_HTTPS_POLICY_WARNING;
340 extra_view_info.text =
341 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSTALLED_BY_ADMIN);
342 extra_view_info.is_text_linked = false;
343 delegate.set_extra_view_info(extra_view_info);
344
345 ShowBubble(&delegate);
346
347 views::View* extra_view = TestCreateExtraView();
348 EXPECT_TRUE(extra_view);
349 EXPECT_EQ("View", std::string(extra_view->GetClassName()));
350 EXPECT_EQ(2, extra_view->child_count());
351 CloseBubble();
352 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698