NaCl docs: add sanitizers to GSoC ideas
[chromium-blink-merge.git] / chrome / browser / chrome_plugin_interactive_test.cc
blob57347309c460470054e9c78c6271ae3f0a087966
1 // Copyright 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.
5 #include "base/files/file_util.h"
6 #include "base/memory/ref_counted.h"
7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/plugins/plugin_prefs.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_commands.h"
14 #include "chrome/browser/ui/find_bar/find_bar.h"
15 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
16 #include "chrome/browser/ui/find_bar/find_bar_host_unittest_util.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/common/pref_names.h"
19 #include "chrome/test/base/in_process_browser_test.h"
20 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/child_process_data.h"
23 #include "content/public/browser/plugin_service.h"
24 #include "content/public/browser/web_contents.h"
25 #include "content/public/common/content_constants.h"
26 #include "content/public/common/content_paths.h"
27 #include "content/public/common/process_type.h"
28 #include "content/public/common/webplugininfo.h"
29 #include "content/public/test/browser_test_utils.h"
30 #include "content/public/test/test_navigation_observer.h"
31 #include "content/public/test/test_utils.h"
33 #if defined(OS_WIN)
34 #include "ui/aura/window.h"
35 #include "ui/aura/window_tree_host.h"
36 #endif
38 #if defined(OS_WIN)
40 namespace {
42 BOOL CALLBACK EnumerateChildren(HWND hwnd, LPARAM l_param) {
43 HWND* child = reinterpret_cast<HWND*>(l_param);
44 *child = hwnd;
45 // The first child window is the plugin, then its children. So stop
46 // enumerating after the first callback.
47 return FALSE;
50 } // namespace
52 typedef InProcessBrowserTest ChromePluginTest;
54 // Test that if a background tab loads an NPAPI plugin, they are displayed after
55 // switching to that page. http://crbug.com/335900
56 // flaky: http://crbug.com/406631
57 IN_PROC_BROWSER_TEST_F(ChromePluginTest, DISABLED_WindowedNPAPIPluginHidden) {
58 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize,
59 true);
61 // First load the page in the background and wait for the NPAPI plugin's
62 // window to be created.
63 GURL url = ui_test_utils::GetTestUrl(
64 base::FilePath(),
65 base::FilePath().AppendASCII("windowed_npapi_plugin.html"));
67 ui_test_utils::NavigateToURLWithDisposition(
68 browser(), url, NEW_BACKGROUND_TAB,
69 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
71 // We create a third window just to trigger the second one to update its
72 // constrained window list. Normally this would be triggered by the status bar
73 // animation closing after the user middle clicked a link.
74 ui_test_utils::NavigateToURLWithDisposition(
75 browser(), GURL("about:blank"), NEW_BACKGROUND_TAB,
76 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
78 base::string16 expected_title(base::ASCIIToUTF16("created"));
79 content::WebContents* tab =
80 browser()->tab_strip_model()->GetWebContentsAt(1);
81 if (tab->GetTitle() != expected_title) {
82 content::TitleWatcher title_watcher(tab, expected_title);
83 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
86 // Now activate the tab and verify that the plugin painted.
87 browser()->tab_strip_model()->ActivateTabAt(1, true);
89 base::string16 expected_title2(base::ASCIIToUTF16("shown"));
90 content::TitleWatcher title_watcher2(tab, expected_title2);
91 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle());
93 HWND child = NULL;
94 HWND hwnd = tab->GetNativeView()->GetHost()->GetAcceleratedWidget();
95 EnumChildWindows(hwnd, EnumerateChildren,reinterpret_cast<LPARAM>(&child));
97 RECT region;
98 int result = GetWindowRgnBox(child, &region);
99 ASSERT_NE(result, NULLREGION);
102 typedef InProcessBrowserTest PrintPreviewTest;
104 // This test verifies that constrained windows aren't covered by windowed NPAPI
105 // plugins. The code which fixes this is in WebContentsViewAura::WindowObserver.
106 // flaky: http://crbug.com/406631
107 IN_PROC_BROWSER_TEST_F(PrintPreviewTest, DISABLED_WindowedNPAPIPluginHidden) {
108 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize,
109 true);
111 // First load the page and wait for the NPAPI plugin's window to display.
112 base::string16 expected_title(base::ASCIIToUTF16("ready"));
113 content::WebContents* tab =
114 browser()->tab_strip_model()->GetActiveWebContents();
115 content::TitleWatcher title_watcher(tab, expected_title);
117 GURL url = ui_test_utils::GetTestUrl(
118 base::FilePath().AppendASCII("printing"),
119 base::FilePath().AppendASCII("npapi_plugin.html"));
120 ui_test_utils::NavigateToURL(browser(), url);
122 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
124 // Now get the region of the plugin before and after the print preview is
125 // shown. They should be different.
126 HWND hwnd = tab->GetNativeView()->GetHost()->GetAcceleratedWidget();
127 HWND child = NULL;
128 EnumChildWindows(hwnd, EnumerateChildren,reinterpret_cast<LPARAM>(&child));
130 RECT region_before, region_after;
131 int result = GetWindowRgnBox(child, &region_before);
132 ASSERT_EQ(result, SIMPLEREGION);
134 // Now print preview.
135 content::TestNavigationObserver nav_observer(NULL);
136 nav_observer.StartWatchingNewWebContents();
137 chrome::ExecuteCommand(browser(), IDC_PRINT);
138 nav_observer.Wait();
139 nav_observer.StopWatchingNewWebContents();
141 result = GetWindowRgnBox(child, &region_after);
142 if (result == NULLREGION) {
143 // Depending on the browser window size, the plugin could be full covered.
144 return;
147 if (result == COMPLEXREGION) {
148 // Complex region, by definition not equal to the initial region.
149 return;
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);
161 typedef InProcessBrowserTest FindInPageControllerTest;
163 void EnsureFindBoxOpen(Browser* browser) {
164 chrome::ShowFindBar(browser);
165 gfx::Point position;
166 bool fully_visible = false;
167 FindBarTesting* find_bar =
168 browser->GetFindBarController()->find_bar()->GetFindBarTesting();
169 EXPECT_TRUE(find_bar->GetFindBarWindowInfo(&position, &fully_visible));
170 EXPECT_TRUE(fully_visible);
173 // Ensure that the find bar is always over a windowed NPAPI plugin.
174 // flaky: http://crbug.com/406631
175 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
176 DISABLED_WindowedNPAPIPluginHidden) {
177 chrome::DisableFindBarAnimationsDuringTesting(true);
178 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize,
179 true);
181 // First load the page and wait for the NPAPI plugin's window to display.
182 base::string16 expected_title(base::ASCIIToUTF16("ready"));
183 content::WebContents* tab =
184 browser()->tab_strip_model()->GetActiveWebContents();
185 content::TitleWatcher title_watcher(tab, expected_title);
187 GURL url = ui_test_utils::GetTestUrl(
188 base::FilePath().AppendASCII("printing"),
189 base::FilePath().AppendASCII("npapi_plugin.html"));
190 ui_test_utils::NavigateToURL(browser(), url);
192 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
194 // Now get the region of the plugin before the find bar is shown.
195 HWND hwnd = tab->GetNativeView()->GetHost()->GetAcceleratedWidget();
196 HWND child = NULL;
197 EnumChildWindows(hwnd, EnumerateChildren, reinterpret_cast<LPARAM>(&child));
199 RECT region_before, region_after;
200 int result = GetWindowRgnBox(child, &region_before);
201 ASSERT_EQ(result, SIMPLEREGION);
203 // Create a new tab and open the find bar there.
204 chrome::NewTab(browser());
205 browser()->tab_strip_model()->ActivateTabAt(1, true);
206 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
208 EnsureFindBoxOpen(browser());
210 // Now switch back to the original tab with the plugin and show the find bar.
211 browser()->tab_strip_model()->ActivateTabAt(0, true);
212 EnsureFindBoxOpen(browser());
214 result = GetWindowRgnBox(child, &region_after);
215 if (result == NULLREGION) {
216 // Depending on the browser window size, the plugin could be full covered.
217 return;
220 if (result == COMPLEXREGION) {
221 // Complex region, by definition not equal to the initial region.
222 return;
225 ASSERT_EQ(result, SIMPLEREGION);
226 bool rects_equal =
227 region_before.left == region_after.left &&
228 region_before.top == region_after.top &&
229 region_before.right == region_after.right &&
230 region_before.bottom == region_after.bottom;
231 ASSERT_FALSE(rects_equal);
234 #endif