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 30 matching lines...) Expand all Loading... | |
41 #include "chrome/browser/prerender/prerender_manager.h" | 41 #include "chrome/browser/prerender/prerender_manager.h" |
42 #include "chrome/browser/prerender/prerender_manager_factory.h" | 42 #include "chrome/browser/prerender/prerender_manager_factory.h" |
43 #include "chrome/browser/profiles/profile.h" | 43 #include "chrome/browser/profiles/profile.h" |
44 #include "chrome/browser/profiles/profile_io_data.h" | 44 #include "chrome/browser/profiles/profile_io_data.h" |
45 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate. h" | 45 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate. h" |
46 #include "chrome/browser/safe_browsing/database_manager.h" | 46 #include "chrome/browser/safe_browsing/database_manager.h" |
47 #include "chrome/browser/safe_browsing/local_database_manager.h" | 47 #include "chrome/browser/safe_browsing/local_database_manager.h" |
48 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 48 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
49 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 49 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
50 #include "chrome/browser/safe_browsing/test_database_manager.h" | 50 #include "chrome/browser/safe_browsing/test_database_manager.h" |
51 #include "chrome/browser/task_management/providers/task_provider_observer.h" | |
52 #include "chrome/browser/task_management/providers/web_contents/web_contents_tag s_manager.h" | |
53 #include "chrome/browser/task_management/providers/web_contents/web_contents_tas k_provider.h" | |
51 #include "chrome/browser/task_manager/task_manager.h" | 54 #include "chrome/browser/task_manager/task_manager.h" |
52 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | 55 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
53 #include "chrome/browser/ui/browser.h" | 56 #include "chrome/browser/ui/browser.h" |
54 #include "chrome/browser/ui/browser_commands.h" | 57 #include "chrome/browser/ui/browser_commands.h" |
55 #include "chrome/browser/ui/browser_finder.h" | 58 #include "chrome/browser/ui/browser_finder.h" |
56 #include "chrome/browser/ui/browser_navigator.h" | 59 #include "chrome/browser/ui/browser_navigator.h" |
57 #include "chrome/browser/ui/browser_window.h" | 60 #include "chrome/browser/ui/browser_window.h" |
58 #include "chrome/browser/ui/location_bar/location_bar.h" | 61 #include "chrome/browser/ui/location_bar/location_bar.h" |
59 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 62 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
60 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 63 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
(...skipping 4012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4073 WebContents* web_contents = | 4076 WebContents* web_contents = |
4074 browser()->tab_strip_model()->GetActiveWebContents(); | 4077 browser()->tab_strip_model()->GetActiveWebContents(); |
4075 bool display_test_result = false; | 4078 bool display_test_result = false; |
4076 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(web_contents, | 4079 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(web_contents, |
4077 "DidDisplayReallyPass()", | 4080 "DidDisplayReallyPass()", |
4078 &display_test_result)); | 4081 &display_test_result)); |
4079 ASSERT_TRUE(display_test_result); | 4082 ASSERT_TRUE(display_test_result); |
4080 } | 4083 } |
4081 #endif // !defined(DISABLE_NACL) | 4084 #endif // !defined(DISABLE_NACL) |
4082 | 4085 |
4086 #if defined(ENABLE_TASK_MANAGER) | |
4087 | |
4088 namespace { | |
4089 | |
4090 const char kPrerenderPage[] = "files/prerender/prerender_page.html"; | |
4091 | |
4092 // Defines a test class for testing that will act as a mock task manager. | |
4093 class MockTaskManager : public task_management::TaskProviderObserver { | |
4094 public: | |
4095 MockTaskManager() {} | |
4096 ~MockTaskManager() override {} | |
4097 | |
4098 // task_management::Task_providerObserver: | |
4099 void TaskAdded(task_management::Task* task) override { | |
4100 CHECK(task); | |
gavinp
2015/06/22 18:38:04
Remove this check, crashing in unit tests is bad f
afakhry
2015/06/22 21:56:17
That CHECK was actually not needed, so removed.
| |
4101 ASSERT_FALSE(provided_tasks_.count(task)); | |
gavinp
2015/06/22 18:38:03
ASSERT_FALSE won't work as many expect here; on fa
afakhry
2015/06/22 21:56:17
Modified to EXPECT_FALSE()
| |
4102 provided_tasks_.insert(task); | |
4103 } | |
4104 | |
4105 void TaskRemoved(task_management::Task* task) override { | |
4106 CHECK(task); | |
4107 ASSERT_TRUE(provided_tasks_.count(task)); | |
4108 provided_tasks_.erase(task); | |
4109 } | |
4110 | |
4111 base::string16 GetPrerenderTitlePrefix() const { | |
4112 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PRERENDER_PREFIX, | |
4113 base::string16()); | |
4114 } | |
4115 | |
4116 const std::set<task_management::WebContentsTag*>& tracked_tags() const { | |
4117 return task_management::WebContentsTagsManager::GetInstance()-> | |
4118 tracked_tags(); | |
4119 } | |
4120 | |
4121 const std::set<task_management::Task*>& provided_tasks() const { | |
4122 return provided_tasks_; | |
4123 } | |
4124 | |
4125 private: | |
4126 std::set<task_management::Task*> provided_tasks_; | |
4127 | |
4128 DISALLOW_COPY_AND_ASSIGN(MockTaskManager); | |
4129 }; | |
4130 | |
4131 } // namespace | |
4132 | |
4133 // Tests the correct recording of tags for the prerender WebContents. | |
4134 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, TaskManagementTagsBasic) { | |
4135 MockTaskManager task_manager; | |
4136 EXPECT_TRUE(task_manager.tracked_tags().empty()); | |
4137 | |
4138 // Start prerendering a page and make sure it's correctly tagged. | |
4139 PrerenderTestURL(kPrerenderPage, FINAL_STATUS_USED, 1); | |
4140 EXPECT_FALSE(task_manager.tracked_tags().empty()); | |
4141 | |
4142 // TODO(afakhry): Once we start tagging the tab contents the below tests | |
gavinp
2015/06/22 18:38:03
Nit: (optional) Remove the extra indent on the sec
afakhry
2015/06/22 21:56:17
Done.
| |
4143 // must be changed. | |
4144 EXPECT_EQ(1U, task_manager.tracked_tags().size()); | |
4145 | |
4146 // Swap in the prerendered content and make sure its tag is removed. | |
4147 NavigateToDestURL(); | |
4148 EXPECT_TRUE(task_manager.tracked_tags().empty()); | |
4149 } | |
4150 | |
4151 // Tests that the task manager will be provided by tasks that correspond to | |
4152 // prerendered WebContents. | |
4153 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, TaskManagementTasksProvided) { | |
4154 MockTaskManager task_manager; | |
4155 EXPECT_TRUE(task_manager.provided_tasks().empty()); | |
gavinp
2015/06/22 18:38:03
It seems like a bit of overkill to assert this eve
afakhry
2015/06/22 21:56:17
Yes it is actually an overkill, and hence removed.
| |
4156 EXPECT_TRUE(task_manager.tracked_tags().empty()); | |
4157 | |
4158 task_management::WebContentsTaskProvider provider; | |
4159 provider.SetObserver(&task_manager); | |
4160 | |
4161 // Still empty, no pre-existing tasks. | |
4162 EXPECT_TRUE(task_manager.provided_tasks().empty()); | |
4163 | |
4164 // Start prerendering a page. | |
4165 PrerenderTestURL(kPrerenderPage, FINAL_STATUS_USED, 1); | |
4166 EXPECT_FALSE(task_manager.tracked_tags().empty()); | |
4167 | |
4168 // TODO(afakhry): The below may not be true after we support more tags. | |
4169 EXPECT_EQ(1U, task_manager.tracked_tags().size()); | |
4170 ASSERT_FALSE(task_manager.provided_tasks().empty()); | |
4171 ASSERT_EQ(1U, task_manager.provided_tasks().size()); | |
4172 | |
4173 const task_management::Task* task = *task_manager.provided_tasks().begin(); | |
4174 EXPECT_EQ(task_management::Task::RENDERER, task->GetType()); | |
4175 const base::string16 title = task->title(); | |
4176 const base::string16 expected_prefix = task_manager.GetPrerenderTitlePrefix(); | |
4177 EXPECT_TRUE(base::StartsWith(title, | |
4178 expected_prefix, | |
4179 base::CompareCase::INSENSITIVE_ASCII)); | |
4180 | |
4181 NavigateToDestURL(); | |
4182 // TODO(afakhry): The below may not be true after we support more tags. | |
4183 EXPECT_TRUE(task_manager.provided_tasks().empty()); | |
4184 } | |
4185 | |
4186 #endif // defined(ENABLE_TASK_MANAGER) | |
4187 | |
4083 } // namespace prerender | 4188 } // namespace prerender |
OLD | NEW |