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 "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 Loading... |
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 // This yields the UI thread to ensure that the real SetIsInert message |
| 10270 // handler runs, in order to guarantee that the update arrives at the |
| 10271 // renderer process before the script below. |
| 10272 { |
| 10273 base::RunLoop loop; |
| 10274 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 10275 loop.QuitClosure()); |
| 10276 loop.Run(); |
| 10277 } |
| 10278 |
| 10279 std::string focused_element; |
| 10280 |
| 10281 // Attempt to change focus in the inert subframe. This should fail. |
| 10282 // The setTimeout ensures that the inert bit can propagate before the |
| 10283 // test JS code runs. |
| 10284 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 10285 iframe_node, |
| 10286 "window.setTimeout(() => {text2.focus();" |
| 10287 "domAutomationController.send(document.activeElement.id);}, 0)", |
| 10288 &focused_element)); |
| 10289 EXPECT_EQ("", focused_element); |
| 10290 } |
| 10291 |
10190 } // namespace content | 10292 } // namespace content |
OLD | NEW |