Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/browser/prerender/prerender_contents.h" | 10 #include "chrome/browser/prerender/prerender_contents.h" |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 // Early out if we're not using TabContents for Prerendering. | 703 // Early out if we're not using TabContents for Prerendering. |
| 704 if (!prerender::PrerenderContents::UseTabContents()) { | 704 if (!prerender::PrerenderContents::UseTabContents()) { |
| 705 SUCCEED(); | 705 SUCCEED(); |
| 706 return; | 706 return; |
| 707 } | 707 } |
| 708 | 708 |
| 709 // Show the task manager. This populates the model. | 709 // Show the task manager. This populates the model. |
| 710 browser()->window()->ShowTaskManager(); | 710 browser()->window()->ShowTaskManager(); |
| 711 | 711 |
| 712 // Start with two resources. | 712 // Start with two resources. |
| 713 EXPECT_EQ(2, model()->ResourceCount()); | |
| 714 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 713 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
| 715 | 714 |
| 716 // The prerender makes three. | 715 // One of the resources that has a TabContents associated with it should have |
| 717 EXPECT_EQ(3, model()->ResourceCount()); | 716 // the Prerender prefix. |
| 717 const string16 prefix = | |
| 718 l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PRERENDER_PREFIX, string16()); | |
| 719 string16 prerender_title; | |
| 720 int num_prerender_tabs = 0; | |
| 718 | 721 |
| 719 // It should have a TabContents associated with it. | 722 VLOG(1) << "After prerender:"; |
| 720 ASSERT_TRUE(model()->GetResourceTabContents(1) != NULL); | 723 for (int i = 0; i < model()->ResourceCount(); ++i) { |
| 721 | 724 VLOG(1) << " " << i << ": " << model()->GetResourceTitle(i); |
| 722 // The prefix should be "Prerender:" | 725 if (model()->GetResourceTabContents(i)) { |
| 723 string16 prefix = | 726 prerender_title = model()->GetResourceTitle(i); |
| 724 l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PRERENDER_PREFIX, | 727 if (StartsWith(prerender_title, prefix, true)) |
| 725 string16()); | 728 ++num_prerender_tabs; |
| 726 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); | 729 } |
| 730 } | |
| 731 ASSERT_EQ(1, num_prerender_tabs); | |
| 732 const string16 prerender_page_title = prerender_title.substr(prefix.length()); | |
| 727 | 733 |
| 728 NavigateToDestURL(); | 734 NavigateToDestURL(); |
| 729 | 735 |
| 730 // Prerender task should become a normal tab. | 736 // There should be no Tabs with the Prerender prefix. |
|
mmenke
2011/05/06 17:29:54
nit: Don't capitalize "tab", as it's not a class,
dominich
2011/05/06 19:19:14
Done.
| |
| 731 EXPECT_EQ(3, model()->ResourceCount()); | 737 const string16 tab_prefix = |
| 738 l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_TAB_PREFIX, string16()); | |
| 739 num_prerender_tabs = 0; | |
| 740 bool found_tab_with_prerender_page_title = false; | |
| 741 VLOG(1) << "After navigate:"; | |
| 742 for (int i = 0; i < model()->ResourceCount(); ++i) { | |
| 743 VLOG(1) << " " << i << ": " << model()->GetResourceTitle(i); | |
| 744 if (model()->GetResourceTabContents(i)) { | |
| 745 string16 tab_title = model()->GetResourceTitle(i); | |
| 746 if (StartsWith(tab_title, prefix, true)) { | |
| 747 ++num_prerender_tabs; | |
| 748 } else { | |
| 749 ASSERT_TRUE(StartsWith(tab_title, tab_prefix, true)); | |
| 732 | 750 |
| 733 // It should have a TabContents associated with it. | 751 // The prerender tab should now be a normal tab but the title should be |
| 734 ASSERT_TRUE(model()->GetResourceTabContents(2) != NULL); | 752 // the same. |
| 735 | 753 const string16 tab_page_title = tab_title.substr(tab_prefix.length()); |
| 736 // The prefix should now be "Tab:" | 754 if (!found_tab_with_prerender_page_title && |
|
mmenke
2011/05/06 17:29:54
Is this first check really needed? Doesn't seem t
dominich
2011/05/06 19:19:14
Done.
| |
| 737 prefix = l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_TAB_PREFIX, | 755 prerender_page_title.compare(tab_page_title) == 0) { |
| 738 string16()); | 756 found_tab_with_prerender_page_title = true; |
| 739 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); | 757 } |
| 758 } | |
| 759 } | |
| 760 } | |
| 761 ASSERT_EQ(0, num_prerender_tabs); | |
| 762 ASSERT_TRUE(found_tab_with_prerender_page_title); | |
| 740 } | 763 } |
| 741 | 764 |
| 742 // Checks that prerenderers will terminate when an audio tag is encountered. | 765 // Checks that prerenderers will terminate when an audio tag is encountered. |
| 743 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHTML5Audio) { | 766 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHTML5Audio) { |
| 744 PrerenderTestURL("files/prerender/prerender_html5_audio.html", | 767 PrerenderTestURL("files/prerender/prerender_html5_audio.html", |
| 745 FINAL_STATUS_HTML5_MEDIA, | 768 FINAL_STATUS_HTML5_MEDIA, |
| 746 1); | 769 1); |
| 747 } | 770 } |
| 748 | 771 |
| 749 // Checks that prerenderers will terminate when a video tag is encountered. | 772 // Checks that prerenderers will terminate when a video tag is encountered. |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 918 std::string replacement_path; | 941 std::string replacement_path; |
| 919 ASSERT_TRUE(net::TestServer::GetFilePathWithReplacements( | 942 ASSERT_TRUE(net::TestServer::GetFilePathWithReplacements( |
| 920 "files/prerender/prerender_with_image.html", | 943 "files/prerender/prerender_with_image.html", |
| 921 replacement_text, | 944 replacement_text, |
| 922 &replacement_path)); | 945 &replacement_path)); |
| 923 PrerenderTestURL(replacement_path, FINAL_STATUS_USED, 1); | 946 PrerenderTestURL(replacement_path, FINAL_STATUS_USED, 1); |
| 924 NavigateToDestURL(); | 947 NavigateToDestURL(); |
| 925 } | 948 } |
| 926 | 949 |
| 927 } // namespace prerender | 950 } // namespace prerender |
| OLD | NEW |