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

Side by Side Diff: content/browser/site_per_process_browsertest.cc

Issue 2883033003: Propagate inert state to OOPIFs when a modal dialog is active (Closed)
Patch Set: Account for Inert attribute Created 3 years, 6 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
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 "content/browser/site_per_process_browsertest.h" 5 #include "content/browser/site_per_process_browsertest.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 10169 matching lines...) Expand 10 before | Expand all | Expand 10 after
10180 10180
10181 // Go back again. This should go to foo.com. 10181 // Go back again. This should go to foo.com.
10182 { 10182 {
10183 TestNavigationObserver back_observer(web_contents()); 10183 TestNavigationObserver back_observer(web_contents());
10184 web_contents()->GetController().GoBack(); 10184 web_contents()->GetController().GoBack();
10185 back_observer.Wait(); 10185 back_observer.Wait();
10186 } 10186 }
10187 EXPECT_EQ(foo_url, web_contents()->GetMainFrame()->GetLastCommittedURL()); 10187 EXPECT_EQ(foo_url, web_contents()->GetMainFrame()->GetLastCommittedURL());
10188 } 10188 }
10189 10189
10190 // Class to sniff incoming IPCs for FrameHostMsg_SetIsInert messages.
10191 class SetIsInertMessageFilter : public content::BrowserMessageFilter {
10192 public:
10193 SetIsInertMessageFilter()
10194 : content::BrowserMessageFilter(FrameMsgStart),
10195 message_loop_runner_(new content::MessageLoopRunner),
10196 msg_received_(false) {}
10197
10198 bool OnMessageReceived(const IPC::Message& message) override {
10199 IPC_BEGIN_MESSAGE_MAP(SetIsInertMessageFilter, message)
10200 IPC_MESSAGE_HANDLER(FrameHostMsg_SetIsInert, OnSetIsInert)
10201 IPC_END_MESSAGE_MAP()
10202 return false;
10203 }
10204
10205 bool is_inert() const { return is_inert_; }
10206
10207 void Wait() { message_loop_runner_->Run(); }
10208
10209 void Reset() {
10210 is_inert_ = false;
10211 message_loop_runner_ = new content::MessageLoopRunner;
10212 msg_received_ = false;
10213 }
10214
10215 private:
10216 ~SetIsInertMessageFilter() override {}
10217
10218 void OnSetIsInert(bool is_inert) {
10219 content::BrowserThread::PostTask(
10220 content::BrowserThread::UI, FROM_HERE,
10221 base::Bind(&SetIsInertMessageFilter::OnSetIsInertOnUI, this, is_inert));
10222 }
10223 void OnSetIsInertOnUI(bool is_inert) {
10224 is_inert_ = is_inert;
10225 if (!msg_received_) {
10226 msg_received_ = true;
10227 message_loop_runner_->Quit();
10228 }
10229 }
10230 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
10231 bool msg_received_;
10232 bool is_inert_;
10233 DISALLOW_COPY_AND_ASSIGN(SetIsInertMessageFilter);
10234 };
10235
10236 // Tests that when a frame contains a modal <dialog> element, out-of-process
10237 // iframe children cannot take focus, because they are inert.
10238 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossProcessInertSubframe) {
10239 GURL main_url(embedded_test_server()->GetURL(
10240 "a.com", "/cross_site_iframe_factory.html?a(b)"));
10241 EXPECT_TRUE(NavigateToURL(shell(), main_url));
10242
10243 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
10244 ->GetFrameTree()
10245 ->root();
10246 ASSERT_EQ(1U, root->child_count());
10247
10248 FrameTreeNode* iframe_node = root->child_at(0);
10249
10250 EXPECT_TRUE(ExecuteScript(
10251 iframe_node,
10252 "document.head.innerHTML = '';"
10253 "document.body.innerHTML = '<input id=\"text1\"> <input id=\"text2\">';"
10254 "text1.focus();"));
10255
10256 scoped_refptr<SetIsInertMessageFilter> filter = new SetIsInertMessageFilter();
10257 root->current_frame_host()->GetProcess()->AddFilter(filter.get());
10258
10259 // Add a <dialog> to the root frame and call showModal on it.
10260 EXPECT_TRUE(ExecuteScript(root,
10261 "let dialog = "
10262 "document.body.appendChild(document.createElement('"
10263 "dialog'));"
10264 "dialog.innerHTML = 'Modal dialog <input>';"
10265 "dialog.showModal();"));
10266 filter->Wait();
10267 EXPECT_TRUE(filter->is_inert());
10268
10269 std::string focused_element;
10270
10271 // Attempt to change focus in the inert subframe. This should fail.
10272 // The setTimeout ensures that the inert bit can propagate before the
dmazzoni 2017/06/05 17:32:42 Usually a setTimeout of anything other than 0 in a
kenrb 2017/06/05 19:25:50 I've tried something a bit different in patchset 1
10273 // test JS code runs.
10274 EXPECT_TRUE(ExecuteScriptAndExtractString(
10275 iframe_node,
10276 "window.setTimeout(() => {text2.focus();"
10277 "domAutomationController.send(document.activeElement.id);}, 100)",
10278 &focused_element));
10279 EXPECT_EQ("", focused_element);
10280 }
10281
10190 } // namespace content 10282 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_widget_host_view_child_frame.cc ('k') | content/common/frame_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698