BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / task_management / providers / web_contents / subframe_task_browsertest.cc
blob53df0796eb7c261fc9d848fbf2b341ef2532794e
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/strings/utf_string_conversions.h"
6 #include "chrome/browser/task_management/task_management_browsertest_util.h"
7 #include "chrome/grit/generated_resources.h"
8 #include "chrome/test/base/in_process_browser_test.h"
9 #include "chrome/test/base/ui_test_utils.h"
10 #include "content/public/test/browser_test_utils.h"
11 #include "content/public/test/test_utils.h"
12 #include "net/dns/mock_host_resolver.h"
13 #include "net/test/embedded_test_server/embedded_test_server.h"
14 #include "ui/base/l10n/l10n_util.h"
16 namespace task_management {
18 namespace {
20 // URL of a test page on a.com that has two cross-site iframes to b.com and
21 // c.com.
22 const char kCrossSitePageUrl[] = "/cross-site/a.com/iframe_cross_site.html";
24 // URL of a test page on a.com that has no cross-site iframes.
25 const char kSimplePageUrl[] = "/cross-site/a.com/title2.html";
27 base::string16 GetExpectedSubframeTitlePrefix() {
28 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_SUBFRAME_PREFIX,
29 base::string16());
32 base::string16 PrefixExpectedTabTitle(const char* title) {
33 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_TAB_PREFIX,
34 base::UTF8ToUTF16(title));
37 } // namespace
39 // A test for OOPIFs and how they show up in the task manager as
40 // SubframeTasks.
41 class SubframeTaskBrowserTest : public InProcessBrowserTest {
42 public:
43 SubframeTaskBrowserTest() {}
44 ~SubframeTaskBrowserTest() override {}
46 void SetUpCommandLine(base::CommandLine* command_line) override {
47 InProcessBrowserTest::SetUpCommandLine(command_line);
48 content::IsolateAllSitesForTesting(command_line);
51 void SetUpOnMainThread() override {
52 host_resolver()->AddRule("*", "127.0.0.1");
53 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
54 content::SetupCrossSiteRedirector(embedded_test_server());
57 void NavigateTo(const char* page_url) const {
58 ui_test_utils::NavigateToURL(browser(),
59 embedded_test_server()->GetURL(page_url));
62 private:
63 DISALLOW_COPY_AND_ASSIGN(SubframeTaskBrowserTest);
66 // Makes sure that, if sites are isolated, the task manager will show the
67 // expected SubframeTasks, and they will be shown as running on different
68 // processes as expected.
69 IN_PROC_BROWSER_TEST_F(SubframeTaskBrowserTest, TaskManagerShowsSubframeTasks) {
70 MockWebContentsTaskManager task_manager;
71 EXPECT_TRUE(task_manager.tasks().empty());
72 task_manager.StartObserving();
74 // Currently only the about:blank page.
75 ASSERT_EQ(1U, task_manager.tasks().size());
76 const Task* about_blank_task = task_manager.tasks().front();
77 EXPECT_EQ(Task::RENDERER, about_blank_task->GetType());
78 EXPECT_EQ(PrefixExpectedTabTitle("about:blank"), about_blank_task->title());
80 NavigateTo(kCrossSitePageUrl);
82 // Whether sites are isolated or not, we expect to have at least one tab
83 // contents task.
84 ASSERT_GE(task_manager.tasks().size(), 1U);
85 const Task* cross_site_task = task_manager.tasks().front();
86 EXPECT_EQ(Task::RENDERER, cross_site_task->GetType());
87 EXPECT_EQ(PrefixExpectedTabTitle("cross-site iframe test"),
88 cross_site_task->title());
90 if (!content::AreAllSitesIsolatedForTesting()) {
91 // Sites are not isolated. No SubframeTasks are expected, just the above
92 // task.
93 ASSERT_EQ(1U, task_manager.tasks().size());
94 } else {
95 // Sites are isolated. We expect, in addition to the above task, two more
96 // SubframeTasks, one for b.com and another for c.com.
97 ASSERT_EQ(3U, task_manager.tasks().size());
98 const Task* subframe_task_1 = task_manager.tasks()[1];
99 const Task* subframe_task_2 = task_manager.tasks()[2];
101 EXPECT_EQ(Task::RENDERER, subframe_task_1->GetType());
102 EXPECT_EQ(Task::RENDERER, subframe_task_2->GetType());
104 EXPECT_TRUE(base::StartsWith(subframe_task_1->title(),
105 GetExpectedSubframeTitlePrefix(),
106 base::CompareCase::INSENSITIVE_ASCII));
107 EXPECT_TRUE(base::StartsWith(subframe_task_2->title(),
108 GetExpectedSubframeTitlePrefix(),
109 base::CompareCase::INSENSITIVE_ASCII));
111 // All tasks must be running on different processes.
112 EXPECT_NE(subframe_task_1->process_id(), subframe_task_2->process_id());
113 EXPECT_NE(subframe_task_1->process_id(), cross_site_task->process_id());
114 EXPECT_NE(subframe_task_2->process_id(), cross_site_task->process_id());
117 // If we navigate to the simple page on a.com which doesn't have cross-site
118 // iframes, we expect not to have any SubframeTasks.
119 NavigateTo(kSimplePageUrl);
121 ASSERT_EQ(1U, task_manager.tasks().size());
122 const Task* simple_page_task = task_manager.tasks().front();
123 EXPECT_EQ(Task::RENDERER, simple_page_task->GetType());
124 EXPECT_EQ(PrefixExpectedTabTitle("Title Of Awesomeness"),
125 simple_page_task->title());
128 } // namespace task_management