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

Side by Side Diff: chrome/browser/task_manager/task_manager_browsertest.cc

Issue 2857263003: Task Manager should listen to WebContentsObserver::RenderFrameCreated. (Closed)
Patch Set: Tweaked the comments as suggested in the CR feedback Created 3 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <stddef.h> 5 #include <stddef.h>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 25 matching lines...) Expand all
36 #include "chrome/test/base/ui_test_utils.h" 36 #include "chrome/test/base/ui_test_utils.h"
37 #include "components/infobars/core/confirm_infobar_delegate.h" 37 #include "components/infobars/core/confirm_infobar_delegate.h"
38 #include "components/infobars/core/infobar.h" 38 #include "components/infobars/core/infobar.h"
39 #include "content/public/browser/notification_service.h" 39 #include "content/public/browser/notification_service.h"
40 #include "content/public/browser/page_navigator.h" 40 #include "content/public/browser/page_navigator.h"
41 #include "content/public/browser/render_frame_host.h" 41 #include "content/public/browser/render_frame_host.h"
42 #include "content/public/common/content_features.h" 42 #include "content/public/common/content_features.h"
43 #include "content/public/common/content_switches.h" 43 #include "content/public/common/content_switches.h"
44 #include "content/public/test/browser_test_utils.h" 44 #include "content/public/test/browser_test_utils.h"
45 #include "content/public/test/content_browser_test_utils.h" 45 #include "content/public/test/content_browser_test_utils.h"
46 #include "content/public/test/test_navigation_observer.h"
46 #include "extensions/browser/extension_system.h" 47 #include "extensions/browser/extension_system.h"
47 #include "extensions/common/extension.h" 48 #include "extensions/common/extension.h"
48 #include "net/dns/mock_host_resolver.h" 49 #include "net/dns/mock_host_resolver.h"
49 #include "net/test/embedded_test_server/embedded_test_server.h" 50 #include "net/test/embedded_test_server/embedded_test_server.h"
50 #include "testing/gmock/include/gmock/gmock.h" 51 #include "testing/gmock/include/gmock/gmock.h"
51 #include "testing/gtest/include/gtest/gtest.h" 52 #include "testing/gtest/include/gtest/gtest.h"
52 #include "ui/base/l10n/l10n_util.h" 53 #include "ui/base/l10n/l10n_util.h"
53 #include "ui/base/page_transition_types.h" 54 #include "ui/base/page_transition_types.h"
55 #include "url/gurl.h"
54 56
55 using content::WebContents; 57 using content::WebContents;
56 using task_manager::browsertest_util::ColumnSpecifier; 58 using task_manager::browsertest_util::ColumnSpecifier;
57 using task_manager::browsertest_util::MatchAboutBlankTab; 59 using task_manager::browsertest_util::MatchAboutBlankTab;
58 using task_manager::browsertest_util::MatchAnyApp; 60 using task_manager::browsertest_util::MatchAnyApp;
59 using task_manager::browsertest_util::MatchAnyExtension; 61 using task_manager::browsertest_util::MatchAnyExtension;
60 using task_manager::browsertest_util::MatchAnySubframe; 62 using task_manager::browsertest_util::MatchAnySubframe;
61 using task_manager::browsertest_util::MatchAnyTab; 63 using task_manager::browsertest_util::MatchAnyTab;
62 using task_manager::browsertest_util::MatchAnyUtility; 64 using task_manager::browsertest_util::MatchAnyUtility;
63 using task_manager::browsertest_util::MatchApp; 65 using task_manager::browsertest_util::MatchApp;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 209 }
208 210
209 bool ShouldExpectSubframes() { 211 bool ShouldExpectSubframes() {
210 return content::AreAllSitesIsolatedForTesting(); 212 return content::AreAllSitesIsolatedForTesting();
211 } 213 }
212 214
213 private: 215 private:
214 DISALLOW_COPY_AND_ASSIGN(TaskManagerOOPIFBrowserTest); 216 DISALLOW_COPY_AND_ASSIGN(TaskManagerOOPIFBrowserTest);
215 }; 217 };
216 218
217 INSTANTIATE_TEST_CASE_P(, TaskManagerOOPIFBrowserTest, ::testing::Bool()); 219 INSTANTIATE_TEST_CASE_P(DefaultIsolation,
220 TaskManagerOOPIFBrowserTest,
221 ::testing::Values(false));
222 INSTANTIATE_TEST_CASE_P(SitePerProcess,
223 TaskManagerOOPIFBrowserTest,
224 ::testing::Values(true));
218 225
219 #if defined(OS_MACOSX) || defined(OS_LINUX) 226 #if defined(OS_MACOSX) || defined(OS_LINUX)
220 #define MAYBE_ShutdownWhileOpen DISABLED_ShutdownWhileOpen 227 #define MAYBE_ShutdownWhileOpen DISABLED_ShutdownWhileOpen
221 #else 228 #else
222 #define MAYBE_ShutdownWhileOpen ShutdownWhileOpen 229 #define MAYBE_ShutdownWhileOpen ShutdownWhileOpen
223 #endif 230 #endif
224 231
225 // Regression test for http://crbug.com/13361 232 // Regression test for http://crbug.com/13361
226 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ShutdownWhileOpen) { 233 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ShutdownWhileOpen) {
227 ShowTaskManager(); 234 ShowTaskManager();
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false); 789 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false);
783 ShowTaskManager(); // Task manager shown AFTER dev tools window. 790 ShowTaskManager(); // Task manager shown AFTER dev tools window.
784 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab())); 791 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
785 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab())); 792 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
786 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); 793 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
787 } 794 }
788 795
789 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, KillSubframe) { 796 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, KillSubframe) {
790 ShowTaskManager(); 797 ShowTaskManager();
791 798
799 content::TestNavigationObserver navigation_observer(
800 browser()->tab_strip_model()->GetActiveWebContents());
792 GURL main_url(embedded_test_server()->GetURL( 801 GURL main_url(embedded_test_server()->GetURL(
793 "/cross-site/a.com/iframe_cross_site.html")); 802 "/cross-site/a.com/iframe_cross_site.html"));
794 browser()->OpenURL(content::OpenURLParams(main_url, content::Referrer(), 803 browser()->OpenURL(content::OpenURLParams(main_url, content::Referrer(),
795 WindowOpenDisposition::CURRENT_TAB, 804 WindowOpenDisposition::CURRENT_TAB,
796 ui::PAGE_TRANSITION_TYPED, false)); 805 ui::PAGE_TRANSITION_TYPED, false));
797 806
798 ASSERT_NO_FATAL_FAILURE( 807 ASSERT_NO_FATAL_FAILURE(
799 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); 808 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
800 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); 809 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
801 810
811 GURL b_url;
802 if (!ShouldExpectSubframes()) { 812 if (!ShouldExpectSubframes()) {
803 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); 813 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
804 } else { 814 } else {
805 ASSERT_NO_FATAL_FAILURE( 815 ASSERT_NO_FATAL_FAILURE(
806 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/"))); 816 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
807 ASSERT_NO_FATAL_FAILURE( 817 ASSERT_NO_FATAL_FAILURE(
808 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); 818 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
809 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe())); 819 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
820
821 // Remember |b_url| to be able to later renavigate to the same URL without
822 // doing any process swaps (we want to avoid redirects that would happen
823 // when going through /cross-site/foo.com/..., because
824 // https://crbug.com/642958 wouldn't repro in presence of process swaps).
825 navigation_observer.Wait();
826 b_url = browser()
827 ->tab_strip_model()
828 ->GetActiveWebContents()
829 ->GetAllFrames()[1]
830 ->GetLastCommittedURL();
831 ASSERT_EQ(b_url.host(), "b.com"); // Sanity check of test code / setup.
832
810 int subframe_b = FindResourceIndex(MatchSubframe("http://b.com/")); 833 int subframe_b = FindResourceIndex(MatchSubframe("http://b.com/"));
811 ASSERT_NE(-1, subframe_b); 834 ASSERT_NE(-1, subframe_b);
812 ASSERT_NE(-1, model()->GetTabId(subframe_b)); 835 ASSERT_NE(-1, model()->GetTabId(subframe_b));
813
814 model()->Kill(subframe_b); 836 model()->Kill(subframe_b);
815 837
816 ASSERT_NO_FATAL_FAILURE( 838 ASSERT_NO_FATAL_FAILURE(
817 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/"))); 839 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
818 ASSERT_NO_FATAL_FAILURE( 840 ASSERT_NO_FATAL_FAILURE(
819 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); 841 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
820 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe())); 842 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
821 ASSERT_NO_FATAL_FAILURE( 843 ASSERT_NO_FATAL_FAILURE(
822 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); 844 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
823 } 845 }
824 846
825 HideTaskManager(); 847 HideTaskManager();
826 ShowTaskManager(); 848 ShowTaskManager();
827 849
828 if (!ShouldExpectSubframes()) { 850 if (!ShouldExpectSubframes()) {
829 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); 851 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
830 } else { 852 } else {
831 ASSERT_NO_FATAL_FAILURE( 853 ASSERT_NO_FATAL_FAILURE(
832 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/"))); 854 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
833 ASSERT_NO_FATAL_FAILURE( 855 ASSERT_NO_FATAL_FAILURE(
834 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); 856 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
835 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe())); 857 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
836 ASSERT_NO_FATAL_FAILURE( 858 ASSERT_NO_FATAL_FAILURE(
837 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); 859 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
860
861 // Reload the subframe and verify it has re-appeared in the task manager.
862 // This is a regression test for https://crbug.com/642958.
863 ASSERT_TRUE(content::ExecuteScript(
864 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(),
865 "document.getElementById('frame1').src = '" + b_url.spec() + "';"));
866 ASSERT_NO_FATAL_FAILURE(
867 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
868 ASSERT_NO_FATAL_FAILURE(
869 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
870 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
871 ASSERT_NO_FATAL_FAILURE(
872 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
838 } 873 }
839 } 874 }
840 875
841 // Tests what happens when a tab navigates to a site (a.com) that it previously 876 // Tests what happens when a tab navigates to a site (a.com) that it previously
842 // has a cross-process subframe into (b.com). 877 // has a cross-process subframe into (b.com).
843 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, NavigateToSubframeProcess) { 878 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, NavigateToSubframeProcess) {
844 ShowTaskManager(); 879 ShowTaskManager();
845 880
846 // Navigate the tab to a page on a.com with cross-process subframes to 881 // Navigate the tab to a page on a.com with cross-process subframes to
847 // b.com and c.com. 882 // b.com and c.com.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 } 973 }
939 974
940 // Tests what happens when a tab navigates a cross-frame iframe (to b.com) 975 // Tests what happens when a tab navigates a cross-frame iframe (to b.com)
941 // back to the site of the parent document (a.com). 976 // back to the site of the parent document (a.com).
942 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, 977 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest,
943 CrossSiteIframeBecomesSameSite) { 978 CrossSiteIframeBecomesSameSite) {
944 ShowTaskManager(); 979 ShowTaskManager();
945 980
946 // Navigate the tab to a page on a.com with cross-process subframes to 981 // Navigate the tab to a page on a.com with cross-process subframes to
947 // b.com and c.com. 982 // b.com and c.com.
983 content::TestNavigationObserver navigation_observer(
984 browser()->tab_strip_model()->GetActiveWebContents());
948 GURL a_dotcom(embedded_test_server()->GetURL( 985 GURL a_dotcom(embedded_test_server()->GetURL(
949 "/cross-site/a.com/iframe_cross_site.html")); 986 "/cross-site/a.com/iframe_cross_site.html"));
950 browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(), 987 browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(),
951 WindowOpenDisposition::CURRENT_TAB, 988 WindowOpenDisposition::CURRENT_TAB,
952 ui::PAGE_TRANSITION_TYPED, false)); 989 ui::PAGE_TRANSITION_TYPED, false));
953 990
954 ASSERT_NO_FATAL_FAILURE( 991 ASSERT_NO_FATAL_FAILURE(
955 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); 992 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
956 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); 993 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
957 994
958 if (!ShouldExpectSubframes()) { 995 if (!ShouldExpectSubframes()) {
959 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); 996 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
960 } else { 997 } else {
961 ASSERT_NO_FATAL_FAILURE( 998 ASSERT_NO_FATAL_FAILURE(
962 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/"))); 999 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
963 ASSERT_NO_FATAL_FAILURE( 1000 ASSERT_NO_FATAL_FAILURE(
964 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); 1001 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
965 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe())); 1002 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
966 } 1003 }
967 1004
968 // Navigate the b.com frame back to a.com. It is no longer a cross-site iframe 1005 // Navigate the b.com frame back to a.com. It is no longer a cross-site iframe
1006 navigation_observer.Wait();
969 ASSERT_TRUE(content::ExecuteScript( 1007 ASSERT_TRUE(content::ExecuteScript(
970 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), 1008 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(),
971 "document.getElementById('frame1').src='/title1.html';" 1009 R"( document.getElementById('frame1').src='/title1.html';
972 "document.title='aac';")); 1010 document.title='aac'; )"));
973 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac"))); 1011 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
974 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); 1012 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
975 if (!ShouldExpectSubframes()) { 1013 if (!ShouldExpectSubframes()) {
976 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); 1014 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
977 } else { 1015 } else {
978 ASSERT_NO_FATAL_FAILURE( 1016 ASSERT_NO_FATAL_FAILURE(
979 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/"))); 1017 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
980 ASSERT_NO_FATAL_FAILURE( 1018 ASSERT_NO_FATAL_FAILURE(
981 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); 1019 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
982 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe())); 1020 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 1168
1131 // Because the subframes for tab 2 are nested, their order is deterministic. 1169 // Because the subframes for tab 2 are nested, their order is deterministic.
1132 EXPECT_EQ("Subframe: http://a.com/", 1170 EXPECT_EQ("Subframe: http://a.com/",
1133 base::UTF16ToUTF8(model()->GetRowTitle(tab2_start + 1))); 1171 base::UTF16ToUTF8(model()->GetRowTitle(tab2_start + 1)));
1134 EXPECT_EQ("Subframe: http://c.com/", 1172 EXPECT_EQ("Subframe: http://c.com/",
1135 base::UTF16ToUTF8(model()->GetRowTitle(tab2_start + 2))); 1173 base::UTF16ToUTF8(model()->GetRowTitle(tab2_start + 2)));
1136 EXPECT_EQ("Subframe: http://b.com/", 1174 EXPECT_EQ("Subframe: http://b.com/",
1137 base::UTF16ToUTF8(model()->GetRowTitle(tab2_start + 3))); 1175 base::UTF16ToUTF8(model()->GetRowTitle(tab2_start + 3)));
1138 } 1176 }
1139 } 1177 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698