| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <queue> | 5 #include <queue> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1476 PrerenderLinkManager* prerender_link_manager = | 1476 PrerenderLinkManager* prerender_link_manager = |
| 1477 PrerenderLinkManagerFactory::GetForProfile( | 1477 PrerenderLinkManagerFactory::GetForProfile( |
| 1478 Profile::FromBrowserContext(guest_web_contents->GetBrowserContext())); | 1478 Profile::FromBrowserContext(guest_web_contents->GetBrowserContext())); |
| 1479 ASSERT_TRUE(prerender_link_manager != NULL); | 1479 ASSERT_TRUE(prerender_link_manager != NULL); |
| 1480 EXPECT_TRUE(prerender_link_manager->IsEmpty()); | 1480 EXPECT_TRUE(prerender_link_manager->IsEmpty()); |
| 1481 } | 1481 } |
| 1482 | 1482 |
| 1483 // Verify that existing <webview>'s are detected when the task manager starts | 1483 // Verify that existing <webview>'s are detected when the task manager starts |
| 1484 // up. | 1484 // up. |
| 1485 IN_PROC_BROWSER_TEST_P(WebViewTest, TaskManagerExistingWebView) { | 1485 IN_PROC_BROWSER_TEST_P(WebViewTest, TaskManagerExistingWebView) { |
| 1486 // This test is for the old implementation of the task manager. We must | |
| 1487 // explicitly disable the new one. | |
| 1488 task_manager::browsertest_util::EnableOldTaskManager(); | |
| 1489 | |
| 1490 ASSERT_TRUE(StartEmbeddedTestServer()); | 1486 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 1491 | 1487 |
| 1492 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html", | 1488 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html", |
| 1493 "web_view/task_manager"); | 1489 "web_view/task_manager"); |
| 1494 | 1490 |
| 1495 chrome::ShowTaskManager(browser()); // Show task manager AFTER guest loads. | 1491 chrome::ShowTaskManager(browser()); // Show task manager AFTER guest loads. |
| 1496 | 1492 |
| 1497 const char* guest_title = "WebViewed test content"; | 1493 const char* guest_title = "WebViewed test content"; |
| 1498 const char* app_name = "<webview> task manager test"; | 1494 const char* app_name = "<webview> task manager test"; |
| 1499 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title))); | 1495 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title))); |
| 1500 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | 1496 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); |
| 1501 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name))); | 1497 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name))); |
| 1502 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name))); | 1498 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name))); |
| 1503 | 1499 |
| 1504 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView())); | 1500 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView())); |
| 1505 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | 1501 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); |
| 1506 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp())); | 1502 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp())); |
| 1507 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground())); | 1503 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground())); |
| 1508 } | 1504 } |
| 1509 | 1505 |
| 1510 // Verify that the task manager notices the creation of new <webview>'s. | 1506 // Verify that the task manager notices the creation of new <webview>'s. |
| 1511 IN_PROC_BROWSER_TEST_P(WebViewTest, TaskManagerNewWebView) { | 1507 IN_PROC_BROWSER_TEST_P(WebViewTest, TaskManagerNewWebView) { |
| 1512 // This test is for the old implementation of the task manager. We must | |
| 1513 // explicitly disable the new one. | |
| 1514 task_manager::browsertest_util::EnableOldTaskManager(); | |
| 1515 | |
| 1516 ASSERT_TRUE(StartEmbeddedTestServer()); | 1508 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 1517 | 1509 |
| 1518 chrome::ShowTaskManager(browser()); // Show task manager BEFORE guest loads. | 1510 chrome::ShowTaskManager(browser()); // Show task manager BEFORE guest loads. |
| 1519 | 1511 |
| 1520 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html", | 1512 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html", |
| 1521 "web_view/task_manager"); | 1513 "web_view/task_manager"); |
| 1522 | 1514 |
| 1523 const char* guest_title = "WebViewed test content"; | 1515 const char* guest_title = "WebViewed test content"; |
| 1524 const char* app_name = "<webview> task manager test"; | 1516 const char* app_name = "<webview> task manager test"; |
| 1525 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title))); | 1517 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title))); |
| (...skipping 1483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3009 gfx::Point embedder_origin = | 3001 gfx::Point embedder_origin = |
| 3010 GetEmbedderWebContents()->GetContainerBounds().origin(); | 3002 GetEmbedderWebContents()->GetContainerBounds().origin(); |
| 3011 guest_rect.Offset(-embedder_origin.x(), -embedder_origin.y()); | 3003 guest_rect.Offset(-embedder_origin.x(), -embedder_origin.y()); |
| 3012 | 3004 |
| 3013 // Generate and send synthetic touch event. | 3005 // Generate and send synthetic touch event. |
| 3014 content::SimulateTouchPressAt(GetEmbedderWebContents(), | 3006 content::SimulateTouchPressAt(GetEmbedderWebContents(), |
| 3015 guest_rect.CenterPoint()); | 3007 guest_rect.CenterPoint()); |
| 3016 EXPECT_TRUE(aura_webview->HasFocus()); | 3008 EXPECT_TRUE(aura_webview->HasFocus()); |
| 3017 } | 3009 } |
| 3018 #endif | 3010 #endif |
| 3019 | |
| 3020 #if defined(ENABLE_TASK_MANAGER) | |
| 3021 | |
| 3022 namespace { | |
| 3023 | |
| 3024 base::string16 GetExpectedPrefix(content::WebContents* web_contents) { | |
| 3025 DCHECK(web_contents); | |
| 3026 guest_view::GuestViewBase* guest = | |
| 3027 guest_view::GuestViewBase::FromWebContents(web_contents); | |
| 3028 DCHECK(guest); | |
| 3029 | |
| 3030 return l10n_util::GetStringFUTF16(guest->GetTaskPrefix(), base::string16()); | |
| 3031 } | |
| 3032 | |
| 3033 const std::vector<task_management::WebContentsTag*>& GetTrackedTags() { | |
| 3034 return task_management::WebContentsTagsManager::GetInstance()-> | |
| 3035 tracked_tags(); | |
| 3036 } | |
| 3037 | |
| 3038 bool HasExpectedGuestTask( | |
| 3039 const task_management::MockWebContentsTaskManager& task_manager, | |
| 3040 content::WebContents* guest_contents) { | |
| 3041 bool found = false; | |
| 3042 for (auto* task: task_manager.tasks()) { | |
| 3043 if (task->GetType() != task_management::Task::GUEST) | |
| 3044 continue; | |
| 3045 EXPECT_FALSE(found); | |
| 3046 found = true; | |
| 3047 const base::string16 title = task->title(); | |
| 3048 const base::string16 expected_prefix = GetExpectedPrefix(guest_contents); | |
| 3049 EXPECT_TRUE(base::StartsWith(title, expected_prefix, | |
| 3050 base::CompareCase::INSENSITIVE_ASCII)); | |
| 3051 } | |
| 3052 return found; | |
| 3053 } | |
| 3054 | |
| 3055 } // namespace | |
| 3056 | |
| 3057 // Tests that the pre-existing WebViews are provided to the task manager. | |
| 3058 IN_PROC_BROWSER_TEST_P(WebViewTest, TaskManagementPreExistingWebViews) { | |
| 3059 ASSERT_TRUE(StartEmbeddedTestServer()); | |
| 3060 | |
| 3061 // Browser tests start with a single tab. | |
| 3062 EXPECT_EQ(1U, GetTrackedTags().size()); | |
| 3063 | |
| 3064 content::WebContents* guest_contents = | |
| 3065 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html", | |
| 3066 "web_view/task_manager"); | |
| 3067 | |
| 3068 task_management::MockWebContentsTaskManager task_manager; | |
| 3069 task_manager.StartObserving(); | |
| 3070 | |
| 3071 // The pre-existing tab and guest tasks are provided. | |
| 3072 // 4 tasks expected. The order is arbitrary. | |
| 3073 // Tab: about:blank, | |
| 3074 // Background Page: <webview> task manager test, | |
| 3075 // App: <webview> task manager test, | |
| 3076 // Webview: WebViewed test content. | |
| 3077 EXPECT_EQ(4U, task_manager.tasks().size()); | |
| 3078 EXPECT_TRUE(HasExpectedGuestTask(task_manager, guest_contents)); | |
| 3079 } | |
| 3080 | |
| 3081 // Tests that the post-existing WebViews are provided to the task manager. | |
| 3082 IN_PROC_BROWSER_TEST_P(WebViewTest, TaskManagementPostExistingWebViews) { | |
| 3083 ASSERT_TRUE(StartEmbeddedTestServer()); | |
| 3084 | |
| 3085 // Browser tests start with a single tab. | |
| 3086 EXPECT_EQ(1U, GetTrackedTags().size()); | |
| 3087 | |
| 3088 task_management::MockWebContentsTaskManager task_manager; | |
| 3089 task_manager.StartObserving(); | |
| 3090 | |
| 3091 // Only the "about:blank" tab shows at the moment. | |
| 3092 ASSERT_EQ(1U, task_manager.tasks().size()); | |
| 3093 const task_management::Task* about_blank_task = task_manager.tasks().back(); | |
| 3094 EXPECT_EQ(task_management::Task::RENDERER, about_blank_task->GetType()); | |
| 3095 EXPECT_EQ(base::UTF8ToUTF16("Tab: about:blank"), about_blank_task->title()); | |
| 3096 | |
| 3097 // Now load a guest web view. | |
| 3098 content::WebContents* guest_contents = | |
| 3099 LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html", | |
| 3100 "web_view/task_manager"); | |
| 3101 // 4 tasks expected. The order is arbitrary. | |
| 3102 // Tab: about:blank, | |
| 3103 // Background Page: <webview> task manager test, | |
| 3104 // App: <webview> task manager test, | |
| 3105 // Webview: WebViewed test content. | |
| 3106 EXPECT_EQ(4U, task_manager.tasks().size()); | |
| 3107 EXPECT_TRUE(HasExpectedGuestTask(task_manager, guest_contents)); | |
| 3108 } | |
| 3109 | |
| 3110 #endif // defined(ENABLE_TASK_MANAGER) | |
| OLD | NEW |