Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: content/browser/frame_host/render_frame_host_impl_browsertest.cc

Issue 860393004: Expose whether a frame is focused to the browser process (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: compilation fix on Android/Mac Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
Charlie Reis 2015/01/22 17:46:04 2015
mlamouri (slow - plz ping) 2015/01/22 18:09:40 Done.
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 "content/public/browser/render_frame_host.h"
6 #include "content/public/browser/web_contents.h"
7 #include "content/public/test/content_browser_test.h"
8 #include "content/public/test/content_browser_test_utils.h"
9 #include "content/public/test/test_utils.h"
10 #include "content/shell/browser/shell.h"
11
12 namespace content {
13
14 using RenderFrameHostImplBrowserTest = ContentBrowserTest;
15
16 // Test that when creating a new window, the main frame is correctly focused.
17 IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IsFocused_AtLoad) {
18 EXPECT_TRUE(
19 NavigateToURL(shell(), GetTestUrl("render_frame_host", "focus.html")));
20
21 // The main frame should be the focused frame according to WebContents.
22 WebContents* web_contents = shell()->web_contents();
23 EXPECT_EQ(web_contents->GetMainFrame(), web_contents->GetFocusedFrame());
24
25 // The WebContents' focused frame should be actually focused.
26 EXPECT_TRUE(web_contents->GetFocusedFrame()->IsFocused());
27 }
28
29 // Test that if the content changes the focused frame, it is correctly exposed.
30 IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IsFocused_Change) {
31 EXPECT_TRUE(
32 NavigateToURL(shell(), GetTestUrl("render_frame_host", "focus.html")));
33
34 WebContents* web_contents = shell()->web_contents();
35
36 std::string frames[2] = { "frame1", "frame2" };
37 for (const std::string& frame : frames) {
38 ExecuteScriptAndGetValue(
39 web_contents->GetMainFrame(), "focus" + frame + "()");
40 EXPECT_NE(web_contents->GetMainFrame(), web_contents->GetFocusedFrame());
41
42 // The WebContents' focused frame should be actually focused.
43 EXPECT_TRUE(web_contents->GetFocusedFrame()->IsFocused());
44
45 EXPECT_EQ(frame, web_contents->GetFocusedFrame()->GetFrameName());
46 }
47 }
48
49 // Test that even if the frame is focused in the frame tree but its
50 // RenderWidgetHost is not focused, it is not considered as focused.
51 IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IsFocused_Widget) {
52 EXPECT_TRUE(
53 NavigateToURL(shell(), GetTestUrl("render_frame_host", "focus.html")));
54 WebContents* web_contents = shell()->web_contents();
55
56 // A second window is created and navigated. It takes the focus.
57 Shell* new_shell = CreateBrowser();
58 EXPECT_TRUE(
59 NavigateToURL(new_shell, GetTestUrl("render_frame_host", "focus.html")));
60 EXPECT_TRUE(new_shell->web_contents()->GetMainFrame()->IsFocused());
61
62 // The first opened window is no longer focused. The main frame is still the
63 // focused frame in the frame tree but as far as RFH is concerned, the frame
64 // is not focused.
65 EXPECT_EQ(web_contents->GetMainFrame(), web_contents->GetFocusedFrame());
66 EXPECT_FALSE(web_contents->GetMainFrame()->IsFocused());
67 }
68
69 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698