| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/location_bar/star_view.h" | 5 #include "chrome/browser/ui/views/location_bar/star_view.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 star_view->OnMousePressed(pressed_event); | 60 star_view->OnMousePressed(pressed_event); |
| 61 // Hide the bubble manually. In the browser this would normally happen during | 61 // Hide the bubble manually. In the browser this would normally happen during |
| 62 // the event processing. | 62 // the event processing. |
| 63 BookmarkBubbleView::Hide(); | 63 BookmarkBubbleView::Hide(); |
| 64 base::MessageLoop::current()->RunUntilIdle(); | 64 base::MessageLoop::current()->RunUntilIdle(); |
| 65 EXPECT_FALSE(BookmarkBubbleView::bookmark_bubble()); | 65 EXPECT_FALSE(BookmarkBubbleView::bookmark_bubble()); |
| 66 star_view->OnMouseReleased(released_event); | 66 star_view->OnMouseReleased(released_event); |
| 67 EXPECT_FALSE(BookmarkBubbleView::bookmark_bubble()); | 67 EXPECT_FALSE(BookmarkBubbleView::bookmark_bubble()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 #if defined(OS_WIN) | |
| 71 | |
| 72 class StarViewTestNoDWM : public InProcessBrowserTest { | |
| 73 public: | |
| 74 StarViewTestNoDWM() {} | |
| 75 | |
| 76 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 77 command_line->AppendSwitch(switches::kDisableDwmComposition); | |
| 78 } | |
| 79 }; | |
| 80 | |
| 81 BOOL CALLBACK EnumerateChildren(HWND hwnd, LPARAM l_param) { | |
| 82 HWND* child = reinterpret_cast<HWND*>(l_param); | |
| 83 *child = hwnd; | |
| 84 // The first child window is the plugin, then its children. So stop | |
| 85 // enumerating after the first callback. | |
| 86 return FALSE; | |
| 87 } | |
| 88 | |
| 89 // Ensure that UIs like the star window, user profiler picker, omnibox | |
| 90 // popup and bookmark editor are always over a windowed NPAPI plugin even if | |
| 91 // kDisableDwmComposition is used. | |
| 92 // flaky: http://crbug.com/406631 | |
| 93 IN_PROC_BROWSER_TEST_F(StarViewTestNoDWM, DISABLED_WindowedNPAPIPluginHidden) { | |
| 94 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize, | |
| 95 true); | |
| 96 | |
| 97 // First switch to a new tab and back, to also test a scenario where we | |
| 98 // stopped watching the root window. | |
| 99 ui_test_utils::NavigateToURLWithDisposition( | |
| 100 browser(), GURL("about:blank"), NEW_FOREGROUND_TAB, | |
| 101 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 102 browser()->tab_strip_model()->ActivateTabAt(0, true); | |
| 103 | |
| 104 // First load the page and wait for the NPAPI plugin's window to display. | |
| 105 base::string16 expected_title(base::ASCIIToUTF16("ready")); | |
| 106 content::WebContents* tab = | |
| 107 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 108 content::TitleWatcher title_watcher(tab, expected_title); | |
| 109 | |
| 110 GURL url = ui_test_utils::GetTestUrl( | |
| 111 base::FilePath().AppendASCII("printing"), | |
| 112 base::FilePath().AppendASCII("npapi_plugin.html")); | |
| 113 ui_test_utils::NavigateToURL(browser(), url); | |
| 114 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | |
| 115 | |
| 116 // Now get the region of the plugin before the star view is shown. | |
| 117 HWND hwnd = tab->GetNativeView()->GetHost()->GetAcceleratedWidget(); | |
| 118 HWND child = NULL; | |
| 119 EnumChildWindows(hwnd, EnumerateChildren,reinterpret_cast<LPARAM>(&child)); | |
| 120 | |
| 121 RECT region_before, region_after; | |
| 122 int result = GetWindowRgnBox(child, ®ion_before); | |
| 123 ASSERT_EQ(result, SIMPLEREGION); | |
| 124 | |
| 125 // Now show the star view | |
| 126 BrowserView* browser_view = reinterpret_cast<BrowserView*>( | |
| 127 browser()->window()); | |
| 128 views::ImageView* star_view = | |
| 129 browser_view->GetToolbarView()->location_bar()->star_view(); | |
| 130 | |
| 131 scoped_refptr<content::MessageLoopRunner> runner = | |
| 132 new content::MessageLoopRunner; | |
| 133 // Verify that clicking once shows the bookmark bubble. | |
| 134 ui_test_utils::MoveMouseToCenterAndPress( | |
| 135 star_view, | |
| 136 ui_controls::LEFT, | |
| 137 ui_controls::DOWN | ui_controls::UP, | |
| 138 runner->QuitClosure()); | |
| 139 runner->Run(); | |
| 140 | |
| 141 EXPECT_TRUE(BookmarkBubbleView::bookmark_bubble()); | |
| 142 | |
| 143 result = GetWindowRgnBox(child, ®ion_after); | |
| 144 if (result == NULLREGION) { | |
| 145 // Depending on the browser window size, the plugin could be full covered. | |
| 146 return; | |
| 147 } | |
| 148 | |
| 149 if (result == COMPLEXREGION) { | |
| 150 // Complex region, by definition not equal to the initial region. | |
| 151 return; | |
| 152 } | |
| 153 | |
| 154 ASSERT_EQ(result, SIMPLEREGION); | |
| 155 bool rects_equal = | |
| 156 region_before.left == region_after.left && | |
| 157 region_before.top == region_after.top && | |
| 158 region_before.right == region_after.right && | |
| 159 region_before.bottom == region_after.bottom; | |
| 160 ASSERT_FALSE(rects_equal); | |
| 161 } | |
| 162 | |
| 163 #endif | |
| 164 | |
| 165 } // namespace | 70 } // namespace |
| OLD | NEW |