1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/task_manager/task_manager.h"
#include "base/files/file_path.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/devtools/devtools_window_testing.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_test_util.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/task_manager/resource_provider.h"
#include "chrome/browser/task_manager/task_manager_browsertest_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/panels/panel_manager.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/infobars/core/confirm_infobar_delegate.h"
#include "components/infobars/core/infobar.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test_utils.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/page_transition_types.h"
using content::WebContents;
using task_manager::browsertest_util::MatchAboutBlankTab;
using task_manager::browsertest_util::MatchAnyApp;
using task_manager::browsertest_util::MatchAnyExtension;
using task_manager::browsertest_util::MatchAnySubframe;
using task_manager::browsertest_util::MatchAnyTab;
using task_manager::browsertest_util::MatchApp;
using task_manager::browsertest_util::MatchExtension;
using task_manager::browsertest_util::MatchSubframe;
using task_manager::browsertest_util::MatchTab;
using task_manager::browsertest_util::WaitForTaskManagerRows;
namespace {
const base::FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html");
} // namespace
class TaskManagerBrowserTest : public ExtensionBrowserTest {
public:
TaskManagerBrowserTest() {}
~TaskManagerBrowserTest() override {}
TaskManagerModel* model() const {
return TaskManager::GetInstance()->model();
}
void ShowTaskManager() {
EXPECT_EQ(0, model()->ResourceCount());
// Show the task manager. This populates the model, and helps with debugging
// (you see the task manager).
chrome::ShowTaskManager(browser());
}
void HideTaskManager() {
// Hide the task manager, and wait for the model to be depopulated.
chrome::HideTaskManager();
base::RunLoop().RunUntilIdle(); // OnWindowClosed happens asynchronously.
EXPECT_EQ(0, model()->ResourceCount());
}
void Refresh() {
model()->Refresh();
}
int GetUpdateTimeMs() {
return TaskManagerModel::kUpdateTimeMs;
}
GURL GetTestURL() {
return ui_test_utils::GetTestUrl(
base::FilePath(base::FilePath::kCurrentDirectory),
base::FilePath(kTitle1File));
}
int FindResourceIndex(const base::string16& title) {
for (int i = 0; i < model()->ResourceCount(); ++i) {
if (title == model()->GetResourceTitle(i))
return i;
}
return -1;
}
protected:
void SetUpCommandLine(base::CommandLine* command_line) override {
ExtensionBrowserTest::SetUpCommandLine(command_line);
// Do not launch device discovery process.
command_line->AppendSwitch(switches::kDisableDeviceDiscoveryNotifications);
}
private:
DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserTest);
};
// Parameterized variant of TaskManagerBrowserTest which runs with/without
// --site-per-process, which enables out of process iframes (OOPIFs).
class TaskManagerOOPIFBrowserTest : public TaskManagerBrowserTest,
public testing::WithParamInterface<bool> {
public:
TaskManagerOOPIFBrowserTest() {}
protected:
void SetUpCommandLine(base::CommandLine* command_line) override {
TaskManagerBrowserTest::SetUpCommandLine(command_line);
if (GetParam())
command_line->AppendSwitch(switches::kSitePerProcess);
}
bool ShouldExpectSubframes() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kSitePerProcess);
}
private:
DISALLOW_COPY_AND_ASSIGN(TaskManagerOOPIFBrowserTest);
};
INSTANTIATE_TEST_CASE_P(, TaskManagerOOPIFBrowserTest, ::testing::Bool());
#if defined(OS_MACOSX) || defined(OS_LINUX)
#define MAYBE_ShutdownWhileOpen DISABLED_ShutdownWhileOpen
#else
#define MAYBE_ShutdownWhileOpen ShutdownWhileOpen
#endif
// Regression test for http://crbug.com/13361
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ShutdownWhileOpen) {
ShowTaskManager();
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) {
ShowTaskManager();
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
// Open a new tab and make sure the task manager notices it.
AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED);
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
// Close the tab and verify that we notice.
browser()->tab_strip_model()->CloseWebContentsAt(0,
TabStripModel::CLOSE_NONE);
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillTab) {
ShowTaskManager();
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
// Open a new tab and make sure the task manager notices it.
AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED);
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
// Killing the tab via task manager should remove the row.
int tab = FindResourceIndex(MatchTab("title1.html"));
ASSERT_NE(-1, tab);
ASSERT_TRUE(model()->GetResourceWebContents(tab) != NULL);
ASSERT_TRUE(model()->CanActivate(tab));
TaskManager::GetInstance()->KillProcess(tab);
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
// Tab should reappear in task manager upon reload.
chrome::Reload(browser(), CURRENT_TAB);
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
}
// Test for http://crbug.com/444722, which is not fixed yet.
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
DISABLED_NavigateAwayFromHungRenderer) {
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
ShowTaskManager();
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
GURL url1(embedded_test_server()->GetURL("/title2.html"));
GURL url3(embedded_test_server()->GetURL("a.com", "/iframe.html"));
// Open a new tab and make sure the task manager notices it.
AddTabAtIndex(0, url1, ui::PAGE_TRANSITION_TYPED);
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchTab("Title Of Awesomeness")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
WebContents* tab1 = browser()->tab_strip_model()->GetActiveWebContents();
// Initiate a navigation that will create a new WebContents in the same
// SiteInstace...
content::WebContentsAddedObserver web_contents_added_observer;
tab1->GetMainFrame()->ExecuteJavaScriptForTests(
base::ASCIIToUTF16("window.open('title3.html', '_blank');"));
// ... then immediately hang the renderer so that title3.html can't load.
tab1->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("while(1);"));
// Blocks until a new WebContents appears.
WebContents* tab2 = web_contents_added_observer.GetWebContents();
// Make sure the new WebContents is in tab1's hung renderer process.
ASSERT_NE(nullptr, tab2);
ASSERT_NE(tab1, tab2);
ASSERT_EQ(tab1->GetMainFrame()->GetProcess(),
tab2->GetMainFrame()->GetProcess())
<< "New WebContents must be in the same process as the old WebContents, "
<< "so that the new tab doesn't finish loading (what this test is all "
<< "about)";
ASSERT_EQ(tab1->GetSiteInstance(), tab2->GetSiteInstance())
<< "New WebContents must initially be in the same site instance as the "
<< "old WebContents";
// Now navigate this tab to a different site. This should wind up in a
// different renderer process, so it should complete and show up in the task
// manager.
tab2->OpenURL(content::OpenURLParams(url3, content::Referrer(), CURRENT_TAB,
ui::PAGE_TRANSITION_TYPED, false));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticePanel) {
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
.AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
.AppendASCII("1.0.0.0")));
// Open a new panel to an extension url.
GURL url(
"chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html");
Panel* panel = PanelManager::GetInstance()->CreatePanel(
web_app::GenerateApplicationNameFromExtensionId(
last_loaded_extension_id()),
browser()->profile(),
url,
gfx::Rect(300, 400),
PanelManager::CREATE_AS_DOCKED);
// Make sure that a task manager model created after the panel shows the
// existence of the panel and the extension.
ShowTaskManager();
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
1,
MatchExtension(
"chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
"french_sentence.html")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
// Close the panel and verify that we notice.
panel->Close();
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
0,
MatchExtension(
"chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
"french_sentence.html")));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticePanelChanges) {
ShowTaskManager();
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
.AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
.AppendASCII("1.0.0.0")));
// Browser, the New Tab Page and Extension background page.
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
// Open a new panel to an extension url and make sure we notice that.
GURL url(
"chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html");
Panel* panel = PanelManager::GetInstance()->CreatePanel(
web_app::GenerateApplicationNameFromExtensionId(
last_loaded_extension_id()),
browser()->profile(),
url,
gfx::Rect(300, 400),
PanelManager::CREATE_AS_DOCKED);
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
1,
MatchExtension(
"chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
"french_sentence.html")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
// Close the panel and verify that we notice.
panel->Close();
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
0,
MatchExtension(
"chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
"french_sentence.html")));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
// Unload extension.
UnloadExtension(last_loaded_extension_id());
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
}
// Kills a process that has more than one task manager entry.
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillPanelViaExtensionResource) {
ShowTaskManager();
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good")
.AppendASCII("Extensions")
.AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
.AppendASCII("1.0.0.0")));
// Open a new panel to an extension url.
GURL url(
"chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
"french_sentence.html");
PanelManager::GetInstance()->CreatePanel(
web_app::GenerateApplicationNameFromExtensionId(
last_loaded_extension_id()),
browser()->profile(),
url,
gfx::Rect(300, 400),
PanelManager::CREATE_AS_DOCKED);
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
1,
MatchExtension(
"chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
"french_sentence.html")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
// Kill the process via the BACKGROUND PAGE (not the panel). Verify that both
// the background page and the panel go away from the task manager.
int background_page = FindResourceIndex(MatchExtension("My extension 1"));
ASSERT_NE(-1, background_page);
ASSERT_TRUE(model()->GetResourceWebContents(background_page) == NULL);
ASSERT_FALSE(model()->CanActivate(background_page));
TaskManager::GetInstance()->KillProcess(background_page);
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
}
// Kills a process that has more than one task manager entry. This test is the
// same as KillPanelViaExtensionResource except it does the kill via the other
// entry.
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillPanelViaPanelResource) {
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good")
.AppendASCII("Extensions")
.AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
.AppendASCII("1.0.0.0")));
// Open a new panel to an extension url.
GURL url(
"chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
"french_sentence.html");
PanelManager::GetInstance()->CreatePanel(
web_app::GenerateApplicationNameFromExtensionId(
last_loaded_extension_id()),
browser()->profile(),
url,
gfx::Rect(300, 400),
PanelManager::CREATE_AS_DOCKED);
ShowTaskManager();
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
1,
MatchExtension(
"chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
"french_sentence.html")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
int background_page = FindResourceIndex(MatchExtension("My extension 1"));
ASSERT_NE(-1, background_page);
ASSERT_TRUE(model()->GetResourceWebContents(background_page) == NULL);
ASSERT_FALSE(model()->CanActivate(background_page));
// Kill the process via the PANEL RESOURCE (not the background page). Verify
// that both the background page and the panel go away from the task manager.
int panel = FindResourceIndex(MatchExtension(
"chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
"french_sentence.html"));
ASSERT_NE(-1, panel);
ASSERT_TRUE(model()->GetResourceWebContents(panel) != NULL);
ASSERT_TRUE(model()->CanActivate(panel));
TaskManager::GetInstance()->KillProcess(panel);
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabChanges) {
ShowTaskManager();
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
.AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
.AppendASCII("1.0.0.0")));
// Browser, Extension background page, and the New Tab Page.
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
// Open a new tab to an extension URL. Afterwards, the third entry (background
// page) should be an extension resource whose title starts with "Extension:".
// The fourth entry (page.html) is also of type extension and has both a
// WebContents and an extension. The title should start with "Extension:".
GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html");
AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchExtension("Foobar")));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
int extension_tab = FindResourceIndex(MatchExtension("Foobar"));
ASSERT_NE(-1, extension_tab);
ASSERT_TRUE(model()->GetResourceWebContents(extension_tab) != NULL);
ASSERT_TRUE(model()->CanActivate(extension_tab));
int background_page = FindResourceIndex(MatchExtension("My extension 1"));
ASSERT_NE(-1, background_page);
ASSERT_TRUE(model()->GetResourceWebContents(background_page) == NULL);
ASSERT_FALSE(model()->CanActivate(background_page));
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTab) {
// With the task manager closed, open a new tab to an extension URL.
// Afterwards, when we open the task manager, the third entry (background
// page) should be an extension resource whose title starts with "Extension:".
// The fourth entry (page.html) is also of type extension and has both a
// WebContents and an extension. The title should start with "Extension:".
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good")
.AppendASCII("Extensions")
.AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
.AppendASCII("1.0.0.0")));
GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html");
AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
ShowTaskManager();
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchExtension("Foobar")));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
int extension_tab = FindResourceIndex(MatchExtension("Foobar"));
ASSERT_NE(-1, extension_tab);
ASSERT_TRUE(model()->GetResourceWebContents(extension_tab) != NULL);
ASSERT_TRUE(model()->CanActivate(extension_tab));
int background_page = FindResourceIndex(MatchExtension("My extension 1"));
ASSERT_NE(-1, background_page);
ASSERT_TRUE(model()->GetResourceWebContents(background_page) == NULL);
ASSERT_FALSE(model()->CanActivate(background_page));
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabChanges) {
ShowTaskManager();
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("packaged_app")));
ExtensionService* service = extensions::ExtensionSystem::Get(
browser()->profile())->extension_service();
const extensions::Extension* extension =
service->GetExtensionById(last_loaded_extension_id(), false);
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
// Open a new tab to the app's launch URL and make sure we notice that.
GURL url(extension->GetResourceURL("main.html"));
AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
// There should be 1 "App: " tab and the original new tab page.
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchApp("Packaged App Test")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
// Check that the third entry (main.html) is of type extension and has both
// a tab contents and an extension.
int app_tab = FindResourceIndex(MatchApp("Packaged App Test"));
ASSERT_NE(-1, app_tab);
ASSERT_TRUE(model()->GetResourceWebContents(app_tab) != NULL);
ASSERT_TRUE(model()->CanActivate(app_tab));
ASSERT_EQ(task_manager::Resource::EXTENSION,
model()->GetResourceType(app_tab));
ASSERT_EQ(2, browser()->tab_strip_model()->count());
// Unload extension to make sure the tab goes away.
UnloadExtension(last_loaded_extension_id());
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_EQ(1, browser()->tab_strip_model()->count());
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTab) {
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("packaged_app")));
ExtensionService* service = extensions::ExtensionSystem::Get(
browser()->profile())->extension_service();
const extensions::Extension* extension =
service->GetExtensionById(last_loaded_extension_id(), false);
// Open a new tab to the app's launch URL and make sure we notice that.
GURL url(extension->GetResourceURL("main.html"));
AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
ShowTaskManager();
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchApp("Packaged App Test")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
// Check that the third entry (main.html) is of type extension and has both
// a tab contents and an extension.
int app_tab = FindResourceIndex(MatchApp("Packaged App Test"));
ASSERT_NE(-1, app_tab);
ASSERT_TRUE(model()->GetResourceWebContents(app_tab) != NULL);
ASSERT_TRUE(model()->CanActivate(app_tab));
ASSERT_EQ(task_manager::Resource::EXTENSION,
model()->GetResourceType(app_tab));
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabChanges) {
ShowTaskManager();
// The app under test acts on URLs whose host is "localhost",
// so the URLs we navigate to must have host "localhost".
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL::Replacements replace_host;
std::string host_str("localhost"); // must stay in scope with replace_host
replace_host.SetHostStr(host_str);
GURL base_url = embedded_test_server()->GetURL(
"/extensions/api_test/app_process/");
base_url = base_url.ReplaceComponents(replace_host);
// Open a new tab to an app URL before the app is loaded.
GURL url(base_url.Resolve("path1/empty.html"));
content::WindowedNotificationObserver observer(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
observer.Wait();
// Check that the new entry's title starts with "Tab:".
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
// Load the hosted app and make sure it still starts with "Tab:",
// since it hasn't changed to an app process yet.
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("api_test").AppendASCII("app_process")));
// Force the TaskManager to query the title.
Refresh();
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
// Now reload and check that the last entry's title now starts with "App:".
ui_test_utils::NavigateToURL(browser(), url);
// Force the TaskManager to query the title.
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp("Unmodified")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
// Disable extension.
DisableExtension(last_loaded_extension_id());
// The hosted app should now show up as a normal "Tab: ".
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
// Reload the page.
ui_test_utils::NavigateToURL(browser(), url);
// No change expected.
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabAfterReload) {
// The app under test acts on URLs whose host is "localhost",
// so the URLs we navigate to must have host "localhost".
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL::Replacements replace_host;
std::string host_str("localhost"); // must stay in scope with replace_host
replace_host.SetHostStr(host_str);
GURL base_url =
embedded_test_server()->GetURL("/extensions/api_test/app_process/");
base_url = base_url.ReplaceComponents(replace_host);
// Open a new tab to an app URL before the app is loaded.
GURL url(base_url.Resolve("path1/empty.html"));
content::WindowedNotificationObserver observer(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
observer.Wait();
// Load the hosted app and make sure it still starts with "Tab:",
// since it hasn't changed to an app process yet.
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("api_test").AppendASCII("app_process")));
// Now reload, which should transition this tab to being an App.
ui_test_utils::NavigateToURL(browser(), url);
ShowTaskManager();
// The TaskManager should show this as an "App: "
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabBeforeReload) {
// The app under test acts on URLs whose host is "localhost",
// so the URLs we navigate to must have host "localhost".
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL::Replacements replace_host;
std::string host_str("localhost"); // must stay in scope with replace_host
replace_host.SetHostStr(host_str);
GURL base_url =
embedded_test_server()->GetURL("/extensions/api_test/app_process/");
base_url = base_url.ReplaceComponents(replace_host);
// Open a new tab to an app URL before the app is loaded.
GURL url(base_url.Resolve("path1/empty.html"));
content::WindowedNotificationObserver observer(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
observer.Wait();
// Load the hosted app and make sure it still starts with "Tab:",
// since it hasn't changed to an app process yet.
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("api_test").AppendASCII("app_process")));
ShowTaskManager();
// The TaskManager should show this as a "Tab: " because the page hasn't been
// reloaded since the hosted app was installed.
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
}
// Regression test for http://crbug.com/18693.
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ReloadExtension) {
ShowTaskManager();
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("common").AppendASCII("background_page")));
// Wait until we see the loaded extension in the task manager (the three
// resources are: the browser process, New Tab Page, and the extension).
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchExtension("background_page")));
// Reload the extension a few times and make sure our resource count doesn't
// increase.
std::string extension_id = last_loaded_extension_id();
for (int i = 1; i <= 5; i++) {
SCOPED_TRACE(testing::Message() << "Reloading extension for the " << i
<< "th time.");
ReloadExtension(extension_id);
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchExtension("background_page")));
}
}
// Crashy, http://crbug.com/42301.
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
DISABLED_PopulateWebCacheFields) {
ShowTaskManager();
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
// Open a new tab and make sure we notice that.
AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED);
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
// Check that we get some value for the cache columns.
DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(resource_count),
l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(resource_count),
l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(resource_count),
l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
}
// Checks that task manager counts a worker thread JS heap size.
// http://crbug.com/241066
// Flaky, http://crbug.com/259368
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DISABLED_WebWorkerJSHeapMemory) {
ui_test_utils::NavigateToURL(browser(), GetTestURL());
const int extra_timeout_ms = 500;
size_t minimal_heap_size = 2 * 1024 * 1024 * sizeof(void*);
std::string test_js = base::StringPrintf(
"var blob = new Blob([\n"
" 'mem = new Array(%lu);',\n"
" 'for (var i = 0; i < mem.length; i += 16) mem[i] = i;',\n"
" 'postMessage();']);\n"
"blobURL = window.URL.createObjectURL(blob);\n"
"worker = new Worker(blobURL);\n"
"// Give the task manager few seconds to poll for JS heap sizes.\n"
"worker.onmessage = setTimeout.bind(\n"
" this,\n"
" function () { window.domAutomationController.send(true); },\n"
" %d);\n"
"worker.postMessage();\n",
static_cast<unsigned long>(minimal_heap_size),
GetUpdateTimeMs() + extra_timeout_ms);
bool ok;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
browser()->tab_strip_model()->GetActiveWebContents(), test_js, &ok));
ASSERT_TRUE(ok);
int resource_index = TaskManager::GetInstance()->model()->ResourceCount() - 1;
size_t result;
ASSERT_TRUE(model()->GetV8Memory(resource_index, &result));
LOG(INFO) << "Got V8 Heap Size " << result << " bytes";
EXPECT_GE(result, minimal_heap_size);
ASSERT_TRUE(model()->GetV8MemoryUsed(resource_index, &result));
LOG(INFO) << "Got V8 Used Heap Size " << result << " bytes";
EXPECT_GE(result, minimal_heap_size);
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsNewDockedWindow) {
ShowTaskManager(); // Task manager shown BEFORE dev tools window.
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
DevToolsWindow* devtools =
DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true);
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsNewUndockedWindow) {
ShowTaskManager(); // Task manager shown BEFORE dev tools window.
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
DevToolsWindow* devtools =
DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false);
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsOldDockedWindow) {
DevToolsWindow* devtools =
DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true);
ShowTaskManager(); // Task manager shown AFTER dev tools window.
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsOldUnockedWindow) {
DevToolsWindow* devtools =
DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false);
ShowTaskManager(); // Task manager shown AFTER dev tools window.
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
}
IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, KillSubframe) {
ShowTaskManager();
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
content::SetupCrossSiteRedirector(embedded_test_server());
GURL main_url(embedded_test_server()->GetURL(
"/cross-site/a.com/iframe_cross_site.html"));
browser()->OpenURL(content::OpenURLParams(main_url, content::Referrer(),
CURRENT_TAB,
ui::PAGE_TRANSITION_TYPED, false));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
if (!ShouldExpectSubframes()) {
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
} else {
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
int subframe_b = FindResourceIndex(MatchSubframe("http://b.com/"));
ASSERT_NE(-1, subframe_b);
ASSERT_TRUE(model()->GetResourceWebContents(subframe_b) != NULL);
ASSERT_TRUE(model()->CanActivate(subframe_b));
TaskManager::GetInstance()->KillProcess(subframe_b);
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
}
HideTaskManager();
ShowTaskManager();
if (!ShouldExpectSubframes()) {
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
} else {
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
}
}
// Tests what happens when a tab navigates to a site (a.com) that it previously
// has a cross-process subframe into (b.com).
//
// TODO(nick): http://crbug.com/442532. Disabled because the second navigation
// hits an ASSERT(frame()) in WebLocalFrameImpl::loadRequest under --site-per-
// process.
IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest,
DISABLED_NavigateToSubframeProcess) {
ShowTaskManager();
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
content::SetupCrossSiteRedirector(embedded_test_server());
// Navigate the tab to a page on a.com with cross-process subframes to
// b.com and c.com.
GURL a_dotcom(embedded_test_server()->GetURL(
"/cross-site/a.com/iframe_cross_site.html"));
browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(),
CURRENT_TAB,
ui::PAGE_TRANSITION_TYPED, false));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
if (!ShouldExpectSubframes()) {
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
} else {
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
}
// Now navigate to a page on b.com with a simple (same-site) iframe.
// This should not show any subframe resources in the task manager.
GURL b_dotcom(
embedded_test_server()->GetURL("/cross-site/b.com/iframe.html"));
browser()->OpenURL(content::OpenURLParams(b_dotcom, content::Referrer(),
CURRENT_TAB,
ui::PAGE_TRANSITION_TYPED, false));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
HideTaskManager();
ShowTaskManager();
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
}
// TODO(nick): Fails flakily under OOPIF due to a ASSERT_NOT_REACHED in
// WebRemoteFrame, at least under debug OSX. http://crbug.com/437956
IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest,
DISABLED_NavigateToSiteWithSubframeToOriginalSite) {
ShowTaskManager();
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
content::SetupCrossSiteRedirector(embedded_test_server());
// Navigate to a page on b.com with a simple (same-site) iframe.
// This should not show any subframe resources in the task manager.
GURL b_dotcom(
embedded_test_server()->GetURL("/cross-site/b.com/iframe.html"));
browser()->OpenURL(content::OpenURLParams(b_dotcom, content::Referrer(),
CURRENT_TAB,
ui::PAGE_TRANSITION_TYPED, false));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
// Now navigate the tab to a page on a.com with cross-process subframes to
// b.com and c.com.
GURL a_dotcom(embedded_test_server()->GetURL(
"/cross-site/a.com/iframe_cross_site.html"));
browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(),
CURRENT_TAB,
ui::PAGE_TRANSITION_TYPED, false));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
if (!ShouldExpectSubframes()) {
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
} else {
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
}
HideTaskManager();
ShowTaskManager();
if (!ShouldExpectSubframes()) {
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
} else {
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
}
}
// Tests what happens when a tab navigates a cross-frame iframe (to b.com)
// back to the site of the parent document (a.com).
//
// TODO(nick): http://crbug.com/433012. Disabled because the second navigation
// crashes the renderer under --site-per-process during blink::Frame::detach().
IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest,
DISABLED_CrossSiteIframeBecomesSameSite) {
ShowTaskManager();
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
content::SetupCrossSiteRedirector(embedded_test_server());
// Navigate the tab to a page on a.com with cross-process subframes to
// b.com and c.com.
GURL a_dotcom(embedded_test_server()->GetURL(
"/cross-site/a.com/iframe_cross_site.html"));
browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(),
CURRENT_TAB,
ui::PAGE_TRANSITION_TYPED, false));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
if (!ShouldExpectSubframes()) {
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
} else {
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
}
// Navigate the b.com frame back to a.com. It is no longer a cross-site iframe
ASSERT_TRUE(content::ExecuteScript(
browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(),
"document.getElementById('frame1').src='/title1.html';"
"document.title='aac';"));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
if (!ShouldExpectSubframes()) {
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
} else {
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
}
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
HideTaskManager();
ShowTaskManager();
if (!ShouldExpectSubframes()) {
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
} else {
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
ASSERT_NO_FATAL_FAILURE(
WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
}
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
}
|