1 // Copyright (c) 2014 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 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
6 
7 #include "build/build_config.h"
8 #include "chrome/browser/ui/views/frame/browser_view.h"
9 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
10 #include "chrome/browser/ui/views/page_action/page_action_icon_view.h"
11 #include "chrome/browser/ui/views/page_info/page_info_bubble_view.h"
12 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
13 #include "chrome/test/base/in_process_browser_test.h"
14 #include "chrome/test/base/interactive_test_utils.h"
15 #include "content/public/test/browser_test.h"
16 #include "content/public/test/test_utils.h"
17 
18 namespace {
19 
20 class LocationIconViewTest : public InProcessBrowserTest {
21  public:
22   LocationIconViewTest() = default;
23   ~LocationIconViewTest() override = default;
24 
25  private:
26   DISALLOW_COPY_AND_ASSIGN(LocationIconViewTest);
27 };
28 
29 // Verify that clicking the location icon a second time hides the bubble.
IN_PROC_BROWSER_TEST_F(LocationIconViewTest,HideOnSecondClick)30 IN_PROC_BROWSER_TEST_F(LocationIconViewTest, HideOnSecondClick) {
31   BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
32   views::View* location_icon_view =
33       browser_view->toolbar()->location_bar()->location_icon_view();
34   ASSERT_TRUE(location_icon_view);
35 
36   // Verify that clicking once shows the location icon bubble.
37   scoped_refptr<content::MessageLoopRunner> runner1 =
38       new content::MessageLoopRunner;
39   ui_test_utils::MoveMouseToCenterAndPress(
40       location_icon_view, ui_controls::LEFT,
41       ui_controls::DOWN | ui_controls::UP, runner1->QuitClosure());
42   runner1->Run();
43 
44   EXPECT_EQ(PageInfoBubbleView::BUBBLE_PAGE_INFO,
45             PageInfoBubbleView::GetShownBubbleType());
46 
47   // Verify that clicking again doesn't reshow it.
48   scoped_refptr<content::MessageLoopRunner> runner2 =
49       new content::MessageLoopRunner;
50   ui_test_utils::MoveMouseToCenterAndPress(
51       location_icon_view, ui_controls::LEFT,
52       ui_controls::DOWN | ui_controls::UP, runner2->QuitClosure());
53   runner2->Run();
54 
55   EXPECT_EQ(PageInfoBubbleView::BUBBLE_NONE,
56             PageInfoBubbleView::GetShownBubbleType());
57 }
58 
59 #if defined(OS_MAC)
60 // TODO(jongkwon.lee): https://crbug.com/825834 NativeWidgetMac::Deactivate is
61 // not implemented on Mac.
62 #define MAYBE_ActivateFirstInactiveBubbleForAccessibility \
63   DISABLED_ActivateFirstInactiveBubbleForAccessibility
64 #else
65 #define MAYBE_ActivateFirstInactiveBubbleForAccessibility \
66   ActivateFirstInactiveBubbleForAccessibility
67 #endif
IN_PROC_BROWSER_TEST_F(LocationIconViewTest,MAYBE_ActivateFirstInactiveBubbleForAccessibility)68 IN_PROC_BROWSER_TEST_F(LocationIconViewTest,
69                        MAYBE_ActivateFirstInactiveBubbleForAccessibility) {
70   BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
71   LocationBarView* location_bar_view = browser_view->GetLocationBarView();
72   EXPECT_FALSE(
73       location_bar_view->ActivateFirstInactiveBubbleForAccessibility());
74 
75   content::WebContents* web_contents =
76       browser()->tab_strip_model()->GetActiveWebContents();
77   browser_view->ShowTranslateBubble(
78       web_contents, translate::TRANSLATE_STEP_AFTER_TRANSLATE, "en", "fr",
79       translate::TranslateErrors::NONE, true);
80 
81   PageActionIconView* icon_view =
82       browser_view->toolbar_button_provider()
83           ->GetPageActionIconView(PageActionIconType::kTranslate);
84   ASSERT_TRUE(icon_view);
85   EXPECT_TRUE(icon_view->GetVisible());
86 
87   // Ensure the bubble's widget is visible, but inactive. Active widgets are
88   // focused by accessibility, so not of concern.
89   views::Widget* widget = icon_view->GetBubble()->GetWidget();
90   widget->Deactivate();
91   widget->ShowInactive();
92   EXPECT_TRUE(widget->IsVisible());
93   EXPECT_FALSE(widget->IsActive());
94 
95   EXPECT_TRUE(location_bar_view->ActivateFirstInactiveBubbleForAccessibility());
96 
97   // Ensure the bubble's widget refreshed appropriately.
98   EXPECT_TRUE(icon_view->GetVisible());
99   EXPECT_TRUE(widget->IsVisible());
100   EXPECT_TRUE(widget->IsActive());
101 }
102 
103 }  // namespace
104