1 // Copyright (c) 2012 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.
7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_window.h"
10 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
11 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h"
12 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
13 #include "chrome/browser/ui/gtk/gtk_util.h"
14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "ui/base/gtk/gtk_hig_constants.h"
17 class BubbleGtkTest
: public InProcessBrowserTest
,
18 public BubbleDelegateGtk
{
20 BubbleGtkTest() : browser_window_(NULL
) {
23 virtual ~BubbleGtkTest() {
26 // BubbleDelegateGtk implementation.
27 virtual void BubbleClosing(BubbleGtk
* bubble
,
28 bool closed_by_escape
) OVERRIDE
{
31 Profile
* GetProfile() {
32 return browser()->profile();
35 GtkWidget
* GetNativeBrowserWindow() {
37 browser_window_
= GTK_WIDGET(browser()->window()->GetNativeWindow());
38 return browser_window_
;
42 GtkWidget
* browser_window_
;
45 // Tests that we can adjust a bubble arrow so we can show a bubble without being
46 // clipped. This test verifies the following four issues:
47 // 1. Shows a bubble to the top-left corner and see its frame style always
48 // becomes ANCHOR_TOP_LEFT.
49 // 2. Shows a bubble to the top-right corner and see its frame style always
50 // becomes ANCHOR_TOP_RIGHT.
51 // 3. Shows a bubble to the bottom-left corner and see its frame style always
52 // becomes ANCHOR_BOTTOM_LEFT.
53 // 4. Shows a bubble to the top-left corner and see its frame style always
54 // becomes ANCHOR_BOTTOM_RIGHT.
55 IN_PROC_BROWSER_TEST_F(BubbleGtkTest
, ArrowLocation
) {
56 int width
= gdk_screen_get_width(gdk_screen_get_default());
57 int height
= gdk_screen_get_height(gdk_screen_get_default());
60 BubbleGtk::FrameStyle expected
;
62 {0, 0, BubbleGtk::ANCHOR_TOP_LEFT
},
63 {width
- 1, 0, BubbleGtk::ANCHOR_TOP_RIGHT
},
64 {0, height
- 1, BubbleGtk::ANCHOR_BOTTOM_LEFT
},
65 {width
- 1, height
- 1, BubbleGtk::ANCHOR_BOTTOM_RIGHT
},
67 static const BubbleGtk::FrameStyle kPreferredLocations
[] = {
68 BubbleGtk::ANCHOR_TOP_LEFT
,
69 BubbleGtk::ANCHOR_TOP_RIGHT
,
70 BubbleGtk::ANCHOR_BOTTOM_LEFT
,
71 BubbleGtk::ANCHOR_BOTTOM_RIGHT
,
74 GtkWidget
* anchor
= GetNativeBrowserWindow();
75 GtkThemeService
* theme_service
= GtkThemeService::GetFrom(GetProfile());
76 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(points
); ++i
) {
77 for (size_t j
= 0; j
< arraysize(kPreferredLocations
); ++j
) {
78 static const char kText
[] =
79 "Google's mission is to organize the world's information and make it"
80 " universally accessible and useful.";
81 GtkWidget
* label
= theme_service
->BuildLabel(kText
, ui::kGdkBlack
);
82 gfx::Rect
rect(points
[i
].x
, points
[i
].y
, 0, 0);
83 BubbleGtk
* bubble
= BubbleGtk::Show(anchor
,
86 kPreferredLocations
[j
],
87 BubbleGtk::MATCH_SYSTEM_THEME
|
88 BubbleGtk::POPUP_WINDOW
|
89 BubbleGtk::GRAB_INPUT
,
92 EXPECT_EQ(points
[i
].expected
, bubble
->actual_frame_style_
);
98 IN_PROC_BROWSER_TEST_F(BubbleGtkTest
, NoArrow
) {
99 int width
= gdk_screen_get_width(gdk_screen_get_default());
100 int height
= gdk_screen_get_height(gdk_screen_get_default());
103 BubbleGtk::FrameStyle expected
;
105 {0, 0, BubbleGtk::FLOAT_BELOW_RECT
},
106 {width
- 1, 0, BubbleGtk::FLOAT_BELOW_RECT
},
107 {0, height
- 1, BubbleGtk::CENTER_OVER_RECT
},
108 {width
- 1, height
- 1, BubbleGtk::CENTER_OVER_RECT
},
110 static const BubbleGtk::FrameStyle kPreferredLocations
[] = {
111 BubbleGtk::FLOAT_BELOW_RECT
,
112 BubbleGtk::CENTER_OVER_RECT
,
115 GtkWidget
* anchor
= GetNativeBrowserWindow();
116 GtkThemeService
* theme_service
= GtkThemeService::GetFrom(GetProfile());
117 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(points
); ++i
) {
118 for (size_t j
= 0; j
< arraysize(kPreferredLocations
); ++j
) {
119 static const char kText
[] =
120 "Google's mission is to organize the world's information and make it"
121 " universally accessible and useful.";
122 GtkWidget
* label
= theme_service
->BuildLabel(kText
, ui::kGdkBlack
);
123 gfx::Rect
rect(points
[i
].x
, points
[i
].y
, 0, 0);
124 BubbleGtk
* bubble
= BubbleGtk::Show(anchor
,
127 kPreferredLocations
[j
],
128 BubbleGtk::MATCH_SYSTEM_THEME
|
129 BubbleGtk::POPUP_WINDOW
|
130 BubbleGtk::GRAB_INPUT
,
133 EXPECT_EQ(points
[i
].expected
, bubble
->actual_frame_style_
);