| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <deque> | 5 #include <deque> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 1995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2006 bool url_b_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileB); | 2006 bool url_b_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileB); |
| 2007 bool url_c_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileC); | 2007 bool url_c_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileC); |
| 2008 EXPECT_TRUE(url_b_is_active_prerender && url_c_is_active_prerender); | 2008 EXPECT_TRUE(url_b_is_active_prerender && url_c_is_active_prerender); |
| 2009 } | 2009 } |
| 2010 | 2010 |
| 2011 // See crbug.com/131836. | 2011 // See crbug.com/131836. |
| 2012 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderTaskManager) { | 2012 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderTaskManager) { |
| 2013 // Show the task manager. This populates the model. | 2013 // Show the task manager. This populates the model. |
| 2014 chrome::OpenTaskManager(current_browser()); | 2014 chrome::OpenTaskManager(current_browser()); |
| 2015 // Wait for the model of task manager to start. | 2015 // Wait for the model of task manager to start. |
| 2016 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | 2016 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); |
| 2017 | 2017 |
| 2018 // Start with two resources. | 2018 // Start with two resources. |
| 2019 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 2019 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
| 2020 | 2020 |
| 2021 // One of the resources that has a WebContents associated with it should have | 2021 // One of the resources that has a WebContents associated with it should have |
| 2022 // the Prerender prefix. | 2022 // the Prerender prefix. |
| 2023 const string16 prefix = | 2023 const string16 prefix = |
| 2024 l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PRERENDER_PREFIX, string16()); | 2024 l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PRERENDER_PREFIX, string16()); |
| 2025 string16 prerender_title; | 2025 string16 prerender_title; |
| 2026 int num_prerender_tabs = 0; | 2026 int num_prerender_tabs = 0; |
| 2027 | 2027 |
| 2028 TaskManagerModel* model = GetModel(); | 2028 TaskManagerModel* model = GetModel(); |
| 2029 // The task manager caches values. Force the titles to be fresh. | 2029 // The task manager caches values. Force the titles to be fresh. |
| 2030 model->Refresh(); | 2030 model->Refresh(); |
| 2031 for (int i = 0; i < model->ResourceCount(); ++i) { | 2031 for (int i = 0; i < model->ResourceCount(); ++i) { |
| 2032 if (model->GetResourceWebContents(i)) { | 2032 if (model->GetResourceWebContents(i)) { |
| 2033 prerender_title = model->GetResourceTitle(i); | 2033 prerender_title = model->GetResourceTitle(i); |
| 2034 if (StartsWith(prerender_title, prefix, true)) | 2034 if (StartsWith(prerender_title, prefix, true)) |
| 2035 ++num_prerender_tabs; | 2035 ++num_prerender_tabs; |
| 2036 } | 2036 } |
| 2037 } | 2037 } |
| 2038 EXPECT_EQ(1, num_prerender_tabs); | 2038 EXPECT_EQ(1, num_prerender_tabs); |
| 2039 const string16 prerender_page_title = prerender_title.substr(prefix.length()); | 2039 const string16 prerender_page_title = prerender_title.substr(prefix.length()); |
| 2040 | 2040 |
| 2041 NavigateToDestURL(); | 2041 NavigateToDestURL(); |
| 2042 | 2042 |
| 2043 // There should be no tabs with the Prerender prefix. | 2043 // There should be no tabs with the Prerender prefix. |
| 2044 const string16 tab_prefix = | 2044 const string16 tab_prefix = |
| 2045 l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_TAB_PREFIX, string16()); | 2045 l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_TAB_PREFIX, string16()); |
| 2046 const string16 instant_tab_prefix = |
| 2047 l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_INSTANT_OVERLAY_PREFIX, |
| 2048 string16()); |
| 2046 num_prerender_tabs = 0; | 2049 num_prerender_tabs = 0; |
| 2047 int num_tabs_with_prerender_page_title = 0; | 2050 int num_tabs_with_prerender_page_title = 0; |
| 2048 model->Refresh(); | 2051 model->Refresh(); |
| 2049 for (int i = 0; i < model->ResourceCount(); ++i) { | 2052 for (int i = 0; i < model->ResourceCount(); ++i) { |
| 2050 if (model->GetResourceWebContents(i)) { | 2053 if (model->GetResourceWebContents(i)) { |
| 2051 string16 tab_title = model->GetResourceTitle(i); | 2054 string16 tab_title = model->GetResourceTitle(i); |
| 2052 if (StartsWith(tab_title, prefix, true)) { | 2055 if (StartsWith(tab_title, prefix, true)) { |
| 2053 ++num_prerender_tabs; | 2056 ++num_prerender_tabs; |
| 2054 } else { | 2057 } else if (StartsWith(tab_title, tab_prefix, true)) { |
| 2055 EXPECT_TRUE(StartsWith(tab_title, tab_prefix, true)); | |
| 2056 | |
| 2057 // The prerender tab should now be a normal tab but the title should be | 2058 // The prerender tab should now be a normal tab but the title should be |
| 2058 // the same. Depending on timing, there may be more than one of these. | 2059 // the same. Depending on timing, there may be more than one of these. |
| 2059 const string16 tab_page_title = tab_title.substr(tab_prefix.length()); | 2060 const string16 tab_page_title = tab_title.substr(tab_prefix.length()); |
| 2060 if (prerender_page_title.compare(tab_page_title) == 0) | 2061 if (prerender_page_title.compare(tab_page_title) == 0) |
| 2061 ++num_tabs_with_prerender_page_title; | 2062 ++num_tabs_with_prerender_page_title; |
| 2063 } else { |
| 2064 EXPECT_TRUE(StartsWith(tab_title, instant_tab_prefix, true)); |
| 2062 } | 2065 } |
| 2063 } | 2066 } |
| 2064 } | 2067 } |
| 2065 EXPECT_EQ(0, num_prerender_tabs); | 2068 EXPECT_EQ(0, num_prerender_tabs); |
| 2066 | 2069 |
| 2067 // We may have deleted the prerender tab, but the swapped in tab should be | 2070 // We may have deleted the prerender tab, but the swapped in tab should be |
| 2068 // active. | 2071 // active. |
| 2069 EXPECT_GE(num_tabs_with_prerender_page_title, 1); | 2072 EXPECT_GE(num_tabs_with_prerender_page_title, 1); |
| 2070 EXPECT_LE(num_tabs_with_prerender_page_title, 2); | 2073 EXPECT_LE(num_tabs_with_prerender_page_title, 2); |
| 2071 } | 2074 } |
| (...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3207 | 3210 |
| 3208 // Checks that deferred redirects in a synchronous XHR abort the | 3211 // Checks that deferred redirects in a synchronous XHR abort the |
| 3209 // prerender. | 3212 // prerender. |
| 3210 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDeferredSynchronousXHR) { | 3213 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDeferredSynchronousXHR) { |
| 3211 PrerenderTestURL("files/prerender/prerender_deferred_sync_xhr.html", | 3214 PrerenderTestURL("files/prerender/prerender_deferred_sync_xhr.html", |
| 3212 FINAL_STATUS_BAD_DEFERRED_REDIRECT, 0); | 3215 FINAL_STATUS_BAD_DEFERRED_REDIRECT, 0); |
| 3213 NavigateToDestURL(); | 3216 NavigateToDestURL(); |
| 3214 } | 3217 } |
| 3215 | 3218 |
| 3216 } // namespace prerender | 3219 } // namespace prerender |
| OLD | NEW |