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

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: kenrb review comment Created 5 years, 10 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
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 "content/browser/frame_host/render_frame_host_impl.h"
6 #include "content/public/browser/render_frame_host.h"
7 #include "content/public/browser/web_contents.h"
8 #include "content/public/test/content_browser_test.h"
9 #include "content/public/test/content_browser_test_utils.h"
10 #include "content/public/test/test_utils.h"
11 #include "content/shell/browser/shell.h"
12
13 namespace content {
14
15 namespace {
16
17 RenderFrameHostImpl* ToRFHI(RenderFrameHost* render_frame_host) {
18 return static_cast<RenderFrameHostImpl*>(render_frame_host);
19 }
20
21 } // anonymous namespace
22
23 using RenderFrameHostImplBrowserTest = ContentBrowserTest;
24
25 // Test that when creating a new window, the main frame is correctly focused.
26 IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IsFocused_AtLoad) {
27 EXPECT_TRUE(
28 NavigateToURL(shell(), GetTestUrl("render_frame_host", "focus.html")));
29
30 // The main frame should be focused.
31 WebContents* web_contents = shell()->web_contents();
32 EXPECT_TRUE(ToRFHI(web_contents->GetMainFrame())->IsFocused());
33 }
34
35 // Test that if the content changes the focused frame, it is correctly exposed.
36 IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IsFocused_Change) {
37 EXPECT_TRUE(
38 NavigateToURL(shell(), GetTestUrl("render_frame_host", "focus.html")));
39
40 WebContents* web_contents = shell()->web_contents();
41
42 std::string frames[2] = { "frame1", "frame2" };
43 for (const std::string& frame : frames) {
44 ExecuteScriptAndGetValue(
45 web_contents->GetMainFrame(), "focus" + frame + "()");
46
47 // The main frame is not the focused frame in the frame tree but the main
48 // frame is focused per RFHI rules because one of its descendant is focused.
49 EXPECT_NE(web_contents->GetMainFrame(), web_contents->GetFocusedFrame());
50 EXPECT_TRUE(ToRFHI(web_contents->GetFocusedFrame())->IsFocused());
51 EXPECT_TRUE(ToRFHI(web_contents->GetMainFrame())->IsFocused());
52 EXPECT_EQ(frame, web_contents->GetFocusedFrame()->GetFrameName());
53 }
54 }
55
56 // Test that even if the frame is focused in the frame tree but its
57 // RenderWidgetHost is not focused, it is not considered as focused.
58 IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, IsFocused_Widget) {
59 EXPECT_TRUE(
60 NavigateToURL(shell(), GetTestUrl("render_frame_host", "focus.html")));
61 WebContents* web_contents = shell()->web_contents();
62
63 // A second window is created and navigated. It takes the focus.
64 Shell* new_shell = CreateBrowser();
65 EXPECT_TRUE(
66 NavigateToURL(new_shell, GetTestUrl("render_frame_host", "focus.html")));
67 EXPECT_TRUE(ToRFHI(new_shell->web_contents()->GetMainFrame())->IsFocused());
68
69 // The first opened window is no longer focused. The main frame is still the
70 // focused frame in the frame tree but as far as RFH is concerned, the frame
71 // is not focused.
72 EXPECT_EQ(web_contents->GetMainFrame(), web_contents->GetFocusedFrame());
73
74 #if defined(OS_MACOSX)
75 EXPECT_TRUE(ToRFHI(web_contents->GetMainFrame())->IsFocused());
76 #else
77 EXPECT_FALSE(ToRFHI(web_contents->GetMainFrame())->IsFocused());
78 #endif
79 }
80
81 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698