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

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

Issue 1852903002: Create an interactive site-per-process browsertest class and move DocumentHasFocus there. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: thestig's comments Created 4 years, 8 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 | « chrome/test/BUILD.gn ('k') | content/public/test/browser_test_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4321 matching lines...) Expand 10 before | Expand all | Expand 10 after
4332 4332
4333 // Check document.activeElement in b.com subframe. It should point to 4333 // Check document.activeElement in b.com subframe. It should point to
4334 // <iframe> for the c.com frame. This is a tricky case where B needs to find 4334 // <iframe> for the c.com frame. This is a tricky case where B needs to find
4335 // out that focus changed from one remote frame to another (A to C). 4335 // out that focus changed from one remote frame to another (A to C).
4336 RenderFrameHost* child_rfh = child->current_frame_host(); 4336 RenderFrameHost* child_rfh = child->current_frame_host();
4337 verify_active_element_property(child_rfh, "tagName", "iframe"); 4337 verify_active_element_property(child_rfh, "tagName", "iframe");
4338 verify_active_element_property(child_rfh, "src", 4338 verify_active_element_property(child_rfh, "src",
4339 grandchild->current_url().spec()); 4339 grandchild->current_url().spec());
4340 } 4340 }
4341 4341
4342 // Check that document.hasFocus() works properly with out-of-process iframes.
4343 // The test builds a page with four cross-site frames and then focuses them one
4344 // by one, checking the value of document.hasFocus() in all frames. For any
4345 // given focused frame, document.hasFocus() should return true for that frame
4346 // and all its ancestor frames.
4347 // Disabled due to flakes; see https://crbug.com/559273.
4348 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DISABLED_DocumentHasFocus) {
4349 GURL main_url(embedded_test_server()->GetURL(
4350 "a.com", "/cross_site_iframe_factory.html?a(b(c),d)"));
4351 EXPECT_TRUE(NavigateToURL(shell(), main_url));
4352
4353 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
4354 ->GetFrameTree()
4355 ->root();
4356
4357 EXPECT_EQ(
4358 " Site A ------------ proxies for B C D\n"
4359 " |--Site B ------- proxies for A C D\n"
4360 " | +--Site C -- proxies for A B D\n"
4361 " +--Site D ------- proxies for A B C\n"
4362 "Where A = http://a.com/\n"
4363 " B = http://b.com/\n"
4364 " C = http://c.com/\n"
4365 " D = http://d.com/",
4366 DepictFrameTree(root));
4367
4368 FrameTreeNode* child1 = root->child_at(0);
4369 FrameTreeNode* child2 = root->child_at(1);
4370 FrameTreeNode* grandchild = root->child_at(0)->child_at(0);
4371
4372 // Helper function to check document.hasFocus() for a given frame.
4373 auto document_has_focus = [](FrameTreeNode* node) {
4374 bool hasFocus = false;
4375 EXPECT_TRUE(ExecuteScriptAndExtractBool(
4376 node->current_frame_host(),
4377 "window.domAutomationController.send(document.hasFocus())",
4378 &hasFocus));
4379 return hasFocus;
4380 };
4381
4382 // The main frame should be focused to start with.
4383 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame());
4384
4385 EXPECT_TRUE(document_has_focus(root));
4386 EXPECT_FALSE(document_has_focus(child1));
4387 EXPECT_FALSE(document_has_focus(grandchild));
4388 EXPECT_FALSE(document_has_focus(child2));
4389
4390 FocusFrame(child1);
4391 EXPECT_EQ(child1, root->frame_tree()->GetFocusedFrame());
4392
4393 EXPECT_TRUE(document_has_focus(root));
4394 EXPECT_TRUE(document_has_focus(child1));
4395 EXPECT_FALSE(document_has_focus(grandchild));
4396 EXPECT_FALSE(document_has_focus(child2));
4397
4398 FocusFrame(grandchild);
4399 EXPECT_EQ(grandchild, root->frame_tree()->GetFocusedFrame());
4400
4401 EXPECT_TRUE(document_has_focus(root));
4402 EXPECT_TRUE(document_has_focus(child1));
4403 EXPECT_TRUE(document_has_focus(grandchild));
4404 EXPECT_FALSE(document_has_focus(child2));
4405
4406 FocusFrame(child2);
4407 EXPECT_EQ(child2, root->frame_tree()->GetFocusedFrame());
4408
4409 EXPECT_TRUE(document_has_focus(root));
4410 EXPECT_FALSE(document_has_focus(child1));
4411 EXPECT_FALSE(document_has_focus(grandchild));
4412 EXPECT_TRUE(document_has_focus(child2));
4413 }
4414
4415 // Check that window.focus works for cross-process subframes. 4342 // Check that window.focus works for cross-process subframes.
4416 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, SubframeWindowFocus) { 4343 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, SubframeWindowFocus) {
4417 GURL main_url(embedded_test_server()->GetURL( 4344 GURL main_url(embedded_test_server()->GetURL(
4418 "a.com", "/cross_site_iframe_factory.html?a(b,c)")); 4345 "a.com", "/cross_site_iframe_factory.html?a(b,c)"));
4419 EXPECT_TRUE(NavigateToURL(shell(), main_url)); 4346 EXPECT_TRUE(NavigateToURL(shell(), main_url));
4420 4347
4421 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) 4348 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
4422 ->GetFrameTree() 4349 ->GetFrameTree()
4423 ->root(); 4350 ->root();
4424 4351
(...skipping 1867 matching lines...) Expand 10 before | Expand all | Expand 10 after
6292 EXPECT_EQ(b_url, root->current_url()); 6219 EXPECT_EQ(b_url, root->current_url());
6293 6220
6294 // Verify that the same RenderViewHost is preserved and that it is no longer 6221 // Verify that the same RenderViewHost is preserved and that it is no longer
6295 // in swapped out state. 6222 // in swapped out state.
6296 EXPECT_EQ(rvh, contents->GetFrameTree()->GetRenderViewHost( 6223 EXPECT_EQ(rvh, contents->GetFrameTree()->GetRenderViewHost(
6297 root->current_frame_host()->GetSiteInstance())); 6224 root->current_frame_host()->GetSiteInstance()));
6298 EXPECT_FALSE(rvh->is_swapped_out_); 6225 EXPECT_FALSE(rvh->is_swapped_out_);
6299 } 6226 }
6300 6227
6301 } // namespace content 6228 } // namespace content
OLDNEW
« no previous file with comments | « chrome/test/BUILD.gn ('k') | content/public/test/browser_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698