OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "content/browser/frame_host/frame_navigation_entry.h" | 9 #include "content/browser/frame_host/frame_navigation_entry.h" |
10 #include "content/browser/frame_host/frame_tree.h" | 10 #include "content/browser/frame_host/frame_tree.h" |
(...skipping 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1380 ASSERT_EQ(2U, entry->root_node()->children.size()); | 1380 ASSERT_EQ(2U, entry->root_node()->children.size()); |
1381 ASSERT_EQ(1U, entry->root_node()->children[1]->children.size()); | 1381 ASSERT_EQ(1U, entry->root_node()->children[1]->children.size()); |
1382 FrameNavigationEntry* frame_entry = | 1382 FrameNavigationEntry* frame_entry = |
1383 entry->root_node()->children[1]->children[0]->frame_entry.get(); | 1383 entry->root_node()->children[1]->children[0]->frame_entry.get(); |
1384 EXPECT_EQ(foo_url, frame_entry->url()); | 1384 EXPECT_EQ(foo_url, frame_entry->url()); |
1385 } else { | 1385 } else { |
1386 // There are no subframe FrameNavigationEntries by default. | 1386 // There are no subframe FrameNavigationEntries by default. |
1387 EXPECT_EQ(0U, entry->root_node()->children.size()); | 1387 EXPECT_EQ(0U, entry->root_node()->children.size()); |
1388 } | 1388 } |
1389 | 1389 |
1390 // TODO(creis): Add tests for another subframe on B, and for a subframe on A | 1390 // 4. Create a third iframe on the same site as the second. This ensures that |
1391 // within it. Both are currently broken. | 1391 // the commit type is correct even when the subframe process already exists. |
| 1392 { |
| 1393 LoadCommittedCapturer capturer(shell()->web_contents()); |
| 1394 std::string script = "var iframe = document.createElement('iframe');" |
| 1395 "iframe.src = '" + foo_url.spec() + "';" |
| 1396 "document.body.appendChild(iframe);"; |
| 1397 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| 1398 capturer.Wait(); |
| 1399 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 1400 } |
| 1401 |
| 1402 // The last committed NavigationEntry shouldn't have changed. |
| 1403 EXPECT_EQ(1, controller.GetEntryCount()); |
| 1404 entry = controller.GetLastCommittedEntry(); |
| 1405 EXPECT_EQ(main_url, entry->GetURL()); |
| 1406 root_entry = entry->root_node()->frame_entry.get(); |
| 1407 EXPECT_EQ(main_url, root_entry->url()); |
| 1408 |
| 1409 // Verify subframe entries if we're in --site-per-process mode. |
| 1410 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1411 switches::kSitePerProcess)) { |
| 1412 // The entry should now have 3 subframe FrameNavigationEntries. |
| 1413 ASSERT_EQ(3U, entry->root_node()->children.size()); |
| 1414 FrameNavigationEntry* frame_entry = |
| 1415 entry->root_node()->children[2]->frame_entry.get(); |
| 1416 EXPECT_EQ(foo_url, frame_entry->url()); |
| 1417 } else { |
| 1418 // There are no subframe FrameNavigationEntries by default. |
| 1419 EXPECT_EQ(0U, entry->root_node()->children.size()); |
| 1420 } |
| 1421 |
| 1422 // 5. Create a nested iframe on the original site (A-B-A). |
| 1423 { |
| 1424 LoadCommittedCapturer capturer(shell()->web_contents()); |
| 1425 std::string script = "var iframe = document.createElement('iframe');" |
| 1426 "iframe.src = '" + frame_url.spec() + "';" |
| 1427 "document.body.appendChild(iframe);"; |
| 1428 FrameTreeNode* child = root->child_at(2); |
| 1429 EXPECT_TRUE(content::ExecuteScript(child->current_frame_host(), script)); |
| 1430 capturer.Wait(); |
| 1431 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 1432 } |
| 1433 |
| 1434 // The last committed NavigationEntry shouldn't have changed. |
| 1435 EXPECT_EQ(1, controller.GetEntryCount()); |
| 1436 entry = controller.GetLastCommittedEntry(); |
| 1437 EXPECT_EQ(main_url, entry->GetURL()); |
| 1438 root_entry = entry->root_node()->frame_entry.get(); |
| 1439 EXPECT_EQ(main_url, root_entry->url()); |
| 1440 |
| 1441 // Verify subframe entries if we're in --site-per-process mode. |
| 1442 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1443 switches::kSitePerProcess)) { |
| 1444 // There should be a corresponding FrameNavigationEntry. |
| 1445 ASSERT_EQ(1U, entry->root_node()->children[2]->children.size()); |
| 1446 FrameNavigationEntry* frame_entry = |
| 1447 entry->root_node()->children[2]->children[0]->frame_entry.get(); |
| 1448 EXPECT_EQ(frame_url, frame_entry->url()); |
| 1449 } else { |
| 1450 // There are no subframe FrameNavigationEntries by default. |
| 1451 EXPECT_EQ(0U, entry->root_node()->children.size()); |
| 1452 } |
1392 | 1453 |
1393 // Check the end result of the frame tree. | 1454 // Check the end result of the frame tree. |
1394 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1455 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1395 switches::kSitePerProcess)) { | 1456 switches::kSitePerProcess)) { |
1396 FrameTreeVisualizer visualizer; | 1457 FrameTreeVisualizer visualizer; |
1397 EXPECT_EQ( | 1458 EXPECT_EQ( |
1398 " Site A ------------ proxies for B\n" | 1459 " Site A ------------ proxies for B\n" |
1399 " |--Site A ------- proxies for B\n" | 1460 " |--Site A ------- proxies for B\n" |
| 1461 " |--Site B ------- proxies for A\n" |
| 1462 " | +--Site B -- proxies for A\n" |
1400 " +--Site B ------- proxies for A\n" | 1463 " +--Site B ------- proxies for A\n" |
1401 " +--Site B -- proxies for A\n" | 1464 " +--Site A -- proxies for B\n" |
1402 "Where A = http://127.0.0.1/\n" | 1465 "Where A = http://127.0.0.1/\n" |
1403 " B = http://foo.com/", | 1466 " B = http://foo.com/", |
1404 visualizer.DepictFrameTree(root)); | 1467 visualizer.DepictFrameTree(root)); |
1405 } | 1468 } |
1406 } | 1469 } |
1407 | 1470 |
1408 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_NEW_SUBFRAME | 1471 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_NEW_SUBFRAME |
1409 // commits. | 1472 // commits. |
1410 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 1473 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
1411 FrameNavigationEntry_NewSubframe) { | 1474 FrameNavigationEntry_NewSubframe) { |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2221 EXPECT_EQ(original_url, capturer.all_params()[1].url); | 2284 EXPECT_EQ(original_url, capturer.all_params()[1].url); |
2222 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); | 2285 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); |
2223 } | 2286 } |
2224 | 2287 |
2225 // Make sure the renderer is still alive. | 2288 // Make sure the renderer is still alive. |
2226 EXPECT_TRUE( | 2289 EXPECT_TRUE( |
2227 ExecuteScript(shell()->web_contents(), "console.log('Success');")); | 2290 ExecuteScript(shell()->web_contents(), "console.log('Success');")); |
2228 } | 2291 } |
2229 | 2292 |
2230 } // namespace content | 2293 } // namespace content |
OLD | NEW |