star_view_browsertest.cc revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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. 4 5#include "chrome/browser/ui/views/location_bar/star_view.h" 6 7#include "base/command_line.h" 8#include "base/prefs/pref_service.h" 9#include "base/strings/utf_string_conversions.h" 10#include "chrome/browser/ui/tabs/tab_strip_model.h" 11#include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h" 12#include "chrome/browser/ui/views/frame/browser_view.h" 13#include "chrome/browser/ui/views/toolbar/toolbar_view.h" 14#include "chrome/common/pref_names.h" 15#include "chrome/test/base/interactive_test_utils.h" 16#include "chrome/test/base/in_process_browser_test.h" 17#include "chrome/test/base/ui_test_utils.h" 18#include "content/public/test/browser_test_utils.h" 19#include "content/public/test/test_utils.h" 20#include "ui/base/ui_base_switches.h" 21 22#if defined(OS_WIN) && defined(USE_AURA) 23#include "content/public/browser/web_contents_view.h" 24#include "ui/aura/root_window.h" 25#include "ui/aura/window.h" 26#endif 27 28namespace { 29 30typedef InProcessBrowserTest StarViewTest; 31 32// Verify that clicking the bookmark star a second time hides the bookmark 33// bubble. 34#if defined(OS_LINUX) && defined(USE_AURA) && !defined(OS_CHROMEOS) 35#define MAYBE_HideOnSecondClick DISABLED_HideOnSecondClick 36#else 37#define MAYBE_HideOnSecondClick HideOnSecondClick 38#endif 39IN_PROC_BROWSER_TEST_F(StarViewTest, MAYBE_HideOnSecondClick) { 40 BrowserView* browser_view = reinterpret_cast<BrowserView*>( 41 browser()->window()); 42 views::View* star_view = 43 browser_view->GetToolbarView()->location_bar()->star_view(); 44 45 ui::MouseEvent pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 46 ui::EF_LEFT_MOUSE_BUTTON); 47 ui::MouseEvent released_event(ui::ET_MOUSE_RELEASED, gfx::Point(), 48 gfx::Point(), ui::EF_LEFT_MOUSE_BUTTON); 49 50 // Verify that clicking once shows the bookmark bubble. 51 EXPECT_FALSE(BookmarkBubbleView::IsShowing()); 52 star_view->OnMousePressed(pressed_event); 53 EXPECT_FALSE(BookmarkBubbleView::IsShowing()); 54 star_view->OnMouseReleased(released_event); 55 EXPECT_TRUE(BookmarkBubbleView::IsShowing()); 56 57 // Verify that clicking again doesn't reshow it. 58 star_view->OnMousePressed(pressed_event); 59 // Hide the bubble manually. In the browser this would normally happen during 60 // the event processing. 61 BookmarkBubbleView::Hide(); 62 base::MessageLoop::current()->RunUntilIdle(); 63 EXPECT_FALSE(BookmarkBubbleView::IsShowing()); 64 star_view->OnMouseReleased(released_event); 65 EXPECT_FALSE(BookmarkBubbleView::IsShowing()); 66} 67 68#if defined(OS_WIN) && defined(USE_AURA) 69 70class StarViewTestNoDWM : public InProcessBrowserTest { 71 public: 72 StarViewTestNoDWM() {} 73 74 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 75 command_line->AppendSwitch(switches::kDisableDwmComposition); 76 } 77}; 78 79BOOL CALLBACK EnumerateChildren(HWND hwnd, LPARAM l_param) { 80 HWND* child = reinterpret_cast<HWND*>(l_param); 81 *child = hwnd; 82 // The first child window is the plugin, then its children. So stop 83 // enumerating after the first callback. 84 return FALSE; 85} 86 87// Ensure that UIs like the star window, user profiler picker, omnibox 88// popup and bookmark editor are always over a windowed NPAPI plugin even if 89// kDisableDwmComposition is used. 90IN_PROC_BROWSER_TEST_F(StarViewTestNoDWM, WindowedNPAPIPluginHidden) { 91 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize, 92 true); 93 94 // First switch to a new tab and back, to also test a scenario where we 95 // stopped watching the root window. 96 ui_test_utils::NavigateToURLWithDisposition( 97 browser(), GURL("about:blank"), NEW_FOREGROUND_TAB, 98 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 99 browser()->tab_strip_model()->ActivateTabAt(0, true); 100 101 // First load the page and wait for the NPAPI plugin's window to display. 102 base::string16 expected_title(ASCIIToUTF16("ready")); 103 content::WebContents* tab = 104 browser()->tab_strip_model()->GetActiveWebContents(); 105 content::TitleWatcher title_watcher(tab, expected_title); 106 107 GURL url = ui_test_utils::GetTestUrl( 108 base::FilePath().AppendASCII("printing"), 109 base::FilePath().AppendASCII("npapi_plugin.html")); 110 ui_test_utils::NavigateToURL(browser(), url); 111 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 112 113 // Now get the region of the plugin before the star view is shown. 114 HWND hwnd = tab->GetView()->GetNativeView()->GetDispatcher()->host()-> 115 GetAcceleratedWidget(); 116 HWND child = NULL; 117 EnumChildWindows(hwnd, EnumerateChildren,reinterpret_cast<LPARAM>(&child)); 118 119 RECT region_before, region_after; 120 int result = GetWindowRgnBox(child, ®ion_before); 121 ASSERT_EQ(result, SIMPLEREGION); 122 123 // Now show the star view 124 BrowserView* browser_view = reinterpret_cast<BrowserView*>( 125 browser()->window()); 126 views::ImageView* star_view = 127 browser_view->GetToolbarView()->location_bar()->star_view(); 128 129 scoped_refptr<content::MessageLoopRunner> runner = 130 new content::MessageLoopRunner; 131 // Verify that clicking once shows the bookmark bubble. 132 ui_test_utils::MoveMouseToCenterAndPress( 133 star_view, 134 ui_controls::LEFT, 135 ui_controls::DOWN | ui_controls::UP, 136 runner->QuitClosure()); 137 runner->Run(); 138 139 EXPECT_TRUE(BookmarkBubbleView::IsShowing()); 140 141 result = GetWindowRgnBox(child, ®ion_after); 142 if (result == NULLREGION) { 143 // Depending on the browser window size, the plugin could be full covered. 144 return; 145 } 146 147 if (result == COMPLEXREGION) { 148 // Complex region, by definition not equal to the initial region. 149 return; 150 } 151 152 ASSERT_EQ(result, SIMPLEREGION); 153 bool rects_equal = 154 region_before.left == region_after.left && 155 region_before.top == region_after.top && 156 region_before.right == region_after.right && 157 region_before.bottom == region_after.bottom; 158 ASSERT_FALSE(rects_equal); 159} 160 161#endif 162 163} // namespace 164